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/>.
21 #include "libsigrok/libsigrok.hpp"
26 %include "std_string.i"
27 %include "std_vector.i"
29 %include "std_shared_ptr.i"
30 %include "exception.i"
34 static int swig_exception_code(int sigrok_exception_code) {
35 switch (sigrok_exception_code) {
37 return SWIG_MemoryError;
39 return SWIG_ValueError;
41 return SWIG_RuntimeError;
50 } catch (sigrok::Error &e) {
51 SWIG_exception(swig_exception_code(e.result),
52 const_cast<char*>(e.what()));
56 template< class T > class enable_shared_from_this;
58 %template(ContextShared) enable_shared_from_this<Context>;
60 %shared_ptr(sigrok::Context);
61 %shared_ptr(sigrok::Driver);
62 %shared_ptr(sigrok::Device);
63 %shared_ptr(sigrok::Configurable);
64 %shared_ptr(sigrok::HardwareDevice);
65 %shared_ptr(sigrok::Channel);
66 %shared_ptr(sigrok::ChannelGroup);
67 %shared_ptr(sigrok::EventSource);
68 %shared_ptr(sigrok::Session);
69 %shared_ptr(sigrok::Packet);
70 %shared_ptr(sigrok::PacketPayload);
71 %shared_ptr(sigrok::Analog);
72 %shared_ptr(sigrok::Logic);
73 %shared_ptr(sigrok::InputFormat);
74 %shared_ptr(sigrok::InputFileDevice);
75 %shared_ptr(sigrok::OutputFormat);
76 %shared_ptr(sigrok::Output);
77 %shared_ptr(sigrok::Trigger);
78 %shared_ptr(sigrok::TriggerStage);
79 %shared_ptr(sigrok::TriggerMatch);
81 %template(StringMap) std::map<std::string, std::string>;
84 std::map<std::string, std::shared_ptr<sigrok::Driver> >;
85 %template(InputFormatMap)
86 std::map<std::string, std::shared_ptr<sigrok::InputFormat> >;
87 %template(OutputFormatMap)
88 std::map<std::string, std::shared_ptr<sigrok::OutputFormat> >;
90 %template(HardwareDeviceVector)
91 std::vector<std::shared_ptr<sigrok::HardwareDevice> >;
93 %template(DeviceVector)
94 std::vector<std::shared_ptr<sigrok::Device> >;
96 %template(ChannelVector)
97 std::vector<std::shared_ptr<sigrok::Channel> >;
99 %template(ChannelGroupMap)
100 std::map<std::string, std::shared_ptr<sigrok::ChannelGroup> >;
102 /* Workaround for SWIG bug. The vector template instantiation
103 isn't needed but somehow fixes a bug that stops the wrapper
104 for the map instantiation from compiling. */
105 %template(ConfigVector)
106 std::vector<const sigrok::ConfigKey *>;
108 std::map<const sigrok::ConfigKey *, Glib::VariantBase>;
110 %template(QuantityFlagVector)
111 std::vector<const sigrok::QuantityFlag *>;
113 %template(TriggerStageVector)
114 std::vector<std::shared_ptr<sigrok::TriggerStage> >;
116 %template(TriggerMatchVector)
117 std::vector<std::shared_ptr<sigrok::TriggerMatch> >;
122 %ignore sigrok::DatafeedCallbackData;
123 %ignore sigrok::SourceCallbackData;
125 %include "libsigrok/libsigrok.hpp"
128 %include "libsigrok/enums.hpp"
131 #define SWIG_ATTRIBUTE_TEMPLATE
133 %include "attribute.i"
136 typedef std::map<std::string, std::shared_ptr<sigrok::Driver> >
138 typedef std::map<std::string, std::shared_ptr<sigrok::InputFormat> >
139 map_string_InputFormat;
140 typedef std::map<std::string, std::shared_ptr<sigrok::OutputFormat> >
141 map_string_OutputFormat;
142 typedef std::map<std::string, std::shared_ptr<sigrok::ChannelGroup> >
143 map_string_ChannelGroup;
146 %attributeval(sigrok::Context,
147 map_string_Driver, drivers, get_drivers);
148 %attributeval(sigrok::Context,
149 map_string_InputFormat, input_formats, get_input_formats);
150 %attributeval(sigrok::Context,
151 map_string_OutputFormat, output_formats, get_output_formats);
153 %attributestring(sigrok::Context,
154 std::string, package_version, get_package_version);
155 %attributestring(sigrok::Context,
156 std::string, lib_version, get_lib_version);
158 %attribute(sigrok::Context,
159 const sigrok::LogLevel *, log_level, get_log_level, set_log_level);
161 %attributestring(sigrok::Context,
162 std::string, log_domain, get_log_domain, set_log_domain);
164 %attributestring(sigrok::Driver, std::string, name, get_name);
165 %attributestring(sigrok::Driver, std::string, long_name, get_long_name);
167 %attributestring(sigrok::InputFormat,
168 std::string, name, get_name);
169 %attributestring(sigrok::InputFormat,
170 std::string, description, get_description);
172 %attributestring(sigrok::OutputFormat,
173 std::string, name, get_name);
174 %attributestring(sigrok::OutputFormat,
175 std::string, description, get_description);
177 %attributestring(sigrok::Device, std::string, vendor, get_vendor);
178 %attributestring(sigrok::Device, std::string, model, get_model);
179 %attributestring(sigrok::Device, std::string, version, get_version);
181 %attributeval(sigrok::Device,
182 std::vector<std::shared_ptr<sigrok::Channel> >,
183 channels, get_channels);
185 /* Using %attributestring for shared_ptr attribute. See
186 http://sourceforge.net/p/swig/mailman/message/31832070/ */
187 %attributestring(sigrok::HardwareDevice,
188 std::shared_ptr<sigrok::Driver>, driver, get_driver);
190 %attributeval(sigrok::HardwareDevice, map_string_ChannelGroup,
191 channel_groups, get_channel_groups);
193 %attributestring(sigrok::Channel, std::string, name, get_name, set_name);
194 %attribute(sigrok::Channel, bool, enabled, get_enabled, set_enabled);
195 %attribute(sigrok::Channel, const sigrok::ChannelType *, type, get_type);
197 %attributestring(sigrok::ChannelGroup, std::string, name, get_name);
198 %attributeval(sigrok::ChannelGroup,
199 std::vector<std::shared_ptr<sigrok::Channel> >,
200 channels, get_channels);
202 %attributestring(sigrok::Trigger, std::string, name, get_name);
203 %attributeval(sigrok::Trigger,
204 std::vector<std::shared_ptr<sigrok::TriggerStage> >,
207 %attribute(sigrok::TriggerStage, int, number, get_number);
208 %attributeval(sigrok::TriggerStage,
209 std::vector<std::shared_ptr<sigrok::TriggerMatch> >,
210 matches, get_matches);
212 %attributestring(sigrok::TriggerMatch,
213 std::shared_ptr<sigrok::Channel>, channel, get_channel);
214 %attribute(sigrok::TriggerMatch, const sigrok::TriggerMatchType *, type, get_type);
215 %attribute(sigrok::TriggerMatch, float, value, get_value);
217 %attributeval(sigrok::Session,
218 std::vector<std::shared_ptr<sigrok::Device> >,
219 devices, get_devices);
221 %attribute(sigrok::Packet, sigrok::PacketPayload *, payload, get_payload);
223 %attribute(sigrok::Analog, int, num_samples, get_num_samples);
224 %attribute(sigrok::Analog, const sigrok::Quantity *, mq, get_mq);
225 %attribute(sigrok::Analog, const sigrok::Unit *, unit, get_unit);
226 %attributeval(sigrok::Analog, std::vector<const sigrok::QuantityFlag *>, mq_flags, get_mq_flags);