diff options
author | Christian Fetzer <fetzer.ch@googlemail.com> | 2013-01-15 21:51:33 +0100 |
---|---|---|
committer | Christian Fetzer <fetzer.ch@googlemail.com> | 2013-02-16 17:18:08 +0100 |
commit | 1d0d85be4e2fdec0613a4ab486cff4332f6ddcb3 (patch) | |
tree | 61de6b7448244d6519379c07bcca99305d8fbd51 | |
parent | 4659e134824d3cd8b18e2bad6409fb4f0a901179 (diff) |
addons: Add WakeOnLan function
WakeOnLan allows addons to send a wol magic packet.
This can be used for example in pvr addons to wake up a pvr backend.
-rw-r--r-- | addons/library.xbmc.addon/libXBMC_addon.h | 15 | ||||
-rw-r--r-- | lib/addons/library.xbmc.addon/libXBMC_addon.cpp | 8 | ||||
-rw-r--r-- | xbmc/addons/AddonCallbacks.h | 2 | ||||
-rw-r--r-- | xbmc/addons/AddonCallbacksAddon.cpp | 7 | ||||
-rw-r--r-- | xbmc/addons/AddonCallbacksAddon.h | 1 |
5 files changed, 33 insertions, 0 deletions
diff --git a/addons/library.xbmc.addon/libXBMC_addon.h b/addons/library.xbmc.addon/libXBMC_addon.h index 35e58fa0e4..4740bd65d3 100644 --- a/addons/library.xbmc.addon/libXBMC_addon.h +++ b/addons/library.xbmc.addon/libXBMC_addon.h @@ -158,6 +158,10 @@ namespace ADDON dlsym(m_libXBMC_addon, "XBMC_queue_notification"); if (XBMC_queue_notification == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } + XBMC_wake_on_lan = (bool (*)(void* HANDLE, void *CB, const char *mac)) + dlsym(m_libXBMC_addon, "XBMC_wake_on_lan"); + if (XBMC_wake_on_lan == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } + XBMC_unknown_to_utf8 = (char* (*)(void* HANDLE, void* CB, const char* str)) dlsym(m_libXBMC_addon, "XBMC_unknown_to_utf8"); if (XBMC_unknown_to_utf8 == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; } @@ -296,6 +300,16 @@ namespace ADDON } /*! + * @brief Send WakeOnLan magic packet. + * @param mac Network address of the host to wake. + * @return True if the magic packet was successfully sent, false otherwise. + */ + bool WakeOnLan(const char* mac) + { + return XBMC_wake_on_lan(m_Handle, m_Callbacks, mac); + } + + /*! * @brief Translate a string with an unknown encoding to UTF8. * @param str The string to translate. * @return The string translated to UTF8. Must be freed by calling FreeString() when done. @@ -541,6 +555,7 @@ namespace ADDON void (*XBMC_log)(void *HANDLE, void* CB, const addon_log_t loglevel, const char *msg); bool (*XBMC_get_setting)(void *HANDLE, void* CB, const char* settingName, void *settingValue); void (*XBMC_queue_notification)(void *HANDLE, void* CB, const queue_msg_t type, const char *msg); + bool (*XBMC_wake_on_lan)(void *HANDLE, void* CB, const char* mac); char* (*XBMC_unknown_to_utf8)(void *HANDLE, void* CB, const char* str); char* (*XBMC_get_localized_string)(void *HANDLE, void* CB, int dwCode); char* (*XBMC_get_dvd_menu_language)(void *HANDLE, void* CB); diff --git a/lib/addons/library.xbmc.addon/libXBMC_addon.cpp b/lib/addons/library.xbmc.addon/libXBMC_addon.cpp index 984942415d..e39931dbe8 100644 --- a/lib/addons/library.xbmc.addon/libXBMC_addon.cpp +++ b/lib/addons/library.xbmc.addon/libXBMC_addon.cpp @@ -84,6 +84,14 @@ DLLEXPORT void XBMC_queue_notification(void *hdl, void* cb, const queue_msg_t ty ((CB_AddOnLib*)cb)->QueueNotification(((AddonCB*)hdl)->addonData, type, msg); } +DLLEXPORT bool XBMC_wake_on_lan(void* hdl, void* cb, char* mac) +{ + if (cb == NULL) + return false; + + return ((CB_AddOnLib*)cb)->WakeOnLan(mac); +} + DLLEXPORT char* XBMC_unknown_to_utf8(void *hdl, void* cb, const char* str) { if (cb == NULL) diff --git a/xbmc/addons/AddonCallbacks.h b/xbmc/addons/AddonCallbacks.h index c2d690bf2b..872424982d 100644 --- a/xbmc/addons/AddonCallbacks.h +++ b/xbmc/addons/AddonCallbacks.h @@ -26,6 +26,7 @@ typedef void (*AddOnLogCallback)(void *addonData, const ADDON::addon_log_t loglevel, const char *msg); typedef void (*AddOnQueueNotification)(void *addonData, const ADDON::queue_msg_t type, const char *msg); +typedef bool (*AddOnWakeOnLan)(const char* mac); typedef bool (*AddOnGetSetting)(void *addonData, const char *settingName, void *settingValue); typedef char* (*AddOnUnknownToUTF8)(const char *sourceDest); typedef char* (*AddOnGetLocalizedString)(const void* addonData, long dwCode); @@ -56,6 +57,7 @@ typedef struct CB_AddOn { AddOnLogCallback Log; AddOnQueueNotification QueueNotification; + AddOnWakeOnLan WakeOnLan; AddOnGetSetting GetSetting; AddOnUnknownToUTF8 UnknownToUTF8; AddOnGetLocalizedString GetLocalizedString; diff --git a/xbmc/addons/AddonCallbacksAddon.cpp b/xbmc/addons/AddonCallbacksAddon.cpp index 152c2c490f..b0dcd0aaa3 100644 --- a/xbmc/addons/AddonCallbacksAddon.cpp +++ b/xbmc/addons/AddonCallbacksAddon.cpp @@ -28,6 +28,7 @@ #include "filesystem/Directory.h" #include "utils/URIUtils.h" #include "FileItem.h" +#include "network/Network.h" using namespace XFILE; @@ -42,6 +43,7 @@ CAddonCallbacksAddon::CAddonCallbacksAddon(CAddon* addon) /* write XBMC addon-on specific add-on function addresses to the callback table */ m_callbacks->Log = AddOnLog; m_callbacks->QueueNotification = QueueNotification; + m_callbacks->WakeOnLan = WakeOnLan; m_callbacks->GetSetting = GetAddonSetting; m_callbacks->UnknownToUTF8 = UnknownToUTF8; m_callbacks->GetLocalizedString = GetLocalizedString; @@ -157,6 +159,11 @@ void CAddonCallbacksAddon::QueueNotification(void *addonData, const queue_msg_t } } +bool CAddonCallbacksAddon::WakeOnLan(const char *mac) +{ + return g_application.getNetwork().WakeOnLan(mac); +} + bool CAddonCallbacksAddon::GetAddonSetting(void *addonData, const char *strSettingName, void *settingValue) { CAddonCallbacks* addon = (CAddonCallbacks*) addonData; diff --git a/xbmc/addons/AddonCallbacksAddon.h b/xbmc/addons/AddonCallbacksAddon.h index 83d8361e50..9e0fd5a5cf 100644 --- a/xbmc/addons/AddonCallbacksAddon.h +++ b/xbmc/addons/AddonCallbacksAddon.h @@ -38,6 +38,7 @@ public: static void AddOnLog(void *addonData, const addon_log_t addonLogLevel, const char *strMessage); static bool GetAddonSetting(void *addonData, const char *strSettingName, void *settingValue); static void QueueNotification(void *addonData, const queue_msg_t type, const char *strMessage); + static bool WakeOnLan(const char *mac); static char* UnknownToUTF8(const char *strSource); static char* GetLocalizedString(const void* addonData, long dwCode); static char* GetDVDMenuLanguage(const void* addonData); |