RDK Documentation (Open Sourced RDK Components)
Bus.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_BUS_HPP_
31 #define _HDMI_CCEC_BUS_HPP_
32 
33 #include <list>
34 
35 #include "osal/Mutex.hpp"
36 #include "osal/Runnable.hpp"
37 #include "osal/Stoppable.hpp"
38 #include "osal/Thread.hpp"
39 #include "osal/EventQueue.hpp"
40 
41 #include "ccec/CCEC.hpp"
42 
46 using CCEC_OSAL::Mutex;
47 
48 CCEC_BEGIN_NAMESPACE
49 
50 class CECFrame;
51 class FrameListener;
52 
53 class Bus {
54 public:
55  static Bus & getInstance(void);
56  void addFrameListener(FrameListener *listener);
57  void removeFrameListener(FrameListener *listener);
58  void send(const CECFrame &frame, int timeout = 0);
59  void sendAsync(const CECFrame &frame);
60  void poll(const LogicalAddress &from, const LogicalAddress &to);
61  void ping(const LogicalAddress &from, const LogicalAddress &to);
62 
63  void start(void);
64  void stop(void);
65 
66 private:
67  class Reader : public Runnable, public Stoppable {
68  public:
69  Reader(Bus &bus) : bus(bus) {}
70  void run(void);
71  void stop(bool block = true);
72  private:
73  Bus &bus;
74  } reader;
75 
76  class Writer : public Runnable, public Stoppable {
77  public:
78  Writer(Bus &bus) : bus(bus) {}
79  void run(void);
80  void stop(bool block = true);
81  private:
82  Bus &bus;
83  } writer;
84 
85  Bus(void);
86  Bus(const Bus &); /* Not allowed */
87  Bus & operator = (const Bus &); /* Not allowed */
88  ~Bus(void);
89 
90 private:
91  std::list<FrameListener *> listeners;
92  Mutex rMutex;
93  Mutex wMutex;
95  volatile bool started;
96 };
97 
98 CCEC_END_NAMESPACE
99 
100 
101 #endif
102 
103 
104 /** @} */
105 /** @} */
Bus::stop
void stop(void)
This function stops the reader & writer threads and removes the instance for Bus.
Definition: Bus.cpp:106
CCEC_OSAL::Mutex
Definition: Mutex.hpp:53
CCEC_OSAL::Runnable
Definition: Runnable.hpp:37
FrameListener
Definition: FrameListener.hpp:39
EventQueue.hpp
This file defines interface of EventQueue class.
Bus::removeFrameListener
void removeFrameListener(FrameListener *listener)
This function is used to remove the listener.
Definition: Bus.cpp:222
Bus::Writer
Definition: Bus.hpp:76
Bus::getInstance
static Bus & getInstance(void)
This function is used to create the instance of Bus class.
Definition: Bus.cpp:58
Thread.hpp
This file defines interface of Thread class.
Bus::Reader::stop
void stop(bool block=true)
This function is used to stop the reader to read frames from the bus.
Definition: Bus.cpp:180
LogicalAddress
Definition: Operands.hpp:409
Bus::poll
void poll(const LogicalAddress &from, const LogicalAddress &to)
This function is used to poll the logical address and returns the ACK or NACK received from other dev...
Definition: Bus.cpp:396
Bus::Writer::stop
void stop(bool block=true)
This function is used to stop the writer for polling the bus and writing to the driver.
Definition: Bus.cpp:294
Bus::sendAsync
void sendAsync(const CECFrame &frame)
This function is used to keep asynchronously sending the frame by keeping copy of cec frame in the qu...
Definition: Bus.cpp:373
Bus::Writer::run
void run(void)
This function is used to poll the bus for frame availability and it writes the CEC frame to the drive...
Definition: Bus.cpp:237
Bus::Bus
Bus(void)
This function is a constructor for the class Bus. It is used to starts the read and write thread whic...
Definition: Bus.cpp:70
CCEC_OSAL::EventQueue
Definition: EventQueue.hpp:62
CCEC_OSAL::Stoppable
Definition: Stoppable.hpp:37
Bus::Reader::run
void run(void)
This function is used to read CECFrame from the driver. This gets notified to the frameListener which...
Definition: Bus.cpp:142
Bus::start
void start(void)
This function starts the threads and gets the instance for Bus.
Definition: Bus.cpp:83
Bus::Reader
Definition: Bus.hpp:67
Bus::~Bus
~Bus(void)
This is a destructor for class BUS. This function initiates the closing of threads and the instance f...
Definition: Bus.cpp:125
Bus
Definition: Bus.hpp:53
Bus::addFrameListener
void addFrameListener(FrameListener *listener)
This function is used to add new listener for reading frames.
Definition: Bus.cpp:207
Mutex.hpp
This file defines interface of Mutex class.
Bus::send
void send(const CECFrame &frame, int timeout=0)
This function is used to write the frame to the driver. If it fails, as it is a synchronous function,...
Definition: Bus.cpp:325
CECFrame
Definition: CECFrame.hpp:40
Bus::ping
void ping(const LogicalAddress &from, const LogicalAddress &to)
This function is used to ping devices, to know whether it present and returns the ACK or NACK receive...
Definition: Bus.cpp:423