IDS peak genericC++  v1.7.2
peak_data_stream_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>
18 
19 #include <memory>
20 #include <string>
21 
22 
23 namespace peak
24 {
25 namespace core
26 {
27 
28 class Device;
29 
38 {
39 public:
40  DataStreamDescriptor() = delete;
41  ~DataStreamDescriptor() override = default;
42  DataStreamDescriptor(const DataStreamDescriptor& other) = delete;
43  DataStreamDescriptor& operator=(const DataStreamDescriptor& other) = delete;
46 
48  std::string Key() const;
49 
59  std::shared_ptr<Device> ParentDevice() const;
60 
71  std::shared_ptr<DataStream> OpenDataStream();
72 
82  std::shared_ptr<DataStream> OpenedDataStream() const;
83 
84 private:
85  PEAK_MODULE_DESCRIPTOR_HANDLE ModuleDescriptorHandle() const override;
86 
87  friend ClassCreator<DataStreamDescriptor>;
89  PEAK_DATA_STREAM_DESCRIPTOR_HANDLE dataStreamDescriptorHandle, const std::weak_ptr<Device>& parentDevice);
90  PEAK_DATA_STREAM_DESCRIPTOR_HANDLE m_backendHandle;
91 
92  std::weak_ptr<Device> m_parentDevice;
93  std::weak_ptr<DataStream> m_openedDataStream;
94 
95  std::string m_key;
96 };
97 
98 } /* namespace core */
99 } /* namespace peak */
100 
101 /* Implementation */
102 namespace peak
103 {
104 namespace core
105 {
106 
108  PEAK_DATA_STREAM_DESCRIPTOR_HANDLE dataStreamDescriptorHandle, const std::weak_ptr<Device>& parentDevice)
109  : m_backendHandle(dataStreamDescriptorHandle)
110  , m_parentDevice(parentDevice)
111  , m_key(QueryStringFromCInterfaceFunction([&](char* key, size_t* keySize) {
112  return PEAK_C_ABI_PREFIX PEAK_DataStreamDescriptor_GetKey(dataStreamDescriptorHandle, key, keySize);
113  }))
114 {}
115 
116 inline std::string DataStreamDescriptor::Key() const
117 {
118  return m_key;
119 }
120 
121 inline std::shared_ptr<Device> DataStreamDescriptor::ParentDevice() const
122 {
123  return LockOrThrow(m_parentDevice);
124 }
125 
126 inline std::shared_ptr<DataStream> DataStreamDescriptor::OpenDataStream()
127 {
128  auto dataStreamHandle = QueryNumericFromCInterfaceFunction<PEAK_DATA_STREAM_HANDLE>(
129  [&](PEAK_DATA_STREAM_HANDLE* _dataStreamHandle) {
130  return PEAK_C_ABI_PREFIX PEAK_DataStreamDescriptor_OpenDataStream(m_backendHandle, _dataStreamHandle);
131  });
132 
133  auto dataStream = std::make_shared<ClassCreator<DataStream>>(dataStreamHandle, m_parentDevice);
134  m_openedDataStream = dataStream;
135  return dataStream;
136 }
137 
138 inline std::shared_ptr<DataStream> DataStreamDescriptor::OpenedDataStream() const
139 {
140  return LockOrThrowOpenedModule(m_openedDataStream);
141 }
142 
143 inline PEAK_MODULE_DESCRIPTOR_HANDLE DataStreamDescriptor::ModuleDescriptorHandle() const
144 {
145  auto moduleDescriptorHandle = QueryNumericFromCInterfaceFunction<PEAK_MODULE_DESCRIPTOR_HANDLE>(
146  [&](PEAK_MODULE_DESCRIPTOR_HANDLE* _moduleDescriptorHandle) {
148  m_backendHandle, _moduleDescriptorHandle);
149  });
150 
151  return moduleDescriptorHandle;
152 }
153 
154 } /* namespace core */
155 } /* namespace peak */
DataStreamDescriptor & operator=(const DataStreamDescriptor &other)=delete
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition: peak_dynamic_loader.h:32
std::shared_ptr< Device > ParentDevice() const
Returns the parent device.
Definition: peak_data_stream_descriptor.hpp:121
std::string Key() const
Returns the unique key.
Definition: peak_data_stream_descriptor.hpp:116
PEAK_C_API PEAK_DataStreamDescriptor_GetKey(PEAK_DATA_STREAM_DESCRIPTOR_HANDLE dataStreamDescriptorHandle, char *key, size_t *keySize)
Asks the given data stream descriptor for its key.
struct PEAK_MODULE_DESCRIPTOR * PEAK_MODULE_DESCRIPTOR_HANDLE
Definition: peak_backend.h:399
std::shared_ptr< DataStream > OpenedDataStream() const
Returns the DataStream that was opened with this DataStreamDescriptor.
Definition: peak_data_stream_descriptor.hpp:138
PEAK_C_API PEAK_DataStreamDescriptor_ToModuleDescriptor(PEAK_DATA_STREAM_DESCRIPTOR_HANDLE dataStreamDescriptorHandle, PEAK_MODULE_DESCRIPTOR_HANDLE *moduleDescriptorHandle)
Casts the given data stream descriptor to a module descriptor.
std::shared_ptr< DataStream > OpenDataStream()
Opens the data stream.
Definition: peak_data_stream_descriptor.hpp:126
The base class for all openable modules.
Definition: peak_module_descriptor.hpp:30
struct PEAK_DATA_STREAM * PEAK_DATA_STREAM_HANDLE
Definition: peak_backend.h:383
#define PEAK_C_ABI_PREFIX
Definition: peak_dll_defines.h:16
~DataStreamDescriptor() override=default
struct PEAK_DATA_STREAM_DESCRIPTOR * PEAK_DATA_STREAM_DESCRIPTOR_HANDLE
Definition: peak_backend.h:379
Encapsulates the GenTL functions associated with a GenTL DataStream module&#39;s ID.
Definition: peak_data_stream_descriptor.hpp:37
PEAK_C_API PEAK_DataStreamDescriptor_OpenDataStream(PEAK_DATA_STREAM_DESCRIPTOR_HANDLE dataStreamDescriptorHandle, PEAK_DATA_STREAM_HANDLE *dataStreamHandle)
Opens the data stream being associated with the given data stream descriptor.