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::Analog);
74 %shared_ptr(sigrok::Logic);
75 %shared_ptr(sigrok::InputFormat);
76 %shared_ptr(sigrok::InputFileDevice);
77 %shared_ptr(sigrok::OutputFormat);
78 %shared_ptr(sigrok::Output);
79 %shared_ptr(sigrok::Trigger);
80 %shared_ptr(sigrok::TriggerStage);
81 %shared_ptr(sigrok::TriggerMatch);
83 %template(StringMap) std::map<std::string, std::string>;
86 std::map<std::string, std::shared_ptr<sigrok::Driver> >;
87 %template(InputFormatMap)
88 std::map<std::string, std::shared_ptr<sigrok::InputFormat> >;
89 %template(OutputFormatMap)
90 std::map<std::string, std::shared_ptr<sigrok::OutputFormat> >;
92 %template(HardwareDeviceVector)
93 std::vector<std::shared_ptr<sigrok::HardwareDevice> >;
95 %template(DeviceVector)
96 std::vector<std::shared_ptr<sigrok::Device> >;
98 %template(ChannelVector)
99 std::vector<std::shared_ptr<sigrok::Channel> >;
101 %template(ChannelGroupMap)
102 std::map<std::string, std::shared_ptr<sigrok::ChannelGroup> >;
104 /* Workaround for SWIG bug. The vector template instantiation
105 isn't needed but somehow fixes a bug that stops the wrapper
106 for the map instantiation from compiling. */
107 %template(ConfigVector)
108 std::vector<const sigrok::ConfigKey *>;
110 std::map<const sigrok::ConfigKey *, Glib::VariantBase>;
112 %template(QuantityFlagVector)
113 std::vector<const sigrok::QuantityFlag *>;
115 %template(TriggerStageVector)
116 std::vector<std::shared_ptr<sigrok::TriggerStage> >;
118 %template(TriggerMatchVector)
119 std::vector<std::shared_ptr<sigrok::TriggerMatch> >;
124 %ignore sigrok::DatafeedCallbackData;
125 %ignore sigrok::SourceCallbackData;
127 %include "libsigrok/libsigrok.hpp"
130 %include "libsigrok/enums.hpp"
133 #define SWIG_ATTRIBUTE_TEMPLATE
135 %include "attribute.i"
138 typedef std::map<std::string, std::shared_ptr<sigrok::Driver> >
140 typedef std::map<std::string, std::shared_ptr<sigrok::InputFormat> >
141 map_string_InputFormat;
142 typedef std::map<std::string, std::shared_ptr<sigrok::OutputFormat> >
143 map_string_OutputFormat;
144 typedef std::map<std::string, std::shared_ptr<sigrok::ChannelGroup> >
145 map_string_ChannelGroup;
148 %attributeval(sigrok::Context,
149 map_string_Driver, drivers, get_drivers);
150 %attributeval(sigrok::Context,
151 map_string_InputFormat, input_formats, get_input_formats);
152 %attributeval(sigrok::Context,
153 map_string_OutputFormat, output_formats, get_output_formats);
155 %attributestring(sigrok::Context,
156 std::string, package_version, get_package_version);
157 %attributestring(sigrok::Context,
158 std::string, lib_version, get_lib_version);
160 %attribute(sigrok::Context,
161 const sigrok::LogLevel *, log_level, get_log_level, set_log_level);
163 %attributestring(sigrok::Context,
164 std::string, log_domain, get_log_domain, set_log_domain);
166 %attributestring(sigrok::Driver, std::string, name, get_name);
167 %attributestring(sigrok::Driver, std::string, long_name, get_long_name);
169 %attributestring(sigrok::InputFormat,
170 std::string, name, get_name);
171 %attributestring(sigrok::InputFormat,
172 std::string, description, get_description);
174 %attributestring(sigrok::OutputFormat,
175 std::string, name, get_name);
176 %attributestring(sigrok::OutputFormat,
177 std::string, description, get_description);
179 %attributestring(sigrok::Device, std::string, vendor, get_vendor);
180 %attributestring(sigrok::Device, std::string, model, get_model);
181 %attributestring(sigrok::Device, std::string, version, get_version);
183 %attributeval(sigrok::Device,
184 std::vector<std::shared_ptr<sigrok::Channel> >,
185 channels, get_channels);
187 /* Using %attributestring for shared_ptr attribute. See
188 http://sourceforge.net/p/swig/mailman/message/31832070/ */
189 %attributestring(sigrok::HardwareDevice,
190 std::shared_ptr<sigrok::Driver>, driver, get_driver);
192 %attributeval(sigrok::HardwareDevice, map_string_ChannelGroup,
193 channel_groups, get_channel_groups);
195 %attributestring(sigrok::Channel, std::string, name, get_name, set_name);
196 %attribute(sigrok::Channel, bool, enabled, get_enabled, set_enabled);
197 %attribute(sigrok::Channel, const sigrok::ChannelType *, type, get_type);
199 %attributestring(sigrok::ChannelGroup, std::string, name, get_name);
200 %attributeval(sigrok::ChannelGroup,
201 std::vector<std::shared_ptr<sigrok::Channel> >,
202 channels, get_channels);
204 %attributestring(sigrok::Trigger, std::string, name, get_name);
205 %attributeval(sigrok::Trigger,
206 std::vector<std::shared_ptr<sigrok::TriggerStage> >,
209 %attribute(sigrok::TriggerStage, int, number, get_number);
210 %attributeval(sigrok::TriggerStage,
211 std::vector<std::shared_ptr<sigrok::TriggerMatch> >,
212 matches, get_matches);
214 %attributestring(sigrok::TriggerMatch,
215 std::shared_ptr<sigrok::Channel>, channel, get_channel);
216 %attribute(sigrok::TriggerMatch, const sigrok::TriggerMatchType *, type, get_type);
217 %attribute(sigrok::TriggerMatch, float, value, get_value);
219 %attributeval(sigrok::Session,
220 std::vector<std::shared_ptr<sigrok::Device> >,
221 devices, get_devices);
223 %attributestring(sigrok::Session,
224 std::shared_ptr<sigrok::Trigger>, trigger, get_trigger, set_trigger)
226 %attribute(sigrok::Packet, sigrok::PacketPayload *, payload, get_payload);
228 %attribute(sigrok::Analog, int, num_samples, get_num_samples);
229 %attribute(sigrok::Analog, const sigrok::Quantity *, mq, get_mq);
230 %attribute(sigrok::Analog, const sigrok::Unit *, unit, get_unit);
231 %attributeval(sigrok::Analog, std::vector<const sigrok::QuantityFlag *>, mq_flags, get_mq_flags);