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