2 * This file is part of the libsigrok project.
4 * Copyright (C) 2013-2014 Martin Ling <martin-sigrok@earth.li>
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.
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.
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/>.
22 @mainpage API Reference
27 The sigrok++ API provides an object-oriented C++ interface to the functionality
28 in libsigrok, including automatic memory and resource management.
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.
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.
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.
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.
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.
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.
73 #include "libsigrok/libsigrok.h"
74 #include <glibmm-2.4/glibmm.h>
87 /* Forward declarations */
92 class SR_API HardwareDevice;
94 class SR_API EventSource;
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;
107 class SR_API PacketPayload;
108 class SR_API PacketType;
109 class SR_API Quantity;
111 class SR_API QuantityFlag;
113 class SR_API InputDevice;
115 class SR_API DataType;
118 /** Exception thrown when an error code is returned by any libsigrok call. */
119 class SR_API Error: public exception
125 const char *what() const throw();
128 /* Base template for classes whose resources are owned by a parent object. */
129 template <class Class, class Parent, typename Struct>
130 class SR_API ParentOwned
133 /* Parent object which owns this child object's underlying structure.
135 This shared pointer will be null when this child is unused, but
136 will be assigned to point to the parent before any shared pointer
137 to this child is handed out to the user.
139 When the reference count of this child falls to zero, this shared
140 pointer to its parent is reset by a custom deleter on the child's
143 This strategy ensures that the destructors for both the child and
144 the parent are called at the correct time, i.e. only when all
145 references to both the parent and all its children are gone. */
146 shared_ptr<Parent> _parent;
148 /* Weak pointer for shared_from_this() implementation. */
149 weak_ptr<Class> _weak_this;
152 /* Get parent object that owns this object. */
153 shared_ptr<Parent> parent()
158 /* Note, this implementation will create a new smart_ptr if none exists. */
159 shared_ptr<Class> shared_from_this()
161 shared_ptr<Class> shared;
163 if (!(shared = _weak_this.lock()))
165 shared = shared_ptr<Class>((Class *) this, reset_parent);
172 shared_ptr<Class> get_shared_pointer(shared_ptr<Parent> parent)
175 throw Error(SR_ERR_BUG);
176 this->_parent = parent;
177 return shared_from_this();
180 shared_ptr<Class> get_shared_pointer(Parent *parent)
183 throw Error(SR_ERR_BUG);
184 return get_shared_pointer(parent->shared_from_this());
187 static void reset_parent(Class *object)
189 if (!object->_parent)
190 throw Error(SR_ERR_BUG);
191 object->_parent.reset();
196 ParentOwned<Class, Parent, Struct>(Struct *structure) :
197 _structure(structure)
202 /* Base template for classes whose resources are owned by the user. */
203 template <class Class, typename Struct>
204 class SR_API UserOwned : public enable_shared_from_this<Class>
207 shared_ptr<Class> shared_from_this()
209 auto shared = enable_shared_from_this<Class>::shared_from_this();
211 throw Error(SR_ERR_BUG);
217 UserOwned<Class, Struct>(Struct *structure) :
218 _structure(structure)
222 /* Deleter needed to allow shared_ptr use with protected destructor. */
226 void operator()(Class *object) { delete object; }
230 /** Type of log callback */
231 typedef function<void(const LogLevel *, string message)> LogCallbackFunction;
233 /** The global libsigrok context */
234 class SR_API Context : public UserOwned<Context, struct sr_context>
237 /** Create new context */
238 static shared_ptr<Context> create();
239 /** libsigrok package version. */
240 string package_version();
241 /** libsigrok library version. */
242 string lib_version();
243 /** Available hardware drivers, indexed by name. */
244 map<string, shared_ptr<Driver> > drivers();
245 /** Available input formats, indexed by name. */
246 map<string, shared_ptr<InputFormat> > input_formats();
247 /** Available output formats, indexed by name. */
248 map<string, shared_ptr<OutputFormat> > output_formats();
249 /** Current log level. */
250 const LogLevel *log_level();
251 /** Set the log level.
252 * @param level LogLevel to use. */
253 void set_log_level(const LogLevel *level);
254 /** Current log domain. */
256 /** Set the log domain.
257 * @param value Log domain prefix string. */
258 void set_log_domain(string value);
259 /** Set the log callback.
260 * @param callback Callback of the form callback(LogLevel, string). */
261 void set_log_callback(LogCallbackFunction callback);
262 /** Set the log callback to the default handler. */
263 void set_log_callback_default();
264 /** Create a new session. */
265 shared_ptr<Session> create_session();
266 /** Load a saved session.
267 * @param filename File name string. */
268 shared_ptr<Session> load_session(string filename);
269 /** Create a new trigger.
270 * @param name Name string for new trigger. */
271 shared_ptr<Trigger> create_trigger(string name);
272 /** Open an input file.
273 * @param filename File name string. */
274 shared_ptr<Input> open_file(string filename);
275 /** Open an input stream based on header data.
276 * @param header Initial data from stream. */
277 shared_ptr<Input> open_stream(string header);
279 map<string, Driver *> _drivers;
280 map<string, InputFormat *> _input_formats;
281 map<string, OutputFormat *> _output_formats;
283 LogCallbackFunction _log_callback;
286 friend class Deleter;
287 friend class Session;
297 /** An object that can be configured. */
298 class SR_API Configurable
301 /** Read configuration for the given key.
302 * @param key ConfigKey to read. */
303 Glib::VariantBase config_get(const ConfigKey *key);
304 /** Set configuration for the given key to a specified value.
305 * @param key ConfigKey to set.
306 * @param value Value to set. */
307 void config_set(const ConfigKey *key, Glib::VariantBase value);
308 /** Enumerate available values for the given configuration key.
309 * @param key ConfigKey to enumerate values for. */
310 Glib::VariantContainerBase config_list(const ConfigKey *key);
311 /** Enumerate available keys, according to a given index key. */
312 map<const ConfigKey *, set<Capability> > config_keys(const ConfigKey *key);
313 /** Check for a key in the list from a given index key. */
314 bool config_check(const ConfigKey *key, const ConfigKey *index_key);
317 struct sr_dev_driver *driver,
318 struct sr_dev_inst *sdi,
319 struct sr_channel_group *channel_group);
320 virtual ~Configurable();
321 struct sr_dev_driver *config_driver;
322 struct sr_dev_inst *config_sdi;
323 struct sr_channel_group *config_channel_group;
326 /** A hardware driver provided by the library */
327 class SR_API Driver :
328 public ParentOwned<Driver, Context, struct sr_dev_driver>,
332 /** Name of this driver. */
334 /** Long name for this driver. */
336 /** Scan for devices and return a list of devices found.
337 * @param options Mapping of (ConfigKey, value) pairs. */
338 vector<shared_ptr<HardwareDevice> > scan(
339 map<const ConfigKey *, Glib::VariantBase> options =
340 map<const ConfigKey *, Glib::VariantBase>());
343 vector<HardwareDevice *> _devices;
344 Driver(struct sr_dev_driver *structure);
346 friend class Context;
347 friend class HardwareDevice;
348 friend class ChannelGroup;
351 /** A generic device, either hardware or virtual */
352 class SR_API Device : public Configurable
355 /** Vendor name for this device. */
357 /** Model name for this device. */
359 /** Version string for this device. */
361 /** Serial number for this device. */
362 string serial_number();
363 /** Connection ID for this device. */
364 string connection_id();
365 /** List of the channels available on this device. */
366 vector<shared_ptr<Channel> > channels();
367 /** Channel groups available on this device, indexed by name. */
368 map<string, shared_ptr<ChannelGroup> > channel_groups();
374 Device(struct sr_dev_inst *structure);
376 virtual shared_ptr<Device> get_shared_from_this() = 0;
377 shared_ptr<Channel> get_channel(struct sr_channel *ptr);
378 struct sr_dev_inst *_structure;
379 map<struct sr_channel *, Channel *> _channels;
380 map<string, ChannelGroup *> _channel_groups;
381 /** Deleter needed to allow shared_ptr use with protected destructor. */
385 void operator()(Device *device) { delete device; }
387 friend class Deleter;
388 friend class Session;
389 friend class Channel;
390 friend class ChannelGroup;
395 /** A real hardware device, connected via a driver */
396 class SR_API HardwareDevice :
397 public UserOwned<HardwareDevice, struct sr_dev_inst>,
401 /** Driver providing this device. */
402 shared_ptr<Driver> driver();
404 HardwareDevice(shared_ptr<Driver> driver, struct sr_dev_inst *structure);
406 shared_ptr<Device> get_shared_from_this();
407 shared_ptr<Driver> _driver;
408 /** Deleter needed to allow shared_ptr use with protected destructor. */
412 void operator()(HardwareDevice *device) { delete device; }
414 friend class Deleter;
416 friend class ChannelGroup;
419 /** A channel on a device */
420 class SR_API Channel :
421 public ParentOwned<Channel, Device, struct sr_channel>
424 /** Current name of this channel. */
426 /** Set the name of this channel. *
427 * @param name Name string to set. */
428 void set_name(string name);
429 /** Type of this channel. */
430 const ChannelType *type();
431 /** Enabled status of this channel. */
433 /** Set the enabled status of this channel.
434 * @param value Boolean value to set. */
435 void set_enabled(bool value);
436 /** Get the index number of this channel. */
437 unsigned int index();
439 Channel(struct sr_channel *structure);
441 const ChannelType * const _type;
443 friend class ChannelGroup;
444 friend class Session;
445 friend class TriggerStage;
448 /** A group of channels on a device, which share some configuration */
449 class SR_API ChannelGroup :
450 public ParentOwned<ChannelGroup, Device, struct sr_channel_group>,
454 /** Name of this channel group. */
456 /** List of the channels in this group. */
457 vector<shared_ptr<Channel> > channels();
459 ChannelGroup(Device *device, struct sr_channel_group *structure);
461 vector<Channel *> _channels;
465 /** A trigger configuration */
466 class SR_API Trigger : public UserOwned<Trigger, struct sr_trigger>
469 /** Name of this trigger configuration. */
471 /** List of the stages in this trigger. */
472 vector<shared_ptr<TriggerStage> > stages();
473 /** Add a new stage to this trigger. */
474 shared_ptr<TriggerStage> add_stage();
476 Trigger(shared_ptr<Context> context, string name);
478 shared_ptr<Context> _context;
479 vector<TriggerStage *> _stages;
480 friend class Deleter;
481 friend class Context;
482 friend class Session;
485 /** A stage in a trigger configuration */
486 class SR_API TriggerStage :
487 public ParentOwned<TriggerStage, Trigger, struct sr_trigger_stage>
490 /** Index number of this stage. */
492 /** List of match conditions on this stage. */
493 vector<shared_ptr<TriggerMatch> > matches();
494 /** Add a new match condition to this stage.
495 * @param channel Channel to match on.
496 * @param type TriggerMatchType to apply. */
497 void add_match(shared_ptr<Channel> channel, const TriggerMatchType *type);
498 /** Add a new match condition to this stage.
499 * @param channel Channel to match on.
500 * @param type TriggerMatchType to apply.
501 * @param value Threshold value. */
502 void add_match(shared_ptr<Channel> channel, const TriggerMatchType *type, float value);
504 vector<TriggerMatch *> _matches;
505 TriggerStage(struct sr_trigger_stage *structure);
507 friend class Trigger;
510 /** A match condition in a trigger configuration */
511 class SR_API TriggerMatch :
512 public ParentOwned<TriggerMatch, TriggerStage, struct sr_trigger_match>
515 /** Channel this condition matches on. */
516 shared_ptr<Channel> channel();
517 /** Type of match. */
518 const TriggerMatchType *type();
519 /** Threshold value. */
522 TriggerMatch(struct sr_trigger_match *structure, shared_ptr<Channel> channel);
524 shared_ptr<Channel> _channel;
525 friend class TriggerStage;
528 /** Type of datafeed callback */
529 typedef function<void(shared_ptr<Device>, shared_ptr<Packet>)>
530 DatafeedCallbackFunction;
532 /* Data required for C callback function to call a C++ datafeed callback */
533 class SR_PRIV DatafeedCallbackData
536 void run(const struct sr_dev_inst *sdi,
537 const struct sr_datafeed_packet *pkt);
539 DatafeedCallbackFunction _callback;
540 DatafeedCallbackData(Session *session,
541 DatafeedCallbackFunction callback);
543 friend class Session;
546 /** Type of source callback */
547 typedef function<bool(Glib::IOCondition)>
548 SourceCallbackFunction;
550 /* Data required for C callback function to call a C++ source callback */
551 class SR_PRIV SourceCallbackData
554 bool run(int revents);
556 SourceCallbackData(shared_ptr<EventSource> source);
557 shared_ptr<EventSource> _source;
558 friend class Session;
561 /** An I/O event source */
562 class SR_API EventSource
565 /** Create an event source from a file descriptor.
566 * @param fd File descriptor.
567 * @param events GLib IOCondition event mask.
568 * @param timeout Timeout in milliseconds.
569 * @param callback Callback of the form callback(events) */
570 static shared_ptr<EventSource> create(int fd, Glib::IOCondition events,
571 int timeout, SourceCallbackFunction callback);
572 /** Create an event source from a GLib PollFD
573 * @param pollfd GLib PollFD
574 * @param timeout Timeout in milliseconds.
575 * @param callback Callback of the form callback(events) */
576 static shared_ptr<EventSource> create(Glib::PollFD pollfd, int timeout,
577 SourceCallbackFunction callback);
578 /** Create an event source from a GLib IOChannel
579 * @param channel GLib IOChannel.
580 * @param events GLib IOCondition event mask.
581 * @param timeout Timeout in milliseconds.
582 * @param callback Callback of the form callback(events) */
583 static shared_ptr<EventSource> create(
584 Glib::RefPtr<Glib::IOChannel> channel, Glib::IOCondition events,
585 int timeout, SourceCallbackFunction callback);
587 EventSource(int timeout, SourceCallbackFunction callback);
595 Glib::PollFD _pollfd;
596 Glib::RefPtr<Glib::IOChannel> _channel;
597 Glib::IOCondition _events;
599 SourceCallbackFunction _callback;
600 /** Deleter needed to allow shared_ptr use with protected destructor. */
604 void operator()(EventSource *source) { delete source; }
606 friend class Deleter;
607 friend class Session;
608 friend class SourceCallbackData;
611 /** A virtual device associated with a stored session */
612 class SR_API SessionDevice :
613 public ParentOwned<SessionDevice, Session, struct sr_dev_inst>,
617 SessionDevice(struct sr_dev_inst *sdi);
619 shared_ptr<Device> get_shared_from_this();
620 /** Deleter needed to allow shared_ptr use with protected destructor. */
624 void operator()(SessionDevice *device) { delete device; }
626 friend class Deleter;
627 friend class Session;
630 /** A sigrok session */
631 class SR_API Session : public UserOwned<Session, struct sr_session>
634 /** Add a device to this session.
635 * @param device Device to add. */
636 void add_device(shared_ptr<Device> device);
637 /** List devices attached to this session. */
638 vector<shared_ptr<Device> > devices();
639 /** Remove all devices from this session. */
640 void remove_devices();
641 /** Add a datafeed callback to this session.
642 * @param callback Callback of the form callback(Device, Packet). */
643 void add_datafeed_callback(DatafeedCallbackFunction callback);
644 /** Remove all datafeed callbacks from this session. */
645 void remove_datafeed_callbacks();
646 /** Add an I/O event source.
647 * @param source EventSource to add. */
648 void add_source(shared_ptr<EventSource> source);
649 /** Remove an event source.
650 * @param source EventSource to remove. */
651 void remove_source(shared_ptr<EventSource> source);
652 /** Start the session. */
654 /** Run the session event loop. */
656 /** Stop the session. */
658 /** Begin saving session to a file.
659 * @param filename File name string. */
660 void begin_save(string filename);
661 /** Append a packet to the session file being saved.
662 * @param packet Packet to append. */
663 void append(shared_ptr<Packet> packet);
664 /** Append raw logic data to the session file being saved. */
665 void append(void *data, size_t length, unsigned int unit_size);
666 /** Get current trigger setting. */
667 shared_ptr<Trigger> trigger();
668 /** Set trigger setting.
669 * @param trigger Trigger object to use. */
670 void set_trigger(shared_ptr<Trigger> trigger);
671 /** Get filename this session was loaded from. */
674 Session(shared_ptr<Context> context);
675 Session(shared_ptr<Context> context, string filename);
677 shared_ptr<Device> get_device(const struct sr_dev_inst *sdi);
678 const shared_ptr<Context> _context;
679 map<const struct sr_dev_inst *, SessionDevice *> _owned_devices;
680 map<const struct sr_dev_inst *, shared_ptr<Device> > _other_devices;
681 vector<DatafeedCallbackData *> _datafeed_callbacks;
682 map<shared_ptr<EventSource>, SourceCallbackData *> _source_callbacks;
685 bool _save_initialized;
686 string _save_filename;
687 uint64_t _save_samplerate;
688 shared_ptr<Trigger> _trigger;
689 friend class Deleter;
690 friend class Context;
691 friend class DatafeedCallbackData;
692 friend class SessionDevice;
695 /** A packet on the session datafeed */
696 class SR_API Packet : public UserOwned<Packet, const struct sr_datafeed_packet>
699 /** Type of this packet. */
700 const PacketType *type();
701 /** Payload of this packet. */
702 shared_ptr<PacketPayload> payload();
704 Packet(shared_ptr<Device> device,
705 const struct sr_datafeed_packet *structure);
707 shared_ptr<Device> _device;
708 PacketPayload *_payload;
709 friend class Deleter;
710 friend class Session;
712 friend class DatafeedCallbackData;
719 /** Abstract base class for datafeed packet payloads */
720 class SR_API PacketPayload
724 virtual ~PacketPayload() = 0;
725 virtual shared_ptr<PacketPayload> get_shared_pointer(Packet *parent) = 0;
726 /** Deleter needed to allow shared_ptr use with protected destructor. */
730 void operator()(PacketPayload *payload) { delete payload; }
732 friend class Deleter;
737 /** Payload of a datafeed header packet */
738 class SR_API Header :
739 public ParentOwned<Header, Packet, const struct sr_datafeed_header>,
743 /* Feed version number. */
745 /* Start time of this session. */
746 Glib::TimeVal start_time();
748 Header(const struct sr_datafeed_header *structure);
750 shared_ptr<PacketPayload> get_shared_pointer(Packet *parent);
754 /** Payload of a datafeed metadata packet */
756 public ParentOwned<Meta, Packet, const struct sr_datafeed_meta>,
760 /* Mapping of (ConfigKey, value) pairs. */
761 map<const ConfigKey *, Glib::VariantBase> config();
763 Meta(const struct sr_datafeed_meta *structure);
765 shared_ptr<PacketPayload> get_shared_pointer(Packet *parent);
766 map<const ConfigKey *, Glib::VariantBase> _config;
770 /** Payload of a datafeed packet with logic data */
772 public ParentOwned<Logic, Packet, const struct sr_datafeed_logic>,
776 /* Pointer to data. */
777 void *data_pointer();
778 /* Data length in bytes. */
779 size_t data_length();
780 /* Size of each sample in bytes. */
781 unsigned int unit_size();
783 Logic(const struct sr_datafeed_logic *structure);
785 shared_ptr<PacketPayload> get_shared_pointer(Packet *parent);
789 /** Payload of a datafeed packet with analog data */
790 class SR_API Analog :
791 public ParentOwned<Analog, Packet, const struct sr_datafeed_analog>,
795 /** Pointer to data. */
796 float *data_pointer();
797 /** Number of samples in this packet. */
798 unsigned int num_samples();
799 /** Channels for which this packet contains data. */
800 vector<shared_ptr<Channel> > channels();
801 /** Measured quantity of the samples in this packet. */
802 const Quantity *mq();
803 /** Unit of the samples in this packet. */
805 /** Measurement flags associated with the samples in this packet. */
806 vector<const QuantityFlag *> mq_flags();
808 Analog(const struct sr_datafeed_analog *structure);
810 shared_ptr<PacketPayload> get_shared_pointer(Packet *parent);
814 /** An input format supported by the library */
815 class SR_API InputFormat :
816 public ParentOwned<InputFormat, Context, const struct sr_input_module>
819 /** Name of this input format. */
821 /** Description of this input format. */
822 string description();
823 /** Options supported by this input format. */
824 map<string, shared_ptr<Option> > options();
825 /** Create an input using this input format.
826 * @param options Mapping of (option name, value) pairs. */
827 shared_ptr<Input> create_input(map<string, Glib::VariantBase> options =
828 map<string, Glib::VariantBase>());
830 InputFormat(const struct sr_input_module *structure);
832 friend class Context;
833 friend class InputDevice;
836 /** An input instance (an input format applied to a file or stream) */
837 class SR_API Input : public UserOwned<Input, const struct sr_input>
840 /** Virtual device associated with this input. */
841 shared_ptr<InputDevice> device();
842 /** Send next stream data.
843 * @param data Next stream data. */
844 void send(string data);
845 /** Signal end of input data. */
848 Input(shared_ptr<Context> context, const struct sr_input *structure);
850 shared_ptr<Context> _context;
851 InputDevice *_device;
852 friend class Deleter;
853 friend class Context;
854 friend class InputFormat;
857 /** A virtual device associated with an input */
858 class SR_API InputDevice :
859 public ParentOwned<InputDevice, Input, struct sr_dev_inst>,
863 InputDevice(shared_ptr<Input> input, struct sr_dev_inst *sdi);
865 shared_ptr<Device> get_shared_from_this();
866 shared_ptr<Input> _input;
870 /** An option used by an output format */
871 class SR_API Option : public UserOwned<Option, const struct sr_option>
874 /** Short name of this option suitable for command line usage. */
876 /** Short name of this option suitable for GUI usage. */
878 /** Description of this option in a sentence. */
879 string description();
880 /** Default value for this option. */
881 Glib::VariantBase default_value();
882 /** Possible values for this option, if a limited set. */
883 vector<Glib::VariantBase> values();
885 Option(const struct sr_option *structure,
886 shared_ptr<const struct sr_option *> structure_array);
888 shared_ptr<const struct sr_option *> _structure_array;
889 friend class Deleter;
890 friend class InputFormat;
891 friend class OutputFormat;
894 /** An output format supported by the library */
895 class SR_API OutputFormat :
896 public ParentOwned<OutputFormat, Context, const struct sr_output_module>
899 /** Name of this output format. */
901 /** Description of this output format. */
902 string description();
903 /** Options supported by this output format. */
904 map<string, shared_ptr<Option> > options();
905 /** Create an output using this format.
906 * @param device Device to output for.
907 * @param options Mapping of (option name, value) pairs. */
908 shared_ptr<Output> create_output(shared_ptr<Device> device,
909 map<string, Glib::VariantBase> options =
910 map<string, Glib::VariantBase>());
912 OutputFormat(const struct sr_output_module *structure);
914 friend class Context;
918 /** An output instance (an output format applied to a device) */
919 class SR_API Output : public UserOwned<Output, const struct sr_output>
922 /** Update output with data from the given packet.
923 * @param packet Packet to handle. */
924 string receive(shared_ptr<Packet> packet);
926 Output(shared_ptr<OutputFormat> format, shared_ptr<Device> device);
927 Output(shared_ptr<OutputFormat> format,
928 shared_ptr<Device> device, map<string, Glib::VariantBase> options);
930 const shared_ptr<OutputFormat> _format;
931 const shared_ptr<Device> _device;
932 const map<string, Glib::VariantBase> _options;
933 friend class Deleter;
934 friend class OutputFormat;
937 /** Base class for objects which wrap an enumeration value from libsigrok */
938 template <typename T> class SR_API EnumValue
941 /** The enum constant associated with this value. */
942 T id() const { return _id; }
943 /** The name associated with this value. */
944 string name() const { return _name; }
946 EnumValue(T id, const char name[]) : _id(id), _name(name) {}
956 #endif // LIBSIGROK_HPP