IDS peak genericC++  v1.4.1
peak_producer_library.hpp
Go to the documentation of this file.
1 
11 #pragma once
12 
13 
15 #include <peak/dll_interface/peak_dll_interface_util.hpp>
18 
19 #include <cstdint>
20 #include <memory>
21 #include <string>
22 #include <vector>
23 
24 
25 namespace peak
26 {
27 namespace core
28 {
29 
37  : public InitOnce
38  , public std::enable_shared_from_this<ProducerLibrary>
39 {
40 public:
41  ProducerLibrary() = delete;
43  ProducerLibrary(const ProducerLibrary& other) = delete;
44  ProducerLibrary& operator=(const ProducerLibrary& other) = delete;
45  ProducerLibrary(ProducerLibrary&& other) = delete;
46  ProducerLibrary& operator=(ProducerLibrary&& other) = delete;
47 
60  static std::shared_ptr<ProducerLibrary> Open(const std::string& ctiPath);
61 
73  std::string Key() const;
74 
87  std::shared_ptr<SystemDescriptor> System() const;
88 
89 private:
90  friend ClassCreator<ProducerLibrary>;
91  explicit ProducerLibrary(PEAK_PRODUCER_LIBRARY_HANDLE producerLibraryHandle);
92  PEAK_PRODUCER_LIBRARY_HANDLE m_backendHandle;
93 
94  void Initialize() const override;
95  mutable std::shared_ptr<SystemDescriptor> m_system;
96 
97  std::string m_key;
98 };
99 
100 } /* namespace core */
101 } /* namespace peak */
102 
103 /* Implementation */
104 namespace peak
105 {
106 namespace core
107 {
108 
109 inline std::shared_ptr<ProducerLibrary> ProducerLibrary::Open(const std::string& ctiPath)
110 {
111  auto producerLibraryHandle = QueryNumericFromCInterfaceFunction<PEAK_PRODUCER_LIBRARY_HANDLE>(
112  [&](PEAK_PRODUCER_LIBRARY_HANDLE* _producerLibraryHandle) {
114  ctiPath.c_str(), ctiPath.size() + 1, _producerLibraryHandle);
115  });
116 
117  return std::make_shared<ClassCreator<ProducerLibrary>>(producerLibraryHandle);
118 }
119 
121  : m_backendHandle(producerLibraryHandle)
122  , m_system()
123  , m_key(QueryStringFromCInterfaceFunction([&](char* key, size_t* keySize) {
124  return PEAK_C_ABI_PREFIX PEAK_ProducerLibrary_GetKey(producerLibraryHandle, key, keySize);
125  }))
126 {}
127 
129 {
130  (void)PEAK_C_ABI_PREFIX PEAK_ProducerLibrary_Destruct(m_backendHandle);
131 }
132 
133 inline std::string ProducerLibrary::Key() const
134 {
135  return m_key;
136 }
137 
138 inline std::shared_ptr<SystemDescriptor> ProducerLibrary::System() const
139 {
140  InitializeIfNecessary();
141 
142  return m_system;
143 }
144 
145 inline void ProducerLibrary::Initialize() const
146 {
147  auto systemDescriptorHandle = QueryNumericFromCInterfaceFunction<PEAK_SYSTEM_DESCRIPTOR_HANDLE>(
148  [&](PEAK_SYSTEM_DESCRIPTOR_HANDLE* _systemDescriptorHandle) {
149  return PEAK_C_ABI_PREFIX PEAK_ProducerLibrary_GetSystem(m_backendHandle, _systemDescriptorHandle);
150  });
151 
152  m_system = std::make_shared<ClassCreator<SystemDescriptor>>(
153  systemDescriptorHandle, std::const_pointer_cast<ProducerLibrary>(shared_from_this()));
154 }
155 
156 } /* namespace core */
157 } /* namespace peak */
struct PEAK_PRODUCER_LIBRARY * PEAK_PRODUCER_LIBRARY_HANDLE
Definition: peak_backend.h:345
static std::shared_ptr< ProducerLibrary > Open(const std::string &ctiPath)
Opens the given producer library (CTI).
Definition: peak_producer_library.hpp:109
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition: peak_dynamic_loader.h:32
std::string Key() const
Returns the unique key.
Definition: peak_producer_library.hpp:133
PEAK_C_API PEAK_ProducerLibrary_GetSystem(PEAK_PRODUCER_LIBRARY_HANDLE producerLibraryHandle, PEAK_SYSTEM_DESCRIPTOR_HANDLE *systemDescriptorHandle)
Asks the given producer library for its system descriptor.
PEAK_C_API PEAK_ProducerLibrary_GetKey(PEAK_PRODUCER_LIBRARY_HANDLE producerLibraryHandle, char *key, size_t *keySize)
Asks the given producer library for its key.
PEAK_C_API PEAK_ProducerLibrary_Construct(const char *ctiPath, size_t ctiPathSize, PEAK_PRODUCER_LIBRARY_HANDLE *producerLibraryHandle)
Creates a producer library.
ProducerLibrary & operator=(const ProducerLibrary &other)=delete
std::shared_ptr< SystemDescriptor > System() const
Returns the system descriptor.
Definition: peak_producer_library.hpp:138
struct PEAK_SYSTEM_DESCRIPTOR * PEAK_SYSTEM_DESCRIPTOR_HANDLE
Definition: peak_backend.h:349
PEAK_C_API PEAK_ProducerLibrary_Destruct(PEAK_PRODUCER_LIBRARY_HANDLE producerLibraryHandle)
Destroys the given producer library.
#define PEAK_C_ABI_PREFIX
Definition: peak_dll_defines.h:16
Represents a GenTL producer library (CTI).
Definition: peak_producer_library.hpp:36
~ProducerLibrary()
Definition: peak_producer_library.hpp:128