X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=include%2Fcecloader.h;h=0440501dad4f9630ae1dd5211b4bf5def64e67c2;hb=4bdea07d9e94c9a86e64ac3a2a4569e5ce73f8d9;hp=7ae8b4984f9d9ae825dc1dfffecc97273e2d7e8c;hpb=cb9128746f5f12e284c3e2efe92a1a5e39ac453c;p=deb_libcec.git diff --git a/include/cecloader.h b/include/cecloader.h index 7ae8b49..0440501 100644 --- a/include/cecloader.h +++ b/include/cecloader.h @@ -54,6 +54,21 @@ CEC::ICECAdapter *LoadLibCec(const char *strName, CEC::cec_logical_address iLogi return static_cast< CEC::ICECAdapter* > (CreateLibCec(strName, (uint8_t) iLogicalAddress, iPhysicalAddress)); } +CEC::ICECAdapter *LibCecInit(const char *strDeviceName, CEC::cec_device_type_list types, const char *strLib = NULL) +{ + if (!g_libCEC) + g_libCEC = LoadLibrary(strLib ? strLib : "libcec.dll"); + if (!g_libCEC) + return NULL; + + typedef void* (__cdecl*_LibCecInit)(const char *, CEC::cec_device_type_list); + _LibCecInit LibCecInit; + LibCecInit = (_LibCecInit) (GetProcAddress(g_libCEC, "CECInit")); + if (!LibCecInit) + return NULL; + return static_cast< CEC::ICECAdapter* > (LibCecInit(strDeviceName, types)); +} + void UnloadLibCec(CEC::ICECAdapter *device) { typedef void (__cdecl*_DestroyLibCec)(void * device); @@ -84,9 +99,9 @@ CEC::ICECAdapter *LoadLibCec(const char *strName, CEC::cec_logical_address iLogi if (!g_libCEC) { #if defined(__APPLE__) - cout << "cannot find " << (strLib ? strLib : "libcec.dylib") << endl; + cout << "cannot find " << (strLib ? strLib : "libcec.dylib") << dlerror() << endl; #else - cout << "cannot find " << (strLib ? strLib : "libcec.so") << endl; + cout << "cannot find " << (strLib ? strLib : "libcec.so") << dlerror() << endl; #endif return NULL; } @@ -96,13 +111,44 @@ CEC::ICECAdapter *LoadLibCec(const char *strName, CEC::cec_logical_address iLogi _CreateLibCec* CreateLibCec = (_CreateLibCec*) dlsym(g_libCEC, "CECCreate"); if (!CreateLibCec) { - cout << "cannot find CreateLibCec" << endl; + cout << "cannot find CECCreate" << endl; return NULL; } return (CEC::ICECAdapter*) CreateLibCec(strName, iLogicalAddress, iPhysicalAddress); } +CEC::ICECAdapter *LibCecInit(const char *strDeviceName, CEC::cec_device_type_list types, const char *strLib = NULL) +{ + if (!g_libCEC) + { +#if defined(__APPLE__) + g_libCEC = dlopen(strLib ? strLib : "libcec.dylib", RTLD_LAZY); +#else + g_libCEC = dlopen(strLib ? strLib : "libcec.so", RTLD_LAZY); +#endif + if (!g_libCEC) + { +#if defined(__APPLE__) + cout << "cannot find " << (strLib ? strLib : "libcec.dylib") << dlerror() << endl; +#else + cout << "cannot find " << (strLib ? strLib : "libcec.so") << dlerror() << endl; +#endif + return NULL; + } + } + + typedef void* _LibCecInit(const char *, CEC::cec_device_type_list); + _LibCecInit* LibCecInit = (_LibCecInit*) dlsym(g_libCEC, "CECInit"); + if (!LibCecInit) + { + cout << "cannot find CECInit" << endl; + return NULL; + } + + return (CEC::ICECAdapter*) LibCecInit(strDeviceName, types); +} + void UnloadLibCec(CEC::ICECAdapter *device) { typedef void* _DestroyLibCec(CEC::ICECAdapter *);