RDK Documentation (Open Sourced RDK Components)
Host.cpp
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 devmgr
26 * @{
27 **/
28 
29 
30 #include <dlfcn.h>
31 #include <stdio.h>
32 
33 #include "ccec/Host.hpp"
34 
35 static int32_t pluginGen = 0;
36 
37 static void *plugin = 0;
38 
39 #define DL_ERROR() printf("dlopen() error : [%s]\r\n", dlerror())
40 
41 #ifndef CEC_HOST_PLUGIN
42 #warning "Using Default CEC_HOST_PLUGIN=librdkcechost.so"
43 #define CEC_HOST_PLUGIN "libRCECHost.so.0"
44 #endif
45 
46 CECHost_Err_t CECHost_LoadPlugin(void)
47 {
48  CECHost_Err_t ret = CECHost_ERR_NONE;
49  if (plugin == NULL) {
50  plugin = dlopen(CEC_HOST_PLUGIN, RTLD_LAZY);
51  if (plugin == NULL) {
52  printf("dlopen() error : [%s]\r\n", dlerror());
53  ret = CECHost_ERR_SYMBOL;
54  }
55  else {
56  pluginGen++;
57  }
58  }
59  else {
60  ret = CECHost_ERR_STATE;
61  }
62 
63  return ret;
64 }
65 
66 CECHost_Err_t CECHost_UnloadPlugin(void)
67 {
68  CECHost_Err_t ret = CECHost_ERR_NONE;
69 
70  if(plugin){
71  dlclose(plugin);
72  plugin = NULL;
73  }
74  else {
75  ret = CECHost_ERR_STATE;
76  }
77 
78  return ret;
79 }
80 
81 static CECHost_Err_t _load(const char *funcName, void **func, int32_t *currGen)
82 {
83  CECHost_Err_t ret = CECHost_ERR_NONE;
84 
85  if (plugin == NULL) return CECHost_ERR_STATE;
86 
87  if (*func == NULL || *currGen != pluginGen) {
88  *func = dlsym(plugin, funcName);
89  if (*func == NULL) {
90  DL_ERROR();
91  ret = CECHost_ERR_SYMBOL;
92  }
93  else {
94  *currGen = pluginGen;
95  }
96  }
97 
98  return ret;
99 }
100 
101 CECHost_Err_t CECHost_Init(const char* name)
102 {
103  typedef CECHost_Err_t(*CECHost_Init_t)(const char *name);
104 
105  static int32_t currGen = pluginGen;
106  static void *f = NULL;
107 
108  CECHost_Err_t ret = _load(__FUNCTION__, &f, &currGen);
109  if (ret == CECHost_ERR_NONE) {
110  ret = ((CECHost_Init_t)f)(name);
111  }
112 
113  return ret;
114 }
115 
116 CECHost_Err_t CECHost_Term(void)
117 {
118  typedef CECHost_Err_t(*CECHost_Term_t)(void);
119 
120  static int32_t currGen = pluginGen;
121  static void *f = NULL;
122 
123  CECHost_Err_t ret = _load(__FUNCTION__, &f, &currGen);
124  if (ret == CECHost_ERR_NONE) {
125  ret = ((CECHost_Term_t)f)();
126  }
127 
128  return ret;
129 }
131 {
132  typedef CECHost_Err_t(*CECHost_SetCallback_t)(CECHost_Callback_t cb);
133 
134  static int32_t currGen = pluginGen;
135  static void *f = NULL;
136 
137  CECHost_Err_t ret = _load(__FUNCTION__, &f, &currGen);
138  if (ret == CECHost_ERR_NONE) {
139  ret = ((CECHost_SetCallback_t)f)(cb);
140  }
141 
142  return ret;
143 }
144 CECHost_Err_t CECHost_GetHdmiOuputPhysicalAddress(uint8_t *byte0, uint8_t *byte1, uint8_t *byte2, uint8_t *byte3)
145 {
146  typedef CECHost_Err_t(*CECHost_GetHdmiOuputPhysicalAddress_t)(uint8_t *byte0, uint8_t *byte1, uint8_t *byte2, uint8_t *byte3);
147 
148  static int32_t currGen = pluginGen;
149  static void *f = NULL;
150 
151  CECHost_Err_t ret = _load(__FUNCTION__, &f, &currGen);
152  if (ret == CECHost_ERR_NONE) {
153  ret = ((CECHost_GetHdmiOuputPhysicalAddress_t)f)(byte0, byte1, byte2, byte3);
154  }
155 
156  return ret;
157 }
158 
159 CECHost_Err_t CECHost_IsHdmiOutputConnected(int32_t *connect)
160 {
161  typedef CECHost_Err_t(*CECHost_IsHdmiOutputConnected_t)(int32_t *connect);
162 
163  static int32_t currGen = pluginGen;
164  static void *f = NULL;
165 
166  CECHost_Err_t ret = _load(__FUNCTION__, &f, &currGen);
167  if (ret == CECHost_ERR_NONE) {
168  ret = ((CECHost_IsHdmiOutputConnected_t)f)(connect);
169  }
170 
171  return ret;
172 }
173 
174 CECHost_Err_t CECHost_GetPowerState(int32_t *state)
175 {
176  typedef CECHost_Err_t(*CECHost_GetPowerState_t)(int32_t *state);
177 
178  static int32_t currGen = pluginGen;
179  static void *f = NULL;
180 
181  CECHost_Err_t ret = _load(__FUNCTION__, &f, &currGen);
182  if (ret == CECHost_ERR_NONE) {
183  ret = ((CECHost_GetPowerState_t)f)(state);
184  }
185 
186  return ret;
187 }
188 CECHost_Err_t CECHost_SetDeviceStatus(int logicalAddress, CECHost_DeviceStatus_t *deviceStatus)
189 {
190  typedef CECHost_Err_t(*CECHost_SetDeviceStatus_t)(int logicalAddress, CECHost_DeviceStatus_t *deviceStatus);
191  static int32_t currGen = pluginGen;
192  static void *f = NULL;
193  CECHost_Err_t ret = _load(__FUNCTION__, &f ,&currGen);
194  if (ret == CECHost_ERR_NONE) {
195  ret = ((CECHost_SetDeviceStatus_t)f)(logicalAddress, deviceStatus);
196  }
197  return ret;
198 
199 }
200 
201 CECHost_Err_t CECHost_SetPowerState(int32_t state)
202 {
203  typedef CECHost_Err_t(*CECHost_SetPowerState_t)(int32_t state);
204 
205  static int32_t currGen = pluginGen;
206  static void *f = NULL;
207 
208  CECHost_Err_t ret = _load(__FUNCTION__, &f, &currGen);
209  if (ret == CECHost_ERR_NONE) {
210  ret = ((CECHost_SetPowerState_t)f)(state);
211  }
212 
213  return ret;
214 }
215 
216 CECHost_Err_t CECHost_GetOSDName(uint8_t *buf, size_t *len)
217 {
218  typedef CECHost_Err_t(*CECHost_GetOSDName_t)(uint8_t *buf, size_t *len);
219 
220  static int32_t currGen = pluginGen;
221  static void *f = NULL;
222 
223  CECHost_Err_t ret = _load(__FUNCTION__, &f, &currGen);
224  if (ret == CECHost_ERR_NONE) {
225  ret = ((CECHost_GetOSDName_t)f)(buf, len);
226  }
227 
228  return ret;
229 }
230 
231 CECHost_Err_t CECHost_IsActive(int32_t *active)
232 {
233  typedef CECHost_Err_t(*CECHost_IsActive_t)(int32_t *active);
234 
235  static int32_t currGen = pluginGen;
236  static void *f = NULL;
237 
238  CECHost_Err_t ret = _load(__FUNCTION__, &f, &currGen);
239  if (ret == CECHost_ERR_NONE) {
240  ret = ((CECHost_IsActive_t)f)(active);
241  }
242 
243  return ret;
244 }
245 
246 
247 
248 /** @} */
249 /** @} */
CECHost_GetPowerState
CECHost_Err_t CECHost_GetPowerState(int32_t *state)
This function is used to get the state of power whether it is ON or in STANDBY state.
Definition: Host.cpp:174
CECHost_IsActive
CECHost_Err_t CECHost_IsActive(int32_t *active)
This function is used to check whether host device is active or not.
Definition: Host.cpp:231
CECHost_IsHdmiOutputConnected
CECHost_Err_t CECHost_IsHdmiOutputConnected(int32_t *connect)
This function is used to check whether the HDMI output is connected or not.
Definition: Host.cpp:159
CECHost_SetDeviceStatus
CECHost_Err_t CECHost_SetDeviceStatus(int logicalAddress, CECHost_DeviceStatus_t *deviceStatus)
This function is used to set and update the device status like power status, logical address,...
Definition: Host.cpp:188
CECHost_GetHdmiOuputPhysicalAddress
CECHost_Err_t CECHost_GetHdmiOuputPhysicalAddress(uint8_t *byte0, uint8_t *byte1, uint8_t *byte2, uint8_t *byte3)
This function is used to get the physical address of the HDMI output port byte by byte.
Definition: Host.cpp:144
CECHost_Term
CECHost_Err_t CECHost_Term(void)
This function is used to de-initialize CEC host device, disconnects and terminates the CEC connection...
Definition: Host.cpp:116
CECHost_SetCallback
CECHost_Err_t CECHost_SetCallback(CECHost_Callback_t cb)
This function is used to set the callback function. It is called by Device Manager application to set...
Definition: Host.cpp:130
CECHost_GetOSDName
CECHost_Err_t CECHost_GetOSDName(uint8_t *name, size_t *len)
This function is used to get OSD name of Host module. Here 'buf' need not to be null terminated....
Definition: Host.cpp:216
CECHost_Init
CECHost_Err_t CECHost_Init(const char *name)
This function is used to initialize CEC host device by registering event handlers and calls like stat...
Definition: Host.cpp:101
CECHost_SetPowerState
CECHost_Err_t CECHost_SetPowerState(int32_t state)
This function is used to set the device power state to be ON or STANDBY.
Definition: Host.cpp:201
_CECHost_Callback_t
Definition: Host.hpp:102
_CECHost_DeviceStatus_t
Definition: Host.hpp:69