void ActiveBehavior::SubmitVisualRequest(double plus)
{
	BehaviorExecutable * behavior = BehaviorFactory::instance().CreateBehavior(GetAgent(), GetType());

	if (behavior){
		Logger::instance().GetTextLogger("executing") << GetAgent().GetWorldState().CurrentTime() << " " << BehaviorFactory::instance().GetBehaviorName(GetType()) << " visual plus: " << plus << std::endl;

		behavior->SubmitVisualRequest(*this, plus);

		delete behavior;
	}
}
Esempio n. 2
0
Agent * TfmccSrcInit (int nodeId, uint16 agentId, 
                      uint32 pktDstAddr, uint16 pktDstAgentId, int8 trackStat)
{
  Agent * a = GetAgent (nodeId, (uint32) agentId);
  TfmccSrcInfo * tsi;
  
  if (a != NULL) return a;
  
  a = RegisterAgent (nodeId, agentId, _nodeTable[nodeId].addr_, 
                     (PktHandler) TfmccSrcPktHandler, 
                     (StartFunc) TfmccSrcStart,
                     (StopFunc) TfmccSrcStop,
                     (TimerFunc) TfmccSrcTimer,
                     (AgentFunc) TfmccSrcPrintStat,
                     NULL);
  tsi = malloc (sizeof (TfmccSrcInfo));
  
  if (tsi == NULL) {
    printf ("Failed to allocate memory for ORMCC source info.\n");
    tw_exit (-1);
  }
  
  memset ((void *) tsi, 0, sizeof (TfmccSrcInfo));
  tsi->pktDstAddr_ = pktDstAddr;
  tsi->pktDstAgentId_ = pktDstAgentId;
  a->info_ = tsi;
  tsi->trackStat_ = trackStat;

  return a;
}
bool ActiveBehavior::Execute()
{
	BehaviorExecutable * behavior = BehaviorFactory::instance().CreateBehavior(GetAgent(), GetType());

	if (behavior){
		Logger::instance().GetTextLogger("executing") << GetAgent().GetWorldState().CurrentTime() << " " << BehaviorFactory::instance().GetBehaviorName(GetType()) << " executing" << std::endl;

		behavior->SubmitVisualRequest(*this);
		bool ret = behavior->Execute(*this);

		delete behavior;
		return ret;
	}
	else {
		return false;
	}
}
bool GEntityManager::GetAgentWatched(UID agentID)
{
	GAgent* theAgent;
	if (GetAgent(agentID, theAgent))
	{
		return theAgent->GetWatched();
	}
	return false;

}
bool GEntityManager::SetAgentWatched(UID agentID, bool isWatched)
{
	GAgent* theAgent;
	if (GetAgent(agentID, theAgent))
	{
		theAgent->SetWatched(isWatched);
		return true;
	}
	return false;
}
Esempio n. 6
0
bool AgentExecutor::UploadFile(const wxString& fileName) {
	if ( !IsConnected() ) {
		if ( !Login() ) {
			return false;
		}
	}

	while (true) {
		try {
			std::auto_ptr<EdiResponse> res(GetAgent().PostFile(fileName) );

            wxString fName(fileName);
			wxFileName fn(fName);

			if ( wxGetApp().GetCfg()->GetChild(ADVPCS_AGENT_CFG)->GetParamAsBool(ADVPCS_HTTP_AGENT_COMPRESED_CFG) ) {
				fName = fn.GetPath(wxPATH_GET_SEPARATOR) + fn.GetName() + ADVPCS_ZIP_EXT;
			} else {
				fName = fn.GetPath(wxPATH_GET_SEPARATOR) + fn.GetName() + ADVPCS_EDI_EXT;
			}

			if ( res->GetCode() == ADVPCS_POST_FILE_RECEIVED_OK - ADVPCS_BASE ) {
				LOG_INFO( GetLogger(), 0, wxString::Format(ADVPCS_UPLOAD_OK, fName));
				 return true;
			}

			::wxMessageBox(wxString::Format("[%ld] %s", res->GetCode(), res->GetMessage()), 
							   ADVPCS_ERROR_TITLE, 
							   wxOK | wxCENTRE | wxICON_ERROR);

			if ( res->GetCode() == ADVPCS_LOGIN_AUTH_ERR - ADVPCS_BASE 
				|| res->GetCode() == ADVPCS_POST_AUTH_ERR - ADVPCS_BASE ) {
				m_connected = false;
                if ( !Login() ) {
					return false;
				} else {
					continue;
				}
			}
			m_connected = false;
			return false;

		} catch ( CXmlLoadException& ) {
			wxMessageBox(ADVPCS_UNEXPECTED_REPLY_MSG, ADVPCS_ERROR_TITLE,
						  wxOK | wxCENTRE | wxICON_ERROR );
			m_connected = false;
			return false;
		} catch ( CAtfException& ex) {
			wxMessageBox((const char*)ex.GetText(), ADVPCS_ERROR_TITLE,
						  wxOK | wxCENTRE | wxICON_ERROR );
			m_connected = false;
			return false;
		};

	}
};
Esempio n. 7
0
void PassPktToUpperLayer (tw_lp * lp, Packet * p)
{
  Agent * a;
  
  if (IsMcastAddr (p->dstAddr_)) {
    a = GetAgent (lp->id, p->dstAddr_);
    if (a == NULL) {
      printf ("Node %d: no agent found for group %ld.\n", 
              lp->id, GetGrpAddr4Print (p->dstAddr_));
      tw_exit (-1);
    }
  }
  else {
    a = GetAgent (lp->id, (uint32) p->dstAgent_);
    if (a == NULL) {
      printf ("Node %d: no agent with id <%d> found.\n", 
              lp->id, p->dstAgent_);
      tw_exit (-1);
    }
  }  

  if (a->handler_) a->handler_ (a, p);
}
Esempio n. 8
0
bool AgentExecutor::RequestStatus() {
    if (!IsConnected() ) {
		if ( !Login() ) {
			return false;
        }
    }      
        
	while ( true ) {
		try {
			std::auto_ptr<EdiResponse> res(GetAgent().GetStatus());

			if ( res->GetCode() == ADVPCS_STATUS_OK - ADVPCS_BASE ) {
				FillStatus(res.get());
				return true;
			}

			if ( res->GetCode() == ADVPCS_STATUS_NOT_AVAILABLE_ERR - ADVPCS_BASE ) {
				return false;
			}

			::wxMessageBox(wxString::Format("[%ld] %s", res->GetCode(), res->GetMessage()), 
									   ADVPCS_ERROR_TITLE, 
									   wxOK | wxCENTRE | wxICON_ERROR);

			if ( res->GetCode() == ADVPCS_LOGIN_AUTH_ERR - ADVPCS_BASE ) {
//				|| res->GetCode() == ADVPCS_STATUS_AUTH_ERR - ADVPCS_BASE ) {
				m_connected = false;
                if ( !Login() ) {
					return false;
				} else {
					continue;
				}
			}
			m_connected = false;
			return false;

		} catch ( CXmlLoadException&  ) {
			wxMessageBox(ADVPCS_UNEXPECTED_REPLY_MSG, ADVPCS_ERROR_TITLE,
						  wxOK | wxCENTRE | wxICON_ERROR );
			m_connected = false;
			return false;
		} catch ( CAtfException& ex) {
			wxMessageBox((const char*)ex.GetText(), ADVPCS_ERROR_TITLE,
						  wxOK | wxCENTRE | wxICON_ERROR );
			m_connected = false;
			return false;
		};
	};
};
    int HttpConnectProxyHttpSocket::ConnectImpl(const char *address)
    {
        ProxyHttpSocket::ConnectImpl(GetProxy());
        Util::AddressParser parser(address);
        Util::AddressParser proxyParser(GetProxy());

        std::ostringstream request;
        request << "CONNECT " << parser.GetHost() << ":" << parser.GetPort() << " HTTP/1.0\r\n";
        request << "Host: " << proxyParser.GetHost() << ":" << proxyParser.GetPort() << "\r\n";
        request << "User-Agent: " << GetAgent() << "\r\n";

        const char *user = proxyParser.GetUser();
        const char *password = proxyParser.GetPassword();

        if (*user || *password) {
		    // Encode user:password
            std::string auth = user;
            auth += ':';
            auth += password;
            auth = Util::BinToBase64(auth.c_str(), auth.length());

            request << "Proxy-Authorization: Basic " << auth << "\r\n";
	    }
    	
        request << "\r\n";

        Send(request.str().c_str());

        std::string response = Receive();

	    if (response.length() < 12) 
            throw ProxyError("Invalid response");
        
        if (response[9] != '2' || response[10] != '0' || response[11] != '0') {
		    // Proxy responded with error
            std::ostringstream msg;
            int err = (response[9] - '0') * 100 + (response[10] - '0') * 10 + (response[11] - '0');
            msg << "Responded with error " << err;
		    throw ProxyError(msg.str().c_str());
	    }

        return 0;
    }
Esempio n. 10
0
bool AgentExecutor::Login(){
	m_connected = false;

	LoginFrame* login = new LoginFrame(::wxTheApp->GetTopWindow(), m_logon);
    while (true) {
		if ( !(wxID_OK == login->ShowModal()) ) {
			 return false;
		}
		try {
			std::auto_ptr<EdiResponse> res(GetAgent().Login(m_logon.GetLogin(), m_logon.GetPassword()));
			if ( res->GetCode() == ADVPCS_LOGIN_OK - ADVPCS_BASE ) {
				FillStatus(res.get());
				m_connected = true;
				return true;
			}

			::wxMessageBox(wxString::Format("[%ld] %s", res->GetCode(), res->GetMessage()), 
						   ADVPCS_ERROR_TITLE, 
						   wxOK | wxCENTRE | wxICON_ERROR);

			if ( res->GetCode() == ADVPCS_LOGIN_PSWD_EXPIRED_ERR - ADVPCS_BASE ) {
				return ChangePassword();
			}
			if ( res->GetCode() != ADVPCS_LOGIN_AUTH_ERR - ADVPCS_BASE ) {
				m_connected = false;
				return false;
			}

		} catch ( CXmlLoadException& ) {
			::wxMessageBox(ADVPCS_UNEXPECTED_REPLY_MSG, ADVPCS_ERROR_TITLE,
						  wxOK | wxCENTRE | wxICON_ERROR );
			return false;
		} catch (CAtfException& ex) {
			::wxMessageBox((const char*)ex.GetText(), ADVPCS_ERROR_TITLE,
						 wxOK | wxCENTRE | wxICON_ERROR );
			return false;
		}
	};
    wxDELETE(login);
    return false;
};
Esempio n. 11
0
bool AgentExecutor::ChangePassword() {
    PassUpdateFrame* passwd = new PassUpdateFrame(wxTheApp->GetTopWindow(), m_logon);
    try {
		while(true) {
			if ( !(wxID_OK == passwd->ShowModal()) ) {
				return false;
			}
#if 0
			if ( !Login(m_logon.GetLogin(), m_logon.GetPassword()) ) {
				continue;
			}
#else
			if ( !IsConnected() ) {
				std::auto_ptr<EdiResponse> res(GetAgent().Login(m_logon.GetLogin(), m_logon.GetPassword()));
				if ( res->GetCode() == ADVPCS_LOGIN_OK - ADVPCS_BASE ) {
					m_connected = true;
				}
				if ( res->GetCode() == ADVPCS_LOGIN_AUTH_ERR - ADVPCS_BASE ) {
					::wxMessageBox(wxString::Format("[%ld] %s", res->GetCode(), res->GetMessage()), 
								   ADVPCS_ERROR_TITLE, 
								   wxOK | wxCENTRE | wxICON_ERROR);
					continue;
				}
				if ( !( res->GetCode() == ADVPCS_LOGIN_PSWD_EXPIRED_ERR - ADVPCS_BASE 
				    || res->GetCode() == ADVPCS_LOGIN_OK - ADVPCS_BASE ) ) 
				{
					::wxMessageBox(wxString::Format("[%ld] %s", res->GetCode(), res->GetMessage()), 
								   ADVPCS_ERROR_TITLE, 
								   wxOK | wxCENTRE | wxICON_ERROR);
					return false;
				}
			}
#endif
			std::auto_ptr<EdiResponse> res(GetAgent().ChangePassword(m_logon.GetLogin(), m_logon.GetPassword(), m_logon.GetNewPassword()));

    		if ( res->GetCode() == ADVPCS_PSWD_OK - ADVPCS_BASE ) {
				FillStatus(res.get());
				m_connected = true;
				::wxMessageBox(ADVPCS_CHANGE_PSWD_OK);
				return true;
			}
 		    ::wxMessageBox(wxString::Format("[%ld] %s", res->GetCode(), res->GetMessage()), 
						   ADVPCS_ERROR_TITLE, 
						   wxOK | wxCENTRE | wxICON_ERROR);
			if ( res->GetCode() == ADVPCS_PSWD_INVALID_ERR - ADVPCS_BASE 
				|| res->GetCode() == ADVPCS_PSWD_DUPLICATE_ERR - ADVPCS_BASE ) 
			{
				continue;
			}
			if ( res->GetCode() == ADVPCS_LOGIN_AUTH_ERR - ADVPCS_BASE  ) {
				m_connected = false;
				continue;
			}
			return false;
		}
	} catch ( CXmlLoadException&  ) {
		wxMessageBox(ADVPCS_UNEXPECTED_REPLY_MSG, ADVPCS_ERROR_TITLE,
					 wxOK | wxCENTRE | wxICON_ERROR );
			return false;
	} catch (CAtfException& ex) {
		wxMessageBox((const char*)ex.GetText(), ADVPCS_ERROR_TITLE,
					 wxOK | wxCENTRE | wxICON_ERROR );
			return false;
	}
	wxDELETE(passwd);
	return false;
};