cec: changed - libcec_configuration.bAutodetectAddress is now read-only, and will...
[deb_libcec.git] / include / cecloader.h
index bfb392978aa9506f6f1ac89b6e7b4977fd464270..5d4361d6199034c31b24732f52fe01c7fa137a8c 100644 (file)
@@ -72,7 +72,7 @@ CEC::ICECAdapter *LibCecInit(const char *strDeviceName, CEC::cec_device_type_lis
  * @param strLib The name of and/or path to libCEC
  * @return An instance of ICECAdapter or NULL on error.
  */
-CEC::ICECAdapter *LibCecInitialise(const CEC::libcec_configuration *configuration, const char *strLib = NULL)
+CEC::ICECAdapter *LibCecInitialise(CEC::libcec_configuration *configuration, const char *strLib = NULL)
 {
   if (!g_libCEC)
 #if defined(_WIN64)
@@ -83,7 +83,7 @@ CEC::ICECAdapter *LibCecInitialise(const CEC::libcec_configuration *configuratio
   if (!g_libCEC)
     return NULL;
 
-  typedef void* (__cdecl*_LibCecInitialise)(const CEC::libcec_configuration *);
+  typedef void* (__cdecl*_LibCecInitialise)(CEC::libcec_configuration *);
   _LibCecInitialise LibCecInitialise;
   LibCecInitialise = (_LibCecInitialise) (GetProcAddress(g_libCEC, "CECInitialise"));
   if (!LibCecInitialise)
@@ -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 <dlfcn.h>
@@ -158,9 +186,10 @@ CEC::ICECAdapter *LibCecInit(const char *strDeviceName, CEC::cec_device_type_lis
 /*!
  * @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(const CEC::CecAdapterConfiguration &configuration)
+CEC::ICECAdapter *LibCecInitialise(CEC::libcec_configuration *configuration, const char *strLib = NULL)
 {
   if (!g_libCEC)
   {
@@ -180,7 +209,7 @@ CEC::ICECAdapter *LibCecInitialise(const CEC::CecAdapterConfiguration &configura
     }
   }
 
-  typedef void* _LibCecInitialise(const CEC::CecAdapterConfiguration &);
+  typedef void* _LibCecInitialise(CEC::libcec_configuration *);
   _LibCecInitialise* LibCecInitialise = (_LibCecInitialise*) dlsym(g_libCEC, "CECInitialise");
   if (!LibCecInitialise)
   {
@@ -205,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_ */