IDS peak genericC++  v1.6.1
peak_interface_descriptor.hpp
Go to the documentation of this file.
1 
11 #pragma once
12 
13 
17 #include <peak/dll_interface/peak_dll_interface_util.hpp>
19 
20 #include <cstdint>
21 #include <memory>
22 #include <string>
23 
24 
25 namespace peak
26 {
27 namespace core
28 {
29 
30 class System;
31 
40 {
41 public:
42  InterfaceDescriptor() = delete;
43  ~InterfaceDescriptor() override = default;
44  InterfaceDescriptor(const InterfaceDescriptor& other) = delete;
45  InterfaceDescriptor& operator=(const InterfaceDescriptor& other) = delete;
46  InterfaceDescriptor(InterfaceDescriptor&& other) = delete;
48 
50  std::string Key() const;
51 
53  RawInformation Info(int32_t infoCommand) const;
64  std::string DisplayName() const;
66  std::string TLType() const;
67 
78  std::shared_ptr<System> ParentSystem() const;
79 
90  std::shared_ptr<Interface> OpenInterface();
100  std::shared_ptr<Interface> OpenedInterface() const;
101 
102 private:
103  PEAK_MODULE_DESCRIPTOR_HANDLE ModuleDescriptorHandle() const override;
104 
105  friend ClassCreator<InterfaceDescriptor>;
107  PEAK_INTERFACE_DESCRIPTOR_HANDLE interfaceDescriptorHandle, const std::weak_ptr<System>& parentSystem);
108  PEAK_INTERFACE_DESCRIPTOR_HANDLE m_backendHandle;
109 
110  std::weak_ptr<System> m_parentSystem;
111  std::weak_ptr<Interface> m_openedInterface;
112 
113  std::string m_key;
114 };
115 
116 } /* namespace core */
117 } /* namespace peak */
118 
119 /* Implementation */
120 namespace peak
121 {
122 namespace core
123 {
124 
126  PEAK_INTERFACE_DESCRIPTOR_HANDLE interfaceDescriptorHandle, const std::weak_ptr<System>& parentSystem)
127  : m_backendHandle(interfaceDescriptorHandle)
128  , m_parentSystem(parentSystem)
129  , m_key(QueryStringFromCInterfaceFunction([&](char* key, size_t* keySize) {
130  return PEAK_C_ABI_PREFIX PEAK_InterfaceDescriptor_GetKey(interfaceDescriptorHandle, key, keySize);
131  }))
132 {}
133 
134 inline std::string InterfaceDescriptor::Key() const
135 {
136  return m_key;
137 }
138 
139 inline RawInformation InterfaceDescriptor::Info(int32_t infoCommand) const
140 {
141  return QueryRawInformationFromCInterfaceFunction([&](int32_t* dataType, uint8_t* buffer, size_t* bufferSize) {
143  m_backendHandle, infoCommand, dataType, buffer, bufferSize);
144  });
145 }
146 
147 inline std::string InterfaceDescriptor::DisplayName() const
148 {
149  return QueryStringFromCInterfaceFunction([&](char* displayName, size_t* displayNameSize) {
151  m_backendHandle, displayName, displayNameSize);
152  });
153 }
154 
155 inline std::string InterfaceDescriptor::TLType() const
156 {
157  return QueryStringFromCInterfaceFunction([&](char* tlType, size_t* tlTypeSize) {
158  return PEAK_C_ABI_PREFIX PEAK_InterfaceDescriptor_GetTLType(m_backendHandle, tlType, tlTypeSize);
159  });
160 }
161 
162 inline std::shared_ptr<System> InterfaceDescriptor::ParentSystem() const
163 {
164  return LockOrThrow(m_parentSystem);
165 }
166 
167 inline std::shared_ptr<Interface> InterfaceDescriptor::OpenInterface()
168 {
169  auto interfaceHandle = QueryNumericFromCInterfaceFunction<PEAK_INTERFACE_HANDLE>(
170  [&](PEAK_INTERFACE_HANDLE* _interfaceHandle) {
171  return PEAK_C_ABI_PREFIX PEAK_InterfaceDescriptor_OpenInterface(m_backendHandle, _interfaceHandle);
172  });
173 
174  auto interface_ = std::make_shared<ClassCreator<Interface>>(interfaceHandle, m_parentSystem);
175  m_openedInterface = interface_;
176  return interface_;
177 }
178 
179 inline std::shared_ptr<Interface> InterfaceDescriptor::OpenedInterface() const
180 {
181  return LockOrThrowOpenedModule(m_openedInterface);
182 }
183 
184 inline PEAK_MODULE_DESCRIPTOR_HANDLE InterfaceDescriptor::ModuleDescriptorHandle() const
185 {
186  auto moduleDescriptorHandle = QueryNumericFromCInterfaceFunction<PEAK_MODULE_DESCRIPTOR_HANDLE>(
187  [&](PEAK_MODULE_DESCRIPTOR_HANDLE* _moduleDescriptorHandle) {
189  m_backendHandle, _moduleDescriptorHandle);
190  });
191 
192  return moduleDescriptorHandle;
193 }
194 
195 } /* namespace core */
196 } /* namespace peak */
PEAK_C_API PEAK_InterfaceDescriptor_ToModuleDescriptor(PEAK_INTERFACE_DESCRIPTOR_HANDLE interfaceDescriptorHandle, PEAK_MODULE_DESCRIPTOR_HANDLE *moduleDescriptorHandle)
Casts the given interface descriptor to a module descriptor.
Encapsulates the GenTL functions associated with a GenTL Interface module&#39;s ID.
Definition: peak_interface_descriptor.hpp:39
~InterfaceDescriptor() override=default
std::shared_ptr< System > ParentSystem() const
Returns the parent system.
Definition: peak_interface_descriptor.hpp:162
std::string DisplayName() const
Returns the display name.
Definition: peak_interface_descriptor.hpp:147
std::shared_ptr< Interface > OpenedInterface() const
Returns the Interface that was opened with this InterfaceDescriptor.
Definition: peak_interface_descriptor.hpp:179
std::string TLType() const
Returns the TL (transport layer) type.
Definition: peak_interface_descriptor.hpp:155
struct PEAK_INTERFACE_DESCRIPTOR * PEAK_INTERFACE_DESCRIPTOR_HANDLE
Definition: peak_backend.h:357
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition: peak_dynamic_loader.h:32
PEAK_C_API PEAK_InterfaceDescriptor_OpenInterface(PEAK_INTERFACE_DESCRIPTOR_HANDLE interfaceDescriptorHandle, PEAK_INTERFACE_HANDLE *interfaceHandle)
Opens the interface being associated with the given interface descriptor.
RawInformation Info(int32_t infoCommand) const
Delivers information based on the given GenTL info command.
Definition: peak_interface_descriptor.hpp:139
PEAK_C_API PEAK_InterfaceDescriptor_GetDisplayName(PEAK_INTERFACE_DESCRIPTOR_HANDLE interfaceDescriptorHandle, char *displayName, size_t *displayNameSize)
Asks the given interface descriptor for its display name.
std::string Key() const
Returns the unique key.
Definition: peak_interface_descriptor.hpp:134
struct PEAK_MODULE_DESCRIPTOR * PEAK_MODULE_DESCRIPTOR_HANDLE
Definition: peak_backend.h:397
PEAK_C_API PEAK_InterfaceDescriptor_GetTLType(PEAK_INTERFACE_DESCRIPTOR_HANDLE interfaceDescriptorHandle, char *tlType, size_t *tlTypeSize)
Asks the given interface descriptor for its TL type.
The base class for all openable modules.
Definition: peak_module_descriptor.hpp:30
InterfaceDescriptor & operator=(const InterfaceDescriptor &other)=delete
#define PEAK_C_ABI_PREFIX
Definition: peak_dll_defines.h:16
struct PEAK_INTERFACE * PEAK_INTERFACE_HANDLE
Definition: peak_backend.h:361
PEAK_C_API PEAK_InterfaceDescriptor_GetKey(PEAK_INTERFACE_DESCRIPTOR_HANDLE interfaceDescriptorHandle, char *key, size_t *keySize)
Asks the given interface descriptor for its key.
The struct returned by all raw information functions.
Definition: peak_common_structs.hpp:24
std::shared_ptr< Interface > OpenInterface()
Opens the interface.
Definition: peak_interface_descriptor.hpp:167
PEAK_C_API PEAK_InterfaceDescriptor_GetInfo(PEAK_INTERFACE_DESCRIPTOR_HANDLE interfaceDescriptorHandle, int32_t infoCommand, int32_t *infoDataType, uint8_t *info, size_t *infoSize)
Asks the given interface descriptor for an information based on a specific command.