]> sigrok.org Git - libsigrok.git/blame - bindings/swig/classes.i
bindings: Expose ConfigKey::identifier as an attribute.
[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);
cac58676 71%shared_ptr(sigrok::SessionDevice);
608b848d
ML
72%shared_ptr(sigrok::Packet);
73%shared_ptr(sigrok::PacketPayload);
2928f47d
ML
74%shared_ptr(sigrok::Header);
75%shared_ptr(sigrok::Meta);
608b848d
ML
76%shared_ptr(sigrok::Analog);
77%shared_ptr(sigrok::Logic);
78%shared_ptr(sigrok::InputFormat);
ca3291e3
ML
79%shared_ptr(sigrok::Input);
80%shared_ptr(sigrok::InputDevice);
58aa1f83 81%shared_ptr(sigrok::Option);
608b848d
ML
82%shared_ptr(sigrok::OutputFormat);
83%shared_ptr(sigrok::Output);
84%shared_ptr(sigrok::Trigger);
85%shared_ptr(sigrok::TriggerStage);
86%shared_ptr(sigrok::TriggerMatch);
87
88%template(StringMap) std::map<std::string, std::string>;
89
90%template(DriverMap)
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> >;
96
97%template(HardwareDeviceVector)
98 std::vector<std::shared_ptr<sigrok::HardwareDevice> >;
99
100%template(DeviceVector)
101 std::vector<std::shared_ptr<sigrok::Device> >;
102
103%template(ChannelVector)
104 std::vector<std::shared_ptr<sigrok::Channel> >;
105
106%template(ChannelGroupMap)
107 std::map<std::string, std::shared_ptr<sigrok::ChannelGroup> >;
108
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 *>;
114%template(ConfigMap)
115 std::map<const sigrok::ConfigKey *, Glib::VariantBase>;
116
58aa1f83
ML
117%template(OptionVector)
118 std::vector<std::shared_ptr<sigrok::Option> >;
119%template(OptionMap)
120 std::map<std::string, std::shared_ptr<sigrok::Option> >;
121
122%template(VariantVector)
123 std::vector<Glib::VariantBase>;
124%template(VariantMap)
125 std::map<std::string, Glib::VariantBase>;
126
608b848d
ML
127%template(QuantityFlagVector)
128 std::vector<const sigrok::QuantityFlag *>;
129
130%template(TriggerStageVector)
131 std::vector<std::shared_ptr<sigrok::TriggerStage> >;
132
133%template(TriggerMatchVector)
134 std::vector<std::shared_ptr<sigrok::TriggerMatch> >;
135
136#define SR_API
137#define SR_PRIV
138
139%ignore sigrok::DatafeedCallbackData;
140%ignore sigrok::SourceCallbackData;
141
608b848d
ML
142#define SWIG_ATTRIBUTE_TEMPLATE
143
144%include "attribute.i"
145
146%inline {
147typedef std::map<std::string, std::shared_ptr<sigrok::Driver> >
148 map_string_Driver;
149typedef std::map<std::string, std::shared_ptr<sigrok::InputFormat> >
150 map_string_InputFormat;
151typedef std::map<std::string, std::shared_ptr<sigrok::OutputFormat> >
152 map_string_OutputFormat;
153typedef std::map<std::string, std::shared_ptr<sigrok::ChannelGroup> >
154 map_string_ChannelGroup;
58aa1f83
ML
155typedef std::map<std::string, std::shared_ptr<sigrok::Option> >
156 map_string_Option;
157typedef std::map<std::string, Glib::VariantBase>
158 map_string_Variant;
2928f47d
ML
159typedef std::map<const sigrok::ConfigKey *, Glib::VariantBase>
160 map_ConfigKey_Variant;
608b848d
ML
161}
162
163%attributeval(sigrok::Context,
3b161085 164 map_string_Driver, drivers, drivers);
608b848d 165%attributeval(sigrok::Context,
3b161085 166 map_string_InputFormat, input_formats, input_formats);
608b848d 167%attributeval(sigrok::Context,
3b161085 168 map_string_OutputFormat, output_formats, output_formats);
608b848d
ML
169
170%attributestring(sigrok::Context,
3b161085 171 std::string, package_version, package_version);
608b848d 172%attributestring(sigrok::Context,
3b161085 173 std::string, lib_version, lib_version);
608b848d
ML
174
175%attribute(sigrok::Context,
3b161085 176 const sigrok::LogLevel *, log_level, log_level, set_log_level);
608b848d
ML
177
178%attributestring(sigrok::Context,
3b161085 179 std::string, log_domain, log_domain, set_log_domain);
608b848d 180
3b161085
ML
181%attributestring(sigrok::Driver, std::string, name, name);
182%attributestring(sigrok::Driver, std::string, long_name, long_name);
608b848d
ML
183
184%attributestring(sigrok::InputFormat,
3b161085 185 std::string, name, name);
608b848d 186%attributestring(sigrok::InputFormat,
3b161085 187 std::string, description, description);
608b848d 188
ca3291e3 189%attributestring(sigrok::Input,
3b161085 190 std::shared_ptr<sigrok::InputDevice>, device, device);
ca3291e3 191
58aa1f83 192%attributestring(sigrok::Option,
3b161085 193 std::string, id, id);
58aa1f83 194%attributestring(sigrok::Option,
3b161085 195 std::string, name, name);
58aa1f83 196%attributestring(sigrok::Option,
3b161085 197 std::string, description, description);
58aa1f83
ML
198/* Currently broken on Python due to some issue with variant typemaps. */
199/* %attributeval(sigrok::Option,
3b161085 200 Glib::VariantBase, default_value, default_value); */
58aa1f83 201%attributeval(sigrok::Option,
3b161085 202 std::vector<Glib::VariantBase>, values, values);
58aa1f83 203
608b848d 204%attributestring(sigrok::OutputFormat,
3b161085 205 std::string, name, name);
608b848d 206%attributestring(sigrok::OutputFormat,
3b161085 207 std::string, description, description);
58aa1f83 208%attributeval(sigrok::OutputFormat,
3b161085 209 map_string_Option, options, options);
608b848d 210
3b161085
ML
211%attributestring(sigrok::Device, std::string, vendor, vendor);
212%attributestring(sigrok::Device, std::string, model, model);
213%attributestring(sigrok::Device, std::string, version, version);
608b848d
ML
214
215%attributeval(sigrok::Device,
216 std::vector<std::shared_ptr<sigrok::Channel> >,
3b161085 217 channels, channels);
608b848d 218
6be7a7f2 219%attributeval(sigrok::Device, map_string_ChannelGroup,
3b161085 220 channel_groups, channel_groups);
6be7a7f2 221
608b848d
ML
222/* Using %attributestring for shared_ptr attribute. See
223 http://sourceforge.net/p/swig/mailman/message/31832070/ */
224%attributestring(sigrok::HardwareDevice,
3b161085 225 std::shared_ptr<sigrok::Driver>, driver, driver);
608b848d 226
3b161085
ML
227%attributestring(sigrok::Channel, std::string, name, name, set_name);
228%attribute(sigrok::Channel, bool, enabled, enabled, set_enabled);
229%attribute(sigrok::Channel, const sigrok::ChannelType *, type, type);
230%attribute(sigrok::Channel, unsigned int, index, index);
608b848d 231
3b161085 232%attributestring(sigrok::ChannelGroup, std::string, name, name);
608b848d
ML
233%attributeval(sigrok::ChannelGroup,
234 std::vector<std::shared_ptr<sigrok::Channel> >,
3b161085 235 channels, channels);
608b848d 236
3b161085 237%attributestring(sigrok::Trigger, std::string, name, name);
608b848d
ML
238%attributeval(sigrok::Trigger,
239 std::vector<std::shared_ptr<sigrok::TriggerStage> >,
3b161085 240 stages, stages);
608b848d 241
3b161085 242%attribute(sigrok::TriggerStage, int, number, number);
608b848d
ML
243%attributeval(sigrok::TriggerStage,
244 std::vector<std::shared_ptr<sigrok::TriggerMatch> >,
3b161085 245 matches, matches);
608b848d
ML
246
247%attributestring(sigrok::TriggerMatch,
3b161085
ML
248 std::shared_ptr<sigrok::Channel>, channel, channel);
249%attribute(sigrok::TriggerMatch, const sigrok::TriggerMatchType *, type, type);
250%attribute(sigrok::TriggerMatch, float, value, value);
608b848d
ML
251
252%attributeval(sigrok::Session,
253 std::vector<std::shared_ptr<sigrok::Device> >,
3b161085 254 devices, devices);
608b848d 255
6fa0eb86 256%attributestring(sigrok::Session,
3b161085 257 std::shared_ptr<sigrok::Trigger>, trigger, trigger, set_trigger);
6fa0eb86 258
1411f7d8
ML
259%attributestring(sigrok::Session, std::string, filename, filename);
260
f591826c
ML
261%attribute(sigrok::Packet,
262 const sigrok::PacketType *, type, type);
2928f47d 263%attributestring(sigrok::Packet,
3b161085 264 std::shared_ptr<sigrok::PacketPayload>, payload, payload);
2928f47d 265
3b161085 266%attributeval(sigrok::Meta, map_ConfigKey_Variant, config, config);
608b848d 267
3b161085
ML
268%attribute(sigrok::Analog, int, num_samples, num_samples);
269%attribute(sigrok::Analog, const sigrok::Quantity *, mq, mq);
270%attribute(sigrok::Analog, const sigrok::Unit *, unit, unit);
271%attributeval(sigrok::Analog, std::vector<const sigrok::QuantityFlag *>, mq_flags, mq_flags);
272
273%include "libsigrok/libsigrok.hpp"
274
fe4096fd 275%include "enums.i"
189461b2
ML
276
277namespace sigrok {
3b161085
ML
278%include "libsigrok/enums.hpp"
279}