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