]> sigrok.org Git - libsigrok.git/blame_incremental - bindings/swig/classes.i
java: Don't use SWIG attribute mechanism.
[libsigrok.git] / bindings / swig / classes.i
... / ...
CommitLineData
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
27static 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
49template< 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#ifndef SWIGJAVA
85
86#define SWIG_ATTRIBUTE_TEMPLATE
87
88%include "attribute.i"
89
90%inline {
91typedef std::map<std::string, std::shared_ptr<sigrok::Driver> >
92 map_string_Driver;
93typedef std::map<std::string, std::shared_ptr<sigrok::InputFormat> >
94 map_string_InputFormat;
95typedef std::map<std::string, std::shared_ptr<sigrok::OutputFormat> >
96 map_string_OutputFormat;
97typedef std::map<std::string, std::shared_ptr<sigrok::ChannelGroup> >
98 map_string_ChannelGroup;
99typedef std::map<std::string, std::shared_ptr<sigrok::Option> >
100 map_string_Option;
101typedef std::map<std::string, Glib::VariantBase>
102 map_string_Variant;
103typedef std::map<const sigrok::ConfigKey *, Glib::VariantBase>
104 map_ConfigKey_Variant;
105}
106
107%attributemap(Context,
108 map_string_Driver, drivers, drivers);
109%attributemap(Context,
110 map_string_InputFormat, input_formats, input_formats);
111%attributemap(Context,
112 map_string_OutputFormat, output_formats, output_formats);
113
114%attributestring(sigrok::Context,
115 std::string, package_version, package_version);
116%attributestring(sigrok::Context,
117 std::string, lib_version, lib_version);
118
119%attribute(sigrok::Context,
120 const sigrok::LogLevel *, log_level, log_level, set_log_level);
121
122%attributestring(sigrok::Driver, std::string, name, name);
123%attributestring(sigrok::Driver, std::string, long_name, long_name);
124
125%attributestring(sigrok::InputFormat,
126 std::string, name, name);
127%attributestring(sigrok::InputFormat,
128 std::string, description, description);
129
130%attributestring(sigrok::Input,
131 std::shared_ptr<sigrok::InputDevice>, device, device);
132
133%attributestring(sigrok::Option,
134 std::string, id, id);
135%attributestring(sigrok::Option,
136 std::string, name, name);
137%attributestring(sigrok::Option,
138 std::string, description, description);
139/* Currently broken on Python due to some issue with variant typemaps. */
140/* %attributevector(Option,
141 Glib::VariantBase, default_value, default_value); */
142%attributevector(Option,
143 std::vector<Glib::VariantBase>, values, values);
144
145%attributestring(sigrok::OutputFormat,
146 std::string, name, name);
147%attributestring(sigrok::OutputFormat,
148 std::string, description, description);
149%attributemap(OutputFormat,
150 map_string_Option, options, options);
151
152%attributestring(sigrok::Device, std::string, vendor, vendor);
153%attributestring(sigrok::Device, std::string, model, model);
154%attributestring(sigrok::Device, std::string, version, version);
155
156%attributevector(Device,
157 std::vector<std::shared_ptr<sigrok::Channel> >,
158 channels, channels);
159
160%attributemap(Device, map_string_ChannelGroup,
161 channel_groups, channel_groups);
162
163/* Using %attributestring for shared_ptr attribute. See
164 http://sourceforge.net/p/swig/mailman/message/31832070/ */
165%attributestring(sigrok::HardwareDevice,
166 std::shared_ptr<sigrok::Driver>, driver, driver);
167
168%attributestring(sigrok::Channel, std::string, name, name, set_name);
169%attribute(sigrok::Channel, bool, enabled, enabled, set_enabled);
170%attribute(sigrok::Channel, const sigrok::ChannelType *, type, type);
171%attribute(sigrok::Channel, unsigned int, index, index);
172
173%attributestring(sigrok::ChannelGroup, std::string, name, name);
174%attributevector(ChannelGroup,
175 std::vector<std::shared_ptr<sigrok::Channel> >,
176 channels, channels);
177
178%attributestring(sigrok::Trigger, std::string, name, name);
179%attributevector(Trigger,
180 std::vector<std::shared_ptr<sigrok::TriggerStage> >,
181 stages, stages);
182
183%attribute(sigrok::TriggerStage, int, number, number);
184%attributevector(TriggerStage,
185 std::vector<std::shared_ptr<sigrok::TriggerMatch> >,
186 matches, matches);
187
188%attributestring(sigrok::TriggerMatch,
189 std::shared_ptr<sigrok::Channel>, channel, channel);
190%attribute(sigrok::TriggerMatch, const sigrok::TriggerMatchType *, type, type);
191%attribute(sigrok::TriggerMatch, float, value, value);
192
193%attributevector(Session,
194 std::vector<std::shared_ptr<sigrok::Device> >,
195 devices, devices);
196
197%attributestring(sigrok::Session,
198 std::shared_ptr<sigrok::Trigger>, trigger, trigger, set_trigger);
199
200%attributestring(sigrok::Session, std::string, filename, filename);
201
202%attribute(sigrok::Packet,
203 const sigrok::PacketType *, type, type);
204
205%attributemap(Meta, map_ConfigKey_Variant, config, config);
206
207%attributevector(Analog,
208 std::vector<std::shared_ptr<sigrok::Channel> >, channels, channels);
209%attribute(sigrok::Analog, int, num_samples, num_samples);
210%attribute(sigrok::Analog, const sigrok::Quantity *, mq, mq);
211%attribute(sigrok::Analog, const sigrok::Unit *, unit, unit);
212%attributevector(Analog, std::vector<const sigrok::QuantityFlag *>, mq_flags, mq_flags);
213
214#endif
215
216%include <libsigrokcxx/libsigrokcxx.hpp>
217
218%include "swig/enums.i"
219
220namespace sigrok {
221%include <libsigrokcxx/enums.hpp>
222}