X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=include%2Fcecloader.h;h=5d4361d6199034c31b24732f52fe01c7fa137a8c;hb=5f2f3609d7ee857ac7e5d03600fbd735e99c892f;hp=624f29a5c7a54961ab53f0565e95945138fbb65c;hpb=3efda01ac7b070e09012a5725112eb44c17001b4;p=deb_libcec.git diff --git a/include/cecloader.h b/include/cecloader.h index 624f29a..5d4361d 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 @@ -206,6 +234,44 @@ 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", 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 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_ */