RDK Documentation (Open Sourced RDK Components)
Connection.hpp
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 
21 
22 /**
23 * @defgroup hdmicec
24 * @{
25 * @defgroup ccec
26 * @{
27 **/
28 
29 
30 #ifndef HDMI_CCEC_CONNECTION_HPP_
31 #define HDMI_CCEC_CONNECTION_HPP_
32 
33 #include <stdlib.h>
34 #include <list>
35 
36 #include "osal/Mutex.hpp"
37 
38 #include "ccec/CCEC.hpp"
39 #include "ccec/FrameListener.hpp"
40 #include "ccec/Operands.hpp"
41 #include "ccec/Driver.hpp"
42 #include "ccec/LibCCEC.hpp"
43 #include "ccec/Exception.hpp"
44 
45 using CCEC_OSAL::Mutex;
46 
47 CCEC_BEGIN_NAMESPACE
48 class Bus;
49 class CECFrame;
50 
51 /**
52  * @brief The connection class provides APIs that allows the application to access CEC Bus.
53  * A connection is a tap into the CEC bus. The application can use a connection to send raw bytes
54  * (in form of CECFrame) onto CEC bus or receive raw bytes from it.
55  * @ingroup HDMI_CEC_CONNECTION
56  */
58 {
59 public:
60  Connection(const LogicalAddress &source = LogicalAddress::UNREGISTERED, bool opened = true, const std::string &name="");
61  virtual ~Connection(void);
62 
63  void open(void);
64  void close(void);
65 
66  void addFrameListener(FrameListener *listener);
67  void removeFrameListener(FrameListener *listener);
68 
69  void send(const CECFrame &frame, int timeout, const Throw_e &doThrow);
70  void sendTo(const LogicalAddress &to, const CECFrame &frame, int timeout, const Throw_e &doThrow);
71  void send(const CECFrame &frame, int timeout = 0);
72  void sendTo(const LogicalAddress &to, const CECFrame &frame, int timeout = 0);
73  void sendToAsync(const LogicalAddress &to, const CECFrame &frame);
74  void poll(const LogicalAddress &from, const Throw_e &doThrow);
75  void ping(const LogicalAddress &from, const LogicalAddress &to, const Throw_e &doThrow);
76 
77  void sendAsync(const CECFrame &frame);
78 
79  const LogicalAddress & getSource(void) {
80  return source;
81  }
82 
83  const void setSource(LogicalAddress &from) {
84  source = from;
85  }
86 
87 private:
88  class DefaultFilter : public FrameFilter {
89  public:
90  DefaultFilter(LogicalAddress &source) : source(source) {}
91  bool isFiltered(const CECFrame &frame);
92  private:
93  LogicalAddress source;
94 
95  };
96 
98  public:
99  DefaultFrameListener(Connection &connection, FrameFilter &filter) : connection(connection), filter(filter) {
100  }
101  void notify(const CECFrame &frame) const;
102  private:
103  Connection &connection;
104  FrameFilter &filter;
105  };
106 
107  void matchSource(const CECFrame &frame);
108  std::string name;
109  LogicalAddress source;
110  Bus &bus;
111  DefaultFilter busFrameFilter;
112  DefaultFrameListener busFrameListener;
113  std::list<FrameListener *> frameListeners;
114  Mutex mutex;
115 };
116 
117 CCEC_END_NAMESPACE
118 
119 #endif
120 
121 
122 /** @} */
123 /** @} */
CCEC_OSAL::Mutex
Definition: Mutex.hpp:53
Connection::send
void send(const CECFrame &frame, int timeout, const Throw_e &doThrow)
This function is used to send CEC frame to CEC Bus.
Definition: Connection.cpp:208
_Throw_e
Definition: Exception.hpp:37
FrameListener
Definition: FrameListener.hpp:39
Connection
The connection class provides APIs that allows the application to access CEC Bus. A connection is a t...
Definition: Connection.hpp:57
Connection::close
void close(void)
Definition: Connection.cpp:73
LogicalAddress
Definition: Operands.hpp:409
Connection::ping
void ping(const LogicalAddress &from, const LogicalAddress &to, const Throw_e &doThrow)
This function is used to send ping message to the Bus.
Definition: Connection.cpp:257
Connection::open
void open(void)
Open a connection to receive CEC packets from the bus.
Definition: Connection.cpp:62
Connection::poll
void poll(const LogicalAddress &from, const Throw_e &doThrow)
This function is used to send poll message to the Bus.
Definition: Connection.cpp:232
Connection::DefaultFrameListener
Definition: Connection.hpp:97
Connection::sendAsync
void sendAsync(const CECFrame &frame)
This function is used to send the CEC frame to physical CEC Bus using asynchronous method.
Definition: Connection.cpp:283
Connection::addFrameListener
void addFrameListener(FrameListener *listener)
This function is used to listen for CECFrame, which is a byte stream that contains raw bytes received...
Definition: Connection.cpp:88
Connection::removeFrameListener
void removeFrameListener(FrameListener *listener)
This function is used to remove the listener information from the queue.
Definition: Connection.cpp:104
Connection::sendToAsync
void sendToAsync(const LogicalAddress &to, const CECFrame &frame)
sends HDMI-CEC frame to CEC Bus using asynchronized method.
Definition: Connection.cpp:167
Connection::sendTo
void sendTo(const LogicalAddress &to, const CECFrame &frame, int timeout, const Throw_e &doThrow)
This function is used to send CEC frame to CEC Bus.
Definition: Connection.cpp:141
Connection::DefaultFilter::isFiltered
bool isFiltered(const CECFrame &frame)
Check the filtered is set for this connection.
Definition: Connection.cpp:300
FrameFilter
Definition: FrameListener.hpp:46
Connection::DefaultFilter
Definition: Connection.hpp:88
Connection::matchSource
void matchSource(const CECFrame &frame)
Match the source address and update the logical address for the Connection.
Definition: Connection.cpp:351
Bus
Definition: Bus.hpp:53
Connection::DefaultFrameListener::notify
void notify(const CECFrame &frame) const
Notify to the application if CECFrame is received. The CEC frame contains the raw bytes.
Definition: Connection.cpp:328
Mutex.hpp
This file defines interface of Mutex class.
CECFrame
Definition: CECFrame.hpp:40