2 * This file is part of the libsigrok project.
4 * Copyright (C) 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/>.
20 #pragma SWIG nowarn=325,401
23 #include "libsigrok/libsigrok.hpp"
28 %include "std_string.i"
29 %include "std_vector.i"
31 %include "std_shared_ptr.i"
32 %include "exception.i"
36 static int swig_exception_code(int sigrok_exception_code) {
37 switch (sigrok_exception_code) {
39 return SWIG_MemoryError;
41 return SWIG_ValueError;
43 return SWIG_RuntimeError;
52 } catch (sigrok::Error &e) {
53 SWIG_exception(swig_exception_code(e.result),
54 const_cast<char*>(e.what()));
58 template< class T > class enable_shared_from_this;
60 %template(ContextShared) enable_shared_from_this<Context>;
62 %shared_ptr(sigrok::Context);
63 %shared_ptr(sigrok::Driver);
64 %shared_ptr(sigrok::Device);
65 %shared_ptr(sigrok::Configurable);
66 %shared_ptr(sigrok::HardwareDevice);
67 %shared_ptr(sigrok::Channel);
68 %shared_ptr(sigrok::ChannelGroup);
69 %shared_ptr(sigrok::EventSource);
70 %shared_ptr(sigrok::Session);
71 %shared_ptr(sigrok::Packet);
72 %shared_ptr(sigrok::PacketPayload);
73 %shared_ptr(sigrok::Header);
74 %shared_ptr(sigrok::Meta);
75 %shared_ptr(sigrok::Analog);
76 %shared_ptr(sigrok::Logic);
77 %shared_ptr(sigrok::InputFormat);
78 %shared_ptr(sigrok::InputFileDevice);
79 %shared_ptr(sigrok::OutputFormat);
80 %shared_ptr(sigrok::Output);
81 %shared_ptr(sigrok::Trigger);
82 %shared_ptr(sigrok::TriggerStage);
83 %shared_ptr(sigrok::TriggerMatch);
85 %template(StringMap) std::map<std::string, std::string>;
88 std::map<std::string, std::shared_ptr<sigrok::Driver> >;
89 %template(InputFormatMap)
90 std::map<std::string, std::shared_ptr<sigrok::InputFormat> >;
91 %template(OutputFormatMap)
92 std::map<std::string, std::shared_ptr<sigrok::OutputFormat> >;
94 %template(HardwareDeviceVector)
95 std::vector<std::shared_ptr<sigrok::HardwareDevice> >;
97 %template(DeviceVector)
98 std::vector<std::shared_ptr<sigrok::Device> >;
100 %template(ChannelVector)
101 std::vector<std::shared_ptr<sigrok::Channel> >;
103 %template(ChannelGroupMap)
104 std::map<std::string, std::shared_ptr<sigrok::ChannelGroup> >;
106 /* Workaround for SWIG bug. The vector template instantiation
107 isn't needed but somehow fixes a bug that stops the wrapper
108 for the map instantiation from compiling. */
109 %template(ConfigVector)
110 std::vector<const sigrok::ConfigKey *>;
112 std::map<const sigrok::ConfigKey *, Glib::VariantBase>;
114 %template(QuantityFlagVector)
115 std::vector<const sigrok::QuantityFlag *>;
117 %template(TriggerStageVector)
118 std::vector<std::shared_ptr<sigrok::TriggerStage> >;
120 %template(TriggerMatchVector)
121 std::vector<std::shared_ptr<sigrok::TriggerMatch> >;
126 %ignore sigrok::DatafeedCallbackData;
127 %ignore sigrok::SourceCallbackData;
129 %include "libsigrok/libsigrok.hpp"
132 %include "libsigrok/enums.hpp"
135 #define SWIG_ATTRIBUTE_TEMPLATE
137 %include "attribute.i"
140 typedef std::map<std::string, std::shared_ptr<sigrok::Driver> >
142 typedef std::map<std::string, std::shared_ptr<sigrok::InputFormat> >
143 map_string_InputFormat;
144 typedef std::map<std::string, std::shared_ptr<sigrok::OutputFormat> >
145 map_string_OutputFormat;
146 typedef std::map<std::string, std::shared_ptr<sigrok::ChannelGroup> >
147 map_string_ChannelGroup;
148 typedef std::map<const sigrok::ConfigKey *, Glib::VariantBase>
149 map_ConfigKey_Variant;
152 %attributeval(sigrok::Context,
153 map_string_Driver, drivers, get_drivers);
154 %attributeval(sigrok::Context,
155 map_string_InputFormat, input_formats, get_input_formats);
156 %attributeval(sigrok::Context,
157 map_string_OutputFormat, output_formats, get_output_formats);
159 %attributestring(sigrok::Context,
160 std::string, package_version, get_package_version);
161 %attributestring(sigrok::Context,
162 std::string, lib_version, get_lib_version);
164 %attribute(sigrok::Context,
165 const sigrok::LogLevel *, log_level, get_log_level, set_log_level);
167 %attributestring(sigrok::Context,
168 std::string, log_domain, get_log_domain, set_log_domain);
170 %attributestring(sigrok::Driver, std::string, name, get_name);
171 %attributestring(sigrok::Driver, std::string, long_name, get_long_name);
173 %attributestring(sigrok::InputFormat,
174 std::string, name, get_name);
175 %attributestring(sigrok::InputFormat,
176 std::string, description, get_description);
178 %attributestring(sigrok::OutputFormat,
179 std::string, name, get_name);
180 %attributestring(sigrok::OutputFormat,
181 std::string, description, get_description);
183 %attributestring(sigrok::Device, std::string, vendor, get_vendor);
184 %attributestring(sigrok::Device, std::string, model, get_model);
185 %attributestring(sigrok::Device, std::string, version, get_version);
187 %attributeval(sigrok::Device,
188 std::vector<std::shared_ptr<sigrok::Channel> >,
189 channels, get_channels);
191 /* Using %attributestring for shared_ptr attribute. See
192 http://sourceforge.net/p/swig/mailman/message/31832070/ */
193 %attributestring(sigrok::HardwareDevice,
194 std::shared_ptr<sigrok::Driver>, driver, get_driver);
196 %attributeval(sigrok::HardwareDevice, map_string_ChannelGroup,
197 channel_groups, get_channel_groups);
199 %attributestring(sigrok::Channel, std::string, name, get_name, set_name);
200 %attribute(sigrok::Channel, bool, enabled, get_enabled, set_enabled);
201 %attribute(sigrok::Channel, const sigrok::ChannelType *, type, get_type);
203 %attributestring(sigrok::ChannelGroup, std::string, name, get_name);
204 %attributeval(sigrok::ChannelGroup,
205 std::vector<std::shared_ptr<sigrok::Channel> >,
206 channels, get_channels);
208 %attributestring(sigrok::Trigger, std::string, name, get_name);
209 %attributeval(sigrok::Trigger,
210 std::vector<std::shared_ptr<sigrok::TriggerStage> >,
213 %attribute(sigrok::TriggerStage, int, number, get_number);
214 %attributeval(sigrok::TriggerStage,
215 std::vector<std::shared_ptr<sigrok::TriggerMatch> >,
216 matches, get_matches);
218 %attributestring(sigrok::TriggerMatch,
219 std::shared_ptr<sigrok::Channel>, channel, get_channel);
220 %attribute(sigrok::TriggerMatch, const sigrok::TriggerMatchType *, type, get_type);
221 %attribute(sigrok::TriggerMatch, float, value, get_value);
223 %attributeval(sigrok::Session,
224 std::vector<std::shared_ptr<sigrok::Device> >,
225 devices, get_devices);
227 %attributestring(sigrok::Session,
228 std::shared_ptr<sigrok::Trigger>, trigger, get_trigger, set_trigger);
230 %attributestring(sigrok::Packet,
231 std::shared_ptr<sigrok::PacketPayload>, payload, get_payload);
233 %attributeval(sigrok::Meta, map_ConfigKey_Variant, config, get_config);
235 %attribute(sigrok::Analog, int, num_samples, get_num_samples);
236 %attribute(sigrok::Analog, const sigrok::Quantity *, mq, get_mq);
237 %attribute(sigrok::Analog, const sigrok::Unit *, unit, get_unit);
238 %attributeval(sigrok::Analog, std::vector<const sigrok::QuantityFlag *>, mq_flags, get_mq_flags);