Skip to content

Commit

Permalink
Added properties and exception - connection.py
Browse files Browse the repository at this point in the history
  • Loading branch information
hyades committed Jul 21, 2013
1 parent f1506f8 commit 76ce533
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 21 deletions.
104 changes: 98 additions & 6 deletions python-api/gstswitch/connection.py
Expand Up @@ -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
Expand All @@ -16,6 +13,7 @@ class Connection(object):
:param: None
"""
CONNECTION_FLAGS = Gio.DBusConnectionFlags.AUTHENTICATION_CLIENT

def __init__(
self,
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions python-api/gstswitch/server.py
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
26 changes: 16 additions & 10 deletions 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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -58,9 +66,7 @@


# time.sleep(0.1)
sources.terminate()
# output.terminate()
s.terminate()
else:
# finally:

# else:
finally:
s.kill()

0 comments on commit 76ce533

Please sign in to comment.