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::Session);
70 %shared_ptr(sigrok::SessionDevice);
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::Input);
79 %shared_ptr(sigrok::InputDevice);
80 %shared_ptr(sigrok::Option);
81 %shared_ptr(sigrok::OutputFormat);
82 %shared_ptr(sigrok::Output);
83 %shared_ptr(sigrok::Trigger);
84 %shared_ptr(sigrok::TriggerStage);
85 %shared_ptr(sigrok::TriggerMatch);
86 %shared_ptr(sigrok::UserDevice);
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;
141 #define SWIG_ATTRIBUTE_TEMPLATE
143 %include "attribute.i"
146 typedef std::map<std::string, std::shared_ptr<sigrok::Driver> >
148 typedef std::map<std::string, std::shared_ptr<sigrok::InputFormat> >
149 map_string_InputFormat;
150 typedef std::map<std::string, std::shared_ptr<sigrok::OutputFormat> >
151 map_string_OutputFormat;
152 typedef std::map<std::string, std::shared_ptr<sigrok::ChannelGroup> >
153 map_string_ChannelGroup;
154 typedef std::map<std::string, std::shared_ptr<sigrok::Option> >
156 typedef std::map<std::string, Glib::VariantBase>
158 typedef std::map<const sigrok::ConfigKey *, Glib::VariantBase>
159 map_ConfigKey_Variant;
162 %attributemap(Context,
163 map_string_Driver, drivers, drivers);
164 %attributemap(Context,
165 map_string_InputFormat, input_formats, input_formats);
166 %attributemap(Context,
167 map_string_OutputFormat, output_formats, output_formats);
169 %attributestring(sigrok::Context,
170 std::string, package_version, package_version);
171 %attributestring(sigrok::Context,
172 std::string, lib_version, lib_version);
174 %attribute(sigrok::Context,
175 const sigrok::LogLevel *, log_level, log_level, set_log_level);
177 %attributestring(sigrok::Driver, std::string, name, name);
178 %attributestring(sigrok::Driver, std::string, long_name, long_name);
180 %attributestring(sigrok::InputFormat,
181 std::string, name, name);
182 %attributestring(sigrok::InputFormat,
183 std::string, description, description);
185 %attributestring(sigrok::Input,
186 std::shared_ptr<sigrok::InputDevice>, device, device);
188 %attributestring(sigrok::Option,
189 std::string, id, id);
190 %attributestring(sigrok::Option,
191 std::string, name, name);
192 %attributestring(sigrok::Option,
193 std::string, description, description);
194 /* Currently broken on Python due to some issue with variant typemaps. */
195 /* %attributevector(Option,
196 Glib::VariantBase, default_value, default_value); */
197 %attributevector(Option,
198 std::vector<Glib::VariantBase>, values, values);
200 %attributestring(sigrok::OutputFormat,
201 std::string, name, name);
202 %attributestring(sigrok::OutputFormat,
203 std::string, description, description);
204 %attributemap(OutputFormat,
205 map_string_Option, options, options);
207 %attributestring(sigrok::Device, std::string, vendor, vendor);
208 %attributestring(sigrok::Device, std::string, model, model);
209 %attributestring(sigrok::Device, std::string, version, version);
211 %attributevector(Device,
212 std::vector<std::shared_ptr<sigrok::Channel> >,
215 %attributemap(Device, map_string_ChannelGroup,
216 channel_groups, channel_groups);
218 /* Using %attributestring for shared_ptr attribute. See
219 http://sourceforge.net/p/swig/mailman/message/31832070/ */
220 %attributestring(sigrok::HardwareDevice,
221 std::shared_ptr<sigrok::Driver>, driver, driver);
223 %attributestring(sigrok::Channel, std::string, name, name, set_name);
224 %attribute(sigrok::Channel, bool, enabled, enabled, set_enabled);
225 %attribute(sigrok::Channel, const sigrok::ChannelType *, type, type);
226 %attribute(sigrok::Channel, unsigned int, index, index);
228 %attributestring(sigrok::ChannelGroup, std::string, name, name);
229 %attributevector(ChannelGroup,
230 std::vector<std::shared_ptr<sigrok::Channel> >,
233 %attributestring(sigrok::Trigger, std::string, name, name);
234 %attributevector(Trigger,
235 std::vector<std::shared_ptr<sigrok::TriggerStage> >,
238 %attribute(sigrok::TriggerStage, int, number, number);
239 %attributevector(TriggerStage,
240 std::vector<std::shared_ptr<sigrok::TriggerMatch> >,
243 %attributestring(sigrok::TriggerMatch,
244 std::shared_ptr<sigrok::Channel>, channel, channel);
245 %attribute(sigrok::TriggerMatch, const sigrok::TriggerMatchType *, type, type);
246 %attribute(sigrok::TriggerMatch, float, value, value);
248 %attributevector(Session,
249 std::vector<std::shared_ptr<sigrok::Device> >,
252 %attributestring(sigrok::Session,
253 std::shared_ptr<sigrok::Trigger>, trigger, trigger, set_trigger);
255 %attributestring(sigrok::Session, std::string, filename, filename);
257 %attribute(sigrok::Packet,
258 const sigrok::PacketType *, type, type);
260 %attributemap(Meta, map_ConfigKey_Variant, config, config);
262 %attributevector(Analog,
263 std::vector<std::shared_ptr<sigrok::Channel> >, channels, channels);
264 %attribute(sigrok::Analog, int, num_samples, num_samples);
265 %attribute(sigrok::Analog, const sigrok::Quantity *, mq, mq);
266 %attribute(sigrok::Analog, const sigrok::Unit *, unit, unit);
267 %attributevector(Analog, std::vector<const sigrok::QuantityFlag *>, mq_flags, mq_flags);
269 %include <libsigrokcxx/libsigrokcxx.hpp>
271 %include "swig/enums.i"
274 %include <libsigrokcxx/enums.hpp>