]> sigrok.org Git - libsigrok.git/blob - bindings/swig/classes.i
f556ba1a2371c9084db9ae4897acad3a1aa0c915
[libsigrok.git] / bindings / swig / classes.i
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
20 #pragma SWIG nowarn=325,401
21
22 %include "typemaps.i"
23 %include "exception.i"
24
25 %{
26
27 static int swig_exception_code(int sigrok_exception_code) {
28     switch (sigrok_exception_code) {
29         case SR_ERR_MALLOC:
30             return SWIG_MemoryError;
31         case SR_ERR_ARG:
32             return SWIG_ValueError;
33         default:
34             return SWIG_RuntimeError;
35     }
36 }
37
38 %}
39
40 %exception {
41     try {
42         $action
43     } catch (sigrok::Error &e) {
44         SWIG_exception(swig_exception_code(e.result),
45             const_cast<char*>(e.what()));
46     }
47 }
48
49 template< class T > class enable_shared_from_this;
50
51 %template(ContextShared) enable_shared_from_this<Context>;
52
53 %shared_ptr(sigrok::Context);
54 %shared_ptr(sigrok::Driver);
55 %shared_ptr(sigrok::Device);
56 %shared_ptr(sigrok::Configurable);
57 %shared_ptr(sigrok::HardwareDevice);
58 %shared_ptr(sigrok::Channel);
59 %shared_ptr(sigrok::ChannelGroup);
60 %shared_ptr(sigrok::Session);
61 %shared_ptr(sigrok::SessionDevice);
62 %shared_ptr(sigrok::Packet);
63 %shared_ptr(sigrok::PacketPayload);
64 %shared_ptr(sigrok::Header);
65 %shared_ptr(sigrok::Meta);
66 %shared_ptr(sigrok::Analog);
67 %shared_ptr(sigrok::Logic);
68 %shared_ptr(sigrok::InputFormat);
69 %shared_ptr(sigrok::Input);
70 %shared_ptr(sigrok::InputDevice);
71 %shared_ptr(sigrok::Option);
72 %shared_ptr(sigrok::OutputFormat);
73 %shared_ptr(sigrok::Output);
74 %shared_ptr(sigrok::Trigger);
75 %shared_ptr(sigrok::TriggerStage);
76 %shared_ptr(sigrok::TriggerMatch);
77 %shared_ptr(sigrok::UserDevice);
78
79 #define SR_API
80 #define SR_PRIV
81
82 %ignore sigrok::DatafeedCallbackData;
83
84 #define SWIG_ATTRIBUTE_TEMPLATE
85
86 %include "attribute.i"
87
88 %inline {
89 typedef std::map<std::string, std::shared_ptr<sigrok::Driver> >
90     map_string_Driver;
91 typedef std::map<std::string, std::shared_ptr<sigrok::InputFormat> >
92     map_string_InputFormat;
93 typedef std::map<std::string, std::shared_ptr<sigrok::OutputFormat> >
94     map_string_OutputFormat;
95 typedef std::map<std::string, std::shared_ptr<sigrok::ChannelGroup> >
96     map_string_ChannelGroup;
97 typedef std::map<std::string, std::shared_ptr<sigrok::Option> >
98     map_string_Option;
99 typedef std::map<std::string, Glib::VariantBase>
100     map_string_Variant;
101 typedef std::map<const sigrok::ConfigKey *, Glib::VariantBase>
102     map_ConfigKey_Variant;
103 }
104
105 %attributemap(Context,
106     map_string_Driver, drivers, drivers);
107 %attributemap(Context,
108     map_string_InputFormat, input_formats, input_formats);
109 %attributemap(Context,
110     map_string_OutputFormat, output_formats, output_formats);
111
112 %attributestring(sigrok::Context,
113     std::string, package_version, package_version);
114 %attributestring(sigrok::Context,
115     std::string, lib_version, lib_version);
116
117 %attribute(sigrok::Context,
118     const sigrok::LogLevel *, log_level, log_level, set_log_level);
119
120 %attributestring(sigrok::Driver, std::string, name, name);
121 %attributestring(sigrok::Driver, std::string, long_name, long_name);
122
123 %attributestring(sigrok::InputFormat,
124     std::string, name, name);
125 %attributestring(sigrok::InputFormat,
126     std::string, description, description);
127
128 %attributestring(sigrok::Input,
129     std::shared_ptr<sigrok::InputDevice>, device, device);
130
131 %attributestring(sigrok::Option,
132     std::string, id, id);
133 %attributestring(sigrok::Option,
134     std::string, name, name);
135 %attributestring(sigrok::Option,
136     std::string, description, description);
137 /* Currently broken on Python due to some issue with variant typemaps. */
138 /* %attributevector(Option,
139     Glib::VariantBase, default_value, default_value); */
140 %attributevector(Option,
141     std::vector<Glib::VariantBase>, values, values);
142
143 %attributestring(sigrok::OutputFormat,
144     std::string, name, name);
145 %attributestring(sigrok::OutputFormat,
146     std::string, description, description);
147 %attributemap(OutputFormat,
148     map_string_Option, options, options);
149
150 %attributestring(sigrok::Device, std::string, vendor, vendor);
151 %attributestring(sigrok::Device, std::string, model, model);
152 %attributestring(sigrok::Device, std::string, version, version);
153
154 %attributevector(Device,
155     std::vector<std::shared_ptr<sigrok::Channel> >,
156     channels, channels);
157
158 %attributemap(Device, map_string_ChannelGroup,
159     channel_groups, channel_groups);
160
161 /* Using %attributestring for shared_ptr attribute. See
162    http://sourceforge.net/p/swig/mailman/message/31832070/ */
163 %attributestring(sigrok::HardwareDevice,
164     std::shared_ptr<sigrok::Driver>, driver, driver);
165
166 %attributestring(sigrok::Channel, std::string, name, name, set_name);
167 %attribute(sigrok::Channel, bool, enabled, enabled, set_enabled);
168 %attribute(sigrok::Channel, const sigrok::ChannelType *, type, type);
169 %attribute(sigrok::Channel, unsigned int, index, index);
170
171 %attributestring(sigrok::ChannelGroup, std::string, name, name);
172 %attributevector(ChannelGroup,
173     std::vector<std::shared_ptr<sigrok::Channel> >,
174     channels, channels);
175
176 %attributestring(sigrok::Trigger, std::string, name, name);
177 %attributevector(Trigger,
178     std::vector<std::shared_ptr<sigrok::TriggerStage> >,
179     stages, stages);
180
181 %attribute(sigrok::TriggerStage, int, number, number);
182 %attributevector(TriggerStage,
183     std::vector<std::shared_ptr<sigrok::TriggerMatch> >,
184     matches, matches);
185
186 %attributestring(sigrok::TriggerMatch,
187     std::shared_ptr<sigrok::Channel>, channel, channel);
188 %attribute(sigrok::TriggerMatch, const sigrok::TriggerMatchType *, type, type);
189 %attribute(sigrok::TriggerMatch, float, value, value);
190
191 %attributevector(Session,
192     std::vector<std::shared_ptr<sigrok::Device> >,
193     devices, devices);
194
195 %attributestring(sigrok::Session,
196     std::shared_ptr<sigrok::Trigger>, trigger, trigger, set_trigger);
197
198 %attributestring(sigrok::Session, std::string, filename, filename);
199
200 %attribute(sigrok::Packet,
201     const sigrok::PacketType *, type, type);
202
203 %attributemap(Meta, map_ConfigKey_Variant, config, config);
204
205 %attributevector(Analog,
206     std::vector<std::shared_ptr<sigrok::Channel> >, channels, channels);
207 %attribute(sigrok::Analog, int, num_samples, num_samples);
208 %attribute(sigrok::Analog, const sigrok::Quantity *, mq, mq);
209 %attribute(sigrok::Analog, const sigrok::Unit *, unit, unit);
210 %attributevector(Analog, std::vector<const sigrok::QuantityFlag *>, mq_flags, mq_flags);
211
212 %include <libsigrokcxx/libsigrokcxx.hpp>
213
214 %include "swig/enums.i"
215
216 namespace sigrok {
217 %include <libsigrokcxx/enums.hpp>
218 }