RDK Documentation (Open Sourced RDK Components)
test_bus_client.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 
21 /**
22 * @defgroup iarmmgrs
23 * @{
24 * @defgroup test
25 * @{
26 **/
27 
28 
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <unistd.h>
32 #include <string.h>
33 #include "libIBus.h"
34 #include "libIBusDaemon.h"
35 #include "pwrMgr.h"
36 #include "irMgr.h"
37 
38 
39 static IARM_Result_t _ReleaseOwnership(void *arg)
40 {
41  printf("############### Bus Client _ReleaseOwnership, CLIENT releasing stuff\r\n");
42 
43  IARM_Result_t retCode = IARM_RESULT_SUCCESS;
44  return retCode;
45 }
46 
47 static void _eventHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len)
48 {
49  if (strcmp(owner, IARM_BUS_PWRMGR_NAME) == 0) {
50  switch (eventId) {
52  {
54  printf("Event IARM_BUS_PWRMGR_EVENT_MODECHANGED: State Changed %d -- > %d\r\n",
55  param->data.state.curState, param->data.state.newState);
56  }
57  break;
58  default:
59  break;
60  }
61  }
62  else if (strcmp(owner, IARM_BUS_IRMGR_NAME) == 0) {
63  switch (eventId) {
65  {
67  int keyCode = irEventData->data.irkey.keyCode;
68  int keyType = irEventData->data.irkey.keyType;
69  printf("Test Bus Client Get IR Key (%x, %x) From IR Manager\r\n", keyCode, keyType);
70  }
71  break;
72  default:
73  break;
74  }
75 
76  }
77 }
78 
79 int main()
80 {
81  IARM_Result_t retCode = IARM_RESULT_SUCCESS;
82  printf("Client Entering %d\r\n", getpid());
83  IARM_Bus_Init("Bus Client");
85 
86  IARM_Bus_RegisterCall(IARM_BUS_COMMON_API_ReleaseOwnership, _ReleaseOwnership);
88  retCode = IARM_BusDaemon_RequestOwnership(IARM_BUS_RESOURCE_FOCUS);
89 
90  int i = 0;
91  while(i < 5) {
92  i++;
93  printf("HeartBeat of Bus Client\r\n");
94  if (i % 2 == 1) {
95  printf("Register IR for Bus Client\r\n");
97  }
98  else {
99  printf("Unregister IR for Bus Client\r\n");
101  }
102  sleep(5);
103  }
104  retCode = IARM_BusDaemon_ReleaseOwnership(IARM_BUS_RESOURCE_FOCUS);
107  IARM_Bus_Term();
108  printf("Bus Client Exiting\r\n");
109 }
110 
111 
112 /** @} */
113 /** @} */
IARM_BUS_PWRMGR_NAME
#define IARM_BUS_PWRMGR_NAME
Definition: pwrMgr.h:54
IARM_Bus_Term
IARM_Result_t IARM_Bus_Term(void)
This API is used to terminate the IARM-Bus library.
IARM_BUS_IRMGR_EVENT_IRKEY
@ IARM_BUS_IRMGR_EVENT_IRKEY
Definition: irMgr.h:220
_PWRMgr_EventData_t
Structure which holds the event data.
Definition: pwrMgr.h:117
IARM_Bus_RegisterEventHandler
IARM_Result_t IARM_Bus_RegisterEventHandler(const char *ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler)
This API register to listen to event and provide the callback function for event notification....
Definition: iarmMgrMocks.cpp:43
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.
IARM_Bus_Disconnect
IARM_Result_t IARM_Bus_Disconnect(void)
This API disconnect Application from IARM Bus so the application will not receive any IARM event or R...
libIBus.h
RDK IARM-Bus API Declarations.
IARM_BUS_IRMGR_NAME
#define IARM_BUS_IRMGR_NAME
Definition: irMgr.h:216
IARM_BUS_PWRMGR_EVENT_MODECHANGED
@ IARM_BUS_PWRMGR_EVENT_MODECHANGED
Definition: pwrMgr.h:60
pwrMgr.h
IARM-Bus Power Manager Public API.
keyType
Definition: reset.c:85
irMgr.h
IARM-Bus IR Manager API.
_IRMgr_EventData_t
Definition: irMgr.h:235
IARM_Bus_Connect
IARM_Result_t IARM_Bus_Connect(void)
This API is used to connect application to the IARM bus daemon. After connected, the application can ...
Definition: iarmMgrMocks.cpp:33
IARM_Bus_UnRegisterEventHandler
IARM_Result_t IARM_Bus_UnRegisterEventHandler(const char *ownerName, IARM_EventId_t eventId)
This API is used to Remove ALL handlers registered for the given event. This API remove the all the e...
IARM_Bus_Init
IARM_Result_t IARM_Bus_Init(const char *name)
This API is used to initialize the IARM-Bus library.
Definition: iarmMgrMocks.cpp:38