X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=include%2Fcecloader.h;h=7a7dce6cf583d70c340e7f1fc9f5d0bcd5c9a595;hb=41b12347891d698c650cbc6fcfc40759d5e1db11;hp=624f29a5c7a54961ab53f0565e95945138fbb65c;hpb=3efda01ac7b070e09012a5725112eb44c17001b4;p=deb_libcec.git diff --git a/include/cecloader.h b/include/cecloader.h index 624f29a..7a7dce6 100644 --- a/include/cecloader.h +++ b/include/cecloader.h @@ -111,6 +111,34 @@ void UnloadLibCec(CEC::ICECAdapter *device) g_libCEC = NULL; } +/*! + * @brief Start the bootloader on the first device that was detected. + * @param strLib The name of and/or path to libCEC + * @return True when the command was sent, false otherwise. + */ +bool LibCecBootloader(const char *strLib = NULL) +{ + if (!g_libCEC) +#if defined(_WIN64) + g_libCEC = LoadLibrary(strLib ? strLib : "libcec.x64.dll"); +#else + g_libCEC = LoadLibrary(strLib ? strLib : "libcec.dll"); +#endif + if (!g_libCEC) + return NULL; + + typedef bool (__cdecl*_LibCecBootloader)(void); + _LibCecBootloader LibCecBootloader; + LibCecBootloader = (_LibCecBootloader) (GetProcAddress(g_libCEC, "CECStartBootloader")); + if (!LibCecBootloader) + return false; + + bool bReturn = LibCecBootloader(); + FreeLibrary(g_libCEC); + g_libCEC = NULL; + return bReturn; +} + #else #include @@ -131,15 +159,11 @@ CEC::ICECAdapter *LibCecInit(const char *strDeviceName, CEC::cec_device_type_lis #if defined(__APPLE__) g_libCEC = dlopen(strLib ? strLib : "libcec.dylib", RTLD_LAZY); #else - g_libCEC = dlopen(strLib ? strLib : "libcec.so", RTLD_LAZY); + g_libCEC = dlopen(strLib ? strLib : "libcec.so." CEC_LIB_VERSION_MAJOR_STR, 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 + cout << dlerror() << endl; return NULL; } } @@ -168,15 +192,11 @@ CEC::ICECAdapter *LibCecInitialise(CEC::libcec_configuration *configuration, con #if defined(__APPLE__) g_libCEC = dlopen(strLib ? strLib : "libcec.dylib", RTLD_LAZY); #else - g_libCEC = dlopen(strLib ? strLib : "libcec.so", RTLD_LAZY); + g_libCEC = dlopen(strLib ? strLib : "libcec.so." CEC_LIB_VERSION_MAJOR_STR, 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 + cout << dlerror() << endl; return NULL; } } @@ -206,6 +226,40 @@ void UnloadLibCec(CEC::ICECAdapter *device) dlclose(g_libCEC); } +/*! + * @brief Start the bootloader on the first device that was detected. + * @param strLib The name of and/or path to libCEC + * @return True when the command was sent, false otherwise. + */ +bool LibCecBootloader(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." CEC_LIB_VERSION_MAJOR_STR, RTLD_LAZY); +#endif + if (!g_libCEC) + { + cout << dlerror() << endl; + return NULL; + } + } + + typedef bool _LibCecBootloader(void); + _LibCecBootloader* LibCecBootloader = (_LibCecBootloader*) dlsym(g_libCEC, "CECStartBootloader"); + if (!LibCecBootloader) + { + cout << "cannot find CECStartBootloader" << endl; + return NULL; + } + + bool bReturn = LibCecBootloader(); + dlclose(g_libCEC); + return bReturn; +} + #endif #endif /* CECLOADER_H_ */