]>
Commit | Line | Data |
---|---|---|
c23c8659 ML |
1 | /* |
2 | * This file is part of the libsigrok project. | |
3 | * | |
4 | * Copyright (C) 2013-2014 Martin Ling <martin-sigrok@earth.li> | |
5 | * | |
6 | * This program is free software: you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation, either version 3 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
19 | ||
07443fd2 ML |
20 | /** |
21 | ||
22 | @mainpage API Reference | |
23 | ||
24 | Introduction | |
25 | ------------ | |
26 | ||
27 | The sigrok++ API provides an object-oriented C++ interface to the functionality | |
28 | in libsigrok, including automatic memory and resource management. | |
29 | ||
30 | It is built on top of the public libsigrok C API, and is designed to be used as | |
31 | a standalone alternative API. Programs should not mix usage of the C and C++ | |
32 | APIs; the C++ interface code needs to have full control of all C API calls for | |
33 | resources to be managed correctly. | |
34 | ||
35 | Memory management | |
36 | ----------------- | |
37 | ||
38 | All runtime objects created through the C++ API are passed and accessed via | |
39 | shared pointers, using the C++11 std::shared_ptr implementation. This means | |
40 | that a reference count is kept for each object. | |
41 | ||
42 | Shared pointers can be copied and assigned in a user's program, automatically | |
43 | updating their reference count and deleting objects when they are no longer in | |
44 | use. The C++ interface code also keeps track of internal dependencies between | |
45 | libsigrok resources, and ensures that objects are not prematurely deleted when | |
46 | their resources are in use by other objects. | |
47 | ||
48 | This means that management of sigrok++ objects and their underlying libsigrok | |
49 | resources can be treated as fully automatic. As long as all shared pointers to | |
50 | objects are deleted or reassigned when no longer in use, all underlying | |
51 | resources will be released at the right time. | |
52 | ||
53 | Getting started | |
54 | --------------- | |
55 | ||
56 | Usage of the C++ API needs to begin with a call to sigrok::Context::create(). | |
57 | This will create the global libsigrok context and returns a shared pointer to | |
58 | the sigrok::Context object. Methods on this object provide access to the | |
59 | hardware drivers, input and output formats supported by the library, as well | |
60 | as means of creating other objects such as sessions and triggers. | |
61 | ||
62 | Error handling | |
63 | -------------- | |
64 | ||
65 | When any libsigrok C API call returns an error, a sigrok::Error exception is | |
66 | raised, which provides access to the error code and description. | |
67 | ||
68 | */ | |
69 | ||
c23c8659 ML |
70 | #ifndef LIBSIGROK_HPP |
71 | #define LIBSIGROK_HPP | |
72 | ||
73 | #include "libsigrok/libsigrok.h" | |
74 | #include <glibmm-2.4/glibmm.h> | |
75 | ||
76 | #include <stdexcept> | |
77 | #include <memory> | |
78 | #include <vector> | |
79 | #include <map> | |
4c7c4194 | 80 | #include <set> |
c23c8659 ML |
81 | |
82 | namespace sigrok | |
83 | { | |
84 | ||
85 | using namespace std; | |
86 | ||
87 | /* Forward declarations */ | |
88 | class SR_API Error; | |
89 | class SR_API Context; | |
90 | class SR_API Driver; | |
91 | class SR_API Device; | |
92 | class SR_API HardwareDevice; | |
93 | class SR_API Channel; | |
94 | class SR_API EventSource; | |
95 | class SR_API Session; | |
96 | class SR_API ConfigKey; | |
97 | class SR_API InputFormat; | |
98 | class SR_API OutputFormat; | |
99 | class SR_API LogLevel; | |
100 | class SR_API ChannelGroup; | |
101 | class SR_API Trigger; | |
102 | class SR_API TriggerStage; | |
103 | class SR_API TriggerMatch; | |
104 | class SR_API TriggerMatchType; | |
105 | class SR_API ChannelType; | |
106 | class SR_API Packet; | |
107 | class SR_API PacketPayload; | |
108 | class SR_API PacketType; | |
109 | class SR_API Quantity; | |
110 | class SR_API Unit; | |
111 | class SR_API QuantityFlag; | |
ca3291e3 ML |
112 | class SR_API Input; |
113 | class SR_API InputDevice; | |
c23c8659 ML |
114 | class SR_API Output; |
115 | class SR_API DataType; | |
58aa1f83 | 116 | class SR_API Option; |
9fa5b426 | 117 | class SR_API UserDevice; |
c23c8659 ML |
118 | |
119 | /** Exception thrown when an error code is returned by any libsigrok call. */ | |
120 | class SR_API Error: public exception | |
121 | { | |
122 | public: | |
123 | Error(int result); | |
124 | ~Error() throw(); | |
125 | const int result; | |
126 | const char *what() const throw(); | |
127 | }; | |
128 | ||
541c855e | 129 | /* Base template for classes whose resources are owned by a parent object. */ |
bf52cc8c | 130 | template <class Class, class Parent, typename Struct> |
541c855e | 131 | class SR_API ParentOwned |
c23c8659 | 132 | { |
7649683c | 133 | protected: |
07443fd2 | 134 | /* Parent object which owns this child object's underlying structure. |
c23c8659 ML |
135 | |
136 | This shared pointer will be null when this child is unused, but | |
137 | will be assigned to point to the parent before any shared pointer | |
138 | to this child is handed out to the user. | |
139 | ||
140 | When the reference count of this child falls to zero, this shared | |
141 | pointer to its parent is reset by a custom deleter on the child's | |
142 | shared pointer. | |
143 | ||
144 | This strategy ensures that the destructors for both the child and | |
145 | the parent are called at the correct time, i.e. only when all | |
146 | references to both the parent and all its children are gone. */ | |
3b161085 | 147 | shared_ptr<Parent> _parent; |
7649683c | 148 | |
0d0170ae | 149 | /* Weak pointer for shared_from_this() implementation. */ |
3b161085 | 150 | weak_ptr<Class> _weak_this; |
0d0170ae | 151 | |
7649683c | 152 | public: |
73a1eb01 ML |
153 | /* Get parent object that owns this object. */ |
154 | shared_ptr<Parent> parent() | |
155 | { | |
156 | return _parent; | |
157 | } | |
158 | ||
0d0170ae | 159 | /* Note, this implementation will create a new smart_ptr if none exists. */ |
bf52cc8c | 160 | shared_ptr<Class> shared_from_this() |
0d0170ae | 161 | { |
bf52cc8c | 162 | shared_ptr<Class> shared; |
0d0170ae | 163 | |
3b161085 | 164 | if (!(shared = _weak_this.lock())) |
0d0170ae | 165 | { |
bf52cc8c | 166 | shared = shared_ptr<Class>((Class *) this, reset_parent); |
3b161085 | 167 | _weak_this = shared; |
0d0170ae ML |
168 | } |
169 | ||
170 | return shared; | |
171 | } | |
172 | ||
bf52cc8c | 173 | shared_ptr<Class> get_shared_pointer(shared_ptr<Parent> parent) |
7649683c | 174 | { |
78132e2a ML |
175 | if (!parent) |
176 | throw Error(SR_ERR_BUG); | |
3b161085 | 177 | this->_parent = parent; |
0d0170ae | 178 | return shared_from_this(); |
7649683c | 179 | } |
0d0170ae | 180 | |
bf52cc8c | 181 | shared_ptr<Class> get_shared_pointer(Parent *parent) |
7649683c | 182 | { |
78132e2a ML |
183 | if (!parent) |
184 | throw Error(SR_ERR_BUG); | |
bf52cc8c | 185 | return get_shared_pointer(parent->shared_from_this()); |
7649683c | 186 | } |
c23c8659 | 187 | protected: |
bf52cc8c | 188 | static void reset_parent(Class *object) |
7649683c | 189 | { |
3b161085 | 190 | if (!object->_parent) |
78132e2a | 191 | throw Error(SR_ERR_BUG); |
3b161085 | 192 | object->_parent.reset(); |
7649683c ML |
193 | } |
194 | ||
3b161085 | 195 | Struct *_structure; |
c23c8659 | 196 | |
541c855e | 197 | ParentOwned<Class, Parent, Struct>(Struct *structure) : |
3b161085 | 198 | _structure(structure) |
c23c8659 ML |
199 | { |
200 | } | |
201 | }; | |
202 | ||
90e89c2a ML |
203 | /* Base template for classes whose resources are owned by the user. */ |
204 | template <class Class, typename Struct> | |
205 | class SR_API UserOwned : public enable_shared_from_this<Class> | |
206 | { | |
207 | public: | |
208 | shared_ptr<Class> shared_from_this() | |
209 | { | |
210 | auto shared = enable_shared_from_this<Class>::shared_from_this(); | |
211 | if (!shared) | |
212 | throw Error(SR_ERR_BUG); | |
213 | return shared; | |
214 | } | |
215 | protected: | |
3b161085 | 216 | Struct *_structure; |
90e89c2a ML |
217 | |
218 | UserOwned<Class, Struct>(Struct *structure) : | |
3b161085 | 219 | _structure(structure) |
90e89c2a ML |
220 | { |
221 | } | |
b4ed33a7 ML |
222 | |
223 | /* Deleter needed to allow shared_ptr use with protected destructor. */ | |
224 | class Deleter | |
225 | { | |
226 | public: | |
227 | void operator()(Class *object) { delete object; } | |
228 | }; | |
90e89c2a ML |
229 | }; |
230 | ||
c23c8659 ML |
231 | /** Type of log callback */ |
232 | typedef function<void(const LogLevel *, string message)> LogCallbackFunction; | |
233 | ||
07443fd2 | 234 | /** The global libsigrok context */ |
90e89c2a | 235 | class SR_API Context : public UserOwned<Context, struct sr_context> |
c23c8659 ML |
236 | { |
237 | public: | |
238 | /** Create new context */ | |
239 | static shared_ptr<Context> create(); | |
240 | /** libsigrok package version. */ | |
3b161085 | 241 | string package_version(); |
c23c8659 | 242 | /** libsigrok library version. */ |
3b161085 | 243 | string lib_version(); |
c23c8659 | 244 | /** Available hardware drivers, indexed by name. */ |
3b161085 | 245 | map<string, shared_ptr<Driver> > drivers(); |
c23c8659 | 246 | /** Available input formats, indexed by name. */ |
3b161085 | 247 | map<string, shared_ptr<InputFormat> > input_formats(); |
c23c8659 | 248 | /** Available output formats, indexed by name. */ |
3b161085 | 249 | map<string, shared_ptr<OutputFormat> > output_formats(); |
c23c8659 | 250 | /** Current log level. */ |
3b161085 | 251 | const LogLevel *log_level(); |
b6f411ac ML |
252 | /** Set the log level. |
253 | * @param level LogLevel to use. */ | |
c23c8659 ML |
254 | void set_log_level(const LogLevel *level); |
255 | /** Current log domain. */ | |
3b161085 | 256 | string log_domain(); |
b6f411ac ML |
257 | /** Set the log domain. |
258 | * @param value Log domain prefix string. */ | |
c23c8659 | 259 | void set_log_domain(string value); |
b6f411ac ML |
260 | /** Set the log callback. |
261 | * @param callback Callback of the form callback(LogLevel, string). */ | |
c23c8659 ML |
262 | void set_log_callback(LogCallbackFunction callback); |
263 | /** Set the log callback to the default handler. */ | |
264 | void set_log_callback_default(); | |
265 | /** Create a new session. */ | |
266 | shared_ptr<Session> create_session(); | |
9fa5b426 ML |
267 | /** Create a new user device. */ |
268 | shared_ptr<UserDevice> create_user_device( | |
269 | string vendor, string model, string version); | |
304be4a7 ML |
270 | /** Create a header packet. */ |
271 | shared_ptr<Packet> create_header_packet(Glib::TimeVal start_time); | |
272 | /** Create a meta packet. */ | |
273 | shared_ptr<Packet> create_meta_packet( | |
274 | map<const ConfigKey *, Glib::VariantBase> config); | |
275 | /** Create a logic packet. */ | |
276 | shared_ptr<Packet> create_logic_packet( | |
277 | void *data_pointer, size_t data_length, unsigned int unit_size); | |
278 | /** Create an analog packet. */ | |
279 | shared_ptr<Packet> create_analog_packet( | |
280 | vector<shared_ptr<Channel> > channels, | |
281 | float *data_pointer, unsigned int num_samples, const Quantity *mq, | |
282 | const Unit *unit, vector<const QuantityFlag *> mqflags); | |
b6f411ac ML |
283 | /** Load a saved session. |
284 | * @param filename File name string. */ | |
c23c8659 | 285 | shared_ptr<Session> load_session(string filename); |
b6f411ac ML |
286 | /** Create a new trigger. |
287 | * @param name Name string for new trigger. */ | |
c23c8659 | 288 | shared_ptr<Trigger> create_trigger(string name); |
ca3291e3 ML |
289 | /** Open an input file. |
290 | * @param filename File name string. */ | |
291 | shared_ptr<Input> open_file(string filename); | |
292 | /** Open an input stream based on header data. | |
293 | * @param header Initial data from stream. */ | |
294 | shared_ptr<Input> open_stream(string header); | |
24287ea9 | 295 | map<string, string> serials(shared_ptr<Driver> driver); |
c23c8659 | 296 | protected: |
3b161085 ML |
297 | map<string, Driver *> _drivers; |
298 | map<string, InputFormat *> _input_formats; | |
299 | map<string, OutputFormat *> _output_formats; | |
300 | Session *_session; | |
301 | LogCallbackFunction _log_callback; | |
c23c8659 ML |
302 | Context(); |
303 | ~Context(); | |
c23c8659 ML |
304 | friend class Deleter; |
305 | friend class Session; | |
306 | friend class Driver; | |
307 | }; | |
308 | ||
4c7c4194 ML |
309 | enum Capability { |
310 | GET = SR_CONF_GET, | |
311 | SET = SR_CONF_SET, | |
312 | LIST = SR_CONF_LIST | |
313 | }; | |
314 | ||
c23c8659 ML |
315 | /** An object that can be configured. */ |
316 | class SR_API Configurable | |
317 | { | |
318 | public: | |
b6f411ac ML |
319 | /** Read configuration for the given key. |
320 | * @param key ConfigKey to read. */ | |
c23c8659 | 321 | Glib::VariantBase config_get(const ConfigKey *key); |
b6f411ac ML |
322 | /** Set configuration for the given key to a specified value. |
323 | * @param key ConfigKey to set. | |
324 | * @param value Value to set. */ | |
c23c8659 | 325 | void config_set(const ConfigKey *key, Glib::VariantBase value); |
b6f411ac ML |
326 | /** Enumerate available values for the given configuration key. |
327 | * @param key ConfigKey to enumerate values for. */ | |
e194c011 | 328 | Glib::VariantContainerBase config_list(const ConfigKey *key); |
d54190a3 | 329 | /** Enumerate available keys, according to a given index key. */ |
4c7c4194 | 330 | map<const ConfigKey *, set<Capability> > config_keys(const ConfigKey *key); |
d9eed47d ML |
331 | /** Check for a key in the list from a given index key. */ |
332 | bool config_check(const ConfigKey *key, const ConfigKey *index_key); | |
c23c8659 ML |
333 | protected: |
334 | Configurable( | |
335 | struct sr_dev_driver *driver, | |
336 | struct sr_dev_inst *sdi, | |
337 | struct sr_channel_group *channel_group); | |
338 | virtual ~Configurable(); | |
339 | struct sr_dev_driver *config_driver; | |
340 | struct sr_dev_inst *config_sdi; | |
341 | struct sr_channel_group *config_channel_group; | |
342 | }; | |
343 | ||
59b74d28 ML |
344 | /** A hardware driver provided by the library */ |
345 | class SR_API Driver : | |
346 | public ParentOwned<Driver, Context, struct sr_dev_driver>, | |
347 | public Configurable | |
348 | { | |
349 | public: | |
350 | /** Name of this driver. */ | |
3b161085 | 351 | string name(); |
59b74d28 | 352 | /** Long name for this driver. */ |
3b161085 | 353 | string long_name(); |
59b74d28 ML |
354 | /** Scan for devices and return a list of devices found. |
355 | * @param options Mapping of (ConfigKey, value) pairs. */ | |
356 | vector<shared_ptr<HardwareDevice> > scan( | |
db560903 ML |
357 | map<const ConfigKey *, Glib::VariantBase> options = |
358 | map<const ConfigKey *, Glib::VariantBase>()); | |
59b74d28 | 359 | protected: |
3b161085 ML |
360 | bool _initialized; |
361 | vector<HardwareDevice *> _devices; | |
59b74d28 ML |
362 | Driver(struct sr_dev_driver *structure); |
363 | ~Driver(); | |
364 | friend class Context; | |
365 | friend class HardwareDevice; | |
366 | friend class ChannelGroup; | |
367 | }; | |
368 | ||
07443fd2 | 369 | /** A generic device, either hardware or virtual */ |
d01d2314 | 370 | class SR_API Device : public Configurable |
c23c8659 ML |
371 | { |
372 | public: | |
373 | /** Vendor name for this device. */ | |
3b161085 | 374 | string vendor(); |
c23c8659 | 375 | /** Model name for this device. */ |
3b161085 | 376 | string model(); |
c23c8659 | 377 | /** Version string for this device. */ |
3b161085 | 378 | string version(); |
d1075e5a ML |
379 | /** Serial number for this device. */ |
380 | string serial_number(); | |
381 | /** Connection ID for this device. */ | |
382 | string connection_id(); | |
c23c8659 | 383 | /** List of the channels available on this device. */ |
3b161085 | 384 | vector<shared_ptr<Channel> > channels(); |
6be7a7f2 | 385 | /** Channel groups available on this device, indexed by name. */ |
3b161085 | 386 | map<string, shared_ptr<ChannelGroup> > channel_groups(); |
c23c8659 ML |
387 | /** Open device. */ |
388 | void open(); | |
389 | /** Close device. */ | |
390 | void close(); | |
391 | protected: | |
392 | Device(struct sr_dev_inst *structure); | |
393 | ~Device(); | |
d01d2314 | 394 | virtual shared_ptr<Device> get_shared_from_this() = 0; |
4178d971 | 395 | shared_ptr<Channel> get_channel(struct sr_channel *ptr); |
3b161085 ML |
396 | struct sr_dev_inst *_structure; |
397 | map<struct sr_channel *, Channel *> _channels; | |
398 | map<string, ChannelGroup *> _channel_groups; | |
c23c8659 ML |
399 | /** Deleter needed to allow shared_ptr use with protected destructor. */ |
400 | class Deleter | |
401 | { | |
402 | public: | |
403 | void operator()(Device *device) { delete device; } | |
404 | }; | |
405 | friend class Deleter; | |
406 | friend class Session; | |
407 | friend class Channel; | |
408 | friend class ChannelGroup; | |
409 | friend class Output; | |
2928f47d | 410 | friend class Analog; |
c23c8659 ML |
411 | }; |
412 | ||
07443fd2 | 413 | /** A real hardware device, connected via a driver */ |
6e5240f4 | 414 | class SR_API HardwareDevice : |
a4e47454 | 415 | public UserOwned<HardwareDevice, struct sr_dev_inst>, |
6e5240f4 | 416 | public Device |
c23c8659 ML |
417 | { |
418 | public: | |
419 | /** Driver providing this device. */ | |
3b161085 | 420 | shared_ptr<Driver> driver(); |
c23c8659 | 421 | protected: |
a4e47454 | 422 | HardwareDevice(shared_ptr<Driver> driver, struct sr_dev_inst *structure); |
c23c8659 | 423 | ~HardwareDevice(); |
d01d2314 | 424 | shared_ptr<Device> get_shared_from_this(); |
a4e47454 ML |
425 | shared_ptr<Driver> _driver; |
426 | /** Deleter needed to allow shared_ptr use with protected destructor. */ | |
427 | class Deleter | |
428 | { | |
429 | public: | |
430 | void operator()(HardwareDevice *device) { delete device; } | |
431 | }; | |
432 | friend class Deleter; | |
c23c8659 ML |
433 | friend class Driver; |
434 | friend class ChannelGroup; | |
435 | }; | |
436 | ||
9fa5b426 ML |
437 | /** A virtual device, created by the user */ |
438 | class SR_API UserDevice : | |
439 | public UserOwned<UserDevice, struct sr_dev_inst>, | |
440 | public Device | |
441 | { | |
442 | public: | |
443 | /** Add a new channel to this device. */ | |
444 | shared_ptr<Channel> add_channel(unsigned int index, const ChannelType *type, string name); | |
445 | protected: | |
446 | UserDevice(string vendor, string model, string version); | |
447 | ~UserDevice(); | |
448 | shared_ptr<Device> get_shared_from_this(); | |
449 | /** Deleter needed to allow shared_ptr use with protected destructor. */ | |
450 | class Deleter | |
451 | { | |
452 | public: | |
453 | void operator()(UserDevice *device) { delete device; } | |
454 | }; | |
455 | friend class Context; | |
456 | friend class Deleter; | |
457 | }; | |
458 | ||
07443fd2 | 459 | /** A channel on a device */ |
bf52cc8c | 460 | class SR_API Channel : |
541c855e | 461 | public ParentOwned<Channel, Device, struct sr_channel> |
c23c8659 ML |
462 | { |
463 | public: | |
464 | /** Current name of this channel. */ | |
3b161085 | 465 | string name(); |
b6f411ac ML |
466 | /** Set the name of this channel. * |
467 | * @param name Name string to set. */ | |
c23c8659 ML |
468 | void set_name(string name); |
469 | /** Type of this channel. */ | |
3b161085 | 470 | const ChannelType *type(); |
c23c8659 | 471 | /** Enabled status of this channel. */ |
3b161085 | 472 | bool enabled(); |
b6f411ac ML |
473 | /** Set the enabled status of this channel. |
474 | * @param value Boolean value to set. */ | |
c23c8659 | 475 | void set_enabled(bool value); |
06bd935e | 476 | /** Get the index number of this channel. */ |
3b161085 | 477 | unsigned int index(); |
c23c8659 ML |
478 | protected: |
479 | Channel(struct sr_channel *structure); | |
480 | ~Channel(); | |
3b161085 | 481 | const ChannelType * const _type; |
c23c8659 | 482 | friend class Device; |
9fa5b426 | 483 | friend class UserDevice; |
c23c8659 ML |
484 | friend class ChannelGroup; |
485 | friend class Session; | |
486 | friend class TriggerStage; | |
304be4a7 | 487 | friend class Context; |
c23c8659 ML |
488 | }; |
489 | ||
07443fd2 | 490 | /** A group of channels on a device, which share some configuration */ |
c23c8659 | 491 | class SR_API ChannelGroup : |
541c855e | 492 | public ParentOwned<ChannelGroup, Device, struct sr_channel_group>, |
c23c8659 ML |
493 | public Configurable |
494 | { | |
495 | public: | |
496 | /** Name of this channel group. */ | |
3b161085 | 497 | string name(); |
c23c8659 | 498 | /** List of the channels in this group. */ |
3b161085 | 499 | vector<shared_ptr<Channel> > channels(); |
c23c8659 | 500 | protected: |
6be7a7f2 | 501 | ChannelGroup(Device *device, struct sr_channel_group *structure); |
c23c8659 | 502 | ~ChannelGroup(); |
3b161085 | 503 | vector<Channel *> _channels; |
6be7a7f2 | 504 | friend class Device; |
c23c8659 ML |
505 | }; |
506 | ||
07443fd2 | 507 | /** A trigger configuration */ |
90e89c2a | 508 | class SR_API Trigger : public UserOwned<Trigger, struct sr_trigger> |
c23c8659 ML |
509 | { |
510 | public: | |
b6f411ac | 511 | /** Name of this trigger configuration. */ |
3b161085 | 512 | string name(); |
b6f411ac | 513 | /** List of the stages in this trigger. */ |
3b161085 | 514 | vector<shared_ptr<TriggerStage> > stages(); |
b6f411ac | 515 | /** Add a new stage to this trigger. */ |
c23c8659 ML |
516 | shared_ptr<TriggerStage> add_stage(); |
517 | protected: | |
518 | Trigger(shared_ptr<Context> context, string name); | |
519 | ~Trigger(); | |
3b161085 ML |
520 | shared_ptr<Context> _context; |
521 | vector<TriggerStage *> _stages; | |
b4ed33a7 | 522 | friend class Deleter; |
c23c8659 | 523 | friend class Context; |
6fa0eb86 | 524 | friend class Session; |
c23c8659 ML |
525 | }; |
526 | ||
07443fd2 | 527 | /** A stage in a trigger configuration */ |
bf52cc8c | 528 | class SR_API TriggerStage : |
541c855e | 529 | public ParentOwned<TriggerStage, Trigger, struct sr_trigger_stage> |
c23c8659 ML |
530 | { |
531 | public: | |
b6f411ac | 532 | /** Index number of this stage. */ |
3b161085 | 533 | int number(); |
b6f411ac | 534 | /** List of match conditions on this stage. */ |
3b161085 | 535 | vector<shared_ptr<TriggerMatch> > matches(); |
b6f411ac ML |
536 | /** Add a new match condition to this stage. |
537 | * @param channel Channel to match on. | |
538 | * @param type TriggerMatchType to apply. */ | |
c23c8659 | 539 | void add_match(shared_ptr<Channel> channel, const TriggerMatchType *type); |
b6f411ac ML |
540 | /** Add a new match condition to this stage. |
541 | * @param channel Channel to match on. | |
542 | * @param type TriggerMatchType to apply. | |
543 | * @param value Threshold value. */ | |
c23c8659 ML |
544 | void add_match(shared_ptr<Channel> channel, const TriggerMatchType *type, float value); |
545 | protected: | |
3b161085 | 546 | vector<TriggerMatch *> _matches; |
c23c8659 ML |
547 | TriggerStage(struct sr_trigger_stage *structure); |
548 | ~TriggerStage(); | |
549 | friend class Trigger; | |
550 | }; | |
551 | ||
07443fd2 | 552 | /** A match condition in a trigger configuration */ |
bf52cc8c | 553 | class SR_API TriggerMatch : |
541c855e | 554 | public ParentOwned<TriggerMatch, TriggerStage, struct sr_trigger_match> |
c23c8659 ML |
555 | { |
556 | public: | |
b6f411ac | 557 | /** Channel this condition matches on. */ |
3b161085 | 558 | shared_ptr<Channel> channel(); |
b6f411ac | 559 | /** Type of match. */ |
3b161085 | 560 | const TriggerMatchType *type(); |
b6f411ac | 561 | /** Threshold value. */ |
3b161085 | 562 | float value(); |
c23c8659 ML |
563 | protected: |
564 | TriggerMatch(struct sr_trigger_match *structure, shared_ptr<Channel> channel); | |
565 | ~TriggerMatch(); | |
3b161085 | 566 | shared_ptr<Channel> _channel; |
c23c8659 ML |
567 | friend class TriggerStage; |
568 | }; | |
569 | ||
570 | /** Type of datafeed callback */ | |
571 | typedef function<void(shared_ptr<Device>, shared_ptr<Packet>)> | |
572 | DatafeedCallbackFunction; | |
573 | ||
07443fd2 | 574 | /* Data required for C callback function to call a C++ datafeed callback */ |
c23c8659 ML |
575 | class SR_PRIV DatafeedCallbackData |
576 | { | |
577 | public: | |
578 | void run(const struct sr_dev_inst *sdi, | |
579 | const struct sr_datafeed_packet *pkt); | |
580 | protected: | |
3b161085 | 581 | DatafeedCallbackFunction _callback; |
c23c8659 ML |
582 | DatafeedCallbackData(Session *session, |
583 | DatafeedCallbackFunction callback); | |
3b161085 | 584 | Session *_session; |
c23c8659 ML |
585 | friend class Session; |
586 | }; | |
587 | ||
588 | /** Type of source callback */ | |
589 | typedef function<bool(Glib::IOCondition)> | |
590 | SourceCallbackFunction; | |
591 | ||
07443fd2 | 592 | /* Data required for C callback function to call a C++ source callback */ |
c23c8659 ML |
593 | class SR_PRIV SourceCallbackData |
594 | { | |
595 | public: | |
596 | bool run(int revents); | |
597 | protected: | |
598 | SourceCallbackData(shared_ptr<EventSource> source); | |
3b161085 | 599 | shared_ptr<EventSource> _source; |
c23c8659 ML |
600 | friend class Session; |
601 | }; | |
602 | ||
07443fd2 | 603 | /** An I/O event source */ |
c23c8659 ML |
604 | class SR_API EventSource |
605 | { | |
606 | public: | |
b6f411ac ML |
607 | /** Create an event source from a file descriptor. |
608 | * @param fd File descriptor. | |
609 | * @param events GLib IOCondition event mask. | |
610 | * @param timeout Timeout in milliseconds. | |
611 | * @param callback Callback of the form callback(events) */ | |
c23c8659 ML |
612 | static shared_ptr<EventSource> create(int fd, Glib::IOCondition events, |
613 | int timeout, SourceCallbackFunction callback); | |
b6f411ac ML |
614 | /** Create an event source from a GLib PollFD |
615 | * @param pollfd GLib PollFD | |
616 | * @param timeout Timeout in milliseconds. | |
617 | * @param callback Callback of the form callback(events) */ | |
c23c8659 ML |
618 | static shared_ptr<EventSource> create(Glib::PollFD pollfd, int timeout, |
619 | SourceCallbackFunction callback); | |
b6f411ac ML |
620 | /** Create an event source from a GLib IOChannel |
621 | * @param channel GLib IOChannel. | |
622 | * @param events GLib IOCondition event mask. | |
623 | * @param timeout Timeout in milliseconds. | |
624 | * @param callback Callback of the form callback(events) */ | |
c23c8659 ML |
625 | static shared_ptr<EventSource> create( |
626 | Glib::RefPtr<Glib::IOChannel> channel, Glib::IOCondition events, | |
627 | int timeout, SourceCallbackFunction callback); | |
628 | protected: | |
629 | EventSource(int timeout, SourceCallbackFunction callback); | |
630 | ~EventSource(); | |
631 | enum source_type { | |
632 | SOURCE_FD, | |
633 | SOURCE_POLLFD, | |
634 | SOURCE_IOCHANNEL | |
3b161085 ML |
635 | } _type; |
636 | int _fd; | |
637 | Glib::PollFD _pollfd; | |
638 | Glib::RefPtr<Glib::IOChannel> _channel; | |
639 | Glib::IOCondition _events; | |
640 | int _timeout; | |
641 | SourceCallbackFunction _callback; | |
c23c8659 ML |
642 | /** Deleter needed to allow shared_ptr use with protected destructor. */ |
643 | class Deleter | |
644 | { | |
645 | public: | |
646 | void operator()(EventSource *source) { delete source; } | |
647 | }; | |
648 | friend class Deleter; | |
649 | friend class Session; | |
650 | friend class SourceCallbackData; | |
651 | }; | |
652 | ||
cac58676 ML |
653 | /** A virtual device associated with a stored session */ |
654 | class SR_API SessionDevice : | |
655 | public ParentOwned<SessionDevice, Session, struct sr_dev_inst>, | |
656 | public Device | |
657 | { | |
658 | protected: | |
659 | SessionDevice(struct sr_dev_inst *sdi); | |
660 | ~SessionDevice(); | |
661 | shared_ptr<Device> get_shared_from_this(); | |
662 | /** Deleter needed to allow shared_ptr use with protected destructor. */ | |
663 | class Deleter | |
664 | { | |
665 | public: | |
666 | void operator()(SessionDevice *device) { delete device; } | |
667 | }; | |
668 | friend class Deleter; | |
669 | friend class Session; | |
670 | }; | |
671 | ||
07443fd2 | 672 | /** A sigrok session */ |
90e89c2a | 673 | class SR_API Session : public UserOwned<Session, struct sr_session> |
c23c8659 ML |
674 | { |
675 | public: | |
b6f411ac ML |
676 | /** Add a device to this session. |
677 | * @param device Device to add. */ | |
c23c8659 ML |
678 | void add_device(shared_ptr<Device> device); |
679 | /** List devices attached to this session. */ | |
3b161085 | 680 | vector<shared_ptr<Device> > devices(); |
c23c8659 ML |
681 | /** Remove all devices from this session. */ |
682 | void remove_devices(); | |
b6f411ac ML |
683 | /** Add a datafeed callback to this session. |
684 | * @param callback Callback of the form callback(Device, Packet). */ | |
c23c8659 ML |
685 | void add_datafeed_callback(DatafeedCallbackFunction callback); |
686 | /** Remove all datafeed callbacks from this session. */ | |
687 | void remove_datafeed_callbacks(); | |
b6f411ac ML |
688 | /** Add an I/O event source. |
689 | * @param source EventSource to add. */ | |
c23c8659 | 690 | void add_source(shared_ptr<EventSource> source); |
b6f411ac ML |
691 | /** Remove an event source. |
692 | * @param source EventSource to remove. */ | |
c23c8659 ML |
693 | void remove_source(shared_ptr<EventSource> source); |
694 | /** Start the session. */ | |
695 | void start(); | |
696 | /** Run the session event loop. */ | |
697 | void run(); | |
698 | /** Stop the session. */ | |
699 | void stop(); | |
b6f411ac ML |
700 | /** Begin saving session to a file. |
701 | * @param filename File name string. */ | |
c23c8659 | 702 | void begin_save(string filename); |
b6f411ac ML |
703 | /** Append a packet to the session file being saved. |
704 | * @param packet Packet to append. */ | |
1d67cfb4 ML |
705 | void append(shared_ptr<Packet> packet); |
706 | /** Append raw logic data to the session file being saved. */ | |
707 | void append(void *data, size_t length, unsigned int unit_size); | |
6fa0eb86 | 708 | /** Get current trigger setting. */ |
3b161085 | 709 | shared_ptr<Trigger> trigger(); |
624d1610 UH |
710 | /** Get the context. */ |
711 | shared_ptr<Context> context(); | |
b6f411ac ML |
712 | /** Set trigger setting. |
713 | * @param trigger Trigger object to use. */ | |
6fa0eb86 | 714 | void set_trigger(shared_ptr<Trigger> trigger); |
1411f7d8 ML |
715 | /** Get filename this session was loaded from. */ |
716 | string filename(); | |
c23c8659 ML |
717 | protected: |
718 | Session(shared_ptr<Context> context); | |
719 | Session(shared_ptr<Context> context, string filename); | |
720 | ~Session(); | |
ca4e307a | 721 | shared_ptr<Device> get_device(const struct sr_dev_inst *sdi); |
3b161085 | 722 | const shared_ptr<Context> _context; |
ca4e307a ML |
723 | map<const struct sr_dev_inst *, SessionDevice *> _owned_devices; |
724 | map<const struct sr_dev_inst *, shared_ptr<Device> > _other_devices; | |
3b161085 ML |
725 | vector<DatafeedCallbackData *> _datafeed_callbacks; |
726 | map<shared_ptr<EventSource>, SourceCallbackData *> _source_callbacks; | |
98d39b91 | 727 | string _filename; |
3b161085 ML |
728 | bool _saving; |
729 | bool _save_initialized; | |
730 | string _save_filename; | |
731 | uint64_t _save_samplerate; | |
732 | shared_ptr<Trigger> _trigger; | |
c23c8659 ML |
733 | friend class Deleter; |
734 | friend class Context; | |
735 | friend class DatafeedCallbackData; | |
98d39b91 | 736 | friend class SessionDevice; |
c23c8659 ML |
737 | }; |
738 | ||
07443fd2 | 739 | /** A packet on the session datafeed */ |
90e89c2a | 740 | class SR_API Packet : public UserOwned<Packet, const struct sr_datafeed_packet> |
c23c8659 ML |
741 | { |
742 | public: | |
90ba83f2 | 743 | /** Type of this packet. */ |
3b161085 | 744 | const PacketType *type(); |
c23c8659 | 745 | /** Payload of this packet. */ |
3b161085 | 746 | shared_ptr<PacketPayload> payload(); |
c23c8659 | 747 | protected: |
2928f47d ML |
748 | Packet(shared_ptr<Device> device, |
749 | const struct sr_datafeed_packet *structure); | |
c23c8659 | 750 | ~Packet(); |
3b161085 ML |
751 | shared_ptr<Device> _device; |
752 | PacketPayload *_payload; | |
c23c8659 ML |
753 | friend class Deleter; |
754 | friend class Session; | |
755 | friend class Output; | |
756 | friend class DatafeedCallbackData; | |
2928f47d ML |
757 | friend class Header; |
758 | friend class Meta; | |
759 | friend class Logic; | |
760 | friend class Analog; | |
304be4a7 | 761 | friend class Context; |
c23c8659 ML |
762 | }; |
763 | ||
07443fd2 | 764 | /** Abstract base class for datafeed packet payloads */ |
c23c8659 ML |
765 | class SR_API PacketPayload |
766 | { | |
767 | protected: | |
768 | PacketPayload(); | |
769 | virtual ~PacketPayload() = 0; | |
4cd883a7 | 770 | virtual shared_ptr<PacketPayload> get_shared_pointer(Packet *parent) = 0; |
2928f47d ML |
771 | /** Deleter needed to allow shared_ptr use with protected destructor. */ |
772 | class Deleter | |
773 | { | |
774 | public: | |
775 | void operator()(PacketPayload *payload) { delete payload; } | |
776 | }; | |
777 | friend class Deleter; | |
c23c8659 ML |
778 | friend class Packet; |
779 | friend class Output; | |
780 | }; | |
781 | ||
2928f47d | 782 | /** Payload of a datafeed header packet */ |
4cd883a7 | 783 | class SR_API Header : |
541c855e | 784 | public ParentOwned<Header, Packet, const struct sr_datafeed_header>, |
4cd883a7 | 785 | public PacketPayload |
2928f47d ML |
786 | { |
787 | public: | |
b6f411ac | 788 | /* Feed version number. */ |
3b161085 | 789 | int feed_version(); |
b6f411ac | 790 | /* Start time of this session. */ |
3b161085 | 791 | Glib::TimeVal start_time(); |
2928f47d ML |
792 | protected: |
793 | Header(const struct sr_datafeed_header *structure); | |
794 | ~Header(); | |
4cd883a7 | 795 | shared_ptr<PacketPayload> get_shared_pointer(Packet *parent); |
2928f47d ML |
796 | friend class Packet; |
797 | }; | |
798 | ||
799 | /** Payload of a datafeed metadata packet */ | |
4cd883a7 | 800 | class SR_API Meta : |
541c855e | 801 | public ParentOwned<Meta, Packet, const struct sr_datafeed_meta>, |
4cd883a7 | 802 | public PacketPayload |
2928f47d ML |
803 | { |
804 | public: | |
b6f411ac | 805 | /* Mapping of (ConfigKey, value) pairs. */ |
3b161085 | 806 | map<const ConfigKey *, Glib::VariantBase> config(); |
2928f47d ML |
807 | protected: |
808 | Meta(const struct sr_datafeed_meta *structure); | |
809 | ~Meta(); | |
4cd883a7 | 810 | shared_ptr<PacketPayload> get_shared_pointer(Packet *parent); |
3b161085 | 811 | map<const ConfigKey *, Glib::VariantBase> _config; |
2928f47d ML |
812 | friend class Packet; |
813 | }; | |
814 | ||
07443fd2 | 815 | /** Payload of a datafeed packet with logic data */ |
4cd883a7 | 816 | class SR_API Logic : |
541c855e | 817 | public ParentOwned<Logic, Packet, const struct sr_datafeed_logic>, |
4cd883a7 | 818 | public PacketPayload |
c23c8659 | 819 | { |
2928f47d ML |
820 | public: |
821 | /* Pointer to data. */ | |
3b161085 | 822 | void *data_pointer(); |
2928f47d | 823 | /* Data length in bytes. */ |
3b161085 | 824 | size_t data_length(); |
2928f47d | 825 | /* Size of each sample in bytes. */ |
3b161085 | 826 | unsigned int unit_size(); |
c23c8659 ML |
827 | protected: |
828 | Logic(const struct sr_datafeed_logic *structure); | |
829 | ~Logic(); | |
4cd883a7 | 830 | shared_ptr<PacketPayload> get_shared_pointer(Packet *parent); |
c23c8659 ML |
831 | friend class Packet; |
832 | }; | |
833 | ||
07443fd2 | 834 | /** Payload of a datafeed packet with analog data */ |
4cd883a7 | 835 | class SR_API Analog : |
541c855e | 836 | public ParentOwned<Analog, Packet, const struct sr_datafeed_analog>, |
4cd883a7 | 837 | public PacketPayload |
c23c8659 ML |
838 | { |
839 | public: | |
2928f47d | 840 | /** Pointer to data. */ |
3b161085 | 841 | float *data_pointer(); |
c23c8659 | 842 | /** Number of samples in this packet. */ |
3b161085 | 843 | unsigned int num_samples(); |
2928f47d | 844 | /** Channels for which this packet contains data. */ |
3b161085 | 845 | vector<shared_ptr<Channel> > channels(); |
c23c8659 | 846 | /** Measured quantity of the samples in this packet. */ |
3b161085 | 847 | const Quantity *mq(); |
c23c8659 | 848 | /** Unit of the samples in this packet. */ |
3b161085 | 849 | const Unit *unit(); |
c23c8659 | 850 | /** Measurement flags associated with the samples in this packet. */ |
3b161085 | 851 | vector<const QuantityFlag *> mq_flags(); |
c23c8659 ML |
852 | protected: |
853 | Analog(const struct sr_datafeed_analog *structure); | |
854 | ~Analog(); | |
4cd883a7 | 855 | shared_ptr<PacketPayload> get_shared_pointer(Packet *parent); |
c23c8659 ML |
856 | friend class Packet; |
857 | }; | |
858 | ||
07443fd2 | 859 | /** An input format supported by the library */ |
c23c8659 | 860 | class SR_API InputFormat : |
541c855e | 861 | public ParentOwned<InputFormat, Context, const struct sr_input_module> |
c23c8659 ML |
862 | { |
863 | public: | |
864 | /** Name of this input format. */ | |
3b161085 | 865 | string name(); |
c23c8659 | 866 | /** Description of this input format. */ |
3b161085 | 867 | string description(); |
ca3291e3 | 868 | /** Options supported by this input format. */ |
3b161085 | 869 | map<string, shared_ptr<Option> > options(); |
ca3291e3 ML |
870 | /** Create an input using this input format. |
871 | * @param options Mapping of (option name, value) pairs. */ | |
db560903 ML |
872 | shared_ptr<Input> create_input(map<string, Glib::VariantBase> options = |
873 | map<string, Glib::VariantBase>()); | |
c23c8659 | 874 | protected: |
ca3291e3 | 875 | InputFormat(const struct sr_input_module *structure); |
c23c8659 ML |
876 | ~InputFormat(); |
877 | friend class Context; | |
ca3291e3 | 878 | friend class InputDevice; |
c23c8659 ML |
879 | }; |
880 | ||
ca3291e3 | 881 | /** An input instance (an input format applied to a file or stream) */ |
90e89c2a | 882 | class SR_API Input : public UserOwned<Input, const struct sr_input> |
c23c8659 ML |
883 | { |
884 | public: | |
ca3291e3 | 885 | /** Virtual device associated with this input. */ |
3b161085 | 886 | shared_ptr<InputDevice> device(); |
ca3291e3 ML |
887 | /** Send next stream data. |
888 | * @param data Next stream data. */ | |
889 | void send(string data); | |
9c51e8ec ML |
890 | /** Signal end of input data. */ |
891 | void end(); | |
c23c8659 | 892 | protected: |
ca3291e3 ML |
893 | Input(shared_ptr<Context> context, const struct sr_input *structure); |
894 | ~Input(); | |
3b161085 ML |
895 | shared_ptr<Context> _context; |
896 | InputDevice *_device; | |
c23c8659 | 897 | friend class Deleter; |
ca3291e3 | 898 | friend class Context; |
c23c8659 ML |
899 | friend class InputFormat; |
900 | }; | |
901 | ||
ca3291e3 | 902 | /** A virtual device associated with an input */ |
6e5240f4 | 903 | class SR_API InputDevice : |
541c855e | 904 | public ParentOwned<InputDevice, Input, struct sr_dev_inst>, |
6e5240f4 | 905 | public Device |
ca3291e3 ML |
906 | { |
907 | protected: | |
908 | InputDevice(shared_ptr<Input> input, struct sr_dev_inst *sdi); | |
909 | ~InputDevice(); | |
d01d2314 | 910 | shared_ptr<Device> get_shared_from_this(); |
3b161085 | 911 | shared_ptr<Input> _input; |
ca3291e3 ML |
912 | friend class Input; |
913 | }; | |
914 | ||
58aa1f83 | 915 | /** An option used by an output format */ |
90e89c2a | 916 | class SR_API Option : public UserOwned<Option, const struct sr_option> |
58aa1f83 ML |
917 | { |
918 | public: | |
919 | /** Short name of this option suitable for command line usage. */ | |
3b161085 | 920 | string id(); |
58aa1f83 | 921 | /** Short name of this option suitable for GUI usage. */ |
3b161085 | 922 | string name(); |
58aa1f83 | 923 | /** Description of this option in a sentence. */ |
3b161085 | 924 | string description(); |
58aa1f83 | 925 | /** Default value for this option. */ |
3b161085 | 926 | Glib::VariantBase default_value(); |
58aa1f83 | 927 | /** Possible values for this option, if a limited set. */ |
3b161085 | 928 | vector<Glib::VariantBase> values(); |
58aa1f83 ML |
929 | protected: |
930 | Option(const struct sr_option *structure, | |
70d3b20b | 931 | shared_ptr<const struct sr_option *> structure_array); |
58aa1f83 | 932 | ~Option(); |
3b161085 | 933 | shared_ptr<const struct sr_option *> _structure_array; |
58aa1f83 | 934 | friend class Deleter; |
43942280 | 935 | friend class InputFormat; |
58aa1f83 ML |
936 | friend class OutputFormat; |
937 | }; | |
938 | ||
07443fd2 | 939 | /** An output format supported by the library */ |
c23c8659 | 940 | class SR_API OutputFormat : |
541c855e | 941 | public ParentOwned<OutputFormat, Context, const struct sr_output_module> |
c23c8659 ML |
942 | { |
943 | public: | |
944 | /** Name of this output format. */ | |
3b161085 | 945 | string name(); |
c23c8659 | 946 | /** Description of this output format. */ |
3b161085 | 947 | string description(); |
58aa1f83 | 948 | /** Options supported by this output format. */ |
3b161085 | 949 | map<string, shared_ptr<Option> > options(); |
b6f411ac ML |
950 | /** Create an output using this format. |
951 | * @param device Device to output for. | |
952 | * @param options Mapping of (option name, value) pairs. */ | |
58aa1f83 | 953 | shared_ptr<Output> create_output(shared_ptr<Device> device, |
db560903 ML |
954 | map<string, Glib::VariantBase> options = |
955 | map<string, Glib::VariantBase>()); | |
c23c8659 | 956 | protected: |
58aa1f83 | 957 | OutputFormat(const struct sr_output_module *structure); |
c23c8659 ML |
958 | ~OutputFormat(); |
959 | friend class Context; | |
960 | friend class Output; | |
961 | }; | |
962 | ||
07443fd2 | 963 | /** An output instance (an output format applied to a device) */ |
90e89c2a | 964 | class SR_API Output : public UserOwned<Output, const struct sr_output> |
c23c8659 ML |
965 | { |
966 | public: | |
b6f411ac ML |
967 | /** Update output with data from the given packet. |
968 | * @param packet Packet to handle. */ | |
c23c8659 ML |
969 | string receive(shared_ptr<Packet> packet); |
970 | protected: | |
971 | Output(shared_ptr<OutputFormat> format, shared_ptr<Device> device); | |
972 | Output(shared_ptr<OutputFormat> format, | |
58aa1f83 | 973 | shared_ptr<Device> device, map<string, Glib::VariantBase> options); |
c23c8659 | 974 | ~Output(); |
3b161085 ML |
975 | const shared_ptr<OutputFormat> _format; |
976 | const shared_ptr<Device> _device; | |
977 | const map<string, Glib::VariantBase> _options; | |
c23c8659 ML |
978 | friend class Deleter; |
979 | friend class OutputFormat; | |
980 | }; | |
981 | ||
982 | /** Base class for objects which wrap an enumeration value from libsigrok */ | |
9d229ecb | 983 | template <class Class, typename Enum> class SR_API EnumValue |
c23c8659 ML |
984 | { |
985 | public: | |
9d229ecb ML |
986 | /** The integer constant associated with this value. */ |
987 | int id() const | |
988 | { | |
989 | return static_cast<int>(_id); | |
990 | } | |
c23c8659 | 991 | /** The name associated with this value. */ |
9d229ecb ML |
992 | string name() const |
993 | { | |
994 | return _name; | |
995 | } | |
996 | /** Get value associated with a given integer constant. */ | |
997 | static const Class *get(int id) | |
998 | { | |
999 | auto key = static_cast<Enum>(id); | |
1000 | if (_values.find(key) == _values.end()) | |
1001 | throw Error(SR_ERR_ARG); | |
1002 | return _values.at(key); | |
1003 | } | |
1004 | /** Get possible values. */ | |
1005 | static std::vector<const Class *> values() | |
1006 | { | |
1007 | std::vector<const Class *> result; | |
1008 | for (auto entry : _values) | |
1009 | result.push_back(entry.second); | |
1010 | return result; | |
1011 | } | |
c23c8659 | 1012 | protected: |
9d229ecb ML |
1013 | EnumValue(Enum id, const char name[]) : _id(id), _name(name) |
1014 | { | |
1015 | } | |
1016 | ~EnumValue() | |
1017 | { | |
1018 | } | |
1019 | static const std::map<const Enum, const Class * const> _values; | |
1020 | const Enum _id; | |
3b161085 | 1021 | const string _name; |
c23c8659 ML |
1022 | }; |
1023 | ||
1024 | #include "enums.hpp" | |
1025 | ||
1026 | } | |
1027 | ||
1028 | #endif // LIBSIGROK_HPP |