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 <libsigrokcxx/libsigrokcxx.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);
87 %shared_ptr(sigrok::UserDevice);
89 %template(StringMap) std::map<std::string, std::string>;
92 std::map<std::string, std::shared_ptr<sigrok::Driver> >;
93 %template(InputFormatMap)
94 std::map<std::string, std::shared_ptr<sigrok::InputFormat> >;
95 %template(OutputFormatMap)
96 std::map<std::string, std::shared_ptr<sigrok::OutputFormat> >;
98 %template(HardwareDeviceVector)
99 std::vector<std::shared_ptr<sigrok::HardwareDevice> >;
101 %template(DeviceVector)
102 std::vector<std::shared_ptr<sigrok::Device> >;
104 %template(ChannelVector)
105 std::vector<std::shared_ptr<sigrok::Channel> >;
107 %template(ChannelGroupMap)
108 std::map<std::string, std::shared_ptr<sigrok::ChannelGroup> >;
110 /* Workaround for SWIG bug. The vector template instantiation
111 isn't needed but somehow fixes a bug that stops the wrapper
112 for the map instantiation from compiling. */
113 %template(ConfigVector)
114 std::vector<const sigrok::ConfigKey *>;
116 std::map<const sigrok::ConfigKey *, Glib::VariantBase>;
118 %template(OptionVector)
119 std::vector<std::shared_ptr<sigrok::Option> >;
121 std::map<std::string, std::shared_ptr<sigrok::Option> >;
123 %template(VariantVector)
124 std::vector<Glib::VariantBase>;
125 %template(VariantMap)
126 std::map<std::string, Glib::VariantBase>;
128 %template(QuantityFlagVector)
129 std::vector<const sigrok::QuantityFlag *>;
131 %template(TriggerStageVector)
132 std::vector<std::shared_ptr<sigrok::TriggerStage> >;
134 %template(TriggerMatchVector)
135 std::vector<std::shared_ptr<sigrok::TriggerMatch> >;
140 %ignore sigrok::DatafeedCallbackData;
141 %ignore sigrok::SourceCallbackData;
143 #define SWIG_ATTRIBUTE_TEMPLATE
145 %include "attribute.i"
148 typedef std::map<std::string, std::shared_ptr<sigrok::Driver> >
150 typedef std::map<std::string, std::shared_ptr<sigrok::InputFormat> >
151 map_string_InputFormat;
152 typedef std::map<std::string, std::shared_ptr<sigrok::OutputFormat> >
153 map_string_OutputFormat;
154 typedef std::map<std::string, std::shared_ptr<sigrok::ChannelGroup> >
155 map_string_ChannelGroup;
156 typedef std::map<std::string, std::shared_ptr<sigrok::Option> >
158 typedef std::map<std::string, Glib::VariantBase>
160 typedef std::map<const sigrok::ConfigKey *, Glib::VariantBase>
161 map_ConfigKey_Variant;
164 %attributemap(Context,
165 map_string_Driver, drivers, drivers);
166 %attributemap(Context,
167 map_string_InputFormat, input_formats, input_formats);
168 %attributemap(Context,
169 map_string_OutputFormat, output_formats, output_formats);
171 %attributestring(sigrok::Context,
172 std::string, package_version, package_version);
173 %attributestring(sigrok::Context,
174 std::string, lib_version, lib_version);
176 %attribute(sigrok::Context,
177 const sigrok::LogLevel *, log_level, log_level, set_log_level);
179 %attributestring(sigrok::Driver, std::string, name, name);
180 %attributestring(sigrok::Driver, std::string, long_name, long_name);
182 %attributestring(sigrok::InputFormat,
183 std::string, name, name);
184 %attributestring(sigrok::InputFormat,
185 std::string, description, description);
187 %attributestring(sigrok::Input,
188 std::shared_ptr<sigrok::InputDevice>, device, device);
190 %attributestring(sigrok::Option,
191 std::string, id, id);
192 %attributestring(sigrok::Option,
193 std::string, name, name);
194 %attributestring(sigrok::Option,
195 std::string, description, description);
196 /* Currently broken on Python due to some issue with variant typemaps. */
197 /* %attributevector(Option,
198 Glib::VariantBase, default_value, default_value); */
199 %attributevector(Option,
200 std::vector<Glib::VariantBase>, values, values);
202 %attributestring(sigrok::OutputFormat,
203 std::string, name, name);
204 %attributestring(sigrok::OutputFormat,
205 std::string, description, description);
206 %attributemap(OutputFormat,
207 map_string_Option, options, options);
209 %attributestring(sigrok::Device, std::string, vendor, vendor);
210 %attributestring(sigrok::Device, std::string, model, model);
211 %attributestring(sigrok::Device, std::string, version, version);
213 %attributevector(Device,
214 std::vector<std::shared_ptr<sigrok::Channel> >,
217 %attributemap(Device, map_string_ChannelGroup,
218 channel_groups, channel_groups);
220 /* Using %attributestring for shared_ptr attribute. See
221 http://sourceforge.net/p/swig/mailman/message/31832070/ */
222 %attributestring(sigrok::HardwareDevice,
223 std::shared_ptr<sigrok::Driver>, driver, driver);
225 %attributestring(sigrok::Channel, std::string, name, name, set_name);
226 %attribute(sigrok::Channel, bool, enabled, enabled, set_enabled);
227 %attribute(sigrok::Channel, const sigrok::ChannelType *, type, type);
228 %attribute(sigrok::Channel, unsigned int, index, index);
230 %attributestring(sigrok::ChannelGroup, std::string, name, name);
231 %attributevector(ChannelGroup,
232 std::vector<std::shared_ptr<sigrok::Channel> >,
235 %attributestring(sigrok::Trigger, std::string, name, name);
236 %attributevector(Trigger,
237 std::vector<std::shared_ptr<sigrok::TriggerStage> >,
240 %attribute(sigrok::TriggerStage, int, number, number);
241 %attributevector(TriggerStage,
242 std::vector<std::shared_ptr<sigrok::TriggerMatch> >,
245 %attributestring(sigrok::TriggerMatch,
246 std::shared_ptr<sigrok::Channel>, channel, channel);
247 %attribute(sigrok::TriggerMatch, const sigrok::TriggerMatchType *, type, type);
248 %attribute(sigrok::TriggerMatch, float, value, value);
250 %attributevector(Session,
251 std::vector<std::shared_ptr<sigrok::Device> >,
254 %attributestring(sigrok::Session,
255 std::shared_ptr<sigrok::Trigger>, trigger, trigger, set_trigger);
257 %attributestring(sigrok::Session, std::string, filename, filename);
259 %attribute(sigrok::Packet,
260 const sigrok::PacketType *, type, type);
262 %attributemap(Meta, map_ConfigKey_Variant, config, config);
264 %attributevector(Analog,
265 std::vector<std::shared_ptr<sigrok::Channel> >, channels, channels);
266 %attribute(sigrok::Analog, int, num_samples, num_samples);
267 %attribute(sigrok::Analog, const sigrok::Quantity *, mq, mq);
268 %attribute(sigrok::Analog, const sigrok::Unit *, unit, unit);
269 %attributevector(Analog, std::vector<const sigrok::QuantityFlag *>, mq_flags, mq_flags);
271 %include <libsigrokcxx/libsigrokcxx.hpp>
273 %include "swig/enums.i"
276 %include <libsigrokcxx/enums.hpp>