Skip to content

Instantly share code, notes, and snippets.

@kmanna
Created January 13, 2014 21:35
Show Gist options
  • Save kmanna/8408614 to your computer and use it in GitHub Desktop.
Save kmanna/8408614 to your computer and use it in GitHub Desktop.
Why so ugly?
/*!
* @brief Create a new libCEC instance.
* @param configuration The configuration to pass to libCEC
* @param strLib The name of and/or path to libCEC
* @return An instance of ICECAdapter or NULL on error.
*/
CEC::ICECAdapter *LibCecInitialise(CEC::libcec_configuration *configuration, const char *strLib = NULL)
{
if (!g_libCEC)
{
#if defined(__APPLE__)
g_libCEC = dlopen(strLib ? strLib : "libcec." CEC_LIB_VERSION_MAJOR_STR ".dylib", RTLD_LAZY);
#elif defined(__ANDROID__)
g_libCEC = dlopen(strLib ? strLib : "libcec.so", 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 void* _LibCecInitialise(CEC::libcec_configuration *);
_LibCecInitialise* LibCecInitialise = (_LibCecInitialise*) dlsym(g_libCEC, "CECInitialise");
if (!LibCecInitialise)
{
cout << "cannot find CECInitialise" << endl;
return NULL;
}
return (CEC::ICECAdapter*) LibCecInitialise(configuration);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment