33 #include "ccec/Host.hpp"
35 static int32_t pluginGen = 0;
37 static void *plugin = 0;
39 #define DL_ERROR() printf("dlopen() error : [%s]\r\n", dlerror())
41 #ifndef CEC_HOST_PLUGIN
42 #warning "Using Default CEC_HOST_PLUGIN=librdkcechost.so"
43 #define CEC_HOST_PLUGIN "libRCECHost.so.0"
46 CECHost_Err_t CECHost_LoadPlugin(
void)
48 CECHost_Err_t ret = CECHost_ERR_NONE;
50 plugin = dlopen(CEC_HOST_PLUGIN, RTLD_LAZY);
52 printf(
"dlopen() error : [%s]\r\n", dlerror());
53 ret = CECHost_ERR_SYMBOL;
60 ret = CECHost_ERR_STATE;
66 CECHost_Err_t CECHost_UnloadPlugin(
void)
68 CECHost_Err_t ret = CECHost_ERR_NONE;
75 ret = CECHost_ERR_STATE;
81 static CECHost_Err_t _load(
const char *funcName,
void **func, int32_t *currGen)
83 CECHost_Err_t ret = CECHost_ERR_NONE;
85 if (plugin == NULL)
return CECHost_ERR_STATE;
87 if (*func == NULL || *currGen != pluginGen) {
88 *func = dlsym(plugin, funcName);
91 ret = CECHost_ERR_SYMBOL;
103 typedef CECHost_Err_t(*CECHost_Init_t)(
const char *name);
105 static int32_t currGen = pluginGen;
106 static void *f = NULL;
108 CECHost_Err_t ret = _load(__FUNCTION__, &f, &currGen);
109 if (ret == CECHost_ERR_NONE) {
110 ret = ((CECHost_Init_t)f)(name);
118 typedef CECHost_Err_t(*CECHost_Term_t)(void);
120 static int32_t currGen = pluginGen;
121 static void *f = NULL;
123 CECHost_Err_t ret = _load(__FUNCTION__, &f, &currGen);
124 if (ret == CECHost_ERR_NONE) {
125 ret = ((CECHost_Term_t)f)();
134 static int32_t currGen = pluginGen;
135 static void *f = NULL;
137 CECHost_Err_t ret = _load(__FUNCTION__, &f, &currGen);
138 if (ret == CECHost_ERR_NONE) {
139 ret = ((CECHost_SetCallback_t)f)(cb);
146 typedef CECHost_Err_t(*CECHost_GetHdmiOuputPhysicalAddress_t)(uint8_t *byte0, uint8_t *byte1, uint8_t *byte2, uint8_t *byte3);
148 static int32_t currGen = pluginGen;
149 static void *f = NULL;
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);
161 typedef CECHost_Err_t(*CECHost_IsHdmiOutputConnected_t)(int32_t *connect);
163 static int32_t currGen = pluginGen;
164 static void *f = NULL;
166 CECHost_Err_t ret = _load(__FUNCTION__, &f, &currGen);
167 if (ret == CECHost_ERR_NONE) {
168 ret = ((CECHost_IsHdmiOutputConnected_t)f)(connect);
176 typedef CECHost_Err_t(*CECHost_GetPowerState_t)(int32_t *state);
178 static int32_t currGen = pluginGen;
179 static void *f = NULL;
181 CECHost_Err_t ret = _load(__FUNCTION__, &f, &currGen);
182 if (ret == CECHost_ERR_NONE) {
183 ret = ((CECHost_GetPowerState_t)f)(state);
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);
203 typedef CECHost_Err_t(*CECHost_SetPowerState_t)(int32_t state);
205 static int32_t currGen = pluginGen;
206 static void *f = NULL;
208 CECHost_Err_t ret = _load(__FUNCTION__, &f, &currGen);
209 if (ret == CECHost_ERR_NONE) {
210 ret = ((CECHost_SetPowerState_t)f)(state);
218 typedef CECHost_Err_t(*CECHost_GetOSDName_t)(uint8_t *buf,
size_t *len);
220 static int32_t currGen = pluginGen;
221 static void *f = NULL;
223 CECHost_Err_t ret = _load(__FUNCTION__, &f, &currGen);
224 if (ret == CECHost_ERR_NONE) {
225 ret = ((CECHost_GetOSDName_t)f)(buf, len);
233 typedef CECHost_Err_t(*CECHost_IsActive_t)(int32_t *active);
235 static int32_t currGen = pluginGen;
236 static void *f = NULL;
238 CECHost_Err_t ret = _load(__FUNCTION__, &f, &currGen);
239 if (ret == CECHost_ERR_NONE) {
240 ret = ((CECHost_IsActive_t)f)(active);