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