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 "exception.i"
27 static int swig_exception_code(int sigrok_exception_code) {
28 switch (sigrok_exception_code) {
30 return SWIG_MemoryError;
32 return SWIG_ValueError;
34 return SWIG_RuntimeError;
43 } catch (sigrok::Error &e) {
44 SWIG_exception(swig_exception_code(e.result),
45 const_cast<char*>(e.what()));
49 template< class T > class enable_shared_from_this;
51 %template(ContextShared) enable_shared_from_this<Context>;
53 %shared_ptr(sigrok::Context);
54 %shared_ptr(sigrok::Driver);
55 %shared_ptr(sigrok::Device);
56 %shared_ptr(sigrok::Configurable);
57 %shared_ptr(sigrok::HardwareDevice);
58 %shared_ptr(sigrok::Channel);
59 %shared_ptr(sigrok::ChannelGroup);
60 %shared_ptr(sigrok::Session);
61 %shared_ptr(sigrok::SessionDevice);
62 %shared_ptr(sigrok::Packet);
63 %shared_ptr(sigrok::PacketPayload);
64 %shared_ptr(sigrok::Header);
65 %shared_ptr(sigrok::Meta);
66 %shared_ptr(sigrok::Analog);
67 %shared_ptr(sigrok::Logic);
68 %shared_ptr(sigrok::InputFormat);
69 %shared_ptr(sigrok::Input);
70 %shared_ptr(sigrok::InputDevice);
71 %shared_ptr(sigrok::Option);
72 %shared_ptr(sigrok::OutputFormat);
73 %shared_ptr(sigrok::Output);
74 %shared_ptr(sigrok::Trigger);
75 %shared_ptr(sigrok::TriggerStage);
76 %shared_ptr(sigrok::TriggerMatch);
77 %shared_ptr(sigrok::UserDevice);
82 %ignore sigrok::DatafeedCallbackData;
86 #define SWIG_ATTRIBUTE_TEMPLATE
88 %include "attribute.i"
91 typedef std::map<std::string, std::shared_ptr<sigrok::Driver> >
93 typedef std::map<std::string, std::shared_ptr<sigrok::InputFormat> >
94 map_string_InputFormat;
95 typedef std::map<std::string, std::shared_ptr<sigrok::OutputFormat> >
96 map_string_OutputFormat;
97 typedef std::map<std::string, std::shared_ptr<sigrok::ChannelGroup> >
98 map_string_ChannelGroup;
99 typedef std::map<std::string, std::shared_ptr<sigrok::Option> >
101 typedef std::map<std::string, Glib::VariantBase>
103 typedef std::map<const sigrok::ConfigKey *, Glib::VariantBase>
104 map_ConfigKey_Variant;
107 %attributemap(Context,
108 map_string_Driver, drivers, drivers);
109 %attributemap(Context,
110 map_string_InputFormat, input_formats, input_formats);
111 %attributemap(Context,
112 map_string_OutputFormat, output_formats, output_formats);
114 %attributestring(sigrok::Context,
115 std::string, package_version, package_version);
116 %attributestring(sigrok::Context,
117 std::string, lib_version, lib_version);
119 %attribute(sigrok::Context,
120 const sigrok::LogLevel *, log_level, log_level, set_log_level);
122 %attributestring(sigrok::Driver, std::string, name, name);
123 %attributestring(sigrok::Driver, std::string, long_name, long_name);
125 %attributestring(sigrok::InputFormat,
126 std::string, name, name);
127 %attributestring(sigrok::InputFormat,
128 std::string, description, description);
130 %attributestring(sigrok::Input,
131 std::shared_ptr<sigrok::InputDevice>, device, device);
133 %attributestring(sigrok::Option,
134 std::string, id, id);
135 %attributestring(sigrok::Option,
136 std::string, name, name);
137 %attributestring(sigrok::Option,
138 std::string, description, description);
139 /* Currently broken on Python due to some issue with variant typemaps. */
140 /* %attributevector(Option,
141 Glib::VariantBase, default_value, default_value); */
142 %attributevector(Option,
143 std::vector<Glib::VariantBase>, values, values);
145 %attributestring(sigrok::OutputFormat,
146 std::string, name, name);
147 %attributestring(sigrok::OutputFormat,
148 std::string, description, description);
149 %attributemap(OutputFormat,
150 map_string_Option, options, options);
152 %attributestring(sigrok::Device, std::string, vendor, vendor);
153 %attributestring(sigrok::Device, std::string, model, model);
154 %attributestring(sigrok::Device, std::string, version, version);
156 %attributevector(Device,
157 std::vector<std::shared_ptr<sigrok::Channel> >,
160 %attributemap(Device, map_string_ChannelGroup,
161 channel_groups, channel_groups);
163 /* Using %attributestring for shared_ptr attribute. See
164 http://sourceforge.net/p/swig/mailman/message/31832070/ */
165 %attributestring(sigrok::HardwareDevice,
166 std::shared_ptr<sigrok::Driver>, driver, driver);
168 %attributestring(sigrok::Channel, std::string, name, name, set_name);
169 %attribute(sigrok::Channel, bool, enabled, enabled, set_enabled);
170 %attribute(sigrok::Channel, const sigrok::ChannelType *, type, type);
171 %attribute(sigrok::Channel, unsigned int, index, index);
173 %attributestring(sigrok::ChannelGroup, std::string, name, name);
174 %attributevector(ChannelGroup,
175 std::vector<std::shared_ptr<sigrok::Channel> >,
178 %attributestring(sigrok::Trigger, std::string, name, name);
179 %attributevector(Trigger,
180 std::vector<std::shared_ptr<sigrok::TriggerStage> >,
183 %attribute(sigrok::TriggerStage, int, number, number);
184 %attributevector(TriggerStage,
185 std::vector<std::shared_ptr<sigrok::TriggerMatch> >,
188 %attributestring(sigrok::TriggerMatch,
189 std::shared_ptr<sigrok::Channel>, channel, channel);
190 %attribute(sigrok::TriggerMatch, const sigrok::TriggerMatchType *, type, type);
191 %attribute(sigrok::TriggerMatch, float, value, value);
193 %attributevector(Session,
194 std::vector<std::shared_ptr<sigrok::Device> >,
197 %attributestring(sigrok::Session,
198 std::shared_ptr<sigrok::Trigger>, trigger, trigger, set_trigger);
200 %attributestring(sigrok::Session, std::string, filename, filename);
202 %attribute(sigrok::Packet,
203 const sigrok::PacketType *, type, type);
205 %attributemap(Meta, map_ConfigKey_Variant, config, config);
207 %attributevector(Analog,
208 std::vector<std::shared_ptr<sigrok::Channel> >, channels, channels);
209 %attribute(sigrok::Analog, int, num_samples, num_samples);
210 %attribute(sigrok::Analog, const sigrok::Quantity *, mq, mq);
211 %attribute(sigrok::Analog, const sigrok::Unit *, unit, unit);
212 %attributevector(Analog, std::vector<const sigrok::QuantityFlag *>, mq_flags, mq_flags);
216 %include <libsigrokcxx/libsigrokcxx.hpp>
218 %include "swig/enums.i"
220 %include <libsigrokcxx/enums.hpp>