]> sigrok.org Git - libsigrok.git/blame - bindings/swig/classes.i
Update bindings for new input API.
[libsigrok.git] / bindings / swig / classes.i
CommitLineData
608b848d
ML
1/*
2 * This file is part of the libsigrok project.
3 *
4 * Copyright (C) 2014 Martin Ling <martin-sigrok@earth.li>
5 *
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.
10 *
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.
15 *
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/>.
18 */
19
d615a396
ML
20#pragma SWIG nowarn=325,401
21
608b848d
ML
22%{
23#include "libsigrok/libsigrok.hpp"
24using namespace std;
25%}
26
27%include "typemaps.i"
28%include "std_string.i"
29%include "std_vector.i"
30%include "std_map.i"
31%include "std_shared_ptr.i"
32%include "exception.i"
33
34%{
35
36static int swig_exception_code(int sigrok_exception_code) {
37 switch (sigrok_exception_code) {
38 case SR_ERR_MALLOC:
39 return SWIG_MemoryError;
40 case SR_ERR_ARG:
41 return SWIG_ValueError;
42 default:
43 return SWIG_RuntimeError;
44 }
45}
46
47%}
48
49%exception {
50 try {
51 $action
52 } catch (sigrok::Error &e) {
53 SWIG_exception(swig_exception_code(e.result),
54 const_cast<char*>(e.what()));
55 }
56}
57
58template< class T > class enable_shared_from_this;
59
60%template(ContextShared) enable_shared_from_this<Context>;
61
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);
2928f47d
ML
73%shared_ptr(sigrok::Header);
74%shared_ptr(sigrok::Meta);
608b848d
ML
75%shared_ptr(sigrok::Analog);
76%shared_ptr(sigrok::Logic);
77%shared_ptr(sigrok::InputFormat);
ca3291e3
ML
78%shared_ptr(sigrok::Input);
79%shared_ptr(sigrok::InputDevice);
58aa1f83 80%shared_ptr(sigrok::Option);
608b848d
ML
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
87%template(StringMap) std::map<std::string, std::string>;
88
89%template(DriverMap)
90 std::map<std::string, std::shared_ptr<sigrok::Driver> >;
91%template(InputFormatMap)
92 std::map<std::string, std::shared_ptr<sigrok::InputFormat> >;
93%template(OutputFormatMap)
94 std::map<std::string, std::shared_ptr<sigrok::OutputFormat> >;
95
96%template(HardwareDeviceVector)
97 std::vector<std::shared_ptr<sigrok::HardwareDevice> >;
98
99%template(DeviceVector)
100 std::vector<std::shared_ptr<sigrok::Device> >;
101
102%template(ChannelVector)
103 std::vector<std::shared_ptr<sigrok::Channel> >;
104
105%template(ChannelGroupMap)
106 std::map<std::string, std::shared_ptr<sigrok::ChannelGroup> >;
107
108/* Workaround for SWIG bug. The vector template instantiation
109 isn't needed but somehow fixes a bug that stops the wrapper
110 for the map instantiation from compiling. */
111%template(ConfigVector)
112 std::vector<const sigrok::ConfigKey *>;
113%template(ConfigMap)
114 std::map<const sigrok::ConfigKey *, Glib::VariantBase>;
115
58aa1f83
ML
116%template(OptionVector)
117 std::vector<std::shared_ptr<sigrok::Option> >;
118%template(OptionMap)
119 std::map<std::string, std::shared_ptr<sigrok::Option> >;
120
121%template(VariantVector)
122 std::vector<Glib::VariantBase>;
123%template(VariantMap)
124 std::map<std::string, Glib::VariantBase>;
125
608b848d
ML
126%template(QuantityFlagVector)
127 std::vector<const sigrok::QuantityFlag *>;
128
129%template(TriggerStageVector)
130 std::vector<std::shared_ptr<sigrok::TriggerStage> >;
131
132%template(TriggerMatchVector)
133 std::vector<std::shared_ptr<sigrok::TriggerMatch> >;
134
135#define SR_API
136#define SR_PRIV
137
138%ignore sigrok::DatafeedCallbackData;
139%ignore sigrok::SourceCallbackData;
140
141%include "libsigrok/libsigrok.hpp"
142
143namespace sigrok {
144%include "libsigrok/enums.hpp"
145}
146
147#define SWIG_ATTRIBUTE_TEMPLATE
148
149%include "attribute.i"
150
151%inline {
152typedef std::map<std::string, std::shared_ptr<sigrok::Driver> >
153 map_string_Driver;
154typedef std::map<std::string, std::shared_ptr<sigrok::InputFormat> >
155 map_string_InputFormat;
156typedef std::map<std::string, std::shared_ptr<sigrok::OutputFormat> >
157 map_string_OutputFormat;
158typedef std::map<std::string, std::shared_ptr<sigrok::ChannelGroup> >
159 map_string_ChannelGroup;
58aa1f83
ML
160typedef std::map<std::string, std::shared_ptr<sigrok::Option> >
161 map_string_Option;
162typedef std::map<std::string, Glib::VariantBase>
163 map_string_Variant;
2928f47d
ML
164typedef std::map<const sigrok::ConfigKey *, Glib::VariantBase>
165 map_ConfigKey_Variant;
608b848d
ML
166}
167
168%attributeval(sigrok::Context,
169 map_string_Driver, drivers, get_drivers);
170%attributeval(sigrok::Context,
171 map_string_InputFormat, input_formats, get_input_formats);
172%attributeval(sigrok::Context,
173 map_string_OutputFormat, output_formats, get_output_formats);
174
175%attributestring(sigrok::Context,
176 std::string, package_version, get_package_version);
177%attributestring(sigrok::Context,
178 std::string, lib_version, get_lib_version);
179
180%attribute(sigrok::Context,
181 const sigrok::LogLevel *, log_level, get_log_level, set_log_level);
182
183%attributestring(sigrok::Context,
184 std::string, log_domain, get_log_domain, set_log_domain);
185
186%attributestring(sigrok::Driver, std::string, name, get_name);
187%attributestring(sigrok::Driver, std::string, long_name, get_long_name);
188
189%attributestring(sigrok::InputFormat,
190 std::string, name, get_name);
191%attributestring(sigrok::InputFormat,
192 std::string, description, get_description);
193
ca3291e3
ML
194%attributestring(sigrok::Input,
195 std::shared_ptr<sigrok::InputDevice>, device, get_device);
196
58aa1f83
ML
197%attributestring(sigrok::Option,
198 std::string, id, get_id);
199%attributestring(sigrok::Option,
200 std::string, name, get_name);
201%attributestring(sigrok::Option,
202 std::string, description, get_description);
203/* Currently broken on Python due to some issue with variant typemaps. */
204/* %attributeval(sigrok::Option,
205 Glib::VariantBase, default_value, get_default_value); */
206%attributeval(sigrok::Option,
207 std::vector<Glib::VariantBase>, values, get_values);
208
608b848d
ML
209%attributestring(sigrok::OutputFormat,
210 std::string, name, get_name);
211%attributestring(sigrok::OutputFormat,
212 std::string, description, get_description);
58aa1f83
ML
213%attributeval(sigrok::OutputFormat,
214 map_string_Option, options, get_options);
608b848d 215
f36ca889 216%attributestring(sigrok::Device, std::string, description, get_description);
608b848d
ML
217%attributestring(sigrok::Device, std::string, vendor, get_vendor);
218%attributestring(sigrok::Device, std::string, model, get_model);
219%attributestring(sigrok::Device, std::string, version, get_version);
220
221%attributeval(sigrok::Device,
222 std::vector<std::shared_ptr<sigrok::Channel> >,
223 channels, get_channels);
224
6be7a7f2
ML
225%attributeval(sigrok::Device, map_string_ChannelGroup,
226 channel_groups, get_channel_groups);
227
608b848d
ML
228/* Using %attributestring for shared_ptr attribute. See
229 http://sourceforge.net/p/swig/mailman/message/31832070/ */
230%attributestring(sigrok::HardwareDevice,
231 std::shared_ptr<sigrok::Driver>, driver, get_driver);
232
608b848d
ML
233%attributestring(sigrok::Channel, std::string, name, get_name, set_name);
234%attribute(sigrok::Channel, bool, enabled, get_enabled, set_enabled);
235%attribute(sigrok::Channel, const sigrok::ChannelType *, type, get_type);
06bd935e 236%attribute(sigrok::Channel, unsigned int, index, get_index);
608b848d
ML
237
238%attributestring(sigrok::ChannelGroup, std::string, name, get_name);
239%attributeval(sigrok::ChannelGroup,
240 std::vector<std::shared_ptr<sigrok::Channel> >,
241 channels, get_channels);
242
243%attributestring(sigrok::Trigger, std::string, name, get_name);
244%attributeval(sigrok::Trigger,
245 std::vector<std::shared_ptr<sigrok::TriggerStage> >,
246 stages, get_stages);
247
248%attribute(sigrok::TriggerStage, int, number, get_number);
249%attributeval(sigrok::TriggerStage,
250 std::vector<std::shared_ptr<sigrok::TriggerMatch> >,
251 matches, get_matches);
252
253%attributestring(sigrok::TriggerMatch,
254 std::shared_ptr<sigrok::Channel>, channel, get_channel);
255%attribute(sigrok::TriggerMatch, const sigrok::TriggerMatchType *, type, get_type);
256%attribute(sigrok::TriggerMatch, float, value, get_value);
257
258%attributeval(sigrok::Session,
259 std::vector<std::shared_ptr<sigrok::Device> >,
260 devices, get_devices);
261
6fa0eb86 262%attributestring(sigrok::Session,
2928f47d 263 std::shared_ptr<sigrok::Trigger>, trigger, get_trigger, set_trigger);
6fa0eb86 264
2928f47d
ML
265%attributestring(sigrok::Packet,
266 std::shared_ptr<sigrok::PacketPayload>, payload, get_payload);
267
268%attributeval(sigrok::Meta, map_ConfigKey_Variant, config, get_config);
608b848d
ML
269
270%attribute(sigrok::Analog, int, num_samples, get_num_samples);
271%attribute(sigrok::Analog, const sigrok::Quantity *, mq, get_mq);
272%attribute(sigrok::Analog, const sigrok::Unit *, unit, get_unit);
273%attributeval(sigrok::Analog, std::vector<const sigrok::QuantityFlag *>, mq_flags, get_mq_flags);