diff --git a/ontopy/ontologenius/__init__.py b/ontopy/ontologenius/__init__.py index d5d7b883..5e455c30 100644 --- a/ontopy/ontologenius/__init__.py +++ b/ontopy/ontologenius/__init__.py @@ -1,5 +1,6 @@ from .clients import * from .clientsIndex import * +from .compat import * from .OntologyManipulator import OntologyManipulator from .OntologyManipulatorIndex import OntologyManipulatorIndex diff --git a/ontopy/ontologenius/clients/ActionClient.py b/ontopy/ontologenius/clients/ActionClient.py index bb84c411..45ff0141 100644 --- a/ontopy/ontologenius/clients/ActionClient.py +++ b/ontopy/ontologenius/clients/ActionClient.py @@ -1,5 +1,3 @@ -import rospy - from .ClientBase import ClientBase class ActionClient(ClientBase): diff --git a/ontopy/ontologenius/clients/ClassClient.py b/ontopy/ontologenius/clients/ClassClient.py index 60114720..2422aa0b 100644 --- a/ontopy/ontologenius/clients/ClassClient.py +++ b/ontopy/ontologenius/clients/ClassClient.py @@ -1,5 +1,3 @@ -import rospy - from .OntologyClient import OntologyClient class ClassClient(OntologyClient): diff --git a/ontopy/ontologenius/clients/ClientBase.py b/ontopy/ontologenius/clients/ClientBase.py index 9c0f4314..b968ebe3 100644 --- a/ontopy/ontologenius/clients/ClientBase.py +++ b/ontopy/ontologenius/clients/ClientBase.py @@ -1,6 +1,6 @@ -import rospy +from ..compat.ros import Ontoros, OntoService -from ontologenius.srv import OntologeniusService +from ontologenius.srv import OntologeniusService, OntologeniusServiceRequest class ClientBase: """The ClientBase class provides an abstraction for any ROS services. @@ -15,7 +15,7 @@ def __init__(self, name): """Constructs a ROS client linked to the service name(str).""" self._name = name self.error_code = 0 - self._client = rospy.ServiceProxy('ontologenius/' + self._name, OntologeniusService, True) + self._client = Ontoros.createService('ontologenius/' + self._name, OntologeniusService) def nb(self): """Gives the total number (int) of service calls from all ClientBase instances since the last reset.""" @@ -37,25 +37,14 @@ def call(self, action, param): If the service call fails, the function returns None """ ClientBase._cpt += 1 - try: - response = self._client(action, param) + request = OntologeniusServiceRequest(action, param) + response = self._client.call(request, ClientBase._verbose) + if(response is None): + self.error_code = -1 + return None + else: self.error_code = response.code return response.values - except (rospy.ServiceException, rospy.exceptions.TransportTerminated) as e: - if ClientBase._verbose == True: - print("Failure to call ontologenius/" + self._name) - self._client = rospy.ServiceProxy('ontologenius/' + self._name, OntologeniusService, True) - try: - response = self._client(action, param) - self.error_code = response.code - if ClientBase._verbose == True: - print("Restored ontologenius/" + self._name) - return response.values - except (rospy.ServiceException, rospy.exceptions.TransportTerminated) as e: - if ClientBase._verbose == True: - print("Failure of service restoration") - self.error_code = -1 - return None def callStr(self, action, param): """Call the service set up in the constructor of ClientBase with the request @@ -63,31 +52,17 @@ def callStr(self, action, param): If the service call fails, the function returns None """ ClientBase._cpt += 1 - try: - response = self._client(action, param) + request = OntologeniusServiceRequest(action, param) + response = self._client.call(request, ClientBase._verbose) + if(response is None): + self.error_code = -1 + return None + else: self.error_code = response.code if len(response.values) > 0: return response.values[0] else: return '' - except (rospy.ServiceException, rospy.exceptions.TransportTerminated) as e: - if ClientBase._verbose == True: - print("Failure to call ontologenius/" + self._name) - self._client = rospy.ServiceProxy('ontologenius/' + self._name, OntologeniusService, True) - try: - response = self._client(action, param) - self.error_code = response.code - if ClientBase._verbose == True: - print("Restored ontologenius/" + self._name) - if len(response.values) > 0: - return response.values[0] - else: - return '' - except (rospy.ServiceException, rospy.exceptions.TransportTerminated) as e: - if ClientBase._verbose == True: - print("Failure of service restoration") - self.error_code = -1 - return None def callNR(self, action, param): """Call the service set up in the constructor of ClientBase with the @@ -95,25 +70,14 @@ def callNR(self, action, param): If the service call fails, the function returns False """ ClientBase._cpt += 1 - try: - response = self._client(action, param) + request = OntologeniusServiceRequest(action, param) + response = self._client.call(request, ClientBase._verbose) + if(response is None): + self.error_code = -1 + return False + else: self.error_code = response.code return True - except (rospy.ServiceException, rospy.exceptions.TransportTerminated) as e: - if ClientBase._verbose == True: - print("Failure to call ontologenius/" + self._name) - self._client = rospy.ServiceProxy('ontologenius/' + self._name, OntologeniusService, True) - try: - response = self._client(action, param) - self.error_code = response.code - if ClientBase._verbose == True: - print("Restored ontologenius/" + self._name) - return True - except (rospy.ServiceException, rospy.exceptions.TransportTerminated) as e: - if ClientBase._verbose == True: - print("Failure of service restoration") - self.error_code = -1 - return False def callBool(self, action, param): """Call the service set up in the constructor of ClientBase with the @@ -122,22 +86,11 @@ def callBool(self, action, param): service is different from SUCCESS. """ ClientBase._cpt += 1 - try: - response = self._client(action, param) + request = OntologeniusServiceRequest(action, param) + response = self._client.call(request, ClientBase._verbose) + if(response is None): + self.error_code = -1 + return False + else: self.error_code = response.code return response.code == 0 - except (rospy.ServiceException, rospy.exceptions.TransportTerminated) as e: - if ClientBase._verbose == True: - print("Failure to call ontologenius/" + self._name) - self._client = rospy.ServiceProxy('ontologenius/' + self._name, OntologeniusService, True) - try: - response = self._client(action, param) - if ClientBase._verbose == True: - print("Restored ontologenius/" + self._name) - self.error_code = response.code - return response.code == 0 - except (rospy.ServiceException, rospy.exceptions.TransportTerminated) as e: - if ClientBase._verbose == True: - print("Failure of service restoration") - self.error_code = -1 - return False diff --git a/ontopy/ontologenius/clients/DataPropertyClient.py b/ontopy/ontologenius/clients/DataPropertyClient.py index bc2b694e..92f1dfa8 100644 --- a/ontopy/ontologenius/clients/DataPropertyClient.py +++ b/ontopy/ontologenius/clients/DataPropertyClient.py @@ -1,5 +1,3 @@ -import rospy - from .OntologyClient import OntologyClient class DataPropertyClient(OntologyClient): diff --git a/ontopy/ontologenius/clients/IndividualClient.py b/ontopy/ontologenius/clients/IndividualClient.py index fbb076f2..22d47c3a 100644 --- a/ontopy/ontologenius/clients/IndividualClient.py +++ b/ontopy/ontologenius/clients/IndividualClient.py @@ -1,5 +1,3 @@ -import rospy - from .OntologyClient import OntologyClient class IndividualClient(OntologyClient): diff --git a/ontopy/ontologenius/clients/ManagerClient.py b/ontopy/ontologenius/clients/ManagerClient.py index 57d9fecc..1f449d0a 100644 --- a/ontopy/ontologenius/clients/ManagerClient.py +++ b/ontopy/ontologenius/clients/ManagerClient.py @@ -1,5 +1,3 @@ -import rospy - from .ClientBase import ClientBase class ManagerClient(ClientBase): diff --git a/ontopy/ontologenius/clients/ObjectPropertyClient.py b/ontopy/ontologenius/clients/ObjectPropertyClient.py index 1d518fa7..3c535067 100644 --- a/ontopy/ontologenius/clients/ObjectPropertyClient.py +++ b/ontopy/ontologenius/clients/ObjectPropertyClient.py @@ -1,5 +1,3 @@ -import rospy - from .OntologyClient import OntologyClient class ObjectPropertyClient(OntologyClient): diff --git a/ontopy/ontologenius/clients/OntologyClient.py b/ontopy/ontologenius/clients/OntologyClient.py index 1dbf4869..0f3d63f0 100644 --- a/ontopy/ontologenius/clients/OntologyClient.py +++ b/ontopy/ontologenius/clients/OntologyClient.py @@ -1,5 +1,3 @@ -import rospy - from .ClientBase import ClientBase class OntologyClient(ClientBase): diff --git a/ontopy/ontologenius/clients/ReasonerClient.py b/ontopy/ontologenius/clients/ReasonerClient.py index 3afd4dd5..79d1c116 100644 --- a/ontopy/ontologenius/clients/ReasonerClient.py +++ b/ontopy/ontologenius/clients/ReasonerClient.py @@ -1,5 +1,3 @@ -import rospy - from .ClientBase import ClientBase class ReasonerClient(ClientBase): diff --git a/ontopy/ontologenius/clientsIndex/ClassIndexClient.py b/ontopy/ontologenius/clientsIndex/ClassIndexClient.py index 5c01e7c2..44586080 100644 --- a/ontopy/ontologenius/clientsIndex/ClassIndexClient.py +++ b/ontopy/ontologenius/clientsIndex/ClassIndexClient.py @@ -1,5 +1,3 @@ -import rospy - from .OntologyIndexClient import OntologyIndexClient class ClassIndexClient(OntologyIndexClient): diff --git a/ontopy/ontologenius/clientsIndex/ClientBaseIndex.py b/ontopy/ontologenius/clientsIndex/ClientBaseIndex.py index 24a2c920..b07f0de0 100644 --- a/ontopy/ontologenius/clientsIndex/ClientBaseIndex.py +++ b/ontopy/ontologenius/clientsIndex/ClientBaseIndex.py @@ -1,6 +1,6 @@ -import rospy +from ..compat.ros import Ontoros, OntoService -from ontologenius.srv import OntologeniusIndexService +from ontologenius.srv import OntologeniusIndexService, OntologeniusIndexServiceRequest class ClientBaseIndex: """The ClientBaseIndex class provides an abstraction for any ROS services. @@ -14,7 +14,7 @@ class ClientBaseIndex: def __init__(self, name): """Constructs a ROS client linked to the service name(str).""" self._name = name - self._client = rospy.ServiceProxy('ontologenius/' + self._name, OntologeniusIndexService, True) + self._client = Ontoros.createService('ontologenius/' + self._name, OntologeniusIndexService) self.error_code = 0 def nb(self): @@ -37,25 +37,14 @@ def call(self, action, param): If the service call fails, the function returns None """ ClientBaseIndex._cpt += 1 - try: - response = self._client(action, param) + request = OntologeniusIndexServiceRequest(action, param) + response = self._client.call(request, ClientBaseIndex._verbose) + if(response is None): + self.error_code = -1 + return None + else: self.error_code = response.code return response.string_values - except (rospy.ServiceException, rospy.exceptions.TransportTerminated) as e: - if ClientBaseIndex._verbose == True: - print("Failure to call ontologenius/" + self._name) - self._client = rospy.ServiceProxy('ontologenius/' + self._name, OntologeniusIndexService, True) - try: - response = self._client(action, param) - self.error_code = response.code - if ClientBaseIndex._verbose == True: - print("Restored ontologenius/" + self._name) - return response.string_values - except (rospy.ServiceException, rospy.exceptions.TransportTerminated) as e: - if ClientBaseIndex._verbose == True: - print("Failure of service restoration") - self.error_code = -1 - return None def callIndexes(self, action, param): """Call the service set up in the constructor of ClientBaseIndex with the request @@ -63,25 +52,14 @@ def callIndexes(self, action, param): If the service call fails, the function returns None """ ClientBaseIndex._cpt += 1 - try: - response = self._client(action, param) + request = OntologeniusIndexServiceRequest(action, param) + response = self._client.call(request, ClientBaseIndex._verbose) + if(response is None): + self.error_code = -1 + return None + else: self.error_code = response.code return response.index_values - except (rospy.ServiceException, rospy.exceptions.TransportTerminated) as e: - if ClientBaseIndex._verbose == True: - print("Failure to call ontologenius/" + self._name) - self._client = rospy.ServiceProxy('ontologenius/' + self._name, OntologeniusIndexService, True) - try: - response = self._client(action, param) - self.error_code = response.code - if ClientBaseIndex._verbose == True: - print("Restored ontologenius/" + self._name) - return response.index_values - except (rospy.ServiceException, rospy.exceptions.TransportTerminated) as e: - if ClientBaseIndex._verbose == True: - print("Failure of service restoration") - self.error_code = -1 - return None def callStr(self, action, param): """Call the service set up in the constructor of ClientBaseIndex with the request @@ -89,31 +67,17 @@ def callStr(self, action, param): If the service call fails, the function returns None """ ClientBaseIndex._cpt += 1 - try: - response = self._client(action, param) + request = OntologeniusIndexServiceRequest(action, param) + response = self._client.call(request, ClientBaseIndex._verbose) + if(response is None): + self.error_code = -1 + return None + else: self.error_code = response.code if len(response.string_values) > 0: return response.string_values[0] else: return '' - except (rospy.ServiceException, rospy.exceptions.TransportTerminated) as e: - if ClientBaseIndex._verbose == True: - print("Failure to call ontologenius/" + self._name) - self._client = rospy.ServiceProxy('ontologenius/' + self._name, OntologeniusIndexService, True) - try: - response = self._client(action, param) - self.error_code = response.code - if ClientBaseIndex._verbose == True: - print("Restored ontologenius/" + self._name) - if len(response.string_values) > 0: - return response.string_values[0] - else: - return '' - except (rospy.ServiceException, rospy.exceptions.TransportTerminated) as e: - if ClientBaseIndex._verbose == True: - print("Failure of service restoration") - self.error_code = -1 - return None def callIndex(self, action, param): """Call the service set up in the constructor of ClientBaseIndex with the request @@ -121,31 +85,17 @@ def callIndex(self, action, param): If the service call fails, the function returns None """ ClientBaseIndex._cpt += 1 - try: - response = self._client(action, param) + request = OntologeniusIndexServiceRequest(action, param) + response = self._client.call(request, ClientBaseIndex._verbose) + if(response is None): + self.error_code = -1 + return None + else: self.error_code = response.code if len(response.index_values) > 0: return response.index_values[0] else: - return '' - except (rospy.ServiceException, rospy.exceptions.TransportTerminated) as e: - if ClientBaseIndex._verbose == True: - print("Failure to call ontologenius/" + self._name) - self._client = rospy.ServiceProxy('ontologenius/' + self._name, OntologeniusIndexService, True) - try: - response = self._client(action, param) - self.error_code = response.code - if ClientBaseIndex._verbose == True: - print("Restored ontologenius/" + self._name) - if len(response.index_values) > 0: - return response.index_values[0] - else: - return '' - except (rospy.ServiceException, rospy.exceptions.TransportTerminated) as e: - if ClientBaseIndex._verbose == True: - print("Failure of service restoration") - self.error_code = -1 - return None + return 0 def callNR(self, action, param): """Call the service set up in the constructor of ClientBaseIndex with the @@ -153,25 +103,14 @@ def callNR(self, action, param): If the service call fails, the function returns False """ ClientBaseIndex._cpt += 1 - try: - response = self._client(action, param) + request = OntologeniusIndexServiceRequest(action, param) + response = self._client.call(request, ClientBaseIndex._verbose) + if(response is None): + self.error_code = -1 + return False + else: self.error_code = response.code return True - except (rospy.ServiceException, rospy.exceptions.TransportTerminated) as e: - if ClientBaseIndex._verbose == True: - print("Failure to call ontologenius/" + self._name) - self._client = rospy.ServiceProxy('ontologenius/' + self._name, OntologeniusIndexService, True) - try: - response = self._client(action, param) - self.error_code = response.code - if ClientBaseIndex._verbose == True: - print("Restored ontologenius/" + self._name) - return True - except (rospy.ServiceException, rospy.exceptions.TransportTerminated) as e: - if ClientBaseIndex._verbose == True: - print("Failure of service restoration") - self.error_code = -1 - return False def callBool(self, action, param): """Call the service set up in the constructor of ClientBaseIndex with the @@ -180,22 +119,11 @@ def callBool(self, action, param): service is different from SUCCESS. """ ClientBaseIndex._cpt += 1 - try: - response = self._client(action, param) + request = OntologeniusIndexServiceRequest(action, param) + response = self._client.call(request, ClientBaseIndex._verbose) + if(response is None): + self.error_code = -1 + return False + else: self.error_code = response.code return response.code == 0 - except (rospy.ServiceException, rospy.exceptions.TransportTerminated) as e: - if ClientBaseIndex._verbose == True: - print("Failure to call ontologenius/" + self._name) - self._client = rospy.ServiceProxy('ontologenius/' + self._name, OntologeniusIndexService, True) - try: - response = self._client(action, param) - if ClientBaseIndex._verbose == True: - print("Restored ontologenius/" + self._name) - self.error_code = response.code - return response.code == 0 - except (rospy.ServiceException, rospy.exceptions.TransportTerminated) as e: - if ClientBaseIndex._verbose == True: - print("Failure of service restoration") - self.error_code = -1 - return False diff --git a/ontopy/ontologenius/clientsIndex/DataPropertyIndexClient.py b/ontopy/ontologenius/clientsIndex/DataPropertyIndexClient.py index ad69edce..30a8a6db 100644 --- a/ontopy/ontologenius/clientsIndex/DataPropertyIndexClient.py +++ b/ontopy/ontologenius/clientsIndex/DataPropertyIndexClient.py @@ -1,5 +1,3 @@ -import rospy - from .OntologyIndexClient import OntologyIndexClient class DataPropertyIndexClient(OntologyIndexClient): diff --git a/ontopy/ontologenius/clientsIndex/IndividualIndexClient.py b/ontopy/ontologenius/clientsIndex/IndividualIndexClient.py index 53ff56ed..d776ae5d 100644 --- a/ontopy/ontologenius/clientsIndex/IndividualIndexClient.py +++ b/ontopy/ontologenius/clientsIndex/IndividualIndexClient.py @@ -1,5 +1,3 @@ -import rospy - from .OntologyIndexClient import OntologyIndexClient class IndividualIndexClient(OntologyIndexClient): diff --git a/ontopy/ontologenius/clientsIndex/ObjectPropertyIndexClient.py b/ontopy/ontologenius/clientsIndex/ObjectPropertyIndexClient.py index 77edfb34..5c27190d 100644 --- a/ontopy/ontologenius/clientsIndex/ObjectPropertyIndexClient.py +++ b/ontopy/ontologenius/clientsIndex/ObjectPropertyIndexClient.py @@ -1,5 +1,3 @@ -import rospy - from .OntologyIndexClient import OntologyIndexClient class ObjectPropertyIndexClient(OntologyIndexClient): diff --git a/ontopy/ontologenius/clientsIndex/OntologyIndexClient.py b/ontopy/ontologenius/clientsIndex/OntologyIndexClient.py index e8163c5a..5807a157 100644 --- a/ontopy/ontologenius/clientsIndex/OntologyIndexClient.py +++ b/ontopy/ontologenius/clientsIndex/OntologyIndexClient.py @@ -1,5 +1,3 @@ -import rospy - from .ClientBaseIndex import ClientBaseIndex class OntologyIndexClient(ClientBaseIndex): diff --git a/ontopy/ontologenius/compat/__init__.py b/ontopy/ontologenius/compat/__init__.py new file mode 100644 index 00000000..10f2a9d2 --- /dev/null +++ b/ontopy/ontologenius/compat/__init__.py @@ -0,0 +1 @@ +from .ros import OntoService, OntoPublisher, OntoSubscriber, Ontoros