RDK Documentation (Open Sourced RDK Components)
dsCompositeIn.c
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  * If not stated otherwise in this file or this component's Licenses.txt file the
21  * following copyright and licenses apply:
22  *
23  * Copyright ARRIS Enterprises, Inc. 2015.
24  *
25  * Licensed under the Apache License, Version 2.0 (the "License");
26  * you may not use this file except in compliance with the License.
27  * You may obtain a copy of the License at
28  *
29  * http://www.apache.org/licenses/LICENSE-2.0
30  *
31  * Unless required by applicable law or agreed to in writing, software
32  * distributed under the License is distributed on an "AS IS" BASIS,
33  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
34  * See the License for the specific language governing permissions and
35  * limitations under
36 */
37 
38 
39 /**
40 * @defgroup devicesettings
41 * @{
42 * @defgroup rpc
43 * @{
44 **/
45 
46 
47 
48 
49 /**
50 * @defgroup devicesettings
51 * @{
52 * @defgroup rpc
53 * @{
54 **/
55 
56 
57 #include <stdio.h>
58 #include <string.h>
59 #include <unistd.h>
60 #include <fcntl.h>
61 #include <sys/types.h>
62 #include <sys/stat.h>
63 #include <pthread.h>
64 #include <dlfcn.h>
65 #include "dsCompositeIn.h"
66 #include "dsRpc.h"
67 #include "dsTypes.h"
68 #include "dsserverlogger.h"
69 #include "dsMgr.h"
70 
71 #include "iarmUtil.h"
72 #include "libIARM.h"
73 #include "libIBus.h"
74 
75 
76 #define direct_list_top(list) ((list))
77 #define IARM_BUS_Lock(lock) pthread_mutex_lock(&fpLock)
78 #define IARM_BUS_Unlock(lock) pthread_mutex_unlock(&fpLock)
79 
80 static int m_isInitialized = 0;
81 static int m_isPlatInitialized=0;
82 static pthread_mutex_t fpLock = PTHREAD_MUTEX_INITIALIZER;
83 
84 IARM_Result_t dsCompositeInMgr_init();
85 IARM_Result_t dsCompositeInMgr_term();
86 IARM_Result_t _dsCompositeInInit(void *arg);
87 IARM_Result_t _dsCompositeInTerm(void *arg);
88 IARM_Result_t _dsCompositeInGetNumberOfInputs(void *arg);
89 IARM_Result_t _dsCompositeInGetStatus(void *arg);
90 IARM_Result_t _dsCompositeInSelectPort(void *arg);
91 IARM_Result_t _dsCompositeInScaleVideo(void *arg);
92 
93 void _dsCompositeInConnectCB(dsCompositeInPort_t port, bool isPortConnected);
94 void _dsCompositeInSignalChangeCB(dsCompositeInPort_t port, dsCompInSignalStatus_t sigStatus);
95 void _dsCompositeInStatusChangeCB(dsCompositeInStatus_t inputStatus);
96 
97 
98 #include <iostream>
99 #include "hostPersistence.hpp"
100 #include <sstream>
101 
102 
103 using namespace std;
104 
105 
106 IARM_Result_t dsCompositeInMgr_init()
107 {
108 
109  _dsCompositeInInit(NULL);
110  IARM_Bus_RegisterCall(IARM_BUS_DSMGR_API_dsCompositeInInit, _dsCompositeInInit);
111 
112  return IARM_RESULT_SUCCESS;
113 }
114 
115 IARM_Result_t dsCompositeInMgr_term()
116 {
117 
118  _dsCompositeInTerm(NULL);
119  return IARM_RESULT_SUCCESS;
120 }
121 
122 IARM_Result_t _dsCompositeInInit(void *arg)
123 {
124  printf("%s:%d ---> m_isInitialized=%d, m_isPlatInitialized=%d \n",
125  __PRETTY_FUNCTION__,__LINE__, m_isInitialized, m_isPlatInitialized);
126 
127  IARM_BUS_Lock(lock);
128 
129 
130 #ifdef HAS_COMPOSITE_IN_SUPPORT
131  if (!m_isPlatInitialized)
132  {
133  typedef dsError_t (*dsCompositeInInit_t)(void);
134  static dsCompositeInInit_t func = 0;
135  if (func == 0) {
136  void *dllib = dlopen(RDK_DSHAL_NAME, RTLD_LAZY);
137  if (dllib) {
138  func = (dsCompositeInInit_t) dlsym(dllib, "dsCompositeInInit");
139  if(func == 0) {
140  printf("dsCompositeInInit(void) is not defined\r\n");
141  }
142  dlclose(dllib);
143  }
144  else {
145  printf("Opening RDK_DSHAL_NAME [%s] failed\r\n", RDK_DSHAL_NAME);
146  }
147  }
148 
149  if(func) {
150  printf("%s:%d - invoking dsCompositeInInit()\n", __PRETTY_FUNCTION__,__LINE__);
151  func();
152  }
153  }
154  m_isPlatInitialized++;
155 #endif
156 
157  if (!m_isInitialized)
158  {
159 #ifdef HAS_COMPOSITE_IN_SUPPORT
160  typedef dsError_t (*dsCompositeInRegisterConnectCB_t)(dsCompositeInConnectCB_t CBFunc);
161  static dsCompositeInRegisterConnectCB_t cbfunc = 0;
162  if (cbfunc == 0) {
163  void *dllib = dlopen(RDK_DSHAL_NAME, RTLD_LAZY);
164  if (dllib) {
165  cbfunc = (dsCompositeInRegisterConnectCB_t) dlsym(dllib, "dsCompositeInRegisterConnectCB");
166  if(cbfunc == 0) {
167  printf("dsCompositeInRegisterConnectCB(dsCompositeInConnectCB_t) is not defined\r\n");
168  }
169  dlclose(dllib);
170  }
171  else {
172  printf("Opening RDK_DSHAL_NAME [%s] failed\r\n", RDK_DSHAL_NAME);
173  }
174  }
175 
176  if(cbfunc) {
177  printf("%s:%d - invoking dsCompositeInRegisterConnectCB()\n", __PRETTY_FUNCTION__,__LINE__);
178  cbfunc(_dsCompositeInConnectCB);
179  }
180 
181  typedef dsError_t (*dsCompositeInRegisterSignalCB_t)(dsCompositeInSignalChangeCB_t CBFunc);
182  static dsCompositeInRegisterSignalCB_t signalChangeCBFunc = 0;
183  if (signalChangeCBFunc == 0) {
184  void *dllib = dlopen(RDK_DSHAL_NAME, RTLD_LAZY);
185  if (dllib) {
186  signalChangeCBFunc = (dsCompositeInRegisterSignalCB_t) dlsym(dllib, "dsCompositeInRegisterSignalChangeCB");
187  if(signalChangeCBFunc == 0) {
188  printf("dsCompositeInRegisterSignalChangeCB(dsCompositeInSignalChangeCB_t) is not defined\r\n");
189  }
190  dlclose(dllib);
191  }
192  else {
193  printf("Opening RDK_DSHAL_NAME [%s] failed\r\n", RDK_DSHAL_NAME);
194  }
195  }
196 
197  if(signalChangeCBFunc) {
198  printf("%s - invoking dsCompositeInRegisterSignalChangeCB()\n", __PRETTY_FUNCTION__);
199  signalChangeCBFunc(_dsCompositeInSignalChangeCB);
200  }
201 
202  typedef dsError_t (*dsCompositeInRegisterStatusChangeCB_t)(dsCompositeInStatusChangeCB_t CBFunc);
203  static dsCompositeInRegisterStatusChangeCB_t statusChangeCBFunc = 0;
204  if (statusChangeCBFunc == 0) {
205  void *dllib = dlopen(RDK_DSHAL_NAME, RTLD_LAZY);
206  if (dllib) {
207  statusChangeCBFunc = (dsCompositeInRegisterStatusChangeCB_t) dlsym(dllib, "dsCompositeInRegisterStatusChangeCB");
208  if(statusChangeCBFunc == 0) {
209  printf("dsCompositeInRegisterStatusChangeCB(dsCompositeInStatusChangeCB_t) is not defined\r\n");
210  }
211  dlclose(dllib);
212  }
213  else {
214  printf("Opening RDK_DSHAL_NAME [%s] failed\r\n", RDK_DSHAL_NAME);
215  }
216  }
217 
218  if(statusChangeCBFunc) {
219  printf("%s - invoking dsCompositeInRegisterStatusChangeCB()\n", __PRETTY_FUNCTION__);
220  statusChangeCBFunc(_dsCompositeInStatusChangeCB);
221  }
222 
223 #endif
224  IARM_Bus_RegisterCall(IARM_BUS_DSMGR_API_dsCompositeInTerm, _dsCompositeInTerm);
225  IARM_Bus_RegisterCall(IARM_BUS_DSMGR_API_dsCompositeInGetNumberOfInputs, _dsCompositeInGetNumberOfInputs);
226  IARM_Bus_RegisterCall(IARM_BUS_DSMGR_API_dsCompositeInGetStatus, _dsCompositeInGetStatus);
227  IARM_Bus_RegisterCall(IARM_BUS_DSMGR_API_dsCompositeInSelectPort, _dsCompositeInSelectPort);
228  IARM_Bus_RegisterCall(IARM_BUS_DSMGR_API_dsCompositeInScaleVideo, _dsCompositeInScaleVideo);
229 
230  m_isInitialized = 1;
231  }
232 
233  IARM_BUS_Unlock(lock);
234 
235  return IARM_RESULT_SUCCESS;
236 }
237 
238 
239 IARM_Result_t _dsCompositeInTerm(void *arg)
240 {
241  _DEBUG_ENTER();
242  printf("%s:%d ---> m_isPlatInitialized=%d\n", __PRETTY_FUNCTION__,__LINE__, m_isPlatInitialized);
243 
244  IARM_BUS_Lock(lock);
245 #ifdef HAS_COMPOSITE_IN_SUPPORT
246  if (m_isPlatInitialized)
247  {
248  m_isPlatInitialized--;
249  if (!m_isPlatInitialized)
250  {
251  typedef dsError_t (*dsCompositeInTerm_t)(void);
252  static dsCompositeInTerm_t func = 0;
253  if (func == 0) {
254  void *dllib = dlopen(RDK_DSHAL_NAME, RTLD_LAZY);
255  if (dllib) {
256  func = (dsCompositeInTerm_t) dlsym(dllib, "dsCompositeInTerm");
257  if(func == 0) {
258  printf("dsCompositeInTerm(void) is not defined\r\n");
259  }
260  dlclose(dllib);
261  }
262  else {
263  printf("Opening RDK_DSHAL_NAME [%s] failed\r\n", RDK_DSHAL_NAME);
264  }
265  }
266  if(func) {
267  printf("%s:%d - invoking dsCompositeInTerm()\n", __PRETTY_FUNCTION__,__LINE__);
268  func();
269  }
270  }
271  }
272 #endif
273  IARM_BUS_Unlock(lock);
274 
275  return IARM_RESULT_SUCCESS;
276 }
277 
278 
279 IARM_Result_t _dsCompositeInGetNumberOfInputs(void *arg)
280 {
281  _DEBUG_ENTER();
282 
284 
285  IARM_BUS_Lock(lock);
286 
287 #ifdef HAS_COMPOSITE_IN_SUPPORT
288  typedef dsError_t (*dsCompositeInGetNumberOfInputs_t)(uint8_t *);
289  static dsCompositeInGetNumberOfInputs_t func = NULL;
290  if (func == 0) {
291  void *dllib = dlopen(RDK_DSHAL_NAME, RTLD_LAZY);
292  if (dllib) {
293  func = (dsCompositeInGetNumberOfInputs_t) dlsym(dllib, "dsCompositeInGetNumberOfInputs");
294  if(func == 0) {
295  printf("dsCompositeInGetNumberOfInputs(uint8_t *) is not defined\r\n");
296  }
297  dlclose(dllib);
298  }
299  else {
300  printf("Opening RDK_DSHAL_NAME [%s] failed\r\n", RDK_DSHAL_NAME);
301  }
302  }
303  if(func) {
304  printf("%s:%d - invoking dsCompositeInGetNumberOfInputs()\n", __PRETTY_FUNCTION__,__LINE__);
305  param->result = func(&param->numCompositeInputs);
306  }
307 #else
308  param->result = dsERR_GENERAL;
309  #endif
310  IARM_BUS_Unlock(lock);
311  return IARM_RESULT_SUCCESS;
312 }
313 
314 IARM_Result_t _dsCompositeInGetStatus(void *arg)
315 {
316  _DEBUG_ENTER();
317 
319 
320  IARM_BUS_Lock(lock);
321 
322 #ifdef HAS_COMPOSITE_IN_SUPPORT
323  typedef dsError_t (*dsCompositeInGetStatus_t)(dsCompositeInStatus_t *);
324  static dsCompositeInGetStatus_t func = NULL;
325  if (func == 0) {
326  void *dllib = dlopen(RDK_DSHAL_NAME, RTLD_LAZY);
327  if (dllib) {
328  func = (dsCompositeInGetStatus_t) dlsym(dllib, "dsCompositeInGetStatus");
329  if(func ==0) {
330  printf("dsCompositeInGetStatus(dsCompositeInStatus_t *) is not defined\r\n");
331  }
332  dlclose(dllib);
333  }
334  else {
335  printf("Opening RDK_DSHAL_NAME [%s] failed\r\n", RDK_DSHAL_NAME);
336  }
337  }
338  if(func) {
339  printf("%s:%d - invoking dsCompositeInGetStatus()\n", __PRETTY_FUNCTION__,__LINE__);
340  param->result = func(&param->status);
341  }
342 #else
343  param->result = dsERR_GENERAL;
344 #endif
345 
346  IARM_BUS_Unlock(lock);
347 
348  return IARM_RESULT_SUCCESS;
349 }
350 
351 IARM_Result_t _dsCompositeInSelectPort(void *arg)
352 {
353  _DEBUG_ENTER();
354 
356 
357  IARM_BUS_Lock(lock);
358 
359 #ifdef HAS_COMPOSITE_IN_SUPPORT
360  typedef dsError_t (*dsCompositeInSelectPort_t)(dsCompositeInPort_t);
361  static dsCompositeInSelectPort_t func = NULL;
362  if (func == 0) {
363  void *dllib = dlopen(RDK_DSHAL_NAME, RTLD_LAZY);
364  if (dllib) {
365  func = (dsCompositeInSelectPort_t) dlsym(dllib, "dsCompositeInSelectPort");
366  if(func == 0) {
367  printf("dsCompositeInSelectPort(dsCompositeInPort_t) is not defined\r\n");
368  }
369  dlclose(dllib);
370  }
371  else {
372  printf("Opening RDK_DSHAL_NAME [%s] failed\r\n", RDK_DSHAL_NAME);
373  }
374  }
375  if(func) {
376  printf("%s:%d - invoking dsCompositeInSelectPort()\n", __PRETTY_FUNCTION__,__LINE__);
377  param->result = func(param->port);
378  }
379 #else
380  param->result = dsERR_GENERAL;
381 #endif
382 
383  IARM_BUS_Unlock(lock);
384 
385  return IARM_RESULT_SUCCESS;
386 }
387 
388 IARM_Result_t _dsCompositeInScaleVideo(void *arg)
389 {
390  _DEBUG_ENTER();
391 
392  IARM_BUS_Lock(lock);
394 
395 #ifdef HAS_COMPOSITE_IN_SUPPORT
396  typedef dsError_t (*dsCompositeInScaleVideo_t)(int32_t , int32_t , int32_t , int32_t);
397  static dsCompositeInScaleVideo_t func = NULL;
398  if (func == 0) {
399  void *dllib = dlopen(RDK_DSHAL_NAME, RTLD_LAZY);
400  if (dllib) {
401  func = (dsCompositeInScaleVideo_t) dlsym(dllib, "dsCompositeInScaleVideo");
402  if(func == 0) {
403  printf("dsCompositeInScaleVideo(int32_t x, int32_t y, int32_t width, int32_t height) is not defined\r\n");
404  }
405  dlclose(dllib);
406  }
407  else {
408  printf("Opening RDK_DSHAL_NAME [%s] failed\r\n", RDK_DSHAL_NAME);
409  }
410  }
411 
412  if(func) {
413  printf("%s:%d - invoking dsCompositeInScaleVideo()\n", __PRETTY_FUNCTION__,__LINE__);
414  param->result = func(param->videoRect.x, param->videoRect.y, param->videoRect.width, param->videoRect.height);
415  }
416 #else
417  param->result = dsERR_GENERAL;
418 #endif
419 
420  IARM_BUS_Unlock(lock);
421 
422  return IARM_RESULT_SUCCESS;
423 }
424 
425 
426 void _dsCompositeInConnectCB(dsCompositeInPort_t port, bool isPortConnected)
427 {
428  IARM_Bus_DSMgr_EventData_t composite_in_hpd_eventData;
429  __TIMESTAMP();
430  printf("%s:%d - COMPOSITE In hotplug update!!!!!!..%d, %d\r\n",__PRETTY_FUNCTION__,__LINE__, port, isPortConnected);
431  composite_in_hpd_eventData.data.composite_in_connect.port = port;
432  composite_in_hpd_eventData.data.composite_in_connect.isPortConnected = isPortConnected;
433 
434  IARM_Bus_BroadcastEvent(IARM_BUS_DSMGR_NAME,
436  (void *)&composite_in_hpd_eventData,
437  sizeof(composite_in_hpd_eventData));
438 
439 }
440 
441 
442 void _dsCompositeInSignalChangeCB(dsCompositeInPort_t port, dsCompInSignalStatus_t sigStatus)
443 {
444  IARM_Bus_DSMgr_EventData_t composite_in_sigStatus_eventData;
445  printf("%s:%d Composite In signal change update!!!!!! Port: %d, Signal Status: %d\r\n", __PRETTY_FUNCTION__, __LINE__, port, sigStatus);
446  composite_in_sigStatus_eventData.data.composite_in_sig_status.port = port;
447  composite_in_sigStatus_eventData.data.composite_in_sig_status.status = sigStatus;
448 
449  IARM_Bus_BroadcastEvent(IARM_BUS_DSMGR_NAME,
451  (void *)&composite_in_sigStatus_eventData,
452  sizeof(composite_in_sigStatus_eventData));
453 
454  printf("%s <-- \n", __PRETTY_FUNCTION__);
455 }
456 
457 void _dsCompositeInStatusChangeCB(dsCompositeInStatus_t inputStatus)
458 {
459  IARM_Bus_DSMgr_EventData_t hdmi_in_status_eventData;
460  printf("%s:%d Composite In status change update!!!!!! Port: %d, isPresented: %d\r\n", __PRETTY_FUNCTION__, __LINE__, inputStatus.activePort, inputStatus.isPresented);
461  hdmi_in_status_eventData.data.composite_in_status.port = inputStatus.activePort;
462  hdmi_in_status_eventData.data.composite_in_status.isPresented = inputStatus.isPresented;
463 
464  IARM_Bus_BroadcastEvent(IARM_BUS_DSMGR_NAME,
466  (void *)&hdmi_in_status_eventData,
467  sizeof(hdmi_in_status_eventData));
468 
469  printf("%s <-- \n", __PRETTY_FUNCTION__);
470 }
471 
472 /** @} */
473 /** @} */
IARM_BUS_DSMGR_EVENT_COMPOSITE_IN_HOTPLUG
@ IARM_BUS_DSMGR_EVENT_COMPOSITE_IN_HOTPLUG
Definition: dsMgr.h:59
_dsCompositeInScaleVideoParam_t
Definition: dsRpc.h:767
dsTypes.h
Device Settings HAL types.
_dsCompositeInStatus_t::activePort
dsCompositeInPort_t activePort
Definition: dsTypes.h:1080
IARM_BUS_DSMGR_EVENT_COMPOSITE_IN_STATUS
@ IARM_BUS_DSMGR_EVENT_COMPOSITE_IN_STATUS
Definition: dsMgr.h:61
dsCompositeInConnectCB_t
void(* dsCompositeInConnectCB_t)(dsCompositeInPort_t Port, bool isPortConnected)
Callback function used to notify applications of COMPOSITE In hot plug status.
Definition: dsCompositeIn.h:183
IARM_Bus_RegisterCall
IARM_Result_t IARM_Bus_RegisterCall(const char *methodName, IARM_BusCall_t handler)
This API is used to register an RPC method that can be invoked by other applications.
dsERR_GENERAL
@ dsERR_GENERAL
Definition: dsError.h:86
dsCompositeInStatusChangeCB_t
void(* dsCompositeInStatusChangeCB_t)(dsCompositeInStatus_t inputStatus)
Callback function used to notify applications of Composite Input status.
Definition: dsCompositeIn.h:237
_dsCompositeInGetNumberOfInputsParam_t
Definition: dsRpc.h:749
IARM_Bus_BroadcastEvent
IARM_Result_t IARM_Bus_BroadcastEvent(const char *ownerName, IARM_EventId_t eventId, void *data, size_t len)
This API is used to publish an Asynchronous event to all IARM client registered for this perticular e...
libIBus.h
RDK IARM-Bus API Declarations.
_dsCompositeInStatus_t
Definition: dsTypes.h:1076
dsCompositeInSignalChangeCB_t
void(* dsCompositeInSignalChangeCB_t)(dsCompositeInPort_t port, dsCompInSignalStatus_t sigStatus)
Callback function used to notify applications of Composite In signal change status.
Definition: dsCompositeIn.h:210
dsCompositeIn.h
Device Settings HAL COMPOSITE Input Public API. This API defines the HAL for the Device Settings COMP...
_dsCompositeInStatus_t::isPresented
bool isPresented
Definition: dsTypes.h:1078
_dsCompositeInGetStatusParam_t
Definition: dsRpc.h:755
_dsCompositeInSelectPortParam_t
Definition: dsRpc.h:761
dsError_t
dsError_t
Device Settings API Error return codes.
Definition: dsError.h:84
IARM_BUS_DSMGR_EVENT_COMPOSITE_IN_SIGNAL_STATUS
@ IARM_BUS_DSMGR_EVENT_COMPOSITE_IN_SIGNAL_STATUS
Definition: dsMgr.h:60
_DSMgr_EventData_t
Definition: dsMgr.h:81