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::SessionDevice);
72 %shared_ptr(sigrok::Packet);
73 %shared_ptr(sigrok::PacketPayload);
74 %shared_ptr(sigrok::Header);
75 %shared_ptr(sigrok::Meta);
76 %shared_ptr(sigrok::Analog);
77 %shared_ptr(sigrok::Logic);
78 %shared_ptr(sigrok::InputFormat);
79 %shared_ptr(sigrok::Input);
80 %shared_ptr(sigrok::InputDevice);
81 %shared_ptr(sigrok::Option);
82 %shared_ptr(sigrok::OutputFormat);
83 %shared_ptr(sigrok::Output);
84 %shared_ptr(sigrok::Trigger);
85 %shared_ptr(sigrok::TriggerStage);
86 %shared_ptr(sigrok::TriggerMatch);
88 %template(StringMap) std::map<std::string, std::string>;
91 std::map<std::string, std::shared_ptr<sigrok::Driver> >;
92 %template(InputFormatMap)
93 std::map<std::string, std::shared_ptr<sigrok::InputFormat> >;
94 %template(OutputFormatMap)
95 std::map<std::string, std::shared_ptr<sigrok::OutputFormat> >;
97 %template(HardwareDeviceVector)
98 std::vector<std::shared_ptr<sigrok::HardwareDevice> >;
100 %template(DeviceVector)
101 std::vector<std::shared_ptr<sigrok::Device> >;
103 %template(ChannelVector)
104 std::vector<std::shared_ptr<sigrok::Channel> >;
106 %template(ChannelGroupMap)
107 std::map<std::string, std::shared_ptr<sigrok::ChannelGroup> >;
109 /* Workaround for SWIG bug. The vector template instantiation
110 isn't needed but somehow fixes a bug that stops the wrapper
111 for the map instantiation from compiling. */
112 %template(ConfigVector)
113 std::vector<const sigrok::ConfigKey *>;
115 std::map<const sigrok::ConfigKey *, Glib::VariantBase>;
117 %template(OptionVector)
118 std::vector<std::shared_ptr<sigrok::Option> >;
120 std::map<std::string, std::shared_ptr<sigrok::Option> >;
122 %template(VariantVector)
123 std::vector<Glib::VariantBase>;
124 %template(VariantMap)
125 std::map<std::string, Glib::VariantBase>;
127 %template(QuantityFlagVector)
128 std::vector<const sigrok::QuantityFlag *>;
130 %template(TriggerStageVector)
131 std::vector<std::shared_ptr<sigrok::TriggerStage> >;
133 %template(TriggerMatchVector)
134 std::vector<std::shared_ptr<sigrok::TriggerMatch> >;
139 %ignore sigrok::DatafeedCallbackData;
140 %ignore sigrok::SourceCallbackData;
142 %include "libsigrok/libsigrok.hpp"
145 %include "libsigrok/enums.hpp"
148 #define SWIG_ATTRIBUTE_TEMPLATE
150 %include "attribute.i"
153 typedef std::map<std::string, std::shared_ptr<sigrok::Driver> >
155 typedef std::map<std::string, std::shared_ptr<sigrok::InputFormat> >
156 map_string_InputFormat;
157 typedef std::map<std::string, std::shared_ptr<sigrok::OutputFormat> >
158 map_string_OutputFormat;
159 typedef std::map<std::string, std::shared_ptr<sigrok::ChannelGroup> >
160 map_string_ChannelGroup;
161 typedef std::map<std::string, std::shared_ptr<sigrok::Option> >
163 typedef std::map<std::string, Glib::VariantBase>
165 typedef std::map<const sigrok::ConfigKey *, Glib::VariantBase>
166 map_ConfigKey_Variant;
169 %attributeval(sigrok::Context,
170 map_string_Driver, drivers, get_drivers);
171 %attributeval(sigrok::Context,
172 map_string_InputFormat, input_formats, get_input_formats);
173 %attributeval(sigrok::Context,
174 map_string_OutputFormat, output_formats, get_output_formats);
176 %attributestring(sigrok::Context,
177 std::string, package_version, get_package_version);
178 %attributestring(sigrok::Context,
179 std::string, lib_version, get_lib_version);
181 %attribute(sigrok::Context,
182 const sigrok::LogLevel *, log_level, get_log_level, set_log_level);
184 %attributestring(sigrok::Context,
185 std::string, log_domain, get_log_domain, set_log_domain);
187 %attributestring(sigrok::Driver, std::string, name, get_name);
188 %attributestring(sigrok::Driver, std::string, long_name, get_long_name);
190 %attributestring(sigrok::InputFormat,
191 std::string, name, get_name);
192 %attributestring(sigrok::InputFormat,
193 std::string, description, get_description);
195 %attributestring(sigrok::Input,
196 std::shared_ptr<sigrok::InputDevice>, device, get_device);
198 %attributestring(sigrok::Option,
199 std::string, id, get_id);
200 %attributestring(sigrok::Option,
201 std::string, name, get_name);
202 %attributestring(sigrok::Option,
203 std::string, description, get_description);
204 /* Currently broken on Python due to some issue with variant typemaps. */
205 /* %attributeval(sigrok::Option,
206 Glib::VariantBase, default_value, get_default_value); */
207 %attributeval(sigrok::Option,
208 std::vector<Glib::VariantBase>, values, get_values);
210 %attributestring(sigrok::OutputFormat,
211 std::string, name, get_name);
212 %attributestring(sigrok::OutputFormat,
213 std::string, description, get_description);
214 %attributeval(sigrok::OutputFormat,
215 map_string_Option, options, get_options);
217 %attributestring(sigrok::Device, std::string, description, get_description);
218 %attributestring(sigrok::Device, std::string, vendor, get_vendor);
219 %attributestring(sigrok::Device, std::string, model, get_model);
220 %attributestring(sigrok::Device, std::string, version, get_version);
222 %attributeval(sigrok::Device,
223 std::vector<std::shared_ptr<sigrok::Channel> >,
224 channels, get_channels);
226 %attributeval(sigrok::Device, map_string_ChannelGroup,
227 channel_groups, get_channel_groups);
229 /* Using %attributestring for shared_ptr attribute. See
230 http://sourceforge.net/p/swig/mailman/message/31832070/ */
231 %attributestring(sigrok::HardwareDevice,
232 std::shared_ptr<sigrok::Driver>, driver, get_driver);
234 %attributestring(sigrok::Channel, std::string, name, get_name, set_name);
235 %attribute(sigrok::Channel, bool, enabled, get_enabled, set_enabled);
236 %attribute(sigrok::Channel, const sigrok::ChannelType *, type, get_type);
237 %attribute(sigrok::Channel, unsigned int, index, get_index);
239 %attributestring(sigrok::ChannelGroup, std::string, name, get_name);
240 %attributeval(sigrok::ChannelGroup,
241 std::vector<std::shared_ptr<sigrok::Channel> >,
242 channels, get_channels);
244 %attributestring(sigrok::Trigger, std::string, name, get_name);
245 %attributeval(sigrok::Trigger,
246 std::vector<std::shared_ptr<sigrok::TriggerStage> >,
249 %attribute(sigrok::TriggerStage, int, number, get_number);
250 %attributeval(sigrok::TriggerStage,
251 std::vector<std::shared_ptr<sigrok::TriggerMatch> >,
252 matches, get_matches);
254 %attributestring(sigrok::TriggerMatch,
255 std::shared_ptr<sigrok::Channel>, channel, get_channel);
256 %attribute(sigrok::TriggerMatch, const sigrok::TriggerMatchType *, type, get_type);
257 %attribute(sigrok::TriggerMatch, float, value, get_value);
259 %attributeval(sigrok::Session,
260 std::vector<std::shared_ptr<sigrok::Device> >,
261 devices, get_devices);
263 %attributestring(sigrok::Session,
264 std::shared_ptr<sigrok::Trigger>, trigger, get_trigger, set_trigger);
266 %attributestring(sigrok::Packet,
267 std::shared_ptr<sigrok::PacketPayload>, payload, get_payload);
269 %attributeval(sigrok::Meta, map_ConfigKey_Variant, config, get_config);
271 %attribute(sigrok::Analog, int, num_samples, get_num_samples);
272 %attribute(sigrok::Analog, const sigrok::Quantity *, mq, get_mq);
273 %attribute(sigrok::Analog, const sigrok::Unit *, unit, get_unit);
274 %attributeval(sigrok::Analog, std::vector<const sigrok::QuantityFlag *>, mq_flags, get_mq_flags);