IDS peak genericC++ v1.17.0
Loading...
Searching...
No Matches
peak_interface_descriptor.hpp
Go to the documentation of this file.
1
6
7#pragma once
8
10
15#include <peak/dll_interface/peak_dll_interface_util.hpp>
17
18#include <cstdint>
19#include <memory>
20#include <string>
21
22
23namespace peak
24{
25namespace core
26{
27
28class System;
29
39{
40public:
42 ~InterfaceDescriptor() override = default;
47
49 std::string Key() const;
50
52 RawInformation Info(int32_t infoCommand) const;
63 std::string DisplayName() const;
64
66 std::string TLType() const;
67
78 std::shared_ptr<System> ParentSystem() const;
79
90 std::shared_ptr<Interface> OpenInterface();
91
101 std::shared_ptr<Interface> OpenedInterface() const;
102
113 PEAK_COMMON_NO_DISCARD std::shared_ptr<Interface> EnsureOpenedInterface();
114
122 PEAK_COMMON_NO_DISCARD bool IsOpened() const;
123
124private:
126
127 friend ClassCreator<InterfaceDescriptor>;
129 PEAK_INTERFACE_DESCRIPTOR_HANDLE interfaceDescriptorHandle, const std::weak_ptr<System>& parentSystem);
130 PEAK_INTERFACE_DESCRIPTOR_HANDLE m_backendHandle;
131
132 std::weak_ptr<System> m_parentSystem;
133 std::weak_ptr<Interface> m_openedInterface;
134
135 std::string m_key;
136};
137
138} /* namespace core */
139} /* namespace peak */
140
141/* Implementation */
142namespace peak
143{
144namespace core
145{
146
148 PEAK_INTERFACE_DESCRIPTOR_HANDLE interfaceDescriptorHandle, const std::weak_ptr<System>& parentSystem)
149 : m_backendHandle(interfaceDescriptorHandle)
150 , m_parentSystem(parentSystem)
151 , m_key(QueryStringFromCInterfaceFunction([&](char* key, size_t* keySize) {
152 return PEAK_C_ABI_PREFIX PEAK_InterfaceDescriptor_GetKey(interfaceDescriptorHandle, key, keySize);
153 }))
154{}
155
156inline std::string InterfaceDescriptor::Key() const
157{
158 return m_key;
159}
160
161inline RawInformation InterfaceDescriptor::Info(int32_t infoCommand) const
162{
163 return QueryRawInformationFromCInterfaceFunction([&](int32_t* dataType, uint8_t* buffer, size_t* bufferSize) {
165 m_backendHandle, infoCommand, dataType, buffer, bufferSize);
166 });
167}
168
169inline std::string InterfaceDescriptor::DisplayName() const
170{
171 return QueryStringFromCInterfaceFunction([&](char* displayName, size_t* displayNameSize) {
173 m_backendHandle, displayName, displayNameSize);
174 });
175}
176
177inline std::string InterfaceDescriptor::TLType() const
178{
179 return QueryStringFromCInterfaceFunction([&](char* tlType, size_t* tlTypeSize) {
180 return PEAK_C_ABI_PREFIX PEAK_InterfaceDescriptor_GetTLType(m_backendHandle, tlType, tlTypeSize);
181 });
182}
183
184inline std::shared_ptr<System> InterfaceDescriptor::ParentSystem() const
185{
186 return LockOrThrow(m_parentSystem);
187}
188
189inline std::shared_ptr<Interface> InterfaceDescriptor::OpenInterface()
190{
191 auto interfaceHandle = QueryNumericFromCInterfaceFunction<PEAK_INTERFACE_HANDLE>(
192 [&](PEAK_INTERFACE_HANDLE* _interfaceHandle) {
193 return PEAK_C_ABI_PREFIX PEAK_InterfaceDescriptor_OpenInterface(m_backendHandle, _interfaceHandle);
194 });
195
196 auto interface_ = std::make_shared<ClassCreator<Interface>>(interfaceHandle, m_parentSystem);
197 m_openedInterface = interface_;
198
199 return interface_;
200}
201
202inline std::shared_ptr<Interface> InterfaceDescriptor::OpenedInterface() const
203{
204 return LockOrThrowOpenedModule(m_openedInterface);
205}
206
207inline std::shared_ptr<Interface> InterfaceDescriptor::EnsureOpenedInterface()
208{
209 return IsOpened() ? OpenedInterface() : OpenInterface();
210}
211
213{
214 return m_openedInterface.expired();
215}
216
218{
219 auto moduleDescriptorHandle = QueryNumericFromCInterfaceFunction<PEAK_MODULE_DESCRIPTOR_HANDLE>(
220 [&](PEAK_MODULE_DESCRIPTOR_HANDLE* _moduleDescriptorHandle) {
222 m_backendHandle, _moduleDescriptorHandle);
223 });
224
225 return moduleDescriptorHandle;
226}
227
228} /* namespace core */
229} /* namespace peak */
std::string TLType() const
Returns the TL (transport layer) type.
Definition peak_interface_descriptor.hpp:177
InterfaceDescriptor(InterfaceDescriptor &&other)=delete
std::shared_ptr< System > ParentSystem() const
Returns the parent system.
Definition peak_interface_descriptor.hpp:184
std::string DisplayName() const
Returns the display name.
Definition peak_interface_descriptor.hpp:169
PEAK_COMMON_NO_DISCARD std::shared_ptr< Interface > EnsureOpenedInterface()
Returns the opened interface or opens it if it is not already open.
Definition peak_interface_descriptor.hpp:207
InterfaceDescriptor(const InterfaceDescriptor &other)=delete
RawInformation Info(int32_t infoCommand) const
Delivers information based on the given GenTL info command.
Definition peak_interface_descriptor.hpp:161
std::shared_ptr< Interface > OpenedInterface() const
Returns the Interface that was opened with this InterfaceDescriptor.
Definition peak_interface_descriptor.hpp:202
InterfaceDescriptor & operator=(InterfaceDescriptor &&other)=delete
InterfaceDescriptor & operator=(const InterfaceDescriptor &other)=delete
std::string Key() const
Returns the unique key.
Definition peak_interface_descriptor.hpp:156
~InterfaceDescriptor() override=default
PEAK_COMMON_NO_DISCARD bool IsOpened() const
Returns whether the interface is open.
Definition peak_interface_descriptor.hpp:212
std::shared_ptr< Interface > OpenInterface()
Opens the interface.
Definition peak_interface_descriptor.hpp:189
virtual PEAK_MODULE_DESCRIPTOR_HANDLE ModuleDescriptorHandle() const =0
Represents a GenTL System module.
Definition peak_system.hpp:49
The "core" namespace contains the direct GenAPI and GenTL wrapper.
Definition peak_buffer.hpp:32
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition peak_buffer.hpp:29
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.
struct PEAK_MODULE_DESCRIPTOR * PEAK_MODULE_DESCRIPTOR_HANDLE
Definition peak_backend.h:415
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.
struct PEAK_INTERFACE_DESCRIPTOR * PEAK_INTERFACE_DESCRIPTOR_HANDLE
Definition peak_backend.h:375
PEAK_C_API PEAK_InterfaceDescriptor_GetKey(PEAK_INTERFACE_DESCRIPTOR_HANDLE interfaceDescriptorHandle, char *key, size_t *keySize)
Asks the given interface descriptor for its key.
struct PEAK_INTERFACE * PEAK_INTERFACE_HANDLE
Definition peak_backend.h:379
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.
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.
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.
#define PEAK_COMMON_NO_DISCARD
Definition peak_common_defines.h:89
#define PEAK_C_ABI_PREFIX
Definition peak_dll_defines.h:13
The struct returned by all raw information functions.
Definition peak_common_structs.hpp:21