123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- #include "stdafx.h"
- #include "SpBase.h"
- #include "HelloService_client_g.h"
- #include <winpr/synch.h>
- #include "modVer.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"; }
- const char* GetEntityVersion() const { return MODULE_VERSION_FULL; }
- 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
- //Sleep(60 * 1000);
- HelloService_ClientBase *client = new HelloService_ClientBase(this);
- Dbg("before connect");
- ErrorCodeEnum Error = client->Connect();
- Dbg("after connect: %d", Error);
- 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();
- }
- else {
- Dbg("Connect failed!");
- client->SafeDelete();
- }
- m_pClient = new HelloService_ClientBase(this);
- m_pClient->Connect();
- #endif
- }
- 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()
|