📄 sessioni.cpp
字号:
// **********************************************************************//// Copyright (c) 2003-2007 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 <SessionI.h>using namespace std;using namespace Demo;class HelloI : public Hello{public: HelloI(const string& name, int id) : _name(name), _id(id) { } virtual ~HelloI() { cout << "Hello object #" << _id << " for session `" << _name << "' destroyed" << endl; } void sayHello(const Ice::Current&) const { cout << "Hello object #" << _id << " for session `" << _name << "' says:\n" << "Hello " << _name << "!" << endl; }private: const string _name; const int _id;};SessionI::SessionI(const string& name) : _name(name), _timestamp(IceUtil::Time::now()), _nextId(0), _destroy(false){ cout << "The session " << _name << " is now created." << endl;}HelloPrxSessionI::createHello(const Ice::Current& c){ Lock sync(*this); if(_destroy) { throw Ice::ObjectNotExistException(__FILE__, __LINE__); } HelloPrx hello = HelloPrx::uncheckedCast(c.adapter->addWithUUID(new HelloI(_name, _nextId++))); _objs.push_back(hello); return hello;}voidSessionI::refresh(const Ice::Current& c){ Lock sync(*this); if(_destroy) { throw Ice::ObjectNotExistException(__FILE__, __LINE__); } _timestamp = IceUtil::Time::now();}stringSessionI::getName(const Ice::Current&) const{ Lock sync(*this); if(_destroy) { throw Ice::ObjectNotExistException(__FILE__, __LINE__); } return _name;}voidSessionI::destroy(const Ice::Current& c){ Lock sync(*this); if(_destroy) { throw Ice::ObjectNotExistException(__FILE__, __LINE__); } _destroy = true; cout << "The session " << _name << " is now destroyed." << endl; try { c.adapter->remove(c.id); for(list<HelloPrx>::const_iterator p = _objs.begin(); p != _objs.end(); ++p) { c.adapter->remove((*p)->ice_getIdentity()); } } catch(const Ice::ObjectAdapterDeactivatedException&) { // This method is called on shutdown of the server, in which // case this exception is expected. } _objs.clear();}IceUtil::TimeSessionI::timestamp() const{ Lock sync(*this); if(_destroy) { throw Ice::ObjectNotExistException(__FILE__, __LINE__); } return _timestamp;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -