IDS peak genericC++  v1.4.1
peak_device_manager.hpp
Go to the documentation of this file.
1 
11 #pragma once
12 
18 #include <peak/generic/peak_t_callback_manager.hpp>
24 
25 #include <type_traits>
26 #include <unordered_map>
27 #include <unordered_set>
28 #include <algorithm>
29 #include <atomic>
30 #include <exception>
31 #include <functional>
32 #include <future>
33 #include <iterator>
34 #include <memory>
35 #include <mutex>
36 #include <utility>
37 #include <vector>
38 
39 namespace peak
40 {
41 
68 class DeviceManager final
69 {
70 public:
72  enum class UpdatePolicy
73  {
76  };
78  enum class ResetPolicy
79  {
80  ErrorOnOpenDevices,
81  IgnoreOpenDevices
82  };
83 
85  using SystemFoundCallback = std::function<void(const std::shared_ptr<const core::System>& foundSystem)>;
89  using InterfaceFoundCallback = std::function<void(const std::shared_ptr<const core::Interface>& foundInterface)>;
93  using InterfaceLostCallback = std::function<void(const std::string& lostInterfaceKey)>;
97  using DeviceFoundCallback = std::function<void(const std::shared_ptr<core::DeviceDescriptor>& foundDevice)>;
101  using DeviceLostCallback = std::function<void(const std::string& lostDeviceKey)>;
105  using UpdateErrorCallback = std::function<void(const std::string& errorDescription)>;
106 
112  static DeviceManager& Instance();
113 
130  void AddProducerLibrary(const std::string& ctiPath);
131 
151  const UpdateErrorCallback& errorCallback = UpdateErrorCallback());
194  void SetInterfaceUpdateTimeout(core::Timeout timeout_ms);
218  void SetDeviceUpdateTimeout(core::Timeout timeout_ms);
219 
229  std::vector<std::shared_ptr<const core::System>> Systems() const;
239  std::vector<std::shared_ptr<const core::Interface>> Interfaces() const;
249  std::vector<std::shared_ptr<core::DeviceDescriptor>> Devices() const;
250 
396 
397 private:
398  DeviceManager(); // private ctor, since this is a singleton
399  ~DeviceManager() = default; // private dtor, since this is a singleton
400 
401  DeviceManager(const DeviceManager& other) = delete;
402  DeviceManager& operator=(const DeviceManager& other) = delete;
403  DeviceManager(DeviceManager&& other) = delete;
404  DeviceManager& operator=(DeviceManager&& other) = delete;
405 
406  void GetLostDevicesFromLostInterfaces(
407  const std::unordered_set<std::string>& lostInterfaces, std::vector<std::string>& lostDevices);
408 
409  void TriggerSystemFoundCallbacks(const std::shared_ptr<const core::System>& foundSystem) const;
410  void TriggerInterfaceFoundCallbacks(const std::shared_ptr<const core::Interface>& foundInterface) const;
411  void TriggerInterfaceLostCallbacks(const std::string& lostInterfaceKey) const;
412  void TriggerDeviceFoundCallbacks(const std::shared_ptr<core::DeviceDescriptor>& foundDevice) const;
413  void TriggerDeviceLostCallbacks(const std::string& lostDeviceKey) const;
414 
415  void CheckDevicesOpened() const;
416 
417  std::mutex m_updateMutex;
418  std::atomic<core::Timeout> m_interfaceUpdateTimeout_ms{ 100 };
419  std::atomic<core::Timeout> m_deviceUpdateTimeout_ms{ 300 };
420 
421  std::vector<std::string> m_producerLibrariesToAdd;
422 
423  std::unordered_map<std::string, std::shared_ptr<core::ProducerLibrary>> m_producerLibraries;
424  std::vector<std::shared_ptr<const core::System>> m_systems;
425  std::vector<std::shared_ptr<const core::Interface>> m_interfaces;
426  std::vector<std::shared_ptr<core::DeviceDescriptor>> m_devices;
427 
428  struct OpenedDevice
429  {
430  std::weak_ptr<core::Device> device;
431  std::string displayName;
432  };
433  std::vector<OpenedDevice> m_openedDevices;
434 
435  core::TTriggerCallbackManager<SystemFoundCallbackHandle, SystemFoundCallback> m_systemFoundCallbackManager;
436  core::TTriggerCallbackManager<InterfaceFoundCallbackHandle, InterfaceFoundCallback> m_interfaceFoundCallbackManager;
437  core::TTriggerCallbackManager<InterfaceLostCallbackHandle, InterfaceLostCallback> m_interfaceLostCallbackManager;
438  core::TTriggerCallbackManager<DeviceFoundCallbackHandle, DeviceFoundCallback> m_deviceFoundCallbackManager;
439  core::TTriggerCallbackManager<DeviceLostCallbackHandle, DeviceLostCallback> m_deviceLostCallbackManager;
440 
441  std::mutex m_producerLibrariesToAddMutex;
442  mutable std::mutex m_systemsMutex;
443  mutable std::mutex m_interfacesMutex;
444  mutable std::mutex m_devicesMutex;
445  mutable std::mutex m_openedDevicesMutex;
446 
447 #ifndef _MSC_VER
448  template <typename T,
449  typename std::enable_if<(noexcept(std::declval<T>()())
450  || (std::is_pointer<typename std::decay<T>::type>::value && __cplusplus < 201703L)
451  // NOTE pre c++17 there is no way to check weather a function pointer is noexcept
452  )
453  && std::is_same<void, decltype(std::declval<T>()())>::value && std::is_move_constructible<T>::value
454  && std::is_nothrow_move_constructible<T>::value,
455  int>::type = 0>
456 #else
457  template <typename T>
458 #endif
459  class RAIIGuard
460  {
461  T m_fun;
462 
463  public:
464  RAIIGuard(T&& fun) noexcept
465  : m_fun(std::forward<T>(fun))
466  {}
467  RAIIGuard(RAIIGuard const&) = delete;
468  RAIIGuard(RAIIGuard&& other) noexcept
469  : m_fun(std::move(other.m_fun))
470  {}
471  ~RAIIGuard() noexcept
472  {
473  m_fun();
474  }
475  };
476  template <typename T>
477  static RAIIGuard<T> makeRAIIGuard(T&& fun) noexcept
478  {
479  return { std::forward<T>(fun) };
480  }
481 };
482 
483 } /* namespace peak */
484 
485 /* Implementation */
486 namespace peak
487 {
488 
490 {
491  static DeviceManager deviceManager{};
492  return deviceManager;
493 }
494 
495 inline DeviceManager::DeviceManager()
496 {
497  if (QueryNumericFromCInterfaceFunction<PEAK_BOOL8>([](PEAK_BOOL8* isInitialized) {
498  return PEAK_C_ABI_PREFIX PEAK_Library_IsInitialized(isInitialized);
499  })
500  == 0)
501  {
503  "IDS peak API library not initialized. Call peak::Library::Initialize() / "
504  "PEAK_C_ABI_PREFIX PEAK_InitializeLibrary() before anything else.");
505  }
506 }
507 
508 inline void DeviceManager::AddProducerLibrary(const std::string& ctiPath)
509 {
510  std::lock_guard<std::mutex> lock(m_producerLibrariesToAddMutex);
511 
512  m_producerLibrariesToAdd.emplace_back(ctiPath);
513 }
514 
515 inline void DeviceManager::Update(UpdatePolicy updatePolicy /*= UpdatePolicy::ScanEnvironmentForProducerLibraries*/,
516  const UpdateErrorCallback& errorCallback /*= UpdateErrorCallback()*/)
517 {
518  std::lock_guard<std::mutex> lockUpdate(m_updateMutex);
519 
520  std::vector<std::shared_ptr<core::System>> allFoundSystems;
521  std::vector<std::shared_ptr<core::Interface>> allFoundInterfaces;
522  std::vector<std::string> allLostInterfaces;
523  std::vector<std::shared_ptr<core::DeviceDescriptor>> allFoundDevices;
524  std::vector<std::string> allLostDevices;
525 
526  auto interfaceUpdateTimeout_ms = m_interfaceUpdateTimeout_ms.load();
527  auto deviceUpdateTimeout_ms = m_deviceUpdateTimeout_ms.load();
528 
529  std::vector<std::string> ctiPaths;
530  // We look for all producer libraries in the current environment if we have to
532  {
534  }
535  // We look for the manually added producer libraries
536  {
537  std::lock_guard<std::mutex> lock(m_producerLibrariesToAddMutex);
538 
539  ctiPaths.reserve(ctiPaths.size() + m_producerLibrariesToAdd.size());
540  std::move(
541  std::begin(m_producerLibrariesToAdd), std::end(m_producerLibrariesToAdd), std::back_inserter(ctiPaths));
542 
543  m_producerLibrariesToAdd.clear();
544  }
545  for (const auto& ctiPath : ctiPaths)
546  {
547  if (!m_producerLibraries.count(ctiPath))
548  {
549  try
550  {
551  auto producerLibrary = core::ProducerLibrary::Open(ctiPath);
552  auto system = producerLibrary->System()->OpenSystem();
553 
554  m_producerLibraries.emplace(ctiPath, producerLibrary);
555  allFoundSystems.emplace_back(system);
556  }
557  catch (const core::NotAvailableException&)
558  {
559  // TL not available or not supported.
560  continue;
561  }
562  catch (const core::NotInitializedException&)
563  {
564  // TODO: check this on creation of DeviceManager?
565  throw; // if this exception occurs, nothing else will work. so we stop here
566  }
567  catch (const core::Exception& ex)
568  {
569  if (errorCallback)
570  {
571  try
572  {
573  errorCallback("[CTI - " + ctiPath + "]: " + ex.what());
574  }
575  catch (...)
576  {}
577  }
578  }
579  }
580  }
581 
582  auto interfaceUpdateFunc = [&interfaceUpdateTimeout_ms, &errorCallback](const std::shared_ptr<core::System>& system)
583  -> std::tuple<std::vector<std::shared_ptr<core::Interface>>, std::vector<std::string>> {
584  std::vector<std::shared_ptr<core::Interface>> foundInterfaces;
585  std::vector<std::string> lostInterfaces;
586 
587  try
588  {
589  auto foundCallbackHandle = system->RegisterInterfaceFoundCallback(
590  [&foundInterfaces](const std::shared_ptr<core::InterfaceDescriptor>& foundInterface) {
591  foundInterfaces.emplace_back(foundInterface->OpenInterface());
592  });
593  auto const foundCallbackCleanupGuard = makeRAIIGuard([system, &foundCallbackHandle]() noexcept {
594  try
595  {
596  system->UnregisterInterfaceFoundCallback(foundCallbackHandle);
597  }
598  catch (const core::Exception&)
599  {
600  std::terminate();
601  }
602  });
603 
604  auto keysById = std::unordered_map<std::string, std::string>();
605  for (const auto& iface : system->Interfaces())
606  {
607  keysById.emplace(iface->ID(), iface->Key());
608  }
609  auto lostCallbackHandle = system->RegisterInterfaceLostCallback(
610  [&lostInterfaces, &keysById](const std::string& lostInterfaceId) {
611  auto idKeyPairIt = keysById.find(lostInterfaceId);
612 
613  if (idKeyPairIt != keysById.end())
614  {
615  lostInterfaces.emplace_back((*idKeyPairIt).second);
616  }
617  });
618  auto const lostCallbackCleanupGuard = makeRAIIGuard([system, &lostCallbackHandle]() noexcept {
619  try
620  {
621  system->UnregisterInterfaceLostCallback(lostCallbackHandle);
622  }
623  catch (const core::Exception&)
624  {
625  std::terminate();
626  }
627  });
628 
629  system->UpdateInterfaces(interfaceUpdateTimeout_ms);
630  }
631  catch (const core::Exception& ex)
632  {
633  if (errorCallback)
634  {
635  try
636  {
637  errorCallback("[System - " + system->Key() + "]: " + ex.what());
638  }
639  catch (...)
640  {}
641  }
642  }
643 
644  return std::make_tuple(foundInterfaces, lostInterfaces);
645  };
646 
647  // We do an update on all available systems
648  const std::launch launchPolicy =
649  std::launch::async; // switching this to std::launch::deferred makes debugging easier
650  std::vector<std::future<std::tuple<std::vector<std::shared_ptr<core::Interface>>, std::vector<std::string>>>>
651  interfaceUpdateFutures;
652  for (const auto& system : m_systems)
653  {
654  interfaceUpdateFutures.emplace_back(
655  std::async(launchPolicy, interfaceUpdateFunc, std::const_pointer_cast<core::System>(system)));
656  }
657  for (const auto& system : allFoundSystems)
658  {
659  interfaceUpdateFutures.emplace_back(std::async(launchPolicy, interfaceUpdateFunc, system));
660  }
661  for (auto& future : interfaceUpdateFutures)
662  {
663  auto foundLostInterfacesTuple = future.get();
664  auto foundInterfaces = std::get<0>(foundLostInterfacesTuple);
665  auto lostInterfaces = std::get<1>(foundLostInterfacesTuple);
666  allFoundInterfaces.reserve(allFoundInterfaces.size() + foundInterfaces.size());
667  std::move(std::begin(foundInterfaces), std::end(foundInterfaces), std::back_inserter(allFoundInterfaces));
668  allLostInterfaces.reserve(allLostInterfaces.size() + lostInterfaces.size());
669  std::move(std::begin(lostInterfaces), std::end(lostInterfaces), std::back_inserter(allLostInterfaces));
670  }
671 
672  auto deviceUpdateFunc = [this, &deviceUpdateTimeout_ms, &errorCallback](
673  const std::shared_ptr<core::Interface>& iface)
674  -> std::tuple<std::vector<std::shared_ptr<core::DeviceDescriptor>>, std::vector<std::string>> {
675  std::vector<std::shared_ptr<core::DeviceDescriptor>> foundDevices;
676  std::vector<std::string> lostDevices;
677 
678  try
679  {
680  auto foundCallbackHandle = iface->RegisterDeviceFoundCallback(
681  [this, &foundDevices](const std::shared_ptr<core::DeviceDescriptor>& foundDevice) {
682  foundDevice->RegisterDeviceOpenedCallback(
683  [this](const std::shared_ptr<core::Device>& openedDevice) {
684  std::lock_guard<std::mutex> lock(m_openedDevicesMutex);
685 
686  // clear out closed devices
687  m_openedDevices.erase(std::remove_if(std::begin(m_openedDevices), std::end(m_openedDevices),
688  [](const OpenedDevice& dev) { return dev.device.expired(); }),
689  std::end(m_openedDevices));
690 
691  // add the new one
692  OpenedDevice device;
693  device.device = openedDevice;
694  device.displayName = openedDevice->DisplayName();
695  m_openedDevices.push_back(device);
696  });
697 
698  foundDevices.emplace_back(foundDevice);
699  });
700  auto const foundCallbackCleanupGuard = makeRAIIGuard([iface, &foundCallbackHandle]() noexcept {
701  try
702  {
703  iface->UnregisterDeviceFoundCallback(foundCallbackHandle);
704  }
705  catch (const core::Exception&)
706  {
707  std::terminate();
708  }
709  });
710 
711  auto keysById = std::unordered_map<std::string, std::string>();
712  for (const auto& device : iface->Devices())
713  {
714  keysById.emplace(device->ID(), device->Key());
715  }
716  auto lostCallbackHandle = iface->RegisterDeviceLostCallback(
717  [&lostDevices, &keysById](const std::string& lostDeviceId) {
718  auto idKeyPairIt = keysById.find(lostDeviceId);
719 
720  if (idKeyPairIt != keysById.end())
721  {
722  lostDevices.emplace_back((*idKeyPairIt).second);
723  }
724  });
725  auto const lostCallbackCleanupGuard = makeRAIIGuard([iface, &lostCallbackHandle]() noexcept {
726  try
727  {
728  iface->UnregisterDeviceLostCallback(lostCallbackHandle);
729  }
730  catch (const core::Exception&)
731  {
732  std::terminate();
733  }
734  });
735 
736  iface->UpdateDevices(deviceUpdateTimeout_ms);
737  }
738  catch (const core::Exception& ex)
739  {
740  if (errorCallback)
741  {
742  try
743  {
744  errorCallback("[Interface - " + iface->Key() + "]: " + ex.what());
745  }
746  catch (...)
747  {}
748  }
749  }
750 
751  return std::make_tuple(foundDevices, lostDevices);
752  };
753 
754  // We do an update on all available interfaces
755  std::vector<std::future<std::tuple<std::vector<std::shared_ptr<core::DeviceDescriptor>>, std::vector<std::string>>>>
756  deviceUpdateFutures;
757  for (const auto& iface : m_interfaces)
758  {
759  deviceUpdateFutures.emplace_back(
760  std::async(launchPolicy, deviceUpdateFunc, std::const_pointer_cast<core::Interface>(iface)));
761  }
762  for (const auto& iface : allFoundInterfaces)
763  {
764  deviceUpdateFutures.emplace_back(std::async(launchPolicy, deviceUpdateFunc, iface));
765  }
766  for (auto& future : deviceUpdateFutures)
767  {
768  auto foundLostDevicesTuple = future.get();
769  auto foundDevices = std::get<0>(foundLostDevicesTuple);
770  auto lostDevices = std::get<1>(foundLostDevicesTuple);
771  allFoundDevices.reserve(allFoundDevices.size() + foundDevices.size());
772  std::move(std::begin(foundDevices), std::end(foundDevices), std::back_inserter(allFoundDevices));
773  allLostDevices.reserve(allLostDevices.size() + lostDevices.size());
774  std::move(std::begin(lostDevices), std::end(lostDevices), std::back_inserter(allLostDevices));
775  }
776 
777  // We trigger all callbacks
778  for (const auto& foundSystem : allFoundSystems)
779  {
780  TriggerSystemFoundCallbacks(foundSystem);
781  }
782 
783  for (const auto& foundInterface : allFoundInterfaces)
784  {
785  TriggerInterfaceFoundCallbacks(foundInterface);
786  }
787  std::unordered_set<std::string> allLostInterfacesLookUp;
788  for (const auto& lostInterfaceKey : allLostInterfaces)
789  {
790  TriggerInterfaceLostCallbacks(lostInterfaceKey);
791  allLostInterfacesLookUp.emplace(lostInterfaceKey);
792  }
793 
794  for (const auto& foundDevice : allFoundDevices)
795  {
796  TriggerDeviceFoundCallbacks(foundDevice);
797  }
798  GetLostDevicesFromLostInterfaces(allLostInterfacesLookUp, allLostDevices);
799  for (const auto& lostDeviceKey : allLostDevices)
800  {
801  TriggerDeviceLostCallbacks(lostDeviceKey);
802  }
803 
804  // We apply the update changes to our internal lists
805  {
806  std::lock_guard<std::mutex> lock(m_systemsMutex);
807  std::lock_guard<std::mutex> lock2(m_interfacesMutex);
808  std::lock_guard<std::mutex> lock3(m_devicesMutex);
809 
810  m_systems.reserve(m_systems.size() + allFoundSystems.size());
811  std::move(std::begin(allFoundSystems), std::end(allFoundSystems), std::back_inserter(m_systems));
812 
813  for (const auto& lostInterfaceKey : allLostInterfaces)
814  {
815  m_interfaces.erase(std::find_if(std::begin(m_interfaces), std::end(m_interfaces),
816  [&lostInterfaceKey](const std::shared_ptr<const core::Interface>& interfaceToCheck) -> bool {
817  return interfaceToCheck->Key() == lostInterfaceKey;
818  }));
819  }
820  m_interfaces.reserve(m_interfaces.size() + allFoundInterfaces.size());
821  std::move(std::begin(allFoundInterfaces), std::end(allFoundInterfaces), std::back_inserter(m_interfaces));
822 
823  for (const auto& lostDeviceKey : allLostDevices)
824  {
825  m_devices.erase(std::find_if(std::begin(m_devices), std::end(m_devices),
826  [&lostDeviceKey](const std::shared_ptr<core::DeviceDescriptor>& deviceToCheck) -> bool {
827  return deviceToCheck->Key() == lostDeviceKey;
828  }));
829  }
830  m_devices.reserve(m_devices.size() + allFoundDevices.size());
831  std::move(std::begin(allFoundDevices), std::end(allFoundDevices), std::back_inserter(m_devices));
832  }
833 }
834 
835 inline void DeviceManager::Reset(ResetPolicy resetPolicy)
836 {
837  std::lock_guard<std::mutex> lockUpdate(m_updateMutex);
838 
839  if (resetPolicy == ResetPolicy::ErrorOnOpenDevices)
840  {
841  // check if any devices are running
842  CheckDevicesOpened();
843  }
844 
845  {
846  std::lock_guard<std::mutex> lock(m_systemsMutex);
847  std::lock_guard<std::mutex> lock2(m_interfacesMutex);
848  std::lock_guard<std::mutex> lock3(m_devicesMutex);
849 
850  for (const auto& lostDevice : m_devices)
851  {
852  TriggerDeviceLostCallbacks(lostDevice->Key());
853  }
854  m_devices.clear();
855 
856  for (const auto& lostInterface : m_interfaces)
857  {
858  TriggerInterfaceLostCallbacks(lostInterface->Key());
859  }
860  m_interfaces.clear();
861 
862  m_systems.clear();
863  m_producerLibraries.clear();
864  }
865 
866  {
867  std::lock_guard<std::mutex> lock(m_producerLibrariesToAddMutex);
868  m_producerLibrariesToAdd.clear();
869  }
870 }
871 
872 inline void DeviceManager::CheckDevicesOpened() const
873 {
874  size_t openDevicesFound = 0;
875  std::string deviceDisplayNames;
876 
877  {
878  std::lock_guard<std::mutex> lock(m_openedDevicesMutex);
879 
880  for (const auto& openedDevice : m_openedDevices)
881  {
882  auto openDevice = openedDevice.device.lock();
883  if (openDevice)
884  {
885  ++openDevicesFound;
886  deviceDisplayNames += openedDevice.displayName;
887  deviceDisplayNames += " ";
888  }
889  }
890  }
891 
892  if (openDevicesFound > 0)
893  {
895  "Can't reset the device manager while there are devices open. The following devices ("
896  + std::to_string(openDevicesFound) + ") are open: " + deviceDisplayNames);
897  }
898 }
899 
901 {
902  return m_interfaceUpdateTimeout_ms;
903 }
904 
906 {
907  m_interfaceUpdateTimeout_ms = timeout_ms;
908 }
909 
911 {
912  return m_deviceUpdateTimeout_ms;
913 }
914 
916 {
917  m_deviceUpdateTimeout_ms = timeout_ms;
918 }
919 
920 inline std::vector<std::shared_ptr<const core::System>> DeviceManager::Systems() const
921 {
922  std::lock_guard<std::mutex> lock(m_systemsMutex);
923 
924  return m_systems;
925 }
926 
927 inline std::vector<std::shared_ptr<const core::Interface>> DeviceManager::Interfaces() const
928 {
929  std::lock_guard<std::mutex> lock(m_interfacesMutex);
930 
931  return m_interfaces;
932 }
933 
934 inline std::vector<std::shared_ptr<core::DeviceDescriptor>> DeviceManager::Devices() const
935 {
936  std::lock_guard<std::mutex> lock(m_devicesMutex);
937 
938  return m_devices;
939 }
940 
942  const DeviceManager::SystemFoundCallback& callback)
943 {
944  return m_systemFoundCallbackManager.RegisterCallback(callback);
945 }
946 
948 {
949  m_systemFoundCallbackManager.UnregisterCallback(callbackHandle);
950 }
951 
954 {
955  return m_interfaceFoundCallbackManager.RegisterCallback(callback);
956 }
957 
959 {
960  m_interfaceFoundCallbackManager.UnregisterCallback(callbackHandle);
961 }
962 
964  const DeviceManager::InterfaceLostCallback& callback)
965 {
966  return m_interfaceLostCallbackManager.RegisterCallback(callback);
967 }
968 
970 {
971  m_interfaceLostCallbackManager.UnregisterCallback(callbackHandle);
972 }
973 
975  const DeviceManager::DeviceFoundCallback& callback)
976 {
977  return m_deviceFoundCallbackManager.RegisterCallback(callback);
978 }
979 
981 {
982  m_deviceFoundCallbackManager.UnregisterCallback(callbackHandle);
983 }
984 
986  const DeviceManager::DeviceLostCallback& callback)
987 {
988  return m_deviceLostCallbackManager.RegisterCallback(callback);
989 }
990 
992 {
993  m_deviceLostCallbackManager.UnregisterCallback(callbackHandle);
994 }
995 
996 inline void DeviceManager::GetLostDevicesFromLostInterfaces(
997  const std::unordered_set<std::string>& lostInterfaces, std::vector<std::string>& lostDevices)
998 {
999  std::lock_guard<std::mutex> lock(m_devicesMutex);
1000 
1001  for (const auto& device : m_devices)
1002  {
1003  if (lostInterfaces.count(device->ParentInterface()->Key()))
1004  {
1005  lostDevices.emplace_back(device->Key());
1006  }
1007  }
1008 }
1009 
1010 inline void DeviceManager::TriggerSystemFoundCallbacks(const std::shared_ptr<const core::System>& foundSystem) const
1011 {
1012  m_systemFoundCallbackManager.TriggerCallbacks(foundSystem);
1013 }
1014 
1015 inline void DeviceManager::TriggerInterfaceFoundCallbacks(
1016  const std::shared_ptr<const core::Interface>& foundInterface) const
1017 {
1018  m_interfaceFoundCallbackManager.TriggerCallbacks(foundInterface);
1019 }
1020 
1021 inline void DeviceManager::TriggerInterfaceLostCallbacks(const std::string& lostInterfaceKey) const
1022 {
1023  m_interfaceLostCallbackManager.TriggerCallbacks(lostInterfaceKey);
1024 }
1025 
1026 inline void DeviceManager::TriggerDeviceFoundCallbacks(const std::shared_ptr<core::DeviceDescriptor>& foundDevice) const
1027 {
1028  m_deviceFoundCallbackManager.TriggerCallbacks(foundDevice);
1029 }
1030 
1031 inline void DeviceManager::TriggerDeviceLostCallbacks(const std::string& lostDeviceKey) const
1032 {
1033  m_deviceLostCallbackManager.TriggerCallbacks(lostDeviceKey);
1034 }
1035 
1036 } /* namespace peak */
std::function< void(const std::string &errorDescription)> UpdateErrorCallback
Definition: peak_device_manager.hpp:105
void AddProducerLibrary(const std::string &ctiPath)
Adds the given producer library (CTI).
Definition: peak_device_manager.hpp:508
std::function< void(const std::string &lostInterfaceKey)> InterfaceLostCallback
Definition: peak_device_manager.hpp:93
static std::shared_ptr< ProducerLibrary > Open(const std::string &ctiPath)
Opens the given producer library (CTI).
Definition: peak_producer_library.hpp:109
std::vector< std::shared_ptr< core::DeviceDescriptor > > Devices() const
Returns the found devices.
Definition: peak_device_manager.hpp:934
int8_t PEAK_BOOL8
Definition: peak_backend.h:26
void SetDeviceUpdateTimeout(core::Timeout timeout_ms)
Sets the device update timeout.
Definition: peak_device_manager.hpp:915
UpdatePolicy
Enum holding the possible update policies.
Definition: peak_device_manager.hpp:72
ResetPolicy
Enum holding the possible reset policies.
Definition: peak_device_manager.hpp:78
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition: peak_dynamic_loader.h:32
DeviceLostCallbackHandle RegisterDeviceLostCallback(const DeviceLostCallback &callback)
Registers a callback for signaling a lost device.
Definition: peak_device_manager.hpp:985
The exception thrown for signaling that the library was not initialized.
Definition: peak_exception.hpp:123
std::function< void(const std::shared_ptr< const core::Interface > &foundInterface)> InterfaceFoundCallback
Definition: peak_device_manager.hpp:89
std::vector< std::shared_ptr< const core::Interface > > Interfaces() const
Returns the found and opened interfaces.
Definition: peak_device_manager.hpp:927
InterfaceLostCallback * InterfaceLostCallbackHandle
Definition: peak_device_manager.hpp:95
std::function< void(const std::shared_ptr< const core::System > &foundSystem)> SystemFoundCallback
Definition: peak_device_manager.hpp:85
SystemFoundCallbackHandle RegisterSystemFoundCallback(const SystemFoundCallback &callback)
Registers a callback for signaling a found system.
Definition: peak_device_manager.hpp:941
void Reset(ResetPolicy resetPolicy=ResetPolicy::ErrorOnOpenDevices)
Resets the DeviceManager.
Definition: peak_device_manager.hpp:835
void UnregisterSystemFoundCallback(SystemFoundCallbackHandle callbackHandle)
Unregisters a system found callback.
Definition: peak_device_manager.hpp:947
core::Timeout InterfaceUpdateTimeout() const
Returns the interface update timeout.
Definition: peak_device_manager.hpp:900
void UnregisterInterfaceFoundCallback(InterfaceFoundCallbackHandle callbackHandle)
Unregisters a interface found callback.
Definition: peak_device_manager.hpp:958
InterfaceFoundCallbackHandle RegisterInterfaceFoundCallback(const InterfaceFoundCallback &callback)
Registers a callback for signaling a found interface.
Definition: peak_device_manager.hpp:952
PEAK_C_API PEAK_Library_IsInitialized(PEAK_BOOL8 *isInitialized)
Checks if the IDS peak API library is initialized.
void Update(UpdatePolicy updatePolicy=UpdatePolicy::ScanEnvironmentForProducerLibraries, const UpdateErrorCallback &errorCallback=UpdateErrorCallback())
Starts an update.
Definition: peak_device_manager.hpp:515
static std::vector< std::string > CollectCTIPaths()
Collects producer library paths found in the current environment.
Definition: peak_environment_inspector.hpp:71
DeviceLostCallback * DeviceLostCallbackHandle
Definition: peak_device_manager.hpp:103
Represents a timeout value in milliseconds.
Definition: peak_timeout.hpp:30
The exception thrown for internal errors.
Definition: peak_exception.hpp:57
The base class for all exceptions thrown by the library.
Definition: peak_exception.hpp:25
DeviceFoundCallbackHandle RegisterDeviceFoundCallback(const DeviceFoundCallback &callback)
Registers a callback for signaling a found device.
Definition: peak_device_manager.hpp:974
The global DeviceManager (singleton) searches all installed producer libraries (*.cti) and enumerates the modules contained in them.
Definition: peak_device_manager.hpp:68
std::function< void(const std::shared_ptr< core::DeviceDescriptor > &foundDevice)> DeviceFoundCallback
Definition: peak_device_manager.hpp:97
#define PEAK_C_ABI_PREFIX
Definition: peak_dll_defines.h:16
static DeviceManager & Instance()
Returns the global DeviceManager.
Definition: peak_device_manager.hpp:489
InterfaceLostCallbackHandle RegisterInterfaceLostCallback(const InterfaceLostCallback &callback)
Registers a callback for signaling a lost interface.
Definition: peak_device_manager.hpp:963
std::function< void(const std::string &lostDeviceKey)> DeviceLostCallback
Definition: peak_device_manager.hpp:101
void UnregisterDeviceLostCallback(DeviceLostCallbackHandle callbackHandle)
Unregisters a device lost callback.
Definition: peak_device_manager.hpp:991
SystemFoundCallback * SystemFoundCallbackHandle
Definition: peak_device_manager.hpp:87
The exception thrown for signaling a feature is not available in the device.
Definition: peak_exception.hpp:97
InterfaceFoundCallback * InterfaceFoundCallbackHandle
Definition: peak_device_manager.hpp:91
DeviceFoundCallback * DeviceFoundCallbackHandle
Definition: peak_device_manager.hpp:99
std::vector< std::shared_ptr< const core::System > > Systems() const
Returns the found and opened systems.
Definition: peak_device_manager.hpp:920
void UnregisterInterfaceLostCallback(InterfaceLostCallbackHandle callbackHandle)
Unregisters an interface lost callback.
Definition: peak_device_manager.hpp:969
core::Timeout DeviceUpdateTimeout() const
Returns the device update timeout.
Definition: peak_device_manager.hpp:910
void UnregisterDeviceFoundCallback(DeviceFoundCallbackHandle callbackHandle)
Unregisters a device found callback.
Definition: peak_device_manager.hpp:980
void SetInterfaceUpdateTimeout(core::Timeout timeout_ms)
Sets the interface update timeout.
Definition: peak_device_manager.hpp:905