IDS peak genericC++  v1.7.0
peak_event.hpp
Go to the documentation of this file.
1 
11 #pragma once
12 
13 
16 #include <peak/dll_interface/peak_dll_interface_util.hpp>
17 
18 #include <cstdint>
19 #include <vector>
20 
21 
22 namespace peak
23 {
24 namespace core
25 {
26 
34 enum class EventType
35 {
36  Error,
40  Module,
41 
42  Custom = 1000
43 };
44 
45 class NodeMap;
46 
51 class Event
52 {
53 public:
54  Event() = delete;
55  ~Event();
56  Event(const Event& other) = delete;
57  Event& operator=(const Event& other) = delete;
58  Event(Event&& other) = delete;
59  Event& operator=(Event&& other) = delete;
60 
62  RawInformation Info(int32_t infoCommand) const;
63 
73  uint64_t ID() const;
74 
86  std::vector<uint8_t> Data() const;
87 
88 
96  EventType Type() const;
97 
110  std::vector<uint8_t> RawData() const;
111 
112 private:
113  friend NodeMap;
114  friend ClassCreator<Event>;
115  explicit Event(PEAK_EVENT_HANDLE eventHandle);
116  PEAK_EVENT_HANDLE m_backendHandle;
117 };
118 
119 } /* namespace core */
120 } /* namespace peak */
121 
122 /* Implementation */
123 namespace peak
124 {
125 namespace core
126 {
127 
128 inline Event::Event(PEAK_EVENT_HANDLE eventHandle)
129  : m_backendHandle(eventHandle)
130 {}
131 
132 inline RawInformation Event::Info(int32_t infoCommand) const
133 {
134  return QueryRawInformationFromCInterfaceFunction([&](int32_t* dataType, uint8_t* buffer, size_t* bufferSize) {
135  return PEAK_C_ABI_PREFIX PEAK_Event_GetInfo(m_backendHandle, infoCommand, dataType, buffer, bufferSize);
136  });
137 }
138 
139 inline uint64_t Event::ID() const
140 {
141  return QueryNumericFromCInterfaceFunction<uint64_t>(
142  [&](uint64_t* id) { return PEAK_C_ABI_PREFIX PEAK_Event_GetID(m_backendHandle, id); });
143 }
144 
145 inline std::vector<uint8_t> Event::Data() const
146 {
147  return QueryNumericArrayFromCInterfaceFunction<uint8_t>([&](uint8_t* data, size_t* dataSize) {
148  return PEAK_C_ABI_PREFIX PEAK_Event_GetData(m_backendHandle, data, dataSize);
149  });
150 }
151 
152 inline EventType Event::Type() const
153 {
154  return static_cast<EventType>(QueryNumericFromCInterfaceFunction<PEAK_EVENT_TYPE>(
155  [&](PEAK_EVENT_TYPE* type) { return PEAK_C_ABI_PREFIX PEAK_Event_GetType(m_backendHandle, type); }));
156 }
157 
158 inline std::vector<uint8_t> Event::RawData() const
159 {
160  return QueryNumericArrayFromCInterfaceFunction<uint8_t>([&](uint8_t* rawData, size_t* rawDataSize) {
161  return PEAK_C_ABI_PREFIX PEAK_Event_GetRawData(m_backendHandle, rawData, rawDataSize);
162  });
163 }
164 
166 {
167  (void)PEAK_C_ABI_PREFIX PEAK_Event_Destruct(m_backendHandle);
168 }
169 
170 inline std::string ToString(EventType entry)
171 {
172  std::string entryString;
173 
174  if (entry == EventType::Error)
175  {
176  entryString = "Error";
177  }
178  else if (entry == EventType::FeatureInvalidate)
179  {
180  entryString = "FeatureInvalidate";
181  }
182  else if (entry == EventType::FeatureChange)
183  {
184  entryString = "FeatureChange";
185  }
186  else if (entry == EventType::RemoteDevice)
187  {
188  entryString = "RemoteDevice";
189  }
190  else if (entry == EventType::Module)
191  {
192  entryString = "Module";
193  }
194  else if (entry >= EventType::Custom)
195  {
196  entryString = "Custom";
197  }
198 
199  return entryString;
200 }
201 
202 } /* namespace core */
203 } /* namespace peak */
Represents a GenAPI node map.
Definition: peak_node_map.hpp:59
std::vector< uint8_t > Data() const
Returns the event payload data.
Definition: peak_event.hpp:145
EventType
Different types of events.
Definition: peak_event.hpp:34
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition: peak_dynamic_loader.h:32
std::string ToString(BufferPayloadType entry)
Definition: peak_buffer.hpp:505
PEAK_C_API PEAK_Event_GetType(PEAK_EVENT_HANDLE eventHandle, PEAK_EVENT_TYPE *type)
Asks the given event for its type.
~Event()
Definition: peak_event.hpp:165
int32_t PEAK_EVENT_TYPE
Definition: peak_backend.h:168
EventType Type() const
Returns the type.
Definition: peak_event.hpp:152
PEAK_C_API PEAK_Event_GetID(PEAK_EVENT_HANDLE eventHandle, uint64_t *id)
Asks the given event for its ID.
PEAK_C_API PEAK_Event_GetData(PEAK_EVENT_HANDLE eventHandle, uint8_t *data, size_t *dataSize)
Asks the given event for its data.
uint64_t ID() const
Returns the ID.
Definition: peak_event.hpp:139
struct PEAK_EVENT * PEAK_EVENT_HANDLE
Definition: peak_backend.h:467
PEAK_C_API PEAK_Event_Destruct(PEAK_EVENT_HANDLE eventHandle)
Destroys the given event.
RawInformation Info(int32_t infoCommand) const
Delivers information based on the given GenTL info command.
Definition: peak_event.hpp:132
Encapsulates the GenTL event data functions.
Definition: peak_event.hpp:51
std::vector< uint8_t > RawData() const
Returns the event raw data.
Definition: peak_event.hpp:158
#define PEAK_C_ABI_PREFIX
Definition: peak_dll_defines.h:16
The struct returned by all raw information functions.
Definition: peak_common_structs.hpp:24
PEAK_C_API PEAK_Event_GetRawData(PEAK_EVENT_HANDLE eventHandle, uint8_t *rawData, size_t *rawDataSize)
Asks the given event for its raw data.
PEAK_C_API PEAK_Event_GetInfo(PEAK_EVENT_HANDLE eventHandle, int32_t infoCommand, int32_t *infoDataType, uint8_t *info, size_t *infoSize)
Asks the given event for an information based on a specific command.