diff --git a/python-api/gstswitch/connection.py b/python-api/gstswitch/connection.py index b48bac7..1e62dad 100644 --- a/python-api/gstswitch/connection.py +++ b/python-api/gstswitch/connection.py @@ -5,9 +5,6 @@ import sys -CONNECTION_FLAGS = Gio.DBusConnectionFlags.AUTHENTICATION_CLIENT - - class Connection(object): """Class which makes all remote object class. Deals with lower level connection and remote method invoking @@ -16,6 +13,7 @@ class Connection(object): :param: None """ + CONNECTION_FLAGS = Gio.DBusConnectionFlags.AUTHENTICATION_CLIENT def __init__( self, @@ -30,6 +28,100 @@ def __init__( self.object_path = object_path self.default_interface = default_interface + @property + def address(self): + return self._address + + @property + def bus_name(self): + if self._bus_name is None: + return None + return self._bus_name + + @property + def object_path(self): + return self._object_path + + @property + def default_interface(self): + return self._default_interface + + @address.setter + def address(self, address): + """Set the Address + http://dbus.freedesktop.org/doc/dbus-specification.html#addresses + """ + if not address: + raise ValueError("Address '{0} cannot be blank'") + else: + try: + a = str(address) + if a.find(':') > 0: + self._address = a + else: + raise ValueError("""Address must follow specifications mentioned at + http://dbus.freedesktop.org/doc/dbus-specification.html#addresses""") + # except TypeError: + # raise TypeError("Address should be a string or buffer, not '{0}'".format(type(address))) + except: + raise + + @bus_name.setter + def bus_name(self, bus_name): + """Set the Bus Name + http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-bus + """ + if bus_name is None: + self._bus_name = None + return + try: + a = str(bus_name) + self._bus_name = a + # except TypeError: + # raise TypeError("Bus Name should be a string or buffer, not '{0}'".format(type(bus_name))) + except: + raise + + @object_path.setter + def object_path(self, object_path): + """Set the object_path + http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-marshaling-object-path + """ + if not object_path: + raise ValueError("object_path '{0} cannot be blank'") + else: + try: + a = str(object_path) + if a[0] == '/': + self._object_path = a + else: + raise ValueError("""object_path must follow specifications mentioned at + http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-marshaling-object-path""") + # except TypeError: + # raise TypeError("object_path should be a string or buffer, not '{0}'".format(type(object_path))) + except: + raise + + @default_interface.setter + def default_interface(self, default_interface): + """Set the default_interface + http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-interface + """ + if not default_interface: + raise ValueError("default_interface '{0} cannot be blank'") + else: + try: + a = str(default_interface) + if a.count('.') > 1: + self._default_interface = a + else: + raise ValueError("""default_interface must follow specifications mentioned at + http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-interface""") + except TypeError: + raise TypeError("default_interface should be a string or buffer, not '{0}'".format(type(default_interface))) + except: + raise + def connect_dbus(self): """Make a new connection using the parameters belonging to the class to the gst-switch-srv over dbus. @@ -42,11 +134,11 @@ def connect_dbus(self): try: connection = Gio.DBusConnection.new_for_address_sync( self.address, - CONNECTION_FLAGS, + self.CONNECTION_FLAGS, None, None) self.connection = connection - except GLib.GError: + except: error = sys.exc_info()[1] message = error.message domain = error.domain @@ -68,7 +160,7 @@ def get_compose_port(self): args, GLib.VariantType.new("(i)"), Gio.DBusCallFlags.NONE, -1, None) return port - except GLib.GError: + except: error = sys.exc_info()[1] message = error.message domain = error.domain diff --git a/python-api/gstswitch/server.py b/python-api/gstswitch/server.py index 1c3c01b..cee639d 100644 --- a/python-api/gstswitch/server.py +++ b/python-api/gstswitch/server.py @@ -54,14 +54,14 @@ def record_file(self): @path.setter def path(self, path): if not path: - raise ValueError("Path. '{0}' be blank".format(path)) + raise ValueError("Path '{0}' cannot be blank".format(path)) else: self._path = path @video_port.setter def video_port(self, video_port): if not video_port: - raise ValueError("Video Port. '{0}' be blank".format(video_port)) + raise ValueError("Video Port '{0}' cannot be blank".format(video_port)) else: try: i = int(video_port) @@ -75,7 +75,7 @@ def video_port(self, video_port): @audio_port.setter def audio_port(self, audio_port): if not audio_port: - raise ValueError("Audio Port. '{0}' be blank".format(audio_port)) + raise ValueError("Audio Port '{0}' cannot be blank".format(audio_port)) else: try: i = int(audio_port) @@ -89,7 +89,7 @@ def audio_port(self, audio_port): @control_port.setter def control_port(self, control_port): if not control_port: - raise ValueError("Control Port. '{0}' be blank".format(control_port)) + raise ValueError("Control Port '{0}' cannot be blank".format(control_port)) else: try: i = int(control_port) @@ -103,7 +103,7 @@ def control_port(self, control_port): @record_file.setter def record_file(self, record_file): if not record_file: - raise ValueError("Record File. '{0}' be blank".format(record_file)) + raise ValueError("Record File '{0}' cannot be blank".format(record_file)) else: try: rec = str(record_file) diff --git a/python-api/gstswitch/test.py b/python-api/gstswitch/test.py index fece61a..284621b 100755 --- a/python-api/gstswitch/test.py +++ b/python-api/gstswitch/test.py @@ -1,4 +1,9 @@ #!/usr/bin/env python + +# WARNING: +# THIS FILE IS ONLY FOR MY PERSONAL TESTING PURPOSES. +# IT IS NOT MADE TO AND SHOULD NOT BE TESTING THE ENTIRE API + from gstswitch import * from helpers import TestSources, PreviewSinks from controller import Controller @@ -9,7 +14,6 @@ # all executables (gst-launch-1.0, gst-switch-srv, gst-switch-ui, gst-switch-cap) at this path path = '/home/hyades/gst/master/gstreamer/tools/' s = Server(path) -get_res = '' try: s.run() # launches the server default parameters port = s.video_port @@ -40,10 +44,14 @@ for mode in modes: print 'composite mode=', mode test_set_composite_mode(mode) - time.sleep(0.3) -except: - a = sys.exc_info() - print a + time.sleep(1) + + sources.terminate() + s.terminate() +# except: +# a = sys.exc_info() +# print a +# raise # test_set_composite_mode(0) # time.sleep(2) # channel = 1 @@ -58,9 +66,7 @@ # time.sleep(0.1) - sources.terminate() -# output.terminate() - s.terminate() -else: -# finally: + +# else: +finally: s.kill()