]> sigrok.org Git - libsigrok.git/blame - bindings/swig/classes.i
bindings: Support get_channel_groups() on base Device class.
[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);
78%shared_ptr(sigrok::InputFileDevice);
79%shared_ptr(sigrok::OutputFormat);
80%shared_ptr(sigrok::Output);
81%shared_ptr(sigrok::Trigger);
82%shared_ptr(sigrok::TriggerStage);
83%shared_ptr(sigrok::TriggerMatch);
84
85%template(StringMap) std::map<std::string, std::string>;
86
87%template(DriverMap)
88 std::map<std::string, std::shared_ptr<sigrok::Driver> >;
89%template(InputFormatMap)
90 std::map<std::string, std::shared_ptr<sigrok::InputFormat> >;
91%template(OutputFormatMap)
92 std::map<std::string, std::shared_ptr<sigrok::OutputFormat> >;
93
94%template(HardwareDeviceVector)
95 std::vector<std::shared_ptr<sigrok::HardwareDevice> >;
96
97%template(DeviceVector)
98 std::vector<std::shared_ptr<sigrok::Device> >;
99
100%template(ChannelVector)
101 std::vector<std::shared_ptr<sigrok::Channel> >;
102
103%template(ChannelGroupMap)
104 std::map<std::string, std::shared_ptr<sigrok::ChannelGroup> >;
105
106/* Workaround for SWIG bug. The vector template instantiation
107 isn't needed but somehow fixes a bug that stops the wrapper
108 for the map instantiation from compiling. */
109%template(ConfigVector)
110 std::vector<const sigrok::ConfigKey *>;
111%template(ConfigMap)
112 std::map<const sigrok::ConfigKey *, Glib::VariantBase>;
113
114%template(QuantityFlagVector)
115 std::vector<const sigrok::QuantityFlag *>;
116
117%template(TriggerStageVector)
118 std::vector<std::shared_ptr<sigrok::TriggerStage> >;
119
120%template(TriggerMatchVector)
121 std::vector<std::shared_ptr<sigrok::TriggerMatch> >;
122
123#define SR_API
124#define SR_PRIV
125
126%ignore sigrok::DatafeedCallbackData;
127%ignore sigrok::SourceCallbackData;
128
129%include "libsigrok/libsigrok.hpp"
130
131namespace sigrok {
132%include "libsigrok/enums.hpp"
133}
134
135#define SWIG_ATTRIBUTE_TEMPLATE
136
137%include "attribute.i"
138
139%inline {
140typedef std::map<std::string, std::shared_ptr<sigrok::Driver> >
141 map_string_Driver;
142typedef std::map<std::string, std::shared_ptr<sigrok::InputFormat> >
143 map_string_InputFormat;
144typedef std::map<std::string, std::shared_ptr<sigrok::OutputFormat> >
145 map_string_OutputFormat;
146typedef std::map<std::string, std::shared_ptr<sigrok::ChannelGroup> >
147 map_string_ChannelGroup;
2928f47d
ML
148typedef std::map<const sigrok::ConfigKey *, Glib::VariantBase>
149 map_ConfigKey_Variant;
608b848d
ML
150}
151
152%attributeval(sigrok::Context,
153 map_string_Driver, drivers, get_drivers);
154%attributeval(sigrok::Context,
155 map_string_InputFormat, input_formats, get_input_formats);
156%attributeval(sigrok::Context,
157 map_string_OutputFormat, output_formats, get_output_formats);
158
159%attributestring(sigrok::Context,
160 std::string, package_version, get_package_version);
161%attributestring(sigrok::Context,
162 std::string, lib_version, get_lib_version);
163
164%attribute(sigrok::Context,
165 const sigrok::LogLevel *, log_level, get_log_level, set_log_level);
166
167%attributestring(sigrok::Context,
168 std::string, log_domain, get_log_domain, set_log_domain);
169
170%attributestring(sigrok::Driver, std::string, name, get_name);
171%attributestring(sigrok::Driver, std::string, long_name, get_long_name);
172
173%attributestring(sigrok::InputFormat,
174 std::string, name, get_name);
175%attributestring(sigrok::InputFormat,
176 std::string, description, get_description);
177
178%attributestring(sigrok::OutputFormat,
179 std::string, name, get_name);
180%attributestring(sigrok::OutputFormat,
181 std::string, description, get_description);
182
183%attributestring(sigrok::Device, std::string, vendor, get_vendor);
184%attributestring(sigrok::Device, std::string, model, get_model);
185%attributestring(sigrok::Device, std::string, version, get_version);
186
187%attributeval(sigrok::Device,
188 std::vector<std::shared_ptr<sigrok::Channel> >,
189 channels, get_channels);
190
6be7a7f2
ML
191%attributeval(sigrok::Device, map_string_ChannelGroup,
192 channel_groups, get_channel_groups);
193
608b848d
ML
194/* Using %attributestring for shared_ptr attribute. See
195 http://sourceforge.net/p/swig/mailman/message/31832070/ */
196%attributestring(sigrok::HardwareDevice,
197 std::shared_ptr<sigrok::Driver>, driver, get_driver);
198
608b848d
ML
199%attributestring(sigrok::Channel, std::string, name, get_name, set_name);
200%attribute(sigrok::Channel, bool, enabled, get_enabled, set_enabled);
201%attribute(sigrok::Channel, const sigrok::ChannelType *, type, get_type);
202
203%attributestring(sigrok::ChannelGroup, std::string, name, get_name);
204%attributeval(sigrok::ChannelGroup,
205 std::vector<std::shared_ptr<sigrok::Channel> >,
206 channels, get_channels);
207
208%attributestring(sigrok::Trigger, std::string, name, get_name);
209%attributeval(sigrok::Trigger,
210 std::vector<std::shared_ptr<sigrok::TriggerStage> >,
211 stages, get_stages);
212
213%attribute(sigrok::TriggerStage, int, number, get_number);
214%attributeval(sigrok::TriggerStage,
215 std::vector<std::shared_ptr<sigrok::TriggerMatch> >,
216 matches, get_matches);
217
218%attributestring(sigrok::TriggerMatch,
219 std::shared_ptr<sigrok::Channel>, channel, get_channel);
220%attribute(sigrok::TriggerMatch, const sigrok::TriggerMatchType *, type, get_type);
221%attribute(sigrok::TriggerMatch, float, value, get_value);
222
223%attributeval(sigrok::Session,
224 std::vector<std::shared_ptr<sigrok::Device> >,
225 devices, get_devices);
226
6fa0eb86 227%attributestring(sigrok::Session,
2928f47d 228 std::shared_ptr<sigrok::Trigger>, trigger, get_trigger, set_trigger);
6fa0eb86 229
2928f47d
ML
230%attributestring(sigrok::Packet,
231 std::shared_ptr<sigrok::PacketPayload>, payload, get_payload);
232
233%attributeval(sigrok::Meta, map_ConfigKey_Variant, config, get_config);
608b848d
ML
234
235%attribute(sigrok::Analog, int, num_samples, get_num_samples);
236%attribute(sigrok::Analog, const sigrok::Quantity *, mq, get_mq);
237%attribute(sigrok::Analog, const sigrok::Unit *, unit, get_unit);
238%attributeval(sigrok::Analog, std::vector<const sigrok::QuantityFlag *>, mq_flags, get_mq_flags);