]> sigrok.org Git - libsigrok.git/commitdiff
python: Add initial support for input and output formats.
authorMartin Ling <redacted>
Mon, 16 Dec 2013 01:21:39 +0000 (01:21 +0000)
committerBert Vermeulen <redacted>
Tue, 17 Dec 2013 01:00:09 +0000 (02:00 +0100)
bindings/python/sigrok/core/classes.py
bindings/swig/libsigrok.i

index 2d998ac9c632823dadcdd0bdfd2880280c338eb6..6b55eb3f99754c7c431290898961874776097e59 100644 (file)
@@ -87,6 +87,8 @@ class Context(object):
         self.struct = sr_context_ptr_ptr_value(context_ptr_ptr)
         self._drivers = None
         self._devices = {}
+        self._input_formats = None
+        self._output_formats = None
         self.session = None
 
     def __del__(self):
@@ -105,6 +107,32 @@ class Context(object):
                     break
         return self._drivers
 
+    @property
+    def input_formats(self):
+        if not self._input_formats:
+            self._input_formats = {}
+            input_list = sr_input_list()
+            for i in itertools.count():
+                input_ptr = sr_input_format_ptr_array_getitem(input_list, i)
+                if input_ptr:
+                    self._input_formats[input_ptr.id] = InputFormat(self, input_ptr)
+                else:
+                    break
+        return self._input_formats
+
+    @property
+    def output_formats(self):
+        if not self._output_formats:
+            self._output_formats = {}
+            output_list = sr_output_list()
+            for i in itertools.count():
+                output_ptr = sr_output_format_ptr_array_getitem(output_list, i)
+                if output_ptr:
+                    self._output_formats[output_ptr.id] = OutputFormat(self, output_ptr)
+                else:
+                    break
+        return self._output_formats
+
 class Driver(object):
 
     def __init__(self, context, struct):
@@ -392,6 +420,34 @@ class Log(object):
     def domain(self, d):
         check(sr_log_logdomain_set(d))
 
+class InputFormat(object):
+
+    def __init__(self, context, struct):
+        self.context = context
+        self.struct = struct
+
+    @property
+    def id(self):
+        return self.struct.id
+
+    @property
+    def description(self):
+        return self.struct.description
+
+class OutputFormat(object):
+
+    def __init__(self, context, struct):
+        self.context = context
+        self.struct = struct
+
+    @property
+    def id(self):
+        return self.struct.id
+
+    @property
+    def description(self):
+        return self.struct.description
+
 class EnumValue(object):
 
     _enum_values = {}
index d18df516bcd6d236d84a8de611f8efe75bfdaea3..9adb153f55958c1edd9a79474ec972387e38e460 100644 (file)
@@ -61,6 +61,8 @@ GVariant *g_variant_get_child_value(GVariant *value, unsigned long index);
 %array_functions(GVariant *, gvariant_ptr_array);
 %pointer_functions(struct sr_context *, sr_context_ptr_ptr);
 %array_functions(struct sr_dev_driver *, sr_dev_driver_ptr_array);
+%array_functions(struct sr_input_format *, sr_input_format_ptr_array);
+%array_functions(struct sr_output_format *, sr_output_format_ptr_array);
 %pointer_cast(gpointer, struct sr_dev_inst *, gpointer_to_sr_dev_inst_ptr);
 %pointer_cast(void *, struct sr_datafeed_logic *, void_ptr_to_sr_datafeed_logic_ptr)
 %pointer_cast(void *, struct sr_datafeed_analog *, void_ptr_to_sr_datafeed_analog_ptr)