| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- #include "stdafx.h"
- #include "SpBase.h"
- #include "HelloService_server_g.h"
- #include "HelloService_msg_g.h"
- using namespace HelloService;
- class HelloService_Session : public HelloService_ServerSessionBase
- {
- public:
- virtual void Handle_Ping(SpOnewayCallContext<HelloService_Ping_Info>::Pointer ctx)
- {
- LOG_FUNCTION();
- LOG_TRACE("handle ping msg !");
- }
- virtual void Handle_Hello(SpReqAnsContext<HelloService_Hello_Req, HelloService_Hello_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- LOG_TRACE("handle hello msg %s!", (LPCTSTR)ctx->Req.txt);
- ctx->Ans.txt = "Hello, this message comes from Hello Service entity!";
- ctx->Answer();
- }
- };
- class HelloServiceEntity : public CEntityBase, public ITimerListener
- {
- public:
- HelloServiceEntity() {}
- virtual ~HelloServiceEntity() {}
- virtual const char *GetEntityName() const { return "HelloService"; }
- virtual void OnTimeout(DWORD dwTimerID)
- {
- Dbg("on timer id %d ", dwTimerID);
- #if 0
- CSmartPointer<IEntityFunction> pFunc = GetFunction();
- CSimpleStringA strValue;
- pFunc->GetSysVar("HelloState", strValue);
- LOG_TRACE("sys var = %s", (LPCSTR)strValue);
- CSimpleStringA strValue1 = CSimpleStringA::Format("%d", atoi((LPCSTR)strValue)+1);
- pFunc->SetSysVar("HelloState", strValue1);
- #endif
- #if 0
- TestEvent evt;
- evt.m1 = "from hello service, m1";
- evt.m2 = 1234;
- SpSendBroadcast(pFunc, SP_MSG_OF(TestEvent), SP_MSG_SIG_OF(TestEvent), evt);
- #endif
- LogEvent(Severity_Middle, 0x20300001, "hello service test");
- }
- void OnPreStart(CAutoArray<CSimpleStringA> strArgs, CSmartPointer<ITransactionContext> pTransactionContext)
- {
- LOG_FUNCTION();
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- virtual void OnStarted()
- {
- LOG_FUNCTION();
- //CSmartPointer<IEntityFunction> pFunc = GetFunction();
- //pFunc->SetTimer(1, this, 2000);
- }
- virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- LOG_FUNCTION();
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- virtual CServerSessionBase *OnNewSession(const char* pszRemoteEntityName, const char * pszClass)
- {
- LOG_FUNCTION();
- return new HelloService_Session();
- }
- virtual bool IsService()const{return true;}
- };
- SP_BEGIN_ENTITY_MAP()
- SP_ENTITY(HelloServiceEntity)
- SP_END_ENTITY_MAP()
|