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
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
def Connect(self): if self._LoadBusConnectCfg() is not True: return False if self.__connectOk is True: return True ret = tbus.Init(self.__selfAddr, BUS_CFG_FILE) if ret != 0: self.__logger.error('Tbus init failed, err = {}'.format(ret)) return False self.__connectOk = True return True
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
def Connect(self): """ Create connection to all related channel """ if self._LoadBusConnectCfg() is not True: return False if self.__connectOk is True: return True tbus_cfg_path = os.path.join(SYS_CONFIG_DIR, TBUS_CFG_PATH) ret = tbus.Init(self.__selfAddr, tbus_cfg_path) if ret != 0: self.__logger.error('Tbus init failed, err = {}'.format(ret)) return False self.__connectOk = True return True
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