]> sigrok.org Git - libsigrok.git/blame - bindings/swig/classes.i
bindings: Use SR_DF_ANALOG, drop SR_DF_ANALOG_OLD support.
[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 22%{
8b2a1843 23#include <libsigrokcxx/libsigrokcxx.hpp>
608b848d
ML
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);
608b848d 69%shared_ptr(sigrok::Session);
cac58676 70%shared_ptr(sigrok::SessionDevice);
608b848d
ML
71%shared_ptr(sigrok::Packet);
72%shared_ptr(sigrok::PacketPayload);
2928f47d
ML
73%shared_ptr(sigrok::Header);
74%shared_ptr(sigrok::Meta);
dd13d47a 75%shared_ptr(sigrok::Analog);
608b848d
ML
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);
9fa5b426 86%shared_ptr(sigrok::UserDevice);
608b848d
ML
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;
608b848d 140
608b848d
ML
141#define SWIG_ATTRIBUTE_TEMPLATE
142
143%include "attribute.i"
144
145%inline {
146typedef std::map<std::string, std::shared_ptr<sigrok::Driver> >
147 map_string_Driver;
148typedef std::map<std::string, std::shared_ptr<sigrok::InputFormat> >
149 map_string_InputFormat;
150typedef std::map<std::string, std::shared_ptr<sigrok::OutputFormat> >
151 map_string_OutputFormat;
152typedef std::map<std::string, std::shared_ptr<sigrok::ChannelGroup> >
153 map_string_ChannelGroup;
58aa1f83
ML
154typedef std::map<std::string, std::shared_ptr<sigrok::Option> >
155 map_string_Option;
156typedef std::map<std::string, Glib::VariantBase>
157 map_string_Variant;
2928f47d
ML
158typedef std::map<const sigrok::ConfigKey *, Glib::VariantBase>
159 map_ConfigKey_Variant;
608b848d
ML
160}
161
062430a2 162%attributemap(Context,
3b161085 163 map_string_Driver, drivers, drivers);
062430a2 164%attributemap(Context,
3b161085 165 map_string_InputFormat, input_formats, input_formats);
062430a2 166%attributemap(Context,
3b161085 167 map_string_OutputFormat, output_formats, output_formats);
608b848d
ML
168
169%attributestring(sigrok::Context,
3b161085 170 std::string, package_version, package_version);
608b848d 171%attributestring(sigrok::Context,
3b161085 172 std::string, lib_version, lib_version);
608b848d
ML
173
174%attribute(sigrok::Context,
3b161085 175 const sigrok::LogLevel *, log_level, log_level, set_log_level);
608b848d 176
3b161085
ML
177%attributestring(sigrok::Driver, std::string, name, name);
178%attributestring(sigrok::Driver, std::string, long_name, long_name);
608b848d
ML
179
180%attributestring(sigrok::InputFormat,
3b161085 181 std::string, name, name);
608b848d 182%attributestring(sigrok::InputFormat,
3b161085 183 std::string, description, description);
608b848d 184
ca3291e3 185%attributestring(sigrok::Input,
3b161085 186 std::shared_ptr<sigrok::InputDevice>, device, device);
ca3291e3 187
58aa1f83 188%attributestring(sigrok::Option,
3b161085 189 std::string, id, id);
58aa1f83 190%attributestring(sigrok::Option,
3b161085 191 std::string, name, name);
58aa1f83 192%attributestring(sigrok::Option,
3b161085 193 std::string, description, description);
58aa1f83 194/* Currently broken on Python due to some issue with variant typemaps. */
062430a2 195/* %attributevector(Option,
3b161085 196 Glib::VariantBase, default_value, default_value); */
062430a2 197%attributevector(Option,
3b161085 198 std::vector<Glib::VariantBase>, values, values);
58aa1f83 199
608b848d 200%attributestring(sigrok::OutputFormat,
3b161085 201 std::string, name, name);
608b848d 202%attributestring(sigrok::OutputFormat,
3b161085 203 std::string, description, description);
062430a2 204%attributemap(OutputFormat,
3b161085 205 map_string_Option, options, options);
608b848d 206
3b161085
ML
207%attributestring(sigrok::Device, std::string, vendor, vendor);
208%attributestring(sigrok::Device, std::string, model, model);
209%attributestring(sigrok::Device, std::string, version, version);
608b848d 210
062430a2 211%attributevector(Device,
608b848d 212 std::vector<std::shared_ptr<sigrok::Channel> >,
3b161085 213 channels, channels);
608b848d 214
062430a2 215%attributemap(Device, map_string_ChannelGroup,
3b161085 216 channel_groups, channel_groups);
6be7a7f2 217
608b848d
ML
218/* Using %attributestring for shared_ptr attribute. See
219 http://sourceforge.net/p/swig/mailman/message/31832070/ */
220%attributestring(sigrok::HardwareDevice,
3b161085 221 std::shared_ptr<sigrok::Driver>, driver, driver);
608b848d 222
3b161085
ML
223%attributestring(sigrok::Channel, std::string, name, name, set_name);
224%attribute(sigrok::Channel, bool, enabled, enabled, set_enabled);
225%attribute(sigrok::Channel, const sigrok::ChannelType *, type, type);
226%attribute(sigrok::Channel, unsigned int, index, index);
608b848d 227
3b161085 228%attributestring(sigrok::ChannelGroup, std::string, name, name);
062430a2 229%attributevector(ChannelGroup,
608b848d 230 std::vector<std::shared_ptr<sigrok::Channel> >,
3b161085 231 channels, channels);
608b848d 232
3b161085 233%attributestring(sigrok::Trigger, std::string, name, name);
062430a2 234%attributevector(Trigger,
608b848d 235 std::vector<std::shared_ptr<sigrok::TriggerStage> >,
3b161085 236 stages, stages);
608b848d 237
3b161085 238%attribute(sigrok::TriggerStage, int, number, number);
062430a2 239%attributevector(TriggerStage,
608b848d 240 std::vector<std::shared_ptr<sigrok::TriggerMatch> >,
3b161085 241 matches, matches);
608b848d
ML
242
243%attributestring(sigrok::TriggerMatch,
3b161085
ML
244 std::shared_ptr<sigrok::Channel>, channel, channel);
245%attribute(sigrok::TriggerMatch, const sigrok::TriggerMatchType *, type, type);
246%attribute(sigrok::TriggerMatch, float, value, value);
608b848d 247
062430a2 248%attributevector(Session,
608b848d 249 std::vector<std::shared_ptr<sigrok::Device> >,
3b161085 250 devices, devices);
608b848d 251
6fa0eb86 252%attributestring(sigrok::Session,
3b161085 253 std::shared_ptr<sigrok::Trigger>, trigger, trigger, set_trigger);
6fa0eb86 254
1411f7d8
ML
255%attributestring(sigrok::Session, std::string, filename, filename);
256
f591826c
ML
257%attribute(sigrok::Packet,
258 const sigrok::PacketType *, type, type);
2928f47d 259
062430a2 260%attributemap(Meta, map_ConfigKey_Variant, config, config);
608b848d 261
dd13d47a 262%attributevector(Analog,
b2063577 263 std::vector<std::shared_ptr<sigrok::Channel> >, channels, channels);
dd13d47a
UH
264%attribute(sigrok::Analog, int, num_samples, num_samples);
265%attribute(sigrok::Analog, const sigrok::Quantity *, mq, mq);
266%attribute(sigrok::Analog, const sigrok::Unit *, unit, unit);
267%attributevector(Analog, std::vector<const sigrok::QuantityFlag *>, mq_flags, mq_flags);
3b161085 268
8b2a1843 269%include <libsigrokcxx/libsigrokcxx.hpp>
3b161085 270
5a3e3428 271%include "swig/enums.i"
189461b2
ML
272
273namespace sigrok {
8b2a1843 274%include <libsigrokcxx/enums.hpp>
3b161085 275}