diff --git a/src/pubsub/pubsub/pubsub_library_v3.py b/src/pubsub/pubsub/pubsub_library_v3.py index 519e108..c235bcc 100644 --- a/src/pubsub/pubsub/pubsub_library_v3.py +++ b/src/pubsub/pubsub/pubsub_library_v3.py @@ -111,16 +111,41 @@ class MinimalSubscriber(Node): #******************************************************************************# class MinimalServiceProvider(Node): - def __init__(self, NODE_NAME, SRV_NAME, SRV_TYPE): + """ Minimal Service Provider Class + Inputs: + * NODE_NAME: string + * SRV_NAME: string + * SRV_TYPE: service type class + * srv_callback_fct: service callback function + + srv_callback_fct - Inputs: + * request: class of type srv request + * response: class of type srv response + + Return: + * response: class of type srv response + """ + + + def __init__(self, NODE_NAME, SRV_NAME, SRV_TYPE, srv_callback_fct=None): self.NODE_NAME = NODE_NAME self.SRV_NAME = SRV_NAME self.SRV_TYPE = SRV_TYPE + if srv_callback_fct == None: + self.srv_callback = self.std_srv_callback + else: + self.srv_callback = srv_callback_fct # Init above laying class "Node" super().__init__(self.NODE_NAME) - print("\tStarting Service Host:\t%s"%(self.SRV_NAME)) - self.srv_host = self.create_service(self.SRV_TYPE, self.SRV_NAME, self.service_callback) + print("\tStarting Service as Host:\t%s"%(self.SRV_NAME)) + #self.srv_host = self.create_service(self.SRV_TYPE, self.SRV_NAME, self.service_callback) + self.srv_host = self.create_service(self.SRV_TYPE, self.SRV_NAME, self.srv_callback) - def service_callback(self, request, response): + + + + #def service_callback(self, request, response): + def std_srv_callback(self, request, response): """ * request: first half of srv-file * response: second half of srv-file @@ -134,7 +159,6 @@ class MinimalServiceProvider(Node): response = self.user_defined(request, response) # Function defined below return response - # Insert your callback code here def user_defined(self, request, response): """ Write your user defined code here which will be run at every service call