Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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)

  1. create a new folder in https://bitbucket.org/socialroboticshub/processing/src/master/ with the name of the service

  2. 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

  3. create a factory file inheriting from the CBSRFactory in the service’s folder, and override the superclass’s methods

  4. create a service file inheriting from CBSRService in the service’s folder, and override the superclass’s methods

  5. update the https://bitbucket.org/socialroboticshub/processing/src/master/deploy_to_docker.sh file in the root folder with the new service files

  6. deploy the new service to the https://bitbucket.org/socialroboticshub/docker/src/master/ folder by running the deploy_to_docker.sh file

  7. update the https://bitbucket.org/socialroboticshub/docker/src/master/docker-compose.yml file in the docker folder with the new service

  8. update 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

  9. update the device listeners in enable_service in the Abstract Connector with the service

  10. update the listened to channels in __listen in the Abstract Connector with the service

  11. create the corresponding event handler method for the service in the Abstract Connector

  12. create the corresponding event handler method for the service in the Basic Connector

  13. use the new service in a new file

The detailed explanation of these steps can be found below:

Too Long Still Read

  1. 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 case

  2. copy the certificate file https://bitbucket.org/socialroboticshub/docker/src/master/cbsr/beamforming/cert.pem from any of the other services' folders into the my_servicefolder

  3. create a my_service_factory.py file in the my_service folder

...

Code Block
breakoutModewide
# ------------------------------------------------------------
# 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
languagepy
###########################
# 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
languagepy
...
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
languagepy
###########################
# 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
breakoutModewide
languagepy
###########################
# 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.pyand running it

...