Commit 79370ec0 authored by Devaev Maxim's avatar Devaev Maxim

Hieratic structure of shareds

parent 41021b91
...@@ -3,6 +3,6 @@ bus_type = session ...@@ -3,6 +3,6 @@ bus_type = session
log_level = 2 log_level = 2
enabled = yes enabled = yes
[hello] [example]
enabled = yes enabled = yes
...@@ -45,22 +45,29 @@ class ServiceRequisitesInterface(object) : ...@@ -45,22 +45,29 @@ class ServiceRequisitesInterface(object) :
##### Public classes ##### ##### Public classes #####
class Service(ServiceInterface, ServiceRequisitesInterface) : class Service(ServiceInterface, ServiceRequisitesInterface) :
Functions = shared.Functions pass
Actions = shared.Actions
##### #####
class CustomObject(dbus.service.Object) : class CustomObject(dbus.service.Object) :
def __init__(self, object_path) : def __init__(self, object_path, shared_path, service) :
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
### Public ### ### Public ###
def objectPath(self) : def objectPath(self) :
self._object_path return self._object_path
def sharedPath(self) :
return self._shared_path
def service(self) :
return self._service
def addToConnection(self, connection = None, path = None) : def addToConnection(self, connection = None, path = None) :
self.add_to_connection(connection, path) self.add_to_connection(connection, path)
...@@ -70,14 +77,14 @@ class CustomObject(dbus.service.Object) : ...@@ -70,14 +77,14 @@ class CustomObject(dbus.service.Object) :
class FunctionObject(CustomObject) : class FunctionObject(CustomObject) :
def __init__(self, object_path) : def __init__(self, object_path, shared_path, service) :
CustomObject.__init__(self, dbus_tools.joinPath(config.value(config.APPLICATION_SECTION, CustomObject.__init__(self, dbus_tools.joinPath(config.value(config.APPLICATION_SECTION,
"service_path"), "functions", object_path)) "service_path"), "functions", object_path), shared_path, service)
class ActionObject(CustomObject) : class ActionObject(CustomObject) :
def __init__(self, object_path) : def __init__(self, object_path, shared_path, service) :
CustomObject.__init__(self, dbus_tools.joinPath(config.value(config.APPLICATION_SECTION, CustomObject.__init__(self, dbus_tools.joinPath(config.value(config.APPLICATION_SECTION,
"service_path"), "actions", object_path)) "service_path"), "actions", object_path), shared_path, service)
##### Private decorators ##### ##### Private decorators #####
......
...@@ -2,49 +2,91 @@ ...@@ -2,49 +2,91 @@
##### Exceptions ##### ##### Exceptions #####
class SharedConflict(Exception) : class SharedsConflict(Exception) :
pass pass
class SharedNotExist(Exception) : class SharedNotExists(Exception) :
pass pass
class SharedObjectsConflict(Exception) :
pass
class SharedObjectNotExists(Exception) :
pass
##### Private meta #####
class SharedMeta(type) : ##### Private classes #####
def __init__(cls, name, bases_list, attrs_dict) : class SharedAbstract :
cls._shared_objects_dict = {} def __init__(entity) :
entity._shareds_dict = {}
entity._shared_objects_dict = {}
### Public ### ### Public ###
def addSharedObject(cls, shared_object_name, shared_object) : def addShared(entity, shared_name) :
if cls._shared_objects_dict.has_key(shared_object_name) : if entity._shareds_dict.has_key(shared_name) :
raise SharedConflict("Shared \"%s\" is already exists in collection \"%s\"" % (shared_object_name, cls.__name__)) raise SharedsConflict("Shared \"%s\" is already exists in collection \"%s\"" % (shared_name, entity.__name__))
entity._shareds_dict[shared_name] = Shared()
setattr(entity, shared_name, entity._shareds_dict[shared_name])
def removeShared(entity, 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__))
entity._shareds_dict.pop(shared_name)
delattr(entity, shared_name)
cls._shared_objects_dict[shared_object_name] = shared_object def hasShared(entity, shared_name) :
setattr(cls, shared_object_name, shared_object) return entity._shareds_dict.has_key(shared_name)
def removeSharedObject(cls, shared_object_name) : def shared(entity, shared_name) :
if not cls._shared_objects_dict.has_key(shared_object_name) : return entity._shareds_dict[shared_name]
raise SharedNotExist("Shared \"%s\" does not exist in collection \"%s\"" % (shared_object_name, cls.__name__))
cls._shared_objects_dict.pop(shared_object_name) def shareds(entity) :
delattr(cls, shared_object_name) return entity._shareds_dict
def hasSharedObject(cls, shared_object) : ###
return ( shared_object in cls._shared_objects_dict.keys() or shared_object in cls._shared_objects_dict.values() )
def sharedObject(cls, shared_object_name) : def addSharedObject(entity, shared_object_name, shared_object) :
return cls._shared_objects_dict[shared_object_name] if entity._shared_objects_dict.has_key(shared_object_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
setattr(entity, shared_object_name, entity._shared_objects_dict[shared_object_name])
def removeSharedObject(entity, 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__))
entity._shared_objects_dict.pop(shared_object_name)
delattr(entity, shared_object_name)
def hasSharedObject(entity, shared_object) :
return ( entity._shared_objects_dict.has_key(shared_object) or shared_object in entity._shared_objects_dict.values() )
def sharedObject(entity, shared_object_name) :
return entity, entity._shared_objects_dict[shared_object_name]
def sharedObjects(entity) :
return entity._shared_objects_dict
class SharedRootMeta(type, SharedAbstract) :
def __init__(cls, name, bases_list, attrs_dict) :
type.__init__(cls, name, bases_list, attrs_dict)
SharedAbstract.__init__(cls)
def sharedObjectsList(cls) : class Shared(object, SharedAbstract) :
return cls._shared_objects_dict def __init__(self) :
object.__init__(self)
SharedAbstract.__init__(self)
##### Public classes ##### ##### Public classes #####
class Functions(object) : class Functions(object) :
__metaclass__ = SharedMeta __metaclass__ = SharedRootMeta
class Actions(object) : class Actions(object) :
__metaclass__ = SharedMeta __metaclass__ = SharedRootMeta
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