Commit 11f3ec4d authored by Devaev Maxim's avatar Devaev Maxim

Hieratical structure of shareds with navigation

parent 46e6171e
...@@ -58,25 +58,52 @@ class Service(ServiceInterface, ServiceRequisitesInterface) : ...@@ -58,25 +58,52 @@ class Service(ServiceInterface, ServiceRequisitesInterface) :
##### #####
class CustomObject(dbus.service.Object) : class CustomObject(dbus.service.Object) :
def __init__(self, object_path, shared_path, service) : def __init__(self, object_path, service = None) :
dbus.service.Object.__init__(self, config.value(config.RUNTIME_SECTION, "bus_name"), object_path) dbus.service.Object.__init__(self, config.value(config.RUNTIME_SECTION, "bus_name"), object_path)
self._object_path = object_path self._object_path = object_path
self._shared_path = shared_path
self._service = service self._service = service
#####
self._shared = None
### Public ### ### Public ###
def name(self) :
if self.shared() == None :
return None
for (shared_object_name, shared_object) in self.shared().sharedObjects().items() :
if shared_object == self :
return shared_object_name
return None
def path(self) :
def build_path(shared) :
if shared != None :
path = build_path(shared.parentShared())
return ( shared.name() if path == None else dbus_tools.joinMethod(path, shared.name()) )
return None
return build_path(self.shared())
def objectPath(self) : def objectPath(self) :
return self._object_path return self._object_path
def sharedPath(self) : ###
return self._shared_path
def setService(self, service) :
self._service = service
def service(self) : def service(self) :
return self._service return self._service
def setShared(self, shared) :
self._shared = shared
def shared(self) :
return self._shared
### ###
def addToConnection(self, connection = None, path = None) : def addToConnection(self, connection = None, path = None) :
...@@ -87,12 +114,12 @@ class CustomObject(dbus.service.Object) : ...@@ -87,12 +114,12 @@ class CustomObject(dbus.service.Object) :
class FunctionObject(CustomObject) : class FunctionObject(CustomObject) :
def __init__(self, object_path, shared_path, service) : def __init__(self, object_path, service = None) :
CustomObject.__init__(self, dbus_tools.joinPath(config.value(config.APPLICATION_SECTION, "service_path"), CustomObject.__init__(self, dbus_tools.joinPath(config.value(config.APPLICATION_SECTION, "service_path"),
"functions", object_path), shared_path, service) "functions", object_path), service)
class ActionObject(CustomObject) : class ActionObject(CustomObject) :
def __init__(self, object_path, shared_path, service) : def __init__(self, object_path, service = None) :
CustomObject.__init__(self, dbus_tools.joinPath(config.value(config.APPLICATION_SECTION, "service_path"), CustomObject.__init__(self, dbus_tools.joinPath(config.value(config.APPLICATION_SECTION, "service_path"),
"actions", object_path), shared_path, service) "actions", object_path), service)
...@@ -21,20 +21,44 @@ class SharedAbstract : ...@@ -21,20 +21,44 @@ class SharedAbstract :
entity._shareds_dict = {} entity._shareds_dict = {}
entity._shared_objects_dict = {} entity._shared_objects_dict = {}
#####
entity._parent_shared = None
### Public ### ### Public ###
def setParentShared(entity, shared) :
entity._parent_shared = shared
def parentShared(entity) :
return entity._parent_shared
###
def name(entity) :
if entity.parentShared() == None :
return None
for (shared_name, shared) in entity.parentShared().shareds().items() :
if shared == entity :
return shared_name
return None
###
def addShared(entity, shared_name) : def addShared(entity, shared_name) :
if entity._shareds_dict.has_key(shared_name) : if entity._shareds_dict.has_key(shared_name) :
raise SharedsConflict("Shared \"%s\" is already exists in collection \"%s\"" % (shared_name, entity.__name__)) raise SharedsConflict("Shared \"%s\" is already exists in collection \"%s\"" % (shared_name, entity.__name__))
entity._shareds_dict[shared_name] = Shared() entity._shareds_dict[shared_name] = Shared()
entity._shareds_dict[shared_name].setParentShared(entity)
setattr(entity, shared_name, entity._shareds_dict[shared_name]) setattr(entity, shared_name, entity._shareds_dict[shared_name])
def removeShared(entity, shared_name) : def removeShared(entity, shared_name) :
if not entity._shareds_dict.has_key(shared_name) : if not entity._shareds_dict.has_key(shared_name) :
raise SharedNotExists("Shared \"%s\" does not exist in collection \"%s\"" % (shared_name, entity.__name__)) raise SharedNotExists("Shared \"%s\" does not exist in collection \"%s\"" % (shared_name, entity.__name__))
entity._shareds_dict[shared_name].setParentShared(None)
entity._shareds_dict.pop(shared_name) entity._shareds_dict.pop(shared_name)
delattr(entity, shared_name) delattr(entity, shared_name)
...@@ -54,12 +78,14 @@ class SharedAbstract : ...@@ -54,12 +78,14 @@ class SharedAbstract :
raise SharedObjectsConflict("Shared object \"%s\" is already exists in collection \"%s\"" % (shared_object_name, entity.__name__)) raise SharedObjectsConflict("Shared object \"%s\" is already exists in collection \"%s\"" % (shared_object_name, entity.__name__))
entity._shared_objects_dict[shared_object_name] = shared_object entity._shared_objects_dict[shared_object_name] = shared_object
entity._shared_objects_dict[shared_object_name].setShared(entity)
setattr(entity, shared_object_name, entity._shared_objects_dict[shared_object_name]) setattr(entity, shared_object_name, entity._shared_objects_dict[shared_object_name])
def removeSharedObject(entity, shared_object_name) : def removeSharedObject(entity, shared_object_name) :
if not entity._shared_objects_dict.has_key(shared_object_name) : if not entity._shared_objects_dict.has_key(shared_object_name) :
raise SharedObjectNotExists("Shared object \"%s\" does not exist in collection \"%s\"" % (shared_object_name, entity.__name__)) raise SharedObjectNotExists("Shared object \"%s\" does not exist in collection \"%s\"" % (shared_object_name, entity.__name__))
entity._shared_objects_dict[shared_object_name].setShared(None)
entity._shared_objects_dict.pop(shared_object_name) entity._shared_objects_dict.pop(shared_object_name)
delattr(entity, shared_object_name) delattr(entity, shared_object_name)
...@@ -87,6 +113,19 @@ class Shared(object, SharedAbstract) : ...@@ -87,6 +113,19 @@ class Shared(object, SharedAbstract) :
class Functions(object) : class Functions(object) :
__metaclass__ = SharedRootMeta __metaclass__ = SharedRootMeta
### Public ###
@classmethod
def name(self) :
return "Functions"
class Actions(object) : class Actions(object) :
__metaclass__ = SharedRootMeta __metaclass__ = SharedRootMeta
### Public ###
@classmethod
def name(self) :
return "Actions"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment