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 /* Note, this implementation will create a new smart_ptr if none exists. */
153 shared_ptr<Class> shared_from_this()
155 shared_ptr<Class> shared;
157 if (!(shared = _weak_this.lock()))
159 shared = shared_ptr<Class>((Class *) this, reset_parent);
166 shared_ptr<Class> get_shared_pointer(shared_ptr<Parent> parent)
169 throw Error(SR_ERR_BUG);
170 this->_parent = parent;
171 return shared_from_this();
174 shared_ptr<Class> get_shared_pointer(Parent *parent)
177 throw Error(SR_ERR_BUG);
178 return get_shared_pointer(parent->shared_from_this());
181 static void reset_parent(Class *object)
183 if (!object->_parent)
184 throw Error(SR_ERR_BUG);
185 object->_parent.reset();
190 ParentOwned<Class, Parent, Struct>(Struct *structure) :
191 _structure(structure)
196 /* Base template for classes whose resources are owned by the user. */
197 template <class Class, typename Struct>
198 class SR_API UserOwned : public enable_shared_from_this<Class>
201 shared_ptr<Class> shared_from_this()
203 auto shared = enable_shared_from_this<Class>::shared_from_this();
205 throw Error(SR_ERR_BUG);
211 UserOwned<Class, Struct>(Struct *structure) :
212 _structure(structure)
216 /* Deleter needed to allow shared_ptr use with protected destructor. */
220 void operator()(Class *object) { delete object; }
224 /** Type of log callback */
225 typedef function<void(const LogLevel *, string message)> LogCallbackFunction;
227 /** The global libsigrok context */
228 class SR_API Context : public UserOwned<Context, struct sr_context>
231 /** Create new context */
232 static shared_ptr<Context> create();
233 /** libsigrok package version. */
234 string package_version();
235 /** libsigrok library version. */
236 string lib_version();
237 /** Available hardware drivers, indexed by name. */
238 map<string, shared_ptr<Driver> > drivers();
239 /** Available input formats, indexed by name. */
240 map<string, shared_ptr<InputFormat> > input_formats();
241 /** Available output formats, indexed by name. */
242 map<string, shared_ptr<OutputFormat> > output_formats();
243 /** Current log level. */
244 const LogLevel *log_level();
245 /** Set the log level.
246 * @param level LogLevel to use. */
247 void set_log_level(const LogLevel *level);
248 /** Current log domain. */
250 /** Set the log domain.
251 * @param value Log domain prefix string. */
252 void set_log_domain(string value);
253 /** Set the log callback.
254 * @param callback Callback of the form callback(LogLevel, string). */
255 void set_log_callback(LogCallbackFunction callback);
256 /** Set the log callback to the default handler. */
257 void set_log_callback_default();
258 /** Create a new session. */
259 shared_ptr<Session> create_session();
260 /** Load a saved session.
261 * @param filename File name string. */
262 shared_ptr<Session> load_session(string filename);
263 /** Create a new trigger.
264 * @param name Name string for new trigger. */
265 shared_ptr<Trigger> create_trigger(string name);
266 /** Open an input file.
267 * @param filename File name string. */
268 shared_ptr<Input> open_file(string filename);
269 /** Open an input stream based on header data.
270 * @param header Initial data from stream. */
271 shared_ptr<Input> open_stream(string header);
273 map<string, Driver *> _drivers;
274 map<string, InputFormat *> _input_formats;
275 map<string, OutputFormat *> _output_formats;
277 LogCallbackFunction _log_callback;
280 friend class Deleter;
281 friend class Session;
291 /** An object that can be configured. */
292 class SR_API Configurable
295 /** Read configuration for the given key.
296 * @param key ConfigKey to read. */
297 Glib::VariantBase config_get(const ConfigKey *key);
298 /** Set configuration for the given key to a specified value.
299 * @param key ConfigKey to set.
300 * @param value Value to set. */
301 void config_set(const ConfigKey *key, Glib::VariantBase value);
302 /** Enumerate available values for the given configuration key.
303 * @param key ConfigKey to enumerate values for. */
304 Glib::VariantContainerBase config_list(const ConfigKey *key);
305 /** Enumerate available keys, according to a given index key. */
306 map<const ConfigKey *, set<Capability> > config_keys(const ConfigKey *key);
307 /** Check for a key in the list from a given index key. */
308 bool config_check(const ConfigKey *key, const ConfigKey *index_key);
311 struct sr_dev_driver *driver,
312 struct sr_dev_inst *sdi,
313 struct sr_channel_group *channel_group);
314 virtual ~Configurable();
315 struct sr_dev_driver *config_driver;
316 struct sr_dev_inst *config_sdi;
317 struct sr_channel_group *config_channel_group;
320 /** A hardware driver provided by the library */
321 class SR_API Driver :
322 public ParentOwned<Driver, Context, struct sr_dev_driver>,
326 /** Name of this driver. */
328 /** Long name for this driver. */
330 /** Scan for devices and return a list of devices found.
331 * @param options Mapping of (ConfigKey, value) pairs. */
332 vector<shared_ptr<HardwareDevice> > scan(
333 map<const ConfigKey *, Glib::VariantBase> options =
334 map<const ConfigKey *, Glib::VariantBase>());
337 vector<HardwareDevice *> _devices;
338 Driver(struct sr_dev_driver *structure);
340 friend class Context;
341 friend class HardwareDevice;
342 friend class ChannelGroup;
345 /** A generic device, either hardware or virtual */
346 class SR_API Device : public Configurable
349 /** Description identifying this device. */
350 virtual string description();
351 /** Vendor name for this device. */
353 /** Model name for this device. */
355 /** Version string for this device. */
357 /** Serial number for this device. */
358 string serial_number();
359 /** Connection ID for this device. */
360 string connection_id();
361 /** List of the channels available on this device. */
362 vector<shared_ptr<Channel> > channels();
363 /** Channel groups available on this device, indexed by name. */
364 map<string, shared_ptr<ChannelGroup> > channel_groups();
370 Device(struct sr_dev_inst *structure);
372 virtual shared_ptr<Device> get_shared_from_this() = 0;
373 shared_ptr<Channel> get_channel(struct sr_channel *ptr);
374 struct sr_dev_inst *_structure;
375 map<struct sr_channel *, Channel *> _channels;
376 map<string, ChannelGroup *> _channel_groups;
377 /** Deleter needed to allow shared_ptr use with protected destructor. */
381 void operator()(Device *device) { delete device; }
383 friend class Deleter;
384 friend class Session;
385 friend class Channel;
386 friend class ChannelGroup;
391 /** A real hardware device, connected via a driver */
392 class SR_API HardwareDevice :
393 public UserOwned<HardwareDevice, struct sr_dev_inst>,
397 /** Driver providing this device. */
398 shared_ptr<Driver> driver();
400 HardwareDevice(shared_ptr<Driver> driver, struct sr_dev_inst *structure);
402 shared_ptr<Device> get_shared_from_this();
403 shared_ptr<Driver> _driver;
404 /** Deleter needed to allow shared_ptr use with protected destructor. */
408 void operator()(HardwareDevice *device) { delete device; }
410 friend class Deleter;
412 friend class ChannelGroup;
415 /** A channel on a device */
416 class SR_API Channel :
417 public ParentOwned<Channel, Device, struct sr_channel>
420 /** Current name of this channel. */
422 /** Set the name of this channel. *
423 * @param name Name string to set. */
424 void set_name(string name);
425 /** Type of this channel. */
426 const ChannelType *type();
427 /** Enabled status of this channel. */
429 /** Set the enabled status of this channel.
430 * @param value Boolean value to set. */
431 void set_enabled(bool value);
432 /** Get the index number of this channel. */
433 unsigned int index();
435 Channel(struct sr_channel *structure);
437 const ChannelType * const _type;
439 friend class ChannelGroup;
440 friend class Session;
441 friend class TriggerStage;
444 /** A group of channels on a device, which share some configuration */
445 class SR_API ChannelGroup :
446 public ParentOwned<ChannelGroup, Device, struct sr_channel_group>,
450 /** Name of this channel group. */
452 /** List of the channels in this group. */
453 vector<shared_ptr<Channel> > channels();
455 ChannelGroup(Device *device, struct sr_channel_group *structure);
457 vector<Channel *> _channels;
461 /** A trigger configuration */
462 class SR_API Trigger : public UserOwned<Trigger, struct sr_trigger>
465 /** Name of this trigger configuration. */
467 /** List of the stages in this trigger. */
468 vector<shared_ptr<TriggerStage> > stages();
469 /** Add a new stage to this trigger. */
470 shared_ptr<TriggerStage> add_stage();
472 Trigger(shared_ptr<Context> context, string name);
474 shared_ptr<Context> _context;
475 vector<TriggerStage *> _stages;
476 friend class Deleter;
477 friend class Context;
478 friend class Session;
481 /** A stage in a trigger configuration */
482 class SR_API TriggerStage :
483 public ParentOwned<TriggerStage, Trigger, struct sr_trigger_stage>
486 /** Index number of this stage. */
488 /** List of match conditions on this stage. */
489 vector<shared_ptr<TriggerMatch> > matches();
490 /** Add a new match condition to this stage.
491 * @param channel Channel to match on.
492 * @param type TriggerMatchType to apply. */
493 void add_match(shared_ptr<Channel> channel, const TriggerMatchType *type);
494 /** Add a new match condition to this stage.
495 * @param channel Channel to match on.
496 * @param type TriggerMatchType to apply.
497 * @param value Threshold value. */
498 void add_match(shared_ptr<Channel> channel, const TriggerMatchType *type, float value);
500 vector<TriggerMatch *> _matches;
501 TriggerStage(struct sr_trigger_stage *structure);
503 friend class Trigger;
506 /** A match condition in a trigger configuration */
507 class SR_API TriggerMatch :
508 public ParentOwned<TriggerMatch, TriggerStage, struct sr_trigger_match>
511 /** Channel this condition matches on. */
512 shared_ptr<Channel> channel();
513 /** Type of match. */
514 const TriggerMatchType *type();
515 /** Threshold value. */
518 TriggerMatch(struct sr_trigger_match *structure, shared_ptr<Channel> channel);
520 shared_ptr<Channel> _channel;
521 friend class TriggerStage;
524 /** Type of datafeed callback */
525 typedef function<void(shared_ptr<Device>, shared_ptr<Packet>)>
526 DatafeedCallbackFunction;
528 /* Data required for C callback function to call a C++ datafeed callback */
529 class SR_PRIV DatafeedCallbackData
532 void run(const struct sr_dev_inst *sdi,
533 const struct sr_datafeed_packet *pkt);
535 DatafeedCallbackFunction _callback;
536 DatafeedCallbackData(Session *session,
537 DatafeedCallbackFunction callback);
539 friend class Session;
542 /** Type of source callback */
543 typedef function<bool(Glib::IOCondition)>
544 SourceCallbackFunction;
546 /* Data required for C callback function to call a C++ source callback */
547 class SR_PRIV SourceCallbackData
550 bool run(int revents);
552 SourceCallbackData(shared_ptr<EventSource> source);
553 shared_ptr<EventSource> _source;
554 friend class Session;
557 /** An I/O event source */
558 class SR_API EventSource
561 /** Create an event source from a file descriptor.
562 * @param fd File descriptor.
563 * @param events GLib IOCondition event mask.
564 * @param timeout Timeout in milliseconds.
565 * @param callback Callback of the form callback(events) */
566 static shared_ptr<EventSource> create(int fd, Glib::IOCondition events,
567 int timeout, SourceCallbackFunction callback);
568 /** Create an event source from a GLib PollFD
569 * @param pollfd GLib PollFD
570 * @param timeout Timeout in milliseconds.
571 * @param callback Callback of the form callback(events) */
572 static shared_ptr<EventSource> create(Glib::PollFD pollfd, int timeout,
573 SourceCallbackFunction callback);
574 /** Create an event source from a GLib IOChannel
575 * @param channel GLib IOChannel.
576 * @param events GLib IOCondition event mask.
577 * @param timeout Timeout in milliseconds.
578 * @param callback Callback of the form callback(events) */
579 static shared_ptr<EventSource> create(
580 Glib::RefPtr<Glib::IOChannel> channel, Glib::IOCondition events,
581 int timeout, SourceCallbackFunction callback);
583 EventSource(int timeout, SourceCallbackFunction callback);
591 Glib::PollFD _pollfd;
592 Glib::RefPtr<Glib::IOChannel> _channel;
593 Glib::IOCondition _events;
595 SourceCallbackFunction _callback;
596 /** Deleter needed to allow shared_ptr use with protected destructor. */
600 void operator()(EventSource *source) { delete source; }
602 friend class Deleter;
603 friend class Session;
604 friend class SourceCallbackData;
607 /** A virtual device associated with a stored session */
608 class SR_API SessionDevice :
609 public ParentOwned<SessionDevice, Session, struct sr_dev_inst>,
612 /** Description identifying this device. */
613 string description();
615 SessionDevice(struct sr_dev_inst *sdi);
617 shared_ptr<Device> get_shared_from_this();
618 /** Deleter needed to allow shared_ptr use with protected destructor. */
622 void operator()(SessionDevice *device) { delete device; }
624 friend class Deleter;
625 friend class Session;
628 /** A sigrok session */
629 class SR_API Session : public UserOwned<Session, struct sr_session>
632 /** Add a device to this session.
633 * @param device Device to add. */
634 void add_device(shared_ptr<Device> device);
635 /** List devices attached to this session. */
636 vector<shared_ptr<Device> > devices();
637 /** Remove all devices from this session. */
638 void remove_devices();
639 /** Add a datafeed callback to this session.
640 * @param callback Callback of the form callback(Device, Packet). */
641 void add_datafeed_callback(DatafeedCallbackFunction callback);
642 /** Remove all datafeed callbacks from this session. */
643 void remove_datafeed_callbacks();
644 /** Add an I/O event source.
645 * @param source EventSource to add. */
646 void add_source(shared_ptr<EventSource> source);
647 /** Remove an event source.
648 * @param source EventSource to remove. */
649 void remove_source(shared_ptr<EventSource> source);
650 /** Start the session. */
652 /** Run the session event loop. */
654 /** Stop the session. */
656 /** Begin saving session to a file.
657 * @param filename File name string. */
658 void begin_save(string filename);
659 /** Append a packet to the session file being saved.
660 * @param packet Packet to append. */
661 void append(shared_ptr<Packet> packet);
662 /** Append raw logic data to the session file being saved. */
663 void append(void *data, size_t length, unsigned int unit_size);
664 /** Get current trigger setting. */
665 shared_ptr<Trigger> trigger();
666 /** Set trigger setting.
667 * @param trigger Trigger object to use. */
668 void set_trigger(shared_ptr<Trigger> trigger);
670 Session(shared_ptr<Context> context);
671 Session(shared_ptr<Context> context, string filename);
673 shared_ptr<Device> get_device(const struct sr_dev_inst *sdi);
674 const shared_ptr<Context> _context;
675 map<const struct sr_dev_inst *, SessionDevice *> _owned_devices;
676 map<const struct sr_dev_inst *, shared_ptr<Device> > _other_devices;
677 vector<DatafeedCallbackData *> _datafeed_callbacks;
678 map<shared_ptr<EventSource>, SourceCallbackData *> _source_callbacks;
681 bool _save_initialized;
682 string _save_filename;
683 uint64_t _save_samplerate;
684 shared_ptr<Trigger> _trigger;
685 friend class Deleter;
686 friend class Context;
687 friend class DatafeedCallbackData;
688 friend class SessionDevice;
691 /** A packet on the session datafeed */
692 class SR_API Packet : public UserOwned<Packet, const struct sr_datafeed_packet>
695 /** Type of this packet. */
696 const PacketType *type();
697 /** Payload of this packet. */
698 shared_ptr<PacketPayload> payload();
700 Packet(shared_ptr<Device> device,
701 const struct sr_datafeed_packet *structure);
703 shared_ptr<Device> _device;
704 PacketPayload *_payload;
705 friend class Deleter;
706 friend class Session;
708 friend class DatafeedCallbackData;
715 /** Abstract base class for datafeed packet payloads */
716 class SR_API PacketPayload
720 virtual ~PacketPayload() = 0;
721 virtual shared_ptr<PacketPayload> get_shared_pointer(Packet *parent) = 0;
722 /** Deleter needed to allow shared_ptr use with protected destructor. */
726 void operator()(PacketPayload *payload) { delete payload; }
728 friend class Deleter;
733 /** Payload of a datafeed header packet */
734 class SR_API Header :
735 public ParentOwned<Header, Packet, const struct sr_datafeed_header>,
739 /* Feed version number. */
741 /* Start time of this session. */
742 Glib::TimeVal start_time();
744 Header(const struct sr_datafeed_header *structure);
746 shared_ptr<PacketPayload> get_shared_pointer(Packet *parent);
750 /** Payload of a datafeed metadata packet */
752 public ParentOwned<Meta, Packet, const struct sr_datafeed_meta>,
756 /* Mapping of (ConfigKey, value) pairs. */
757 map<const ConfigKey *, Glib::VariantBase> config();
759 Meta(const struct sr_datafeed_meta *structure);
761 shared_ptr<PacketPayload> get_shared_pointer(Packet *parent);
762 map<const ConfigKey *, Glib::VariantBase> _config;
766 /** Payload of a datafeed packet with logic data */
768 public ParentOwned<Logic, Packet, const struct sr_datafeed_logic>,
772 /* Pointer to data. */
773 void *data_pointer();
774 /* Data length in bytes. */
775 size_t data_length();
776 /* Size of each sample in bytes. */
777 unsigned int unit_size();
779 Logic(const struct sr_datafeed_logic *structure);
781 shared_ptr<PacketPayload> get_shared_pointer(Packet *parent);
785 /** Payload of a datafeed packet with analog data */
786 class SR_API Analog :
787 public ParentOwned<Analog, Packet, const struct sr_datafeed_analog>,
791 /** Pointer to data. */
792 float *data_pointer();
793 /** Number of samples in this packet. */
794 unsigned int num_samples();
795 /** Channels for which this packet contains data. */
796 vector<shared_ptr<Channel> > channels();
797 /** Measured quantity of the samples in this packet. */
798 const Quantity *mq();
799 /** Unit of the samples in this packet. */
801 /** Measurement flags associated with the samples in this packet. */
802 vector<const QuantityFlag *> mq_flags();
804 Analog(const struct sr_datafeed_analog *structure);
806 shared_ptr<PacketPayload> get_shared_pointer(Packet *parent);
810 /** An input format supported by the library */
811 class SR_API InputFormat :
812 public ParentOwned<InputFormat, Context, const struct sr_input_module>
815 /** Name of this input format. */
817 /** Description of this input format. */
818 string description();
819 /** Options supported by this input format. */
820 map<string, shared_ptr<Option> > options();
821 /** Create an input using this input format.
822 * @param options Mapping of (option name, value) pairs. */
823 shared_ptr<Input> create_input(map<string, Glib::VariantBase> options =
824 map<string, Glib::VariantBase>());
826 InputFormat(const struct sr_input_module *structure);
828 friend class Context;
829 friend class InputDevice;
832 /** An input instance (an input format applied to a file or stream) */
833 class SR_API Input : public UserOwned<Input, const struct sr_input>
836 /** Virtual device associated with this input. */
837 shared_ptr<InputDevice> device();
838 /** Send next stream data.
839 * @param data Next stream data. */
840 void send(string data);
841 /** Signal end of input data. */
844 Input(shared_ptr<Context> context, const struct sr_input *structure);
846 shared_ptr<Context> _context;
847 InputDevice *_device;
848 friend class Deleter;
849 friend class Context;
850 friend class InputFormat;
853 /** A virtual device associated with an input */
854 class SR_API InputDevice :
855 public ParentOwned<InputDevice, Input, struct sr_dev_inst>,
859 /** Description identifying this device. */
860 string description();
862 InputDevice(shared_ptr<Input> input, struct sr_dev_inst *sdi);
864 shared_ptr<Device> get_shared_from_this();
865 shared_ptr<Input> _input;
869 /** An option used by an output format */
870 class SR_API Option : public UserOwned<Option, const struct sr_option>
873 /** Short name of this option suitable for command line usage. */
875 /** Short name of this option suitable for GUI usage. */
877 /** Description of this option in a sentence. */
878 string description();
879 /** Default value for this option. */
880 Glib::VariantBase default_value();
881 /** Possible values for this option, if a limited set. */
882 vector<Glib::VariantBase> values();
884 Option(const struct sr_option *structure,
885 shared_ptr<const struct sr_option *> structure_array);
887 shared_ptr<const struct sr_option *> _structure_array;
888 friend class Deleter;
889 friend class InputFormat;
890 friend class OutputFormat;
893 /** An output format supported by the library */
894 class SR_API OutputFormat :
895 public ParentOwned<OutputFormat, Context, const struct sr_output_module>
898 /** Name of this output format. */
900 /** Description of this output format. */
901 string description();
902 /** Options supported by this output format. */
903 map<string, shared_ptr<Option> > options();
904 /** Create an output using this format.
905 * @param device Device to output for.
906 * @param options Mapping of (option name, value) pairs. */
907 shared_ptr<Output> create_output(shared_ptr<Device> device,
908 map<string, Glib::VariantBase> options =
909 map<string, Glib::VariantBase>());
911 OutputFormat(const struct sr_output_module *structure);
913 friend class Context;
917 /** An output instance (an output format applied to a device) */
918 class SR_API Output : public UserOwned<Output, const struct sr_output>
921 /** Update output with data from the given packet.
922 * @param packet Packet to handle. */
923 string receive(shared_ptr<Packet> packet);
925 Output(shared_ptr<OutputFormat> format, shared_ptr<Device> device);
926 Output(shared_ptr<OutputFormat> format,
927 shared_ptr<Device> device, map<string, Glib::VariantBase> options);
929 const shared_ptr<OutputFormat> _format;
930 const shared_ptr<Device> _device;
931 const map<string, Glib::VariantBase> _options;
932 friend class Deleter;
933 friend class OutputFormat;
936 /** Base class for objects which wrap an enumeration value from libsigrok */
937 template <typename T> class SR_API EnumValue
940 /** The enum constant associated with this value. */
941 T id() const { return _id; }
942 /** The name associated with this value. */
943 string name() const { return _name; }
945 EnumValue(T id, const char name[]) : _id(id), _name(name) {}
955 #endif // LIBSIGROK_HPP