示例#1
0
def initialize(register_ip_address) -> MSkeletonAccess:
    # Get the service descriptions from the mmu register
    client = ThriftClient(register_ip_address.Address,
                          register_ip_address.Port, MSkeletonAccess.Client)
    client.__enter__(
    )  ## Todo: this appears dirty and we should probably clean this up in the future.
    return client._access
示例#2
0
 def GetPathPlanningService(self):
     if self.__PathPlanningService is None:
         description = self._get_service_description("pathPlanningService")
         self.__PathPlanningService = ThriftClient(
             description.Addresses[0].Address,
             description.Addresses[0].Port, MPathPlanningService.Client)
         self.__PathPlanningService.__enter__()
     return self.__PathPlanningService._access
示例#3
0
 def GetRetargetingService(self):
     if self.__RetargetingService is None:
         description = self._get_service_description("Retargeting")
         self.__RetargetingService = ThriftClient(
             description.Addresses[0].Address,
             description.Addresses[0].Port, MRetargetingService.Client)
         self.__RetargetingService.__enter__()
     return self.__RetargetingService._access
示例#4
0
def get_adapter_descriptions(ip_address, session_id):
    """
    Connects to the given address and returns the description for all found adapters
    
    Parameters
    ---------
    ip_address : MIPAddress
        The address
        
    Returns
    ---------
    list<AdapterDescription>
        All available adapters
    """
    
    assert (isinstance(ip_address, MIPAddress)), "The given ip_address is no MIPAddress"
    
    
    # Get the service descriptions from the mmu register
    with ThriftClient(ip_address.Address, ip_address.Port, MMIRegisterService.Client) as client:
        descriptions = client._access.GetRegisteredAdapters(session_id)
    
    if descriptions is None or len(descriptions) == 0:
        print('No adapter descriptions received.')
    
    return descriptions
 def register_adapter(self):
     registered = False
     while registered != True:
         try:
             with ThriftClient(self.r_address.Address, self.r_address.Port,
                               MMIRegisterService.Client) as client:
                 response = client._access.RegisterAdapter(
                     self.session_data.adapter_description)
                 registered = response.Successful
                 if registered == True:
                     print("Sucessfully registered adapter at MMIRegister")
         except Exception as x:
             print("Failed to register at MMIRegister")
             time.sleep(1)
示例#6
0
    def initialize(self):
        """
        Initializes the service access.
        """

        descriptions = None

        # Get the service descriptions from the mmu register
        with ThriftClient(self._register_ip_address.Address,
                          self._register_ip_address.Port,
                          MMIRegisterService.Client) as client:
            descriptions = client._access.GetRegisteredServices(
                self.__sessionID)

        if descriptions is None or len(descriptions) == 0:
            print('No service descriptions received.')

        # Store descriptions into dictionary
        for description in descriptions:
            self.service_descriptions[description.Name] = description
示例#7
0
class ServiceAccess(object):
    """
    An access point to the standard MMI Services
    
    Attributes
    ----------
    
    _address : str
        The root address which is used to get the information 
        about all available services and accessing them
        
    service_descriptions : dict
        A dictionary with all descriptions for the different services
    """
    def __init__(self, register_ip_address, sessionID):
        """
        The default constructor which requires the root address.
        
        Parameters
        ----------
        register_ip_address : MIPAddress
            The root register ip address to access the services
        """

        assert (isinstance(
            register_ip_address,
            MIPAddress)), 'The register_address is no MIPAddress'

        self._register_ip_address = register_ip_address
        self.service_descriptions = dict()
        self.__RetargetingService = None
        self.__PathPlanningService = None
        self.__sessionID = sessionID
        self.initialize()

    def _get_service_description(self, service_name):
        """
        Returns the description of a given service name
        
        Parameters
        -----------
        service_name : str
            The service name
            
        Returns
        ---------
        ServiceDescription
            The description of the service
        """

        assert (isinstance(service_name, str)), "service_name is no string"

        description = None

        if service_name not in self.service_descriptions:
            self.initialize()

        if service_name in self.service_descriptions:
            description = self.service_descriptions[service_name]
            print("service found: ", description)

        return description

    def initialize(self):
        """
        Initializes the service access.
        """

        descriptions = None

        # Get the service descriptions from the mmu register
        with ThriftClient(self._register_ip_address.Address,
                          self._register_ip_address.Port,
                          MMIRegisterService.Client) as client:
            descriptions = client._access.GetRegisteredServices(
                self.__sessionID)

        if descriptions is None or len(descriptions) == 0:
            print('No service descriptions received.')

        # Store descriptions into dictionary
        for description in descriptions:
            self.service_descriptions[description.Name] = description

    def GetRetargetingService(self):
        if self.__RetargetingService is None:
            description = self._get_service_description("Retargeting")
            self.__RetargetingService = ThriftClient(
                description.Addresses[0].Address,
                description.Addresses[0].Port, MRetargetingService.Client)
            self.__RetargetingService.__enter__()
        return self.__RetargetingService._access

    def GetPathPlanningService(self):
        if self.__PathPlanningService is None:
            description = self._get_service_description("pathPlanningService")
            self.__PathPlanningService = ThriftClient(
                description.Addresses[0].Address,
                description.Addresses[0].Port, MPathPlanningService.Client)
            self.__PathPlanningService.__enter__()
        return self.__PathPlanningService._access