diff options
author | Matthew Newhook <matthew@zeroc.com> | 2005-04-14 01:29:28 +0000 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2005-04-14 01:29:28 +0000 |
commit | 7316f0f15f5d3019d5af909438adec113cd7cf87 (patch) | |
tree | 6406baa1a19d795e70aba4d9f936d7b3e43e085b /cpp/demo/Ice/session/SessionI.cpp | |
parent | fixes (diff) | |
download | ice-7316f0f15f5d3019d5af909438adec113cd7cf87.tar.bz2 ice-7316f0f15f5d3019d5af909438adec113cd7cf87.tar.xz ice-7316f0f15f5d3019d5af909438adec113cd7cf87.zip |
demo refactor/redesign.
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(); +} |