Ejemplo n.º 1
0
    def Initialize(self, selfAddr=None):
        """
        Initialize message manager, parse tbus configure file and initialize tbus
        return: True or Flase
        """
        if os.path.exists(self.__cfgPath):
            self._Register()

            config = ConfigParser.ConfigParser(strict=False)
            config.read(self.__cfgPath)
            gameRegAddr = "GameReg" + str(self.__index) + "Addr"
            strgameRegAddr = config.get('BusConf', gameRegAddr)

            if selfAddr is None:
                AgentAddr = "Agent" + str(self.__index) + "Addr"
                strselfAddr = config.get('BusConf', AgentAddr)
            else:
                strselfAddr = config.get('BusConf', selfAddr)
            self.__gameRegAddr = tbus.GetAddress(strgameRegAddr)
            self.__selfAddr = tbus.GetAddress(strselfAddr)
            LOG.info("gamereg addr is {0}, self addr is {1}" \
                     .format(self.__gameRegAddr, self.__selfAddr))
            ret = tbus.Init(self.__selfAddr, self.__cfgPath)
            if ret != 0:
                LOG.error('tbus init failed with return code[{0}]'.format(ret))
                return False

            return True

        else:
            LOG.error('tbus config file not exist in {0}'.format(
                self.__cfgPath))
            return False
Ejemplo n.º 2
0
    def _LoadBusConnectCfg(self):
        ret = True
        tbus_cfg_path = os.path.join(SYS_CONFIG_DIR, TBUS_CFG_PATH)
        if os.path.exists(tbus_cfg_path):
            config = configparser.ConfigParser(strict=False)
            config.read(tbus_cfg_path)

            selfAddrStr = config.get('BusConf', 'Agent1Addr')
            mcAddrStr = config.get('BusConf', 'MCAddr')
            gameRegAddrStr = config.get('BusConf', 'GameReg1Addr')
            sdkToolAddrStr = config.get('BusConf', 'SDKToolAddr')

            self.__selfAddr = tbus.GetAddress(selfAddrStr)
            self.__mcAddr = tbus.GetAddress(mcAddrStr)
            self.__gameRegAddr = tbus.GetAddress(gameRegAddrStr)
            self.__sdkToolAddr = tbus.GetAddress(sdkToolAddrStr)

            if self.__selfAddr is None or self.__mcAddr is None or self.__gameRegAddr is None:
                self.__logger.error('Wrong bus address!')
                ret = False
        else:
            self.__logger.error('Bus cfg file not exists!')
            ret = False

        return ret
Ejemplo n.º 3
0
    def initialize(self, self_addr=None):
        """
        Initialize message manager, parse tbus configure file and initialize tbus
        return: True or Flase
        """

        if os.path.exists(self.__cfg_path):
            self._register()

            config = ConfigParser.ConfigParser(strict=False)
            config.read(self.__cfg_path)
            game_reg_addr = "GameReg" + str(self.__index) + "Addr"
            strgame_reg_addr = config.get('BusConf', game_reg_addr)

            ui_recognize_addr = "UI" + str(self.__index) + "Addr"
            str_ui_addr = config.get('BusConf', ui_recognize_addr)

            agent_addr = "Agent" + str(self.__index) + "Addr"
            str_agent_addr = config.get('BusConf', agent_addr)

            sdktool_addr = "SDKToolAddr"
            str_tool_addr = config.get('BusConf', sdktool_addr)

            if self_addr is None:
                agent_addr = "Agent" + str(self.__index) + "Addr"
                strself_addr = config.get('BusConf', agent_addr)
            else:
                strself_addr = config.get('BusConf', self_addr)
            self.__game_reg_addr = tbus.GetAddress(strgame_reg_addr)
            self.__uirecognize_addr = tbus.GetAddress(str_ui_addr)
            self.__agent_addr = tbus.GetAddress(str_agent_addr)
            self.__sdk_tool_addr = tbus.GetAddress(str_tool_addr)
            self.__self_addr = tbus.GetAddress(strself_addr)

            LOG.info("strgameRegAddr is {0}, strUIAddr is {1}, "
                     "strAgentAddr: {2}".format(strgame_reg_addr, str_ui_addr,
                                                str_agent_addr))

            LOG.info("gamereg addr is {0}, self addr is {1}".format(
                self.__game_reg_addr, self.__self_addr))
            ret = tbus.Init(self.__self_addr, self.__cfg_path)
            if ret != 0:
                LOG.error('tbus init failed with return code[{0}]'.format(ret))
                return False

            LOG.info("*************__agent_addr {} **************".format(
                self.__agent_addr))

            return True

        else:
            LOG.error('tbus config file not exist in {0}'.format(
                self.__cfg_path))
            return False
Ejemplo n.º 4
0
    def Initialize(self, cfgFile):
        """
        Initialize this module, read the conifg from cfgFile and call tbus.Init
        """
        tbusArgs = self._LoadTbusConfig(cfgFile)

        self.__selfAddr = tbus.GetAddress(tbusArgs['IOServiceAddr'])
        self.__MCAddr = tbus.GetAddress(tbusArgs['MCAddr'])

        # if any address is None, then error
        if None in [self.__selfAddr, self.__MCAddr]:
            LOG.error('TBus get address failed')
            return False

        ret = tbus.Init(self.__selfAddr, cfgFile)
        if ret != 0:
            LOG.error('TBus Init failed with return code[{0}]'.format(ret))
            return False
        return True
Ejemplo n.º 5
0
    def _LoadBusConnectCfg(self):
        ret = True

        if os.path.exists(BUS_CFG_FILE):
            config = configparser.ConfigParser(strict=False)
            config.read(BUS_CFG_FILE)

            selfAddrStr = config.get('BusConf', 'Agent1Addr')
            mcAddrStr = config.get('BusConf', 'MCAddr')

            self.__selfAddr = tbus.GetAddress(selfAddrStr)
            self.__mcAddr = tbus.GetAddress(mcAddrStr)

            if self.__selfAddr is None or self.__mcAddr is None:
                self.__logger.error('Wrong bus address!')
                ret = False
        else:
            self.__logger.error('Bus cfg file not exists!')
            ret = False

        return ret
Ejemplo n.º 6
0
    def Initialize(self, configFile):
        """
        Initialize this module, read the conifg from cfgFile and call tbus.Init
        """
        tbusArgs = self._LoadTbusConfig(configFile)

        self.__selfAddr = tbus.GetAddress(tbusArgs['MCAddr'])
        self.__IOAddr = tbus.GetAddress(tbusArgs['IOServiceAddr'])
        self.__Reg1Addr = tbus.GetAddress(tbusArgs['GameReg1Addr'])
        self.__Reg2Addr = tbus.GetAddress(tbusArgs['GameReg1Addr'])
        self.__UI1Addr = tbus.GetAddress(tbusArgs['UI1Addr'])
        self.__UI2Addr = tbus.GetAddress(tbusArgs['UI2Addr'])
        self.__Agent1Addr = tbus.GetAddress(tbusArgs['Agent1Addr'])
        self.__Agent2Addr = tbus.GetAddress(tbusArgs['Agent2Addr'])

        # if any address is None, then error
        if None in [
                self.__selfAddr, self.__IOAddr, self.__Reg1Addr,
                self.__Reg2Addr, self.__UI1Addr, self.__UI2Addr,
                self.__Agent1Addr, self.__Agent2Addr
        ]:
            LOG.error('TBus get address failed')
            return False

        ret = tbus.Init(self.__selfAddr, configFile)
        if ret != 0:
            LOG.error('TBus Init failed with return code[%s]', ret)
            return False

        if self.__runType == RUN_TYPE_UI_AI:
            self.__recvAddrsSet = (self.__IOAddr, self.__Reg1Addr,
                                   self.__Reg2Addr, self.__UI1Addr,
                                   self.__UI2Addr)
            self.__recvAgentAddrsSet = (self.__Agent1Addr, self.__Agent2Addr)
        elif self.__runType == RUN_TYPE_AI:
            self.__recvAddrsSet = (self.__IOAddr, self.__Reg1Addr,
                                   self.__Reg2Addr)
            self.__recvAgentAddrsSet = (self.__Agent1Addr, self.__Agent2Addr)
        elif self.__runType == RUN_TYPE_UI:
            self.__recvAddrsSet = (self.__IOAddr, self.__UI1Addr,
                                   self.__UI2Addr)

        return True