_instance = None
+ tag_locators={}
+
def __init__ (self, api):
self.api=api
# 'tagname'=>'tag_id'
self.set_cache(tagname,tag_type)
return tag_type
+ # a locator is a function that retrieves - or creates - a tag_type instance
+ @staticmethod
+ def register_tag_locator (name, tag_locator):
+ Accessor.tag_locators[name]=tag_locator
+
+ @staticmethod
+ def retrieve_tag_locator (name):
+ return Accessor.tag_locators[name]
+
+ # this is designed to be part of the 'service plc start' sequence
+ # it ensures the creation of all the tagtypes defined
+ # in the various accessors
+ # it's not easy to have define_accessors do this because at
+ # load-time as we do not have an instance of API yet
+ def run_all_tag_locators (self):
+ for (name, tag_locator) in Accessor.tag_locators.items():
+ tag_locator(self)
####################
# make it a singleton so we can cache stuff in there over time
# locate the tag and create it if needed
# this method is attached to the Accessor class
- def locate_or_create_tag (self):
+ def tag_locator (self):
return self.locate_or_create_tag (tagname=tagname,
category=category,
description=description,
roles=set_roles)
# attach it to the Accessor class
- setattr(Accessor,locator_name,locate_or_create_tag)
+ Accessor.register_tag_locator(locator_name,tag_locator)
# body of the get method
def get_call (self, auth, id_or_name):
# locate the tag, see above
- locator = getattr(Accessor,locator_name)
- tag_type = locator(AccessorSingleton(self.api))
+ tag_locator = Accessor.retrieve_tag_locator(locator_name)
+ tag_type = tag_locator(AccessorSingleton(self.api))
tag_type_id=tag_type['tag_type_id']
filter = {'tag_type_id':tag_type_id}
primary_id = obj[primary_key]
# locate the tag, see above
- locator = getattr(Accessor,locator_name)
- tag_type = locator(AccessorSingleton(self.api))
+ tag_locator = Accessor.retrieve_tag_locator(locator_name)
+ tag_type = tag_locator(AccessorSingleton(self.api))
tag_type_id = tag_type['tag_type_id']
# check authorization
--- /dev/null
+#!/usr/bin/plcsh
+# -*- python -*-
+
+#
+# priority: 901
+#
+
+from PLC.Accessor import AccessorSingleton
+
+if __name__ == '__main__':
+ print "Ensuring creationg of accessor tags"
+ print 'api=%r'%api
+ AccessorSingleton(api).run_all_tag_locators()
+