Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 import OpenRTM_aist
00021
00022
00023 class Factory:
00024
00025 FACTORY_OK = 0
00026 FACTORY_ERROR = 1
00027 ALREADY_EXISTS = 2
00028 NOT_FOUND = 3
00029 INVALID_ARG = 4
00030 UNKNOWN_ERROR = 5
00031
00032
00033 def __init__(self):
00034 self._creators = {}
00035
00036
00037
00038 def hasFactory(self, id):
00039 if not self._creators.has_key(id):
00040 return False
00041 return True
00042
00043
00044
00045 def getIdentifiers(self):
00046 idlist = []
00047
00048 for id in self._creators.keys():
00049 idlist.append(id)
00050 idlist.sort()
00051 return idlist
00052
00053
00054
00055
00056
00057 def addFactory(self, id, creator, destructor):
00058 if not creator:
00059 return self.INVALID_ARG
00060
00061 if self._creators.has_key(id):
00062 return self.ALREADY_EXISTS
00063
00064 self._creators[id] = creator
00065 return self.FACTORY_OK
00066
00067
00068
00069 def removeFactory(self, id):
00070 if not self._creators.has_key(id):
00071 return self.NOT_FOUND
00072
00073 del self._creators[id]
00074 return self.FACTORY_OK
00075
00076
00077
00078 def createObject(self, id):
00079 if not self._creators.has_key(id):
00080 print "Factory.createObject return None id: ", id
00081 return None
00082 return self._creators[id]()
00083
00084
00085
00086 def deleteObject(self, obj, id=None):
00087 if id:
00088 if not self._creators.has_key(id):
00089 return
00090
00091 del obj
00092 return
00093
00094
00095 gfactory = None
00096
00097 class GlobalFactory(Factory):
00098 def __init__(self):
00099 Factory.__init__(self)
00100 pass
00101
00102
00103 def instance():
00104 global gfactory
00105
00106 if gfactory is None:
00107 gfactory = GlobalFactory()
00108
00109 return gfactory
00110
00111 instance = staticmethod(instance)
00112
00113
00114 def __del__(self):
00115 pass