]> sigrok.org Git - libsigrok.git/blob - bindings/swig/libsigrok.i
Rename 'struct sr_probe' to 'struct sr_channel' everywhere.
[libsigrok.git] / bindings / swig / libsigrok.i
1 /*
2  * This file is part of the libsigrok project.
3  *
4  * Copyright (C) 2013 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 %include "cpointer.i"
21 %include "carrays.i"
22 %include "stdint.i"
23
24 %{
25 #include "libsigrok/libsigrok.h"
26 %}
27
28 typedef void *gpointer;
29 typedef int gboolean;
30
31 typedef struct _GSList GSList;
32
33 struct _GSList
34 {
35         gpointer data;
36         GSList *next;
37 };
38
39 void g_slist_free(GSList *list);
40
41 GVariant *g_variant_new_uint64(uint64_t value);
42 GVariant *g_variant_new_boolean(gboolean value);
43 GVariant *g_variant_new_double(double value);
44 GVariant *g_variant_new_string(char *value);
45 GVariant *g_variant_new_tuple(GVariant *children[], unsigned long n_children);
46 char *g_variant_get_type_string(GVariant *value);
47 uint64_t g_variant_get_uint64(GVariant *value);
48 gboolean g_variant_get_boolean(GVariant *value);
49 double g_variant_get_double(GVariant *value);
50 char *g_variant_get_string(GVariant *value, unsigned long *length);
51 GVariant *g_variant_get_child_value(GVariant *value, unsigned long index);
52
53 typedef guint (*GHashFunc)(gconstpointer key);
54 typedef gboolean (*GEqualFunc)(gconstpointer a, gconstpointer b);
55 typedef void (*GDestroyNotify)(gpointer data);
56
57 GHashTable *g_hash_table_new_full(GHashFunc hash_func, GEqualFunc key_equal_func,
58         GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func);
59 void g_hash_table_insert(GHashTable *hash_table, gpointer key, gpointer value);
60 void g_hash_table_destroy(GHashTable *hash_table);
61
62 %callback("%s_ptr");
63 guint g_str_hash(gconstpointer v);
64 gboolean g_str_equal(gconstpointer v1, gconstpointer v2);;
65 void g_free(gpointer mem);
66 %nocallback;
67
68 gchar *g_strdup(const char *str);
69
70 typedef struct _GString GString;
71
72 struct _GString
73 {
74   char *str;
75   gsize len;
76   gsize allocated_len;
77 };
78
79 gchar *g_string_free(GString *string, gboolean free_segment);
80
81 %include "libsigrok/libsigrok.h"
82 #undef SR_API
83 #define SR_API
84 %ignore sr_config_info_name_get;
85 %include "libsigrok/proto.h"
86 %include "libsigrok/version.h"
87
88 %array_class(float, float_array);
89 %pointer_functions(uint8_t *, uint8_ptr_ptr);
90 %pointer_functions(uint64_t, uint64_ptr);
91 %pointer_functions(GString *, gstring_ptr_ptr);
92 %pointer_functions(GVariant *, gvariant_ptr_ptr);
93 %array_functions(GVariant *, gvariant_ptr_array);
94 %pointer_functions(struct sr_context *, sr_context_ptr_ptr);
95 %array_functions(struct sr_dev_driver *, sr_dev_driver_ptr_array);
96 %array_functions(struct sr_input_format *, sr_input_format_ptr_array);
97 %array_functions(struct sr_output_format *, sr_output_format_ptr_array);
98 %pointer_cast(gpointer, struct sr_dev_inst *, gpointer_to_sr_dev_inst_ptr);
99 %pointer_cast(void *, struct sr_datafeed_logic *, void_ptr_to_sr_datafeed_logic_ptr)
100 %pointer_cast(void *, struct sr_datafeed_analog *, void_ptr_to_sr_datafeed_analog_ptr)
101 %pointer_cast(void *, struct sr_channel *, void_ptr_to_sr_channel_ptr)
102 %pointer_cast(void *, struct sr_channel_group *, void_ptr_to_sr_channel_group_ptr)
103
104 %extend sr_input_format {
105         int call_format_match(const char *filename) {
106                 return $self->format_match(filename);
107         }
108
109         int call_init(struct sr_input *in, const char *filename) {
110                 return $self->init(in, filename);
111         }
112
113         int call_loadfile(struct sr_input *in, const char *filename) {
114                 return $self->loadfile(in, filename);
115         }
116 }
117
118 %extend sr_output_format {
119         int call_init(struct sr_output *o) {
120                 return $self->init(o);
121         }
122
123         int call_event(struct sr_output *o, int event_type, uint8_t **data_out,
124                         uint64_t *length_out) {
125                 return $self->event(o, event_type, data_out, length_out);
126         }
127
128         int call_data(struct sr_output *o, const void *data_in,
129                         uint64_t length_in, uint8_t **data_out, uint64_t *length_out) {
130                 return $self->data(o, data_in, length_in, data_out, length_out);
131         }
132
133         int call_receive(struct sr_output *o, const struct sr_dev_inst *sdi,
134                         const struct sr_datafeed_packet *packet, GString **out) {
135                 return $self->receive(o, sdi, packet, out);
136         }
137
138         int call_cleanup(struct sr_output *o) {
139                 return $self->cleanup(o);
140         }
141 }