Ejemplo n.º 1
0
    def submit(self, event=None):
        '''
        Method invoked to alter the behavior of some simulated CORBA method/attribute

        Paremeters:
        - event This is ignored!
        '''

        method_name = self.comp_method

        if self.operation_type == "Attributes":
            method_name = "_get_" + method_name

        #create the temporary dictionary
        temp_dict = {
            'Value': None,
            'Timeout': float(self.sleepCounter.getvalue())
        }

        #get the code to be executed yielding a return value
        temp_dict['Value'] = self.st.getvalue().strip().split('\n')
        temp_dict['Value'] = getCompLocalNSList(
            self.comp_name) + temp_dict['Value']
        temp_dict['Value'] = listToCodeObj(temp_dict['Value'], {})

        #store it globally
        getSimProxy(self.comp_name).gui_handler.setMethod(
            method_name, temp_dict)
Ejemplo n.º 2
0
    def submit(self, event=None):
        '''
        Method invoked to alter the behavior of some simulated CORBA method/attribute

        Paremeters:
        - event This is ignored!
        '''
        
        method_name = self.comp_method
        
        if self.operation_type=="Attributes":
            method_name = "_get_" + method_name
        
        #create the temporary dictionary
        temp_dict = { 'Value': None,
                      'Timeout': float(self.sleepCounter.getvalue())}
        
        #get the code to be executed yielding a return value
        temp_dict['Value'] = self.st.getvalue().strip().split('\n')
        temp_dict['Value'] = getCompLocalNSList(self.comp_name) + temp_dict['Value']
        temp_dict['Value'] = listToCodeObj(temp_dict['Value'], 
                                           {})
        
        
        
        #store it globally
        getSimProxy(self.comp_name).gui_handler.setMethod(method_name, 
                                                          temp_dict)
Ejemplo n.º 3
0
    def initialize(self):
        '''
        Overriden from baseclass.
        '''
        #we can finally access the IR location and call BaseSimulator's
        #constructor...dynamically changing this object's inheritance
        BaseSimulator.__init__(self, self.ir, self._get_name())

        #         # hook to call the initialize method from the Simulation Server
        #         simServer = getSimProxy(self._get_name(), self.ir).server_handler
        #         print 'Getting initialize method from server'
        #         initMethodDict = simServer.getMethod('initialize2')
        #         if initMethodDict != None:
        #              print 'executing initialize method: ' + str(initMethodDict['Value'])
        #              _executeDict(initMethodDict, [self], getCompLocalNS(self._get_name()))

        #add myself to the global lis
        addComponent(self._get_name(), self)

        # Create a BehaviorProxy, passing the interface repository id to the
        # constructor.
        proxy = getSimProxy(self._get_name(), self.ir)

        #possible for developers to configure an initialize method
        #for the simulated component.
        ns = getCompLocalNS(self._get_name())
        ns['SELF'] = self
        _execute(self._get_name(), "initialize", [self], ns)

        #create the object used to dispatch events automatically
        self.event_dispatcher = EventDispatcher(self)

        #handle attributes that should NOT be generically simulated
        self.__setupSpecialCases()
Ejemplo n.º 4
0
def _execute(comp_name, meth_name, args, local_ns):
    '''
    Given a component name/type as well as a method or CORBA attribute name,
    this function will simulate the execution of it. It first searches to see
    if the user has specified some code to be executed using the API; followed
    by a search of the CDB; and finally tries to generate a return value on the
    fly.

    Parameters:
    - comp_name is the name of the component being simulated
    - meth_name is the name of the method being simulated
    - local_ns is the local namespace
    
    Returns: Anything

    Raises: Anything
    '''     
    ret_val = _executeDict(getSimProxy(comp_name).getMethod(meth_name), 
                           args,
                           local_ns)
        
    LOGGER.logDebug(meth_name + " return value looks like:" + str(ret_val) + " of type:" + str(type(ret_val)))
    return ret_val
Ejemplo n.º 5
0
def _execute(comp_name, meth_name, args, local_ns):
    '''
    Given a component name/type as well as a method or CORBA attribute name,
    this function will simulate the execution of it. It first searches to see
    if the user has specified some code to be executed using the API; followed
    by a search of the CDB; and finally tries to generate a return value on the
    fly.

    Parameters:
    - comp_name is the name of the component being simulated
    - meth_name is the name of the method being simulated
    - local_ns is the local namespace
    
    Returns: Anything

    Raises: Anything
    '''
    ret_val = _executeDict(
        getSimProxy(comp_name).getMethod(meth_name), args, local_ns)

    LOGGER.logDebug(meth_name + " return value looks like:" + str(ret_val) +
                    " of type:" + str(type(ret_val)))
    return ret_val
Ejemplo n.º 6
0
    def initialize (self):
        '''
        Overriden from baseclass.
        '''
        #we can finally access the IR location and call BaseSimulator's
        #constructor...dynamically changing this object's inheritance
        #BaseSimulator.__init__(self, self.ir, self._get_name()) # Don't do it because is done in __init__

#         # hook to call the initialize method from the Simulation Server
#         simServer = getSimProxy(self._get_name(), self.ir).server_handler
#         print 'Getting initialize method from server'
#         initMethodDict = simServer.getMethod('initialize2')
#         if initMethodDict != None:
#              print 'executing initialize method: ' + str(initMethodDict['Value'])
#              _executeDict(initMethodDict, [self], getCompLocalNS(self._get_name()))

        #add myself to the global lis
        addComponent(self._get_name(), self)

        # Create a BehaviorProxy, passing the interface repository id to the
        # constructor.
        proxy = getSimProxy(self._get_name(), self.ir)
                
        #possible for developers to configure an initialize method
        #for the simulated component.
        ns = getCompLocalNS(self._get_name())
        ns['SELF'] = self
        _execute(self._get_name(),
                 "initialize",
                 [self],
                 ns)
                
        #create the object used to dispatch events automatically         
        self.event_dispatcher = EventDispatcher(self)

        #handle attributes that should NOT be generically simulated
        self.__setupSpecialCases()
Ejemplo n.º 7
0
    def __setupSpecialCases(self):
        '''
        Helper method designed to handle special cases that we do not necessarily
        want being 100% simulated like BACI properties, callbacks, etc.
        '''
        #look in the CDB for instructions on how to setup the special cases. This
        #is mainly used to see if the end-user has specified some devIO class to
        #be used with a BACI property.
        if_list = getSuperIDs(self.ir)
        if_list.append(self.ir)
        simCDB = getSimProxy(self._get_name(), self.ir).cdb_handler
        simServer = getSimProxy(self._get_name(), self.ir).server_handler

        #IFR
        ir = interfaceRepository()

        #_executeXyz methods need an argument list
        args = [self]

        #get an interface description for this component
        interf = ir.lookup_id(self._NP_RepositoryId)
        interf = interf._narrow(CORBA.InterfaceDef)
        interf = interf.describe_interface()

        #use the IFR descrip to go searching for BACI properties
        for attribute in interf.attributes:
            
            #if the typecode is NOT an object reference it cannot be a BACI property.
            #that implies it's OK to skip
            if not isinstance(attribute.type, omniORB.tcInternal.TypeCode_objref):
                continue

            #save the short version of the attribute's ID (i.e., ROdouble)
            tempType = attribute.type.id().split(":")[1].split("/").pop()

            #sequence BACI property
            if (tempType=="ROstringSeq")or(tempType=="ROdoubleSeq")or(tempType=="RWdoubleSeq")or(tempType=="ROlongSeq")or(tempType=="RWlongSeq")or(tempType=="ROfloatSeq")or(tempType=="RWfloatSeq"):
                attrDict = simServer.getMethod(attribute.name)
                if attrDict == None: attrDict = simCDB.getMethod(attribute.name)
                if  attrDict!= None:
                    devio = _executeDict(attrDict, args, getCompLocalNS(self._get_name()))
                else:
                    devio = DevIO([])                    
                    
                addProperty(self, attribute.name, devio_ref=devio)
                continue

            #double BACI property
            elif (tempType=="ROdouble")or(tempType=="RWdouble"):
                attrDict = simServer.getMethod(attribute.name)
                if attrDict == None: attrDict = simCDB.getMethod(attribute.name)

                if  attrDict!= None:
                    devio = _executeDict(attrDict, args, getCompLocalNS(self._get_name()))
                else:
                    devio = DevIO(float(0))                    
                    
                addProperty(self, attribute.name, devio_ref=devio)
                continue

            #float BACI property
            elif (tempType=="ROfloat")or(tempType=="RWfloat"):
                attrDict = simServer.getMethod(attribute.name)
                if attrDict == None: attrDict = simCDB.getMethod(attribute.name)

                if  attrDict!= None:
                    devio = _executeDict(attrDict, args, getCompLocalNS(self._get_name()))
                else:
                    devio = DevIO(float(0))                    
                    
                addProperty(self, attribute.name, devio_ref=devio)
                continue


            #long BACI property
            elif (tempType=="ROlong")or(tempType=="RWlong"):
                attrDict = simServer.getMethod(attribute.name)
                if attrDict == None: attrDict = simCDB.getMethod(attribute.name)
                if  attrDict!= None:
                    devio = _executeDict(attrDict, args, getCompLocalNS(self._get_name()))
                else:
                    devio = DevIO(0)                    
                    
                addProperty(self, attribute.name, devio_ref=devio)
                continue

            #long (Python long also) BACI property
            elif (tempType=="ROpattern")or(tempType=="RWpattern")or(tempType=="ROlongLong")or(tempType=="RWlongLong")or(tempType=="ROuLongLong")or(tempType=="ROuLongLong"):
                attrDict = simServer.getMethod(attribute.name)
                if attrDict == None: attrDict = simCDB.getMethod(attribute.name)
                if  attrDict!= None:
                    devio = _executeDict(attrDict, args, getCompLocalNS(self._get_name()))
                else:
                    devio = DevIO(0L)                    
                    
                addProperty(self, attribute.name, devio_ref=devio)
                continue

            #string BACI property
            elif (tempType=="ROstring")or(tempType=="RWstring"):
                attrDict = simServer.getMethod(attribute.name)
                if attrDict == None: attrDict = simCDB.getMethod(attribute.name)
                if  attrDict!= None:
                    devio = _executeDict(attrDict, args, getCompLocalNS(self._get_name()))
                else:
                    devio = DevIO("")                    
                    
                addProperty(self, attribute.name, devio_ref=devio)
                continue

            else:
                
                ifrName = attribute.type.id()
                
                try:
                    #get an interface description for this property
                    tIfr = ir.lookup_id(ifrName)
                    tIfr = tIfr._narrow(CORBA.InterfaceDef)
                    tIfr = tIfr.describe_interface()

                    for tAttr in tIfr.attributes:
                        #check if it's a default_value AND an enum!
                        if (tAttr.name=="default_value") and (tAttr.type.kind()==CORBA.tk_enum):
                            #GREAT! It's completely safe to add!
                            attrDict = simServer.getMethod(attribute.name)
                            if attrDict == None: attrDict = simCDB.getMethod(attribute.name)
                            if  attrDict!= None:
                                devio = _executeDict(attrDict, args, getCompLocalNS(self._get_name()))
                            else:
                                devio = DevIO(getRandomEnum(tAttr.type))
                            addProperty(self, attribute.name, devio_ref=devio)
                                              
                            break

                except:
                    print_exc()
                    continue