12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- #include "stdafx.h"
- #include "SpBase.h"
- #include "HelloService_client_g.h"
- using namespace HelloService;
- class HelloClientEntity : public CEntityBase, public ITimerListener, public ISysVarListener
- {
- public:
- HelloClientEntity() : m_pClient(NULL) {}
- virtual ~HelloClientEntity() {}
- virtual const char *GetEntityName() const { return "HelloClient"; }
- virtual void OnTimeout(DWORD dwTimerID)
- {
- LOG_FUNCTION();
- m_pClient->Ping();
- }
- virtual void OnSysVarEvent(const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName)
- {
- LOG_TRACE("entity:%s key:%s value:%s", pszEntityName, pszKey, pszValue);
- }
- virtual void OnStarted()
- {
- LOG_FUNCTION();
- //MessageBox(0, 0, 0, 0);
- CSmartPointer<IEntityFunction> pFunc = GetFunction();
- //pFunc->SetTimer(1, this, 1000);
- //pFunc->RegistSysVarEvent("HelloState", this);
- #if 1
- HelloService_ClientBase *client = new HelloService_ClientBase(this);
- Dbg("before connect");
- ErrorCodeEnum Error = client->Connect();
- Dbg("after connect");
- if (Error == Error_Succeed) {
- LOG_TRACE("connect ok!");
- // invoke Ping method
- Dbg("before ping");
- Error = client->Ping();
- LOG_ASSERT(Error == Error_Succeed);
- Dbg("after ping");
- // invoke Hello method
- HelloService_Hello_Req Hello_Req; // request msg
- HelloService_Hello_Ans Hello_Ans; // answer msg,
- Hello_Req.txt = "Hello, this message comes from HelloClient entity!";
- Dbg("before hello");
- Error = client->Hello(Hello_Req, Hello_Ans, -1);
- Dbg("after hello");
- //LOG_ASSERT(Error == Error_Succeed);
- //LOG_TRACE((LPCSTR)Hello_Ans.txt);
- client->GetFunction()->CloseSession();
- }
- client->SafeDelete();
- #endif
- m_pClient = new HelloService_ClientBase(this);
- m_pClient->Connect();
- }
- virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- LOG_FUNCTION();
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- private:
- HelloService_ClientBase *m_pClient;
- };
- SP_BEGIN_ENTITY_MAP()
- SP_ENTITY(HelloClientEntity)
- SP_END_ENTITY_MAP()
|