예제 #1
0
	Bool HsGateway::Init(const AString& sCfg)
	{
		if (!m_bRunning)
		{
			HawkXmlFile xmlCfg;
			HawkXmlDocument<AString> xmlDoc;
			if (!xmlCfg.Open(sCfg, xmlDoc))
			{
				HawkPrint("Gateway Open Config Error.");
				return false;
			}

			AXmlElement* pRoot  = xmlDoc.GetRoot();
			AXmlElement* pCfg   = pRoot->GetChildren("GwCfg");

			if(!pCfg || !pCfg->GetAttribute("Frontend") || !pCfg->GetAttribute("Backend"))
			{
				HawkPrint("Gateway Config Tag Error.");
				return false;
			}

			AString sFrontend = pCfg->GetAttribute("Frontend")->StringValue();
			AString sBackend  = pCfg->GetAttribute("Backend")->StringValue();
			HawkStringUtil::Replace<AString>(sBackend, "*", "127.0.0.1");

			Int32 iThread     = 4;
			if (pCfg->GetAttribute("Threads"))
				iThread = pCfg->GetAttribute("Threads")->IntValue();
			
			Bool bCrossDomain = false;
			if (pCfg->GetAttribute("CrossDomain"))
				bCrossDomain = pCfg->GetAttribute("CrossDomain")->BoolValue();

			if (pCfg->GetAttribute("Platform"))
				m_iPlatform = pCfg->GetAttribute("Platform")->IntValue();

			AString sProfiler = "";
			if (pCfg->GetAttribute("Profiler"))
				sProfiler = pCfg->GetAttribute("Profiler")->StringValue();

			Int32 iKeepAlive = 0;
			if (pCfg->GetAttribute("KeepAlive"))
				iKeepAlive = pCfg->GetAttribute("KeepAlive")->IntValue();

			if (HawkGateway::Init(sFrontend, sBackend, iThread))
			{
				P_ProtocolManager->SetSizeLimit(PAGE_SIZE);

				if (iKeepAlive > 0)
					SetSessionTimeout(iKeepAlive);

				if (bCrossDomain)
					TurnOnCrossDomain();

				if (sProfiler.size())
					TurnOnProfiler(sProfiler);

				return true;
			}
		}
		return false;
	}
예제 #2
0
	Bool HsLogger::Init(const AString& sCfg)
	{
		if (!m_bRunning)
		{
			HawkXmlFile xmlCfg;
			HawkXmlDocument<AString> xmlDoc;
			if (!xmlCfg.Open(sCfg, xmlDoc))
			{
				HawkPrint("LogServer Open Config Error.");
				return false;
			}

			AXmlElement* pRoot  = xmlDoc.GetRoot();
			AXmlElement* pCfg   = pRoot->GetChildren("LgCfg");
			AXmlElement* pDbCfg = pRoot->GetChildren("DbCfg");

			if(!pCfg || !pDbCfg || !pCfg->GetAttribute("Addr"))
			{
				HawkPrint("LogServer Config Tag Error.");
				return false;
			}

			AString sAddr = pCfg->GetAttribute("Addr")->StringValue();

			if (pRoot->GetAttribute("Console"))
				EnableConsole(pRoot->GetAttribute("Console")->BoolValue());

			HawkDatabase::DBConn sConn(HawkDatabase::HDB_MYSQL);

			if (pDbCfg->GetAttribute("Host"))
				sConn.SetHost(pDbCfg->GetAttribute("Host")->StringValue());

			if (pDbCfg->GetAttribute("Port"))
				sConn.SetPort(pDbCfg->GetAttribute("Port")->IntValue());

			if (pDbCfg->GetAttribute("User"))
				sConn.SetUser(pDbCfg->GetAttribute("User")->StringValue());

			if (pDbCfg->GetAttribute("Pwd"))
				sConn.SetPwd(pDbCfg->GetAttribute("Pwd")->StringValue());

			sConn.SetDBName(pDbCfg->GetAttribute("DB")->StringValue());
			
			return HawkLogServer::Init(sAddr, sConn);
		}
		return false;
	}