221 if (CPrivateBase::m_interface->globalSingleInstance !=
nullptr)
222 throw std::logic_error(
"kodi::addon::CInstancePeripheral: Creation of more as one in single "
223 "instance way is not allowed!");
225 SetAddonStruct(CPrivateBase::m_interface->firstKodiInstance);
226 CPrivateBase::m_interface->globalSingleInstance =
this;
266 if (CPrivateBase::m_interface->globalSingleInstance !=
nullptr)
267 throw std::logic_error(
"kodi::addon::CInstancePeripheral: Creation of multiple together with "
268 "single instance way is not allowed!");
270 SetAddonStruct(instance);
342 std::vector<std::shared_ptr<kodi::addon::Peripheral>>& scan_results)
423 std::string& controllerId)
440 const std::string& controllerId)
458 const std::string& controller_id,
459 std::vector<kodi::addon::JoystickFeature>& features)
475 const std::string& controller_id,
476 const std::vector<kodi::addon::JoystickFeature>& features)
508 const std::vector<kodi::addon::DriverPrimitive>& primitives)
535 const std::string& controller_id)
561 const std::string
AddonPath()
const {
return m_instanceData->props->addon_path; }
573 const std::string
UserPath()
const {
return m_instanceData->props->user_path; }
583 return m_instanceData->toKodi->trigger_scan(m_instanceData->toKodi->kodiInstance);
595 void RefreshButtonMaps(
const std::string& deviceName =
"",
const std::string& controllerId =
"")
597 return m_instanceData->toKodi->refresh_button_maps(m_instanceData->toKodi->kodiInstance,
598 deviceName.c_str(), controllerId.c_str());
614 return m_instanceData->toKodi->feature_count(m_instanceData->toKodi->kodiInstance,
615 controllerId.c_str(), type);
629 return m_instanceData->toKodi->feature_type(m_instanceData->toKodi->kodiInstance,
630 controllerId.c_str(), featureName.c_str());
639 instance->hdl =
this;
641 instance->peripheral->toAddon->get_capabilities = ADDON_GetCapabilities;
642 instance->peripheral->toAddon->perform_device_scan = ADDON_PerformDeviceScan;
643 instance->peripheral->toAddon->free_scan_results = ADDON_FreeScanResults;
644 instance->peripheral->toAddon->get_events = ADDON_GetEvents;
645 instance->peripheral->toAddon->free_events = ADDON_FreeEvents;
646 instance->peripheral->toAddon->send_event = ADDON_SendEvent;
648 instance->peripheral->toAddon->get_joystick_info = ADDON_GetJoystickInfo;
649 instance->peripheral->toAddon->free_joystick_info = ADDON_FreeJoystickInfo;
650 instance->peripheral->toAddon->get_appearance = ADDON_GetAppearance;
651 instance->peripheral->toAddon->set_appearance = ADDON_SetAppearance;
652 instance->peripheral->toAddon->get_features = ADDON_GetFeatures;
653 instance->peripheral->toAddon->free_features = ADDON_FreeFeatures;
654 instance->peripheral->toAddon->map_features = ADDON_MapFeatures;
655 instance->peripheral->toAddon->get_ignored_primitives = ADDON_GetIgnoredPrimitives;
656 instance->peripheral->toAddon->free_primitives = ADDON_FreePrimitives;
657 instance->peripheral->toAddon->set_ignored_primitives = ADDON_SetIgnoredPrimitives;
658 instance->peripheral->toAddon->save_button_map = ADDON_SaveButtonMap;
659 instance->peripheral->toAddon->revert_button_map = ADDON_RevertButtonMap;
660 instance->peripheral->toAddon->reset_button_map = ADDON_ResetButtonMap;
661 instance->peripheral->toAddon->power_off_joystick = ADDON_PowerOffJoystick;
663 m_instanceData = instance->peripheral;
664 m_instanceData->toAddon->addonInstance =
this;
670 if (!addonInstance || !capabilities)
674 static_cast<CInstancePeripheral*
>(addonInstance->toAddon->addonInstance)
675 ->GetCapabilities(peripheralCapabilities);
680 unsigned int* peripheral_count,
683 if (!addonInstance || !peripheral_count || !scan_results)
686 std::vector<std::shared_ptr<kodi::addon::Peripheral>> peripherals;
687 PERIPHERAL_ERROR err =
static_cast<CInstancePeripheral*
>(addonInstance->toAddon->addonInstance)
688 ->PerformDeviceScan(peripherals);
691 *peripheral_count =
static_cast<unsigned int>(peripherals.size());
692 kodi::addon::Peripherals::ToStructs(peripherals, scan_results);
699 unsigned int peripheral_count,
705 kodi::addon::Peripherals::FreeStructs(peripheral_count, scan_results);
709 unsigned int* event_count,
712 if (!addonInstance || !event_count || !events)
715 std::vector<kodi::addon::PeripheralEvent> peripheralEvents;
716 PERIPHERAL_ERROR err =
static_cast<CInstancePeripheral*
>(addonInstance->toAddon->addonInstance)
717 ->GetEvents(peripheralEvents);
720 *event_count =
static_cast<unsigned int>(peripheralEvents.size());
721 kodi::addon::PeripheralEvents::ToStructs(peripheralEvents, events);
728 unsigned int event_count,
734 kodi::addon::PeripheralEvents::FreeStructs(event_count, events);
740 if (!addonInstance || !event)
742 return static_cast<CInstancePeripheral*
>(addonInstance->toAddon->addonInstance)
749 if (!addonInstance || !info)
753 PERIPHERAL_ERROR err =
static_cast<CInstancePeripheral*
>(addonInstance->toAddon->addonInstance)
754 ->GetJoystickInfo(index, addonInfo);
757 addonInfo.ToStruct(*info);
769 kodi::addon::Joystick::FreeStruct(*info);
775 unsigned int bufferSize)
777 if (addonInstance ==
nullptr || joystick ==
nullptr || buffer ==
nullptr || bufferSize == 0)
781 std::string controllerId;
783 PERIPHERAL_ERROR err =
static_cast<CInstancePeripheral*
>(addonInstance->toAddon->addonInstance)
784 ->GetAppearance(addonJoystick, controllerId);
787 std::strncpy(buffer, controllerId.c_str(), bufferSize - 1);
788 buffer[bufferSize - 1] =
'\0';
796 const char* controllerId)
798 if (addonInstance ==
nullptr || joystick ==
nullptr || controllerId ==
nullptr)
802 std::string strControllerId(controllerId);
804 return static_cast<CInstancePeripheral*
>(addonInstance->toAddon->addonInstance)
805 ->SetAppearance(addonJoystick, strControllerId);
810 const char* controller_id,
811 unsigned int* feature_count,
814 if (!addonInstance || !joystick || !controller_id || !feature_count || !features)
818 std::vector<kodi::addon::JoystickFeature> featuresVector;
820 PERIPHERAL_ERROR err =
static_cast<CInstancePeripheral*
>(addonInstance->toAddon->addonInstance)
821 ->GetFeatures(addonJoystick, controller_id, featuresVector);
824 *feature_count =
static_cast<unsigned int>(featuresVector.size());
825 kodi::addon::JoystickFeatures::ToStructs(featuresVector, features);
832 unsigned int feature_count,
838 kodi::addon::JoystickFeatures::FreeStructs(feature_count, features);
843 const char* controller_id,
844 unsigned int feature_count,
847 if (!addonInstance || !joystick || !controller_id || (feature_count > 0 && !features))
851 std::vector<kodi::addon::JoystickFeature> primitiveVector;
853 for (
unsigned int i = 0; i < feature_count; i++)
854 primitiveVector.emplace_back(*(features + i));
856 return static_cast<CInstancePeripheral*
>(addonInstance->toAddon->addonInstance)
857 ->MapFeatures(addonJoystick, controller_id, primitiveVector);
863 unsigned int* primitive_count,
866 if (!addonInstance || !joystick || !primitive_count || !primitives)
870 std::vector<kodi::addon::DriverPrimitive> primitiveVector;
872 PERIPHERAL_ERROR err =
static_cast<CInstancePeripheral*
>(addonInstance->toAddon->addonInstance)
873 ->GetIgnoredPrimitives(addonJoystick, primitiveVector);
876 *primitive_count =
static_cast<unsigned int>(primitiveVector.size());
877 kodi::addon::DriverPrimitives::ToStructs(primitiveVector, primitives);
884 unsigned int primitive_count,
890 kodi::addon::DriverPrimitives::FreeStructs(primitive_count, primitives);
896 unsigned int primitive_count,
899 if (!addonInstance || !joystick || (primitive_count > 0 && !primitives))
903 std::vector<kodi::addon::DriverPrimitive> primitiveVector;
905 for (
unsigned int i = 0; i < primitive_count; i++)
906 primitiveVector.emplace_back(*(primitives + i));
908 return static_cast<CInstancePeripheral*
>(addonInstance->toAddon->addonInstance)
909 ->SetIgnoredPrimitives(addonJoystick, primitiveVector);
915 if (!addonInstance || !joystick)
919 static_cast<CInstancePeripheral*
>(addonInstance->toAddon->addonInstance)
920 ->SaveButtonMap(addonJoystick);
926 if (!addonInstance || !joystick)
930 static_cast<CInstancePeripheral*
>(addonInstance->toAddon->addonInstance)
931 ->RevertButtonMap(addonJoystick);
936 const char* controller_id)
938 if (!addonInstance || !joystick || !controller_id)
942 static_cast<CInstancePeripheral*
>(addonInstance->toAddon->addonInstance)
943 ->ResetButtonMap(addonJoystick, controller_id);
952 static_cast<CInstancePeripheral*
>(addonInstance->toAddon->addonInstance)
953 ->PowerOffJoystick(index);