__all__ = ['Error', 'Context', 'Driver', 'Device', 'Session', 'Packet', 'Log',
'LogLevel', 'PacketType', 'Quantity', 'Unit', 'QuantityFlag', 'ConfigKey',
- 'ProbeType', 'Probe', 'ProbeGroup']
+ 'ProbeType', 'Probe', 'ProbeGroup', 'InputFormat', 'OutputFormat',
+ 'InputFile']
class Error(Exception):
def description(self):
return self.struct.description
+ def format_match(self, filename):
+ return bool(self.struct.call_format_match(filename))
+
+class InputFile(object):
+
+ def __init__(self, format, filename, **kwargs):
+ self.format = format
+ self.filename = filename
+ self.struct = sr_input()
+ self.struct.format = self.format.struct
+ self.struct.param = g_hash_table_new_full(
+ g_str_hash, g_str_equal, g_free, g_free)
+ for key, value in kwargs.items():
+ g_hash_table_insert(self.struct.param, g_strdup(key), g_strdup(str(value)))
+ check(self.format.struct.call_init(self.struct, self.filename))
+
+ def load(self):
+ check(self.format.struct.call_loadfile(self.struct, self.filename))
+
+ def __del__(self):
+ g_hash_table_destroy(self.struct.param)
+
class OutputFormat(object):
def __init__(self, context, struct):
char *g_variant_get_string(GVariant *value, unsigned long *length);
GVariant *g_variant_get_child_value(GVariant *value, unsigned long index);
+typedef guint (*GHashFunc)(gconstpointer key);
+typedef gboolean (*GEqualFunc)(gconstpointer a, gconstpointer b);
+typedef void (*GDestroyNotify)(gpointer data);
+
+GHashTable *g_hash_table_new_full(GHashFunc hash_func, GEqualFunc key_equal_func,
+ GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func);
+void g_hash_table_insert(GHashTable *hash_table, gpointer key, gpointer value);
+void g_hash_table_destroy(GHashTable *hash_table);
+
+%constant guint g_str_hash(gconstpointer v);
+%constant gboolean g_str_equal(gconstpointer v1, gconstpointer v2);;
+%constant void g_free(gpointer mem);
+
+gchar *g_strdup(const char *str);
+
%include "libsigrok/libsigrok.h"
#undef SR_API
#define SR_API
%pointer_cast(void *, struct sr_datafeed_analog *, void_ptr_to_sr_datafeed_analog_ptr)
%pointer_cast(void *, struct sr_probe *, void_ptr_to_sr_probe_ptr)
%pointer_cast(void *, struct sr_probe_group *, void_ptr_to_sr_probe_group_ptr)
+
+%extend sr_input_format {
+ int call_format_match(const char *filename) {
+ return $self->format_match(filename);
+ }
+
+ int call_init(struct sr_input *in, const char *filename) {
+ return $self->init(in, filename);
+ }
+
+ int call_loadfile(struct sr_input *in, const char *filename) {
+ return $self->loadfile(in, filename);
+ }
+}