diff --git a/src/ble/ctrlm_ble_controller.cpp b/src/ble/ctrlm_ble_controller.cpp index d86650db..61e26ffd 100644 --- a/src/ble/ctrlm_ble_controller.cpp +++ b/src/ble/ctrlm_ble_controller.cpp @@ -531,13 +531,30 @@ void ctrlm_obj_controller_ble_t::setSupportedIrdbs(uint8_t vendor_support_bitmas this->irdbs_supported_ = vendor_support_bitmask; ctrlm_irdb_interface_t *irdb = ctrlm_main_irdb_get(); - ctrlm_irdb_vendor_info_t vendor_info; - if (irdb && irdb->get_vendor_info(vendor_info)) { - XLOGD_INFO("Controller <%s> IRDBs supported bitmask = <0x%X>, which %s support the loaded IRDB plugin vendor <%s>", - ieee_address_get().to_string().c_str(), vendor_support_bitmask, - isSupportedIrdb(vendor_info) ? "DOES" : "does NOT", vendor_info.name.c_str()); + + if (irdb == NULL) { + XLOGD_ERROR("IRDB interface is NULL!!!"); + return; + } + + ctrlm_irdb_vendor_info_t rcu_vendor_info{}; + rcu_vendor_info.rcu_support_bitmask = vendor_support_bitmask; + if (!irdb->set_vendor(rcu_vendor_info)) { + XLOGD_ERROR("Failed to set IRDB vendor info for controller <%s> with bitmask <0x%X>.", + ieee_address_get().to_string().c_str(), vendor_support_bitmask); + } + + ctrlm_irdb_vendor_info_t vendor_info{}; + if (irdb->get_vendor_info(vendor_info)) { + if (isSupportedIrdb(vendor_info)) { + XLOGD_INFO("Controller <%s> IRDBs supported bitmask = <0x%X>, which DOES support the loaded IRDB plugin vendor <%s>", + ieee_address_get().to_string().c_str(), vendor_support_bitmask, vendor_info.name.c_str()); + } else { + XLOGD_ERROR("Controller <%s> IRDBs supported bitmask = <0x%X>, which does NOT support the loaded IRDB plugin vendor <%s>", + ieee_address_get().to_string().c_str(), vendor_support_bitmask, vendor_info.name.c_str()); + } } else { - XLOGD_INFO("Controller <%s> IRDBs supported bitmask = <0x%X>, couldn't retrieve IRDB plugin vendor info.", + XLOGD_WARN("Controller <%s> IRDBs supported bitmask = <0x%X>, couldn't retrieve IRDB plugin vendor info.", ieee_address_get().to_string().c_str(), vendor_support_bitmask); } } diff --git a/src/ble/hal/blercu/bleservices/gatt/gatt_infraredservice.cpp b/src/ble/hal/blercu/bleservices/gatt/gatt_infraredservice.cpp index 8d8061d5..40dff3c6 100644 --- a/src/ble/hal/blercu/bleservices/gatt/gatt_infraredservice.cpp +++ b/src/ble/hal/blercu/bleservices/gatt/gatt_infraredservice.cpp @@ -422,6 +422,11 @@ void GattInfraredService::requestIrSupport() // sanity check we actually have a ir support characteristic if (!m_irSupportCharacteristic || !m_irSupportCharacteristic->isValid()) { XLOGD_WARN("missing ir support characteristic"); + + // Set ir support back to invalid value and notify + m_irSupport = 0; + m_irSupportChangedSlots.invoke(m_irSupport); + return; } @@ -434,8 +439,9 @@ void GattInfraredService::requestIrSupport() XLOGD_ERROR("failed to get initial ir support code due to <%s>", reply->errorMessage().c_str()); + // Set ir support back to invalid value and notify m_irSupport = 0; - + m_irSupportChangedSlots.invoke(m_irSupport); } else { std::vector value; diff --git a/src/irdb/ctrlm_irdb_interface.cpp b/src/irdb/ctrlm_irdb_interface.cpp index 1bc55ffd..5dd99c8f 100644 --- a/src/irdb/ctrlm_irdb_interface.cpp +++ b/src/irdb/ctrlm_irdb_interface.cpp @@ -68,6 +68,8 @@ typedef struct { std::string (*pluginVersion)() = NULL; bool (*pluginInitialize)() = NULL; bool (*pluginGetVendorInfo)(ctrlm_irdb_vendor_info_t &info) = NULL; + bool (*pluginGetSupportedVendors)(std::vector &info) = NULL; + bool (*pluginSetPreferredVendor)(const ctrlm_irdb_vendor_info_t &vendor) = NULL; bool (*pluginGetManufacturers)(ctrlm_irdb_manufacturer_list_t &manufacturers, ctrlm_irdb_dev_type_t type, const std::string &prefix) = NULL; bool (*pluginGetModels)(ctrlm_irdb_model_list_t &models, ctrlm_irdb_dev_type_t type, const std::string &manufacturer, const std::string &prefix) = NULL; bool (*pluginGetEntryIds)(ctrlm_irdb_entry_id_list_t &codes, ctrlm_irdb_dev_type_t type, const std::string &manufacturer, const std::string &model) = NULL; @@ -132,6 +134,8 @@ ctrlm_irdb_interface_t::ctrlm_irdb_interface_t(bool platform_tv) { g_irdb.pluginVersion = STUB_irdb_version; g_irdb.pluginInitialize = STUB_ctrlm_irdb_initialize; g_irdb.pluginGetVendorInfo = STUB_ctrlm_irdb_get_vendor_info; + g_irdb.pluginSetPreferredVendor = STUB_ctrlm_irdb_set_preferred_vendor; + g_irdb.pluginGetSupportedVendors = STUB_ctrlm_irdb_get_supported_vendor_info; g_irdb.pluginGetManufacturers = STUB_ctrlm_irdb_get_manufacturers; g_irdb.pluginGetModels = STUB_ctrlm_irdb_get_models; g_irdb.pluginGetEntryIds = STUB_ctrlm_irdb_get_entry_ids; @@ -182,6 +186,20 @@ ctrlm_irdb_interface_t::ctrlm_irdb_interface_t(bool platform_tv) { } dlerror(); // Clear any existing error + *(void **) (&g_irdb.pluginGetSupportedVendors) = dlsym(m_irdbPluginHandle, "ctrlm_irdb_get_supported_vendor_info"); + if ((error = dlerror()) != NULL) { + XLOGD_ERROR("Failed to find plugin method (ctrlm_irdb_get_supported_vendor_info), error <%s>, Using STUB implementation", error); + g_irdb.pluginGetSupportedVendors = STUB_ctrlm_irdb_get_supported_vendor_info; + } + dlerror(); // Clear any existing error + + *(void **) (&g_irdb.pluginSetPreferredVendor) = dlsym(m_irdbPluginHandle, "ctrlm_irdb_set_preferred_vendor"); + if ((error = dlerror()) != NULL) { + XLOGD_ERROR("Failed to find plugin method (ctrlm_irdb_set_preferred_vendor), error <%s>, Using STUB implementation", error); + g_irdb.pluginSetPreferredVendor = STUB_ctrlm_irdb_set_preferred_vendor; + } + dlerror(); // Clear any existing error + *(void **) (&g_irdb.pluginGetManufacturers) = dlsym(m_irdbPluginHandle, "ctrlm_irdb_get_manufacturers"); if ((error = dlerror()) != NULL) { XLOGD_ERROR("Failed to find plugin method (ctrlm_irdb_get_manufacturers), error <%s>, Using STUB implementation", error); @@ -278,6 +296,17 @@ bool ctrlm_irdb_interface_t::open_plugin() { } } XLOGD_INFO("IRDB plugin opened, ret = <%s>", ret ? "SUCCESS" : "ERROR"); + + if (g_irdb.pluginGetSupportedVendors) { + std::vector supported_vendors; + if ((*g_irdb.pluginGetSupportedVendors)(supported_vendors) == true) { + for (const auto &it : supported_vendors) { + XLOGD_INFO("Found supported IRDB Vendor <%s, 0x%X>", it.name.c_str(), it.rcu_support_bitmask); + } + } else { + XLOGD_WARN("Unable to query IRDB plugin for list of supported vendors, check version of the plugin..."); + } + } return ret; } @@ -299,6 +328,14 @@ bool ctrlm_irdb_interface_t::get_vendor_info(ctrlm_irdb_vendor_info_t &info) { return false; } +bool ctrlm_irdb_interface_t::set_vendor(const ctrlm_irdb_vendor_info_t &info) { + std::unique_lock guard(m_mutex); + if (g_irdb.pluginSetPreferredVendor) { + return (*g_irdb.pluginSetPreferredVendor)(info); + } + return false; +} + void ctrlm_irdb_interface_t::on_thunder_ready() { #if defined(CTRLM_THUNDER) diff --git a/src/irdb/ctrlm_irdb_interface.h b/src/irdb/ctrlm_irdb_interface.h index 9e7da14e..3dbf94d7 100644 --- a/src/irdb/ctrlm_irdb_interface.h +++ b/src/irdb/ctrlm_irdb_interface.h @@ -70,6 +70,7 @@ class ctrlm_irdb_interface_t { virtual ~ctrlm_irdb_interface_t(); bool get_vendor_info(ctrlm_irdb_vendor_info_t &info); + bool set_vendor(const ctrlm_irdb_vendor_info_t &info); bool get_manufacturers(ctrlm_irdb_manufacturer_list_t &manufacturers, ctrlm_irdb_dev_type_t type, const std::string &prefix = ""); bool get_models(ctrlm_irdb_model_list_t &models, ctrlm_irdb_dev_type_t type, const std::string &manufacturer, const std::string &prefix = ""); bool get_irdb_entry_ids(ctrlm_irdb_entry_id_list_t &codes, ctrlm_irdb_dev_type_t type, const std::string &manufacturer, const std::string &model = ""); diff --git a/src/irdb/ctrlm_irdb_plugin.h b/src/irdb/ctrlm_irdb_plugin.h index 7e1ced22..b115773d 100644 --- a/src/irdb/ctrlm_irdb_plugin.h +++ b/src/irdb/ctrlm_irdb_plugin.h @@ -88,6 +88,12 @@ bool ctrlm_irdb_close(); bool ctrlm_irdb_initialize(); +// Will return info on all the IRDB vendors currently installed, could be multiple vendors returned +bool ctrlm_irdb_get_supported_vendor_info(std::vector &info); + +// Tell the IRDB plugin which vendor(s) the RCU supports +bool ctrlm_irdb_set_preferred_vendor(const ctrlm_irdb_vendor_info_t &vendor); + bool ctrlm_irdb_get_vendor_info(ctrlm_irdb_vendor_info_t &info); bool ctrlm_irdb_get_manufacturers(ctrlm_irdb_manufacturer_list_t &manufacturers, ctrlm_irdb_dev_type_t type, const std::string &prefix); diff --git a/src/irdb/ctrlm_irdb_stub.cpp b/src/irdb/ctrlm_irdb_stub.cpp index 898cb4f0..8161e45c 100644 --- a/src/irdb/ctrlm_irdb_stub.cpp +++ b/src/irdb/ctrlm_irdb_stub.cpp @@ -46,6 +46,16 @@ bool STUB_ctrlm_irdb_get_vendor_info(ctrlm_irdb_vendor_info_t &info) XLOGD_ERROR("not implemented"); return(false); } +bool STUB_ctrlm_irdb_get_supported_vendor_info(std::vector &info) +{ + XLOGD_ERROR("not implemented"); + return(false); +} +bool STUB_ctrlm_irdb_set_preferred_vendor(const ctrlm_irdb_vendor_info_t &info) +{ + XLOGD_ERROR("not implemented"); + return(false); +} bool STUB_ctrlm_irdb_get_manufacturers(ctrlm_irdb_manufacturer_list_t &manufacturers, ctrlm_irdb_dev_type_t type, const std::string &prefix) { XLOGD_ERROR("not implemented"); diff --git a/src/irdb/ctrlm_irdb_stub.h b/src/irdb/ctrlm_irdb_stub.h index 477ec9f3..a03f6f83 100644 --- a/src/irdb/ctrlm_irdb_stub.h +++ b/src/irdb/ctrlm_irdb_stub.h @@ -32,6 +32,10 @@ bool STUB_ctrlm_irdb_initialize(); bool STUB_ctrlm_irdb_get_vendor_info(ctrlm_irdb_vendor_info_t &info); +bool STUB_ctrlm_irdb_get_supported_vendor_info(std::vector &info); + +bool STUB_ctrlm_irdb_set_preferred_vendor(const ctrlm_irdb_vendor_info_t &info); + bool STUB_ctrlm_irdb_get_manufacturers(ctrlm_irdb_manufacturer_list_t &manufacturers, ctrlm_irdb_dev_type_t type, const std::string &prefix); bool STUB_ctrlm_irdb_get_models(ctrlm_irdb_model_list_t &models, ctrlm_irdb_dev_type_t type, const std::string &manufacturer, const std::string &prefix);