]>
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 | %include "typemaps.i" |
608b848d ML |
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); | |
608b848d | 60 | %shared_ptr(sigrok::Session); |
cac58676 | 61 | %shared_ptr(sigrok::SessionDevice); |
608b848d ML |
62 | %shared_ptr(sigrok::Packet); |
63 | %shared_ptr(sigrok::PacketPayload); | |
2928f47d ML |
64 | %shared_ptr(sigrok::Header); |
65 | %shared_ptr(sigrok::Meta); | |
dd13d47a | 66 | %shared_ptr(sigrok::Analog); |
608b848d ML |
67 | %shared_ptr(sigrok::Logic); |
68 | %shared_ptr(sigrok::InputFormat); | |
ca3291e3 ML |
69 | %shared_ptr(sigrok::Input); |
70 | %shared_ptr(sigrok::InputDevice); | |
58aa1f83 | 71 | %shared_ptr(sigrok::Option); |
608b848d ML |
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); | |
9fa5b426 | 77 | %shared_ptr(sigrok::UserDevice); |
608b848d | 78 | |
608b848d ML |
79 | #define SR_API |
80 | #define SR_PRIV | |
81 | ||
82 | %ignore sigrok::DatafeedCallbackData; | |
608b848d | 83 | |
d0fa4ac1 ML |
84 | #ifndef SWIGJAVA |
85 | ||
608b848d ML |
86 | #define SWIG_ATTRIBUTE_TEMPLATE |
87 | ||
88 | %include "attribute.i" | |
89 | ||
90 | %inline { | |
91 | typedef std::map<std::string, std::shared_ptr<sigrok::Driver> > | |
92 | map_string_Driver; | |
93 | typedef std::map<std::string, std::shared_ptr<sigrok::InputFormat> > | |
94 | map_string_InputFormat; | |
95 | typedef std::map<std::string, std::shared_ptr<sigrok::OutputFormat> > | |
96 | map_string_OutputFormat; | |
97 | typedef std::map<std::string, std::shared_ptr<sigrok::ChannelGroup> > | |
98 | map_string_ChannelGroup; | |
58aa1f83 ML |
99 | typedef std::map<std::string, std::shared_ptr<sigrok::Option> > |
100 | map_string_Option; | |
101 | typedef std::map<std::string, Glib::VariantBase> | |
102 | map_string_Variant; | |
2928f47d ML |
103 | typedef std::map<const sigrok::ConfigKey *, Glib::VariantBase> |
104 | map_ConfigKey_Variant; | |
608b848d ML |
105 | } |
106 | ||
062430a2 | 107 | %attributemap(Context, |
3b161085 | 108 | map_string_Driver, drivers, drivers); |
062430a2 | 109 | %attributemap(Context, |
3b161085 | 110 | map_string_InputFormat, input_formats, input_formats); |
062430a2 | 111 | %attributemap(Context, |
3b161085 | 112 | map_string_OutputFormat, output_formats, output_formats); |
608b848d ML |
113 | |
114 | %attributestring(sigrok::Context, | |
3b161085 | 115 | std::string, package_version, package_version); |
608b848d | 116 | %attributestring(sigrok::Context, |
3b161085 | 117 | std::string, lib_version, lib_version); |
608b848d ML |
118 | |
119 | %attribute(sigrok::Context, | |
3b161085 | 120 | const sigrok::LogLevel *, log_level, log_level, set_log_level); |
608b848d | 121 | |
3b161085 ML |
122 | %attributestring(sigrok::Driver, std::string, name, name); |
123 | %attributestring(sigrok::Driver, std::string, long_name, long_name); | |
608b848d ML |
124 | |
125 | %attributestring(sigrok::InputFormat, | |
3b161085 | 126 | std::string, name, name); |
608b848d | 127 | %attributestring(sigrok::InputFormat, |
3b161085 | 128 | std::string, description, description); |
608b848d | 129 | |
ca3291e3 | 130 | %attributestring(sigrok::Input, |
3b161085 | 131 | std::shared_ptr<sigrok::InputDevice>, device, device); |
ca3291e3 | 132 | |
58aa1f83 | 133 | %attributestring(sigrok::Option, |
3b161085 | 134 | std::string, id, id); |
58aa1f83 | 135 | %attributestring(sigrok::Option, |
3b161085 | 136 | std::string, name, name); |
58aa1f83 | 137 | %attributestring(sigrok::Option, |
3b161085 | 138 | std::string, description, description); |
58aa1f83 | 139 | /* Currently broken on Python due to some issue with variant typemaps. */ |
062430a2 | 140 | /* %attributevector(Option, |
3b161085 | 141 | Glib::VariantBase, default_value, default_value); */ |
062430a2 | 142 | %attributevector(Option, |
3b161085 | 143 | std::vector<Glib::VariantBase>, values, values); |
58aa1f83 | 144 | |
608b848d | 145 | %attributestring(sigrok::OutputFormat, |
3b161085 | 146 | std::string, name, name); |
608b848d | 147 | %attributestring(sigrok::OutputFormat, |
3b161085 | 148 | std::string, description, description); |
062430a2 | 149 | %attributemap(OutputFormat, |
3b161085 | 150 | map_string_Option, options, options); |
608b848d | 151 | |
3b161085 ML |
152 | %attributestring(sigrok::Device, std::string, vendor, vendor); |
153 | %attributestring(sigrok::Device, std::string, model, model); | |
154 | %attributestring(sigrok::Device, std::string, version, version); | |
608b848d | 155 | |
062430a2 | 156 | %attributevector(Device, |
608b848d | 157 | std::vector<std::shared_ptr<sigrok::Channel> >, |
3b161085 | 158 | channels, channels); |
608b848d | 159 | |
062430a2 | 160 | %attributemap(Device, map_string_ChannelGroup, |
3b161085 | 161 | channel_groups, channel_groups); |
6be7a7f2 | 162 | |
608b848d ML |
163 | /* Using %attributestring for shared_ptr attribute. See |
164 | http://sourceforge.net/p/swig/mailman/message/31832070/ */ | |
165 | %attributestring(sigrok::HardwareDevice, | |
3b161085 | 166 | std::shared_ptr<sigrok::Driver>, driver, driver); |
608b848d | 167 | |
3b161085 ML |
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); | |
608b848d | 172 | |
3b161085 | 173 | %attributestring(sigrok::ChannelGroup, std::string, name, name); |
062430a2 | 174 | %attributevector(ChannelGroup, |
608b848d | 175 | std::vector<std::shared_ptr<sigrok::Channel> >, |
3b161085 | 176 | channels, channels); |
608b848d | 177 | |
3b161085 | 178 | %attributestring(sigrok::Trigger, std::string, name, name); |
062430a2 | 179 | %attributevector(Trigger, |
608b848d | 180 | std::vector<std::shared_ptr<sigrok::TriggerStage> >, |
3b161085 | 181 | stages, stages); |
608b848d | 182 | |
3b161085 | 183 | %attribute(sigrok::TriggerStage, int, number, number); |
062430a2 | 184 | %attributevector(TriggerStage, |
608b848d | 185 | std::vector<std::shared_ptr<sigrok::TriggerMatch> >, |
3b161085 | 186 | matches, matches); |
608b848d ML |
187 | |
188 | %attributestring(sigrok::TriggerMatch, | |
3b161085 ML |
189 | std::shared_ptr<sigrok::Channel>, channel, channel); |
190 | %attribute(sigrok::TriggerMatch, const sigrok::TriggerMatchType *, type, type); | |
191 | %attribute(sigrok::TriggerMatch, float, value, value); | |
608b848d | 192 | |
062430a2 | 193 | %attributevector(Session, |
608b848d | 194 | std::vector<std::shared_ptr<sigrok::Device> >, |
3b161085 | 195 | devices, devices); |
608b848d | 196 | |
6fa0eb86 | 197 | %attributestring(sigrok::Session, |
3b161085 | 198 | std::shared_ptr<sigrok::Trigger>, trigger, trigger, set_trigger); |
6fa0eb86 | 199 | |
1411f7d8 ML |
200 | %attributestring(sigrok::Session, std::string, filename, filename); |
201 | ||
f591826c ML |
202 | %attribute(sigrok::Packet, |
203 | const sigrok::PacketType *, type, type); | |
2928f47d | 204 | |
062430a2 | 205 | %attributemap(Meta, map_ConfigKey_Variant, config, config); |
608b848d | 206 | |
dd13d47a | 207 | %attributevector(Analog, |
b2063577 | 208 | std::vector<std::shared_ptr<sigrok::Channel> >, channels, channels); |
dd13d47a UH |
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); | |
3b161085 | 213 | |
d0fa4ac1 ML |
214 | #endif |
215 | ||
8b2a1843 | 216 | %include <libsigrokcxx/libsigrokcxx.hpp> |
3b161085 | 217 | |
5a3e3428 | 218 | %include "swig/enums.i" |
189461b2 | 219 | |
8b2a1843 | 220 | %include <libsigrokcxx/enums.hpp> |