The code for all the services can be found at https://bitbucket.org/socialroboticshub/processing/src/master/ . Creating a new service can be done as follows, and then included in the repository by opening a Pull Request:
TLDR (Too Long Didn’t Read)
create a new folder in https://bitbucket.org/socialroboticshub/processing/src/master/ with the name of the service
copy the certificate file https://bitbucket.org/socialroboticshub/docker/src/master/cbsr/beamforming/cert.pem from any of the other services' folders into the service’s folder
create a factory file inheriting from the
CBSRFactory
in the service’s folder, and override the superclass’s methodscreate a service file inheriting from
CBSRService
in the service’s folder, and override the superclass’s methodsupdate the https://bitbucket.org/socialroboticshub/processing/src/master/deploy_to_docker.sh file in the root folder with the new service files
deploy the new service to the https://bitbucket.org/socialroboticshub/docker/src/master/ folder by running the
deploy_to_docker.sh
fileupdate the https://bitbucket.org/socialroboticshub/docker/src/master/docker-compose.yml file in the
docker
folder with the new serviceupdate the topics in the constructor of the Abstract Connector from the https://bitbucket.org/socialroboticshub/connectors/src/master/python/social_interaction_cloud/ folder with the name of the new service
update the device listeners in
enable_service
in the Abstract Connector with the serviceupdate the listened to channels in
__listen
in the Abstract Connector with the servicecreate the corresponding event handler method for the service in the Abstract Connector
create the corresponding event handler method for the service in the Basic Connector
use the new service in a new file
The detailed explanation of these steps can be found below:
Too Long Still Read
create a new folder in https://bitbucket.org/socialroboticshub/processing/src/master/ with the name of the service.
my_service
will be used as the example folder and service name in this casecopy the certificate file https://bitbucket.org/socialroboticshub/docker/src/master/cbsr/beamforming/cert.pem from any of the other services' folders into the
my_service
foldercreate a
my_service_factory.py
file in themy_service
folder
...
Code Block | ||
---|---|---|
| ||
# ------------------------------------------------------------ # My service # ------------------------------------------------------------ my_service: image: python3 build: context: . dockerfile: Dockerfile.python3 hostname: my_service user: "${NEW_UID}:${NEW_GID}" env_file: - ./.env working_dir: /my_service command: python3 my_service_factory.py volumes: - ./cbsr/mock:/my_service:rw${MOUNT_OPTIONS} tty: true stdin_open: false networks: app_net: ipv4_address: 172.16.238.x # address has to differ from those of the already existing services' depends_on: - redis - dialogflow # - any other services my_service depends on |
8. add the name of the new service my_service
into the topics
list update the topics
in the constructor of the Abstract Connector abstract_connector.py
in from the https://bitbucket.org/socialroboticshub/connectors/src/master/python/social_interaction_cloud/ folder with the name of the new service
topics = [..., 'my_service']
9. add the service my_service
to update the corresponding list of devices listeners in enable_service
in abstract_connector.py
, if the services uses either the camera or the microphone with my_service
Code Block | ||
---|---|---|
| ||
########################### # Management # ########################### def enable_service(self, name: str) -> None: ... elif ... and name == 'my_service': for mic in self.devices[self.device_types['mic']]: pipe.publish(name, mic) ... |
9. add the new channel my_service
into the listened to 10. update the channels in __listen
in abstract_connector.py
with my_service
Code Block | ||
---|---|---|
| ||
... elif channel = 'my_service': self.on_my_service(message=data.decode('utf-8')) ... |
1011. create the corresponding event handler method on_my_service
in abstract_connector.py
Code Block | ||
---|---|---|
| ||
########################### # Event handlers # ########################### ... def on_my_service(self, message: str) -> None: pass ... |
1112. create the corresponding inherited event handler method on_my_service
in basic_connector.py
Code Block | ||||
---|---|---|---|---|
| ||||
########################### # Event handlers # ########################### ... def on_my_service(self, message: str) -> None: """ :param message: the message published on the my_service channel This method notifies the listeners that a new message has been posted on the my_service channel; This method can be further inherited and overridden """ self.__notify_listeners('onMyService', message) ... |
1213. use the new service by creating a new file my_service_example.py
and running it
...