srv callback now accepts functions from outside
This commit is contained in:
parent
7d0e7f1786
commit
e5d6633aca
@ -111,16 +111,41 @@ class MinimalSubscriber(Node):
|
|||||||
#******************************************************************************#
|
#******************************************************************************#
|
||||||
|
|
||||||
class MinimalServiceProvider(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.NODE_NAME = NODE_NAME
|
||||||
self.SRV_NAME = SRV_NAME
|
self.SRV_NAME = SRV_NAME
|
||||||
self.SRV_TYPE = SRV_TYPE
|
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"
|
# Init above laying class "Node"
|
||||||
super().__init__(self.NODE_NAME)
|
super().__init__(self.NODE_NAME)
|
||||||
print("\tStarting Service Host:\t%s"%(self.SRV_NAME))
|
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.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
|
* request: first half of srv-file
|
||||||
* response: second 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
|
response = self.user_defined(request, response) # Function defined below
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
# Insert your callback code here
|
# Insert your callback code here
|
||||||
def user_defined(self, request, response):
|
def user_defined(self, request, response):
|
||||||
""" Write your user defined code here which will be run at every service call
|
""" Write your user defined code here which will be run at every service call
|
||||||
|
Loading…
Reference in New Issue
Block a user