diff options
Diffstat (limited to 'cpp/demo/Ice/session/SessionI.cpp')
-rwxr-xr-x | cpp/demo/Ice/session/SessionI.cpp | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/cpp/demo/Ice/session/SessionI.cpp b/cpp/demo/Ice/session/SessionI.cpp new file mode 100755 index 00000000000..4ad2c42dc1c --- /dev/null +++ b/cpp/demo/Ice/session/SessionI.cpp @@ -0,0 +1,95 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#include <Ice/Ice.h> +#include <SessionFactoryI.h> + +using namespace std; +using namespace Demo; + +class HelloI : public Hello +{ +public: + + HelloI(int id) : + _id(id) + { + } + + ~HelloI() + { + cout << _id << ": ~Hello" << endl; + } + + void + sayHello(const Ice::Current&) const + { + cout << _id << ": Hello World!" << endl; + } + +private: + + const int _id; +}; + +SessionI::SessionI(const Ice::ObjectAdapterPtr& adapter, const IceUtil::Time& timeout) : + _adapter(adapter), + _timeout(timeout), + _nextId(0), + _destroy(false), + _refreshTime(IceUtil::Time::now()) +{ +} + +SessionI::~SessionI() +{ + cout << "~SessionI" << endl; +} + +HelloPrx +SessionI::createHello(const Ice::Current&) +{ + HelloPrx hello = HelloPrx::uncheckedCast(_adapter->addWithUUID(new HelloI(_nextId++))); + _objs.push_back(hello); + return hello; +} + +void +SessionI::destroy(const Ice::Current& c) +{ + Lock sync(*this); + _destroy = true; +} + +void +SessionI::refresh(const Ice::Current& c) +{ + Lock sync(*this); + _refreshTime = IceUtil::Time::now(); +} + +bool +SessionI::destroyed() const +{ + Lock sync(*this); + return _destroy || (IceUtil::Time::now() - _refreshTime) > _timeout; +} + +void +SessionI::destroyCallback() +{ + Lock sync(*this); + cout << "destroying session: _destroy=" << _destroy << " timeout=" + << ((IceUtil::Time::now()-_refreshTime) > _timeout) << endl; + for(list<HelloPrx>::const_iterator p = _objs.begin(); p != _objs.end(); ++p) + { + _adapter->remove((*p)->ice_getIdentity()); + } + _objs.clear(); +} |