]>
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 | |
608b848d ML |
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; | |
58aa1f83 ML |
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; | |
2928f47d ML |
101 | typedef std::map<const sigrok::ConfigKey *, Glib::VariantBase> |
102 | map_ConfigKey_Variant; | |
608b848d ML |
103 | } |
104 | ||
062430a2 | 105 | %attributemap(Context, |
3b161085 | 106 | map_string_Driver, drivers, drivers); |
062430a2 | 107 | %attributemap(Context, |
3b161085 | 108 | map_string_InputFormat, input_formats, input_formats); |
062430a2 | 109 | %attributemap(Context, |
3b161085 | 110 | map_string_OutputFormat, output_formats, output_formats); |
608b848d ML |
111 | |
112 | %attributestring(sigrok::Context, | |
3b161085 | 113 | std::string, package_version, package_version); |
608b848d | 114 | %attributestring(sigrok::Context, |
3b161085 | 115 | std::string, lib_version, lib_version); |
608b848d ML |
116 | |
117 | %attribute(sigrok::Context, | |
3b161085 | 118 | const sigrok::LogLevel *, log_level, log_level, set_log_level); |
608b848d | 119 | |
3b161085 ML |
120 | %attributestring(sigrok::Driver, std::string, name, name); |
121 | %attributestring(sigrok::Driver, std::string, long_name, long_name); | |
608b848d ML |
122 | |
123 | %attributestring(sigrok::InputFormat, | |
3b161085 | 124 | std::string, name, name); |
608b848d | 125 | %attributestring(sigrok::InputFormat, |
3b161085 | 126 | std::string, description, description); |
608b848d | 127 | |
ca3291e3 | 128 | %attributestring(sigrok::Input, |
3b161085 | 129 | std::shared_ptr<sigrok::InputDevice>, device, device); |
ca3291e3 | 130 | |
58aa1f83 | 131 | %attributestring(sigrok::Option, |
3b161085 | 132 | std::string, id, id); |
58aa1f83 | 133 | %attributestring(sigrok::Option, |
3b161085 | 134 | std::string, name, name); |
58aa1f83 | 135 | %attributestring(sigrok::Option, |
3b161085 | 136 | std::string, description, description); |
58aa1f83 | 137 | /* Currently broken on Python due to some issue with variant typemaps. */ |
062430a2 | 138 | /* %attributevector(Option, |
3b161085 | 139 | Glib::VariantBase, default_value, default_value); */ |
062430a2 | 140 | %attributevector(Option, |
3b161085 | 141 | std::vector<Glib::VariantBase>, values, values); |
58aa1f83 | 142 | |
608b848d | 143 | %attributestring(sigrok::OutputFormat, |
3b161085 | 144 | std::string, name, name); |
608b848d | 145 | %attributestring(sigrok::OutputFormat, |
3b161085 | 146 | std::string, description, description); |
062430a2 | 147 | %attributemap(OutputFormat, |
3b161085 | 148 | map_string_Option, options, options); |
608b848d | 149 | |
3b161085 ML |
150 | %attributestring(sigrok::Device, std::string, vendor, vendor); |
151 | %attributestring(sigrok::Device, std::string, model, model); | |
152 | %attributestring(sigrok::Device, std::string, version, version); | |
608b848d | 153 | |
062430a2 | 154 | %attributevector(Device, |
608b848d | 155 | std::vector<std::shared_ptr<sigrok::Channel> >, |
3b161085 | 156 | channels, channels); |
608b848d | 157 | |
062430a2 | 158 | %attributemap(Device, map_string_ChannelGroup, |
3b161085 | 159 | channel_groups, channel_groups); |
6be7a7f2 | 160 | |
608b848d ML |
161 | /* Using %attributestring for shared_ptr attribute. See |
162 | http://sourceforge.net/p/swig/mailman/message/31832070/ */ | |
163 | %attributestring(sigrok::HardwareDevice, | |
3b161085 | 164 | std::shared_ptr<sigrok::Driver>, driver, driver); |
608b848d | 165 | |
3b161085 ML |
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); | |
608b848d | 170 | |
3b161085 | 171 | %attributestring(sigrok::ChannelGroup, std::string, name, name); |
062430a2 | 172 | %attributevector(ChannelGroup, |
608b848d | 173 | std::vector<std::shared_ptr<sigrok::Channel> >, |
3b161085 | 174 | channels, channels); |
608b848d | 175 | |
3b161085 | 176 | %attributestring(sigrok::Trigger, std::string, name, name); |
062430a2 | 177 | %attributevector(Trigger, |
608b848d | 178 | std::vector<std::shared_ptr<sigrok::TriggerStage> >, |
3b161085 | 179 | stages, stages); |
608b848d | 180 | |
3b161085 | 181 | %attribute(sigrok::TriggerStage, int, number, number); |
062430a2 | 182 | %attributevector(TriggerStage, |
608b848d | 183 | std::vector<std::shared_ptr<sigrok::TriggerMatch> >, |
3b161085 | 184 | matches, matches); |
608b848d ML |
185 | |
186 | %attributestring(sigrok::TriggerMatch, | |
3b161085 ML |
187 | std::shared_ptr<sigrok::Channel>, channel, channel); |
188 | %attribute(sigrok::TriggerMatch, const sigrok::TriggerMatchType *, type, type); | |
189 | %attribute(sigrok::TriggerMatch, float, value, value); | |
608b848d | 190 | |
062430a2 | 191 | %attributevector(Session, |
608b848d | 192 | std::vector<std::shared_ptr<sigrok::Device> >, |
3b161085 | 193 | devices, devices); |
608b848d | 194 | |
6fa0eb86 | 195 | %attributestring(sigrok::Session, |
3b161085 | 196 | std::shared_ptr<sigrok::Trigger>, trigger, trigger, set_trigger); |
6fa0eb86 | 197 | |
1411f7d8 ML |
198 | %attributestring(sigrok::Session, std::string, filename, filename); |
199 | ||
f591826c ML |
200 | %attribute(sigrok::Packet, |
201 | const sigrok::PacketType *, type, type); | |
2928f47d | 202 | |
062430a2 | 203 | %attributemap(Meta, map_ConfigKey_Variant, config, config); |
608b848d | 204 | |
dd13d47a | 205 | %attributevector(Analog, |
b2063577 | 206 | std::vector<std::shared_ptr<sigrok::Channel> >, channels, channels); |
dd13d47a UH |
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); | |
3b161085 | 211 | |
8b2a1843 | 212 | %include <libsigrokcxx/libsigrokcxx.hpp> |
3b161085 | 213 | |
5a3e3428 | 214 | %include "swig/enums.i" |
189461b2 ML |
215 | |
216 | namespace sigrok { | |
8b2a1843 | 217 | %include <libsigrokcxx/enums.hpp> |
3b161085 | 218 | } |