summaryrefslogtreecommitdiff
path: root/cpp/demo/Ice/session
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/demo/Ice/session')
-rwxr-xr-xcpp/demo/Ice/session/Client.cpp248
-rwxr-xr-xcpp/demo/Ice/session/ReapThread.cpp62
-rwxr-xr-xcpp/demo/Ice/session/ReapThread.h8
-rwxr-xr-xcpp/demo/Ice/session/SessionI.cpp34
4 files changed, 176 insertions, 176 deletions
diff --git a/cpp/demo/Ice/session/Client.cpp b/cpp/demo/Ice/session/Client.cpp
index 28a0393a1bd..89b05b09c1d 100755
--- a/cpp/demo/Ice/session/Client.cpp
+++ b/cpp/demo/Ice/session/Client.cpp
@@ -19,42 +19,42 @@ class SessionRefreshThread : public IceUtil::Thread, public IceUtil::Monitor<Ice
public:
SessionRefreshThread(const Ice::LoggerPtr& logger, const IceUtil::Time& timeout, const SessionPrx& session) :
- _logger(logger),
- _session(session),
- _timeout(timeout),
- _terminated(false)
+ _logger(logger),
+ _session(session),
+ _timeout(timeout),
+ _terminated(false)
{
}
virtual void
run()
{
- Lock sync(*this);
- while(!_terminated)
- {
- timedWait(_timeout);
- if(!_terminated)
- {
- try
- {
- _session->refresh();
- }
- catch(const Ice::Exception& ex)
- {
- Ice::Warning warn(_logger);
- warn << "SessionRefreshThread: " << ex;
- _terminated = true;
- }
- }
- }
+ Lock sync(*this);
+ while(!_terminated)
+ {
+ timedWait(_timeout);
+ if(!_terminated)
+ {
+ try
+ {
+ _session->refresh();
+ }
+ catch(const Ice::Exception& ex)
+ {
+ Ice::Warning warn(_logger);
+ warn << "SessionRefreshThread: " << ex;
+ _terminated = true;
+ }
+ }
+ }
}
void
terminate()
{
- Lock sync(*this);
- _terminated = true;
- notify();
+ Lock sync(*this);
+ _terminated = true;
+ notify();
}
private:
@@ -109,24 +109,24 @@ SessionClient::run(int argc, char* argv[])
cin >> name;
if(!cin.good())
{
- return EXIT_FAILURE;
+ return EXIT_FAILURE;
}
Ice::ObjectPrx base = communicator()->propertyToProxy("SessionFactory.Proxy");
SessionFactoryPrx factory = SessionFactoryPrx::checkedCast(base);
if(!factory)
{
- cerr << argv[0] << ": invalid proxy" << endl;
- return EXIT_FAILURE;
+ cerr << argv[0] << ": invalid proxy" << endl;
+ return EXIT_FAILURE;
}
{
- IceUtil::Mutex::Lock sync(_mutex);
- _session = factory->create(name);
-
- _refresh = new SessionRefreshThread(
- communicator()->getLogger(), IceUtil::Time::seconds(5), _session);
- _refresh->start();
+ IceUtil::Mutex::Lock sync(_mutex);
+ _session = factory->create(name);
+
+ _refresh = new SessionRefreshThread(
+ communicator()->getLogger(), IceUtil::Time::seconds(5), _session);
+ _refresh->start();
}
vector<HelloPrx> hellos;
@@ -135,85 +135,85 @@ SessionClient::run(int argc, char* argv[])
try
{
- bool destroy = true;
- bool shutdown = false;
- while(true)
- {
- cout << "==> ";
- char c;
- cin >> c;
- if(!cin.good())
- {
- break;
- }
- if(isdigit(c))
- {
- string s;
- s += c;
- vector<HelloPrx>::size_type index = atoi(s.c_str());
- if(index < hellos.size())
- {
- hellos[index]->sayHello();
- }
- else
- {
- cout << "Index is too high. " << hellos.size() << " hello objects exist so far.\n"
- << "Use `c' to create a new hello object." << endl;
- }
- }
- else if(c == 'c')
- {
- hellos.push_back(_session->createHello());
- cout << "Created hello object " << hellos.size() - 1 << endl;
- }
- else if(c == 's')
- {
- destroy = false;
- shutdown = true;
- break;
- }
- else if(c == 'x')
- {
- break;
- }
- else if(c == 't')
- {
- destroy = false;
- break;
- }
- else if(c == '?')
- {
- menu();
- }
- else
- {
- cout << "Unknown command `" << c << "'." << endl;
- menu();
- }
- }
+ bool destroy = true;
+ bool shutdown = false;
+ while(true)
+ {
+ cout << "==> ";
+ char c;
+ cin >> c;
+ if(!cin.good())
+ {
+ break;
+ }
+ if(isdigit(c))
+ {
+ string s;
+ s += c;
+ vector<HelloPrx>::size_type index = atoi(s.c_str());
+ if(index < hellos.size())
+ {
+ hellos[index]->sayHello();
+ }
+ else
+ {
+ cout << "Index is too high. " << hellos.size() << " hello objects exist so far.\n"
+ << "Use `c' to create a new hello object." << endl;
+ }
+ }
+ else if(c == 'c')
+ {
+ hellos.push_back(_session->createHello());
+ cout << "Created hello object " << hellos.size() - 1 << endl;
+ }
+ else if(c == 's')
+ {
+ destroy = false;
+ shutdown = true;
+ break;
+ }
+ else if(c == 'x')
+ {
+ break;
+ }
+ else if(c == 't')
+ {
+ destroy = false;
+ break;
+ }
+ else if(c == '?')
+ {
+ menu();
+ }
+ else
+ {
+ cout << "Unknown command `" << c << "'." << endl;
+ menu();
+ }
+ }
- //
- // The refresher thread must be terminated before destroy is
- // called, otherwise it might get ObjectNotExistException. refresh
- // is set to 0 so that if session->destroy() raises an exception
- // the thread will not be re-terminated and re-joined.
- //
- cleanup(destroy);
- if(shutdown)
- {
- factory->shutdown();
- }
+ //
+ // The refresher thread must be terminated before destroy is
+ // called, otherwise it might get ObjectNotExistException. refresh
+ // is set to 0 so that if session->destroy() raises an exception
+ // the thread will not be re-terminated and re-joined.
+ //
+ cleanup(destroy);
+ if(shutdown)
+ {
+ factory->shutdown();
+ }
}
catch(...)
{
- try
- {
- cleanup(true);
- }
- catch(...)
- {
- }
- throw;
+ try
+ {
+ cleanup(true);
+ }
+ catch(...)
+ {
+ }
+ throw;
}
return EXIT_SUCCESS;
@@ -232,15 +232,15 @@ SessionClient::interruptCallback(int)
try
{
- communicator()->destroy();
+ communicator()->destroy();
}
catch(const IceUtil::Exception& ex)
{
- cerr << appName() << ": " << ex << endl;
+ cerr << appName() << ": " << ex << endl;
}
catch(...)
{
- cerr << appName() << ": unknown exception" << endl;
+ cerr << appName() << ": unknown exception" << endl;
}
exit(EXIT_SUCCESS);
}
@@ -251,15 +251,15 @@ SessionClient::cleanup(bool destroy)
IceUtil::Mutex::Lock sync(_mutex);
if(_refresh)
{
- _refresh->terminate();
- _refresh->getThreadControl().join();
- _refresh = 0;
+ _refresh->terminate();
+ _refresh->getThreadControl().join();
+ _refresh = 0;
}
if(destroy && _session)
{
- _session->destroy();
- _session = 0;
+ _session->destroy();
+ _session = 0;
}
}
@@ -267,11 +267,11 @@ void
SessionClient::menu()
{
cout <<
- "usage:\n"
- "c: create a new per-client hello object\n"
- "0-9: send a greeting to a hello object\n"
- "s: shutdown the server and exit\n"
- "x: exit\n"
- "t: exit without destroying the session\n"
- "?: help\n";
+ "usage:\n"
+ "c: create a new per-client hello object\n"
+ "0-9: send a greeting to a hello object\n"
+ "s: shutdown the server and exit\n"
+ "x: exit\n"
+ "t: exit without destroying the session\n"
+ "?: help\n";
}
diff --git a/cpp/demo/Ice/session/ReapThread.cpp b/cpp/demo/Ice/session/ReapThread.cpp
index 26d25ff506a..7257bd0994c 100755
--- a/cpp/demo/Ice/session/ReapThread.cpp
+++ b/cpp/demo/Ice/session/ReapThread.cpp
@@ -25,38 +25,38 @@ ReapThread::run()
while(!_terminated)
{
- timedWait(_timeout);
+ timedWait(_timeout);
- if(!_terminated)
- {
- list<SessionProxyPair>::iterator p = _sessions.begin();
- while(p != _sessions.end())
- {
- try
- {
- //
- // Session destruction may take time in a
- // real-world example. Therefore the current time
- // is computed for each iteration.
- //
- if((IceUtil::Time::now() - p->session->timestamp()) > _timeout)
- {
- string name = p->proxy->getName();
- p->proxy->destroy();
- cout << "The session " << name << " has timed out." << endl;
- p = _sessions.erase(p);
- }
- else
- {
- ++p;
- }
- }
- catch(const Ice::ObjectNotExistException&)
- {
- p = _sessions.erase(p);
- }
- }
- }
+ if(!_terminated)
+ {
+ list<SessionProxyPair>::iterator p = _sessions.begin();
+ while(p != _sessions.end())
+ {
+ try
+ {
+ //
+ // Session destruction may take time in a
+ // real-world example. Therefore the current time
+ // is computed for each iteration.
+ //
+ if((IceUtil::Time::now() - p->session->timestamp()) > _timeout)
+ {
+ string name = p->proxy->getName();
+ p->proxy->destroy();
+ cout << "The session " << name << " has timed out." << endl;
+ p = _sessions.erase(p);
+ }
+ else
+ {
+ ++p;
+ }
+ }
+ catch(const Ice::ObjectNotExistException&)
+ {
+ p = _sessions.erase(p);
+ }
+ }
+ }
}
}
diff --git a/cpp/demo/Ice/session/ReapThread.h b/cpp/demo/Ice/session/ReapThread.h
index b7fc1434cf0..f96cf25036a 100755
--- a/cpp/demo/Ice/session/ReapThread.h
+++ b/cpp/demo/Ice/session/ReapThread.h
@@ -30,10 +30,10 @@ private:
bool _terminated;
struct SessionProxyPair
{
- SessionProxyPair(const Demo::SessionPrx& p, const SessionIPtr& s) :
- proxy(p), session(s) { }
- const Demo::SessionPrx proxy;
- const SessionIPtr session;
+ SessionProxyPair(const Demo::SessionPrx& p, const SessionIPtr& s) :
+ proxy(p), session(s) { }
+ const Demo::SessionPrx proxy;
+ const SessionIPtr session;
};
std::list<SessionProxyPair> _sessions;
};
diff --git a/cpp/demo/Ice/session/SessionI.cpp b/cpp/demo/Ice/session/SessionI.cpp
index d458b4117e4..a0e70e24168 100755
--- a/cpp/demo/Ice/session/SessionI.cpp
+++ b/cpp/demo/Ice/session/SessionI.cpp
@@ -17,21 +17,21 @@ class HelloI : public Hello
public:
HelloI(const string& name, int id) :
- _name(name),
- _id(id)
+ _name(name),
+ _id(id)
{
}
virtual ~HelloI()
{
- cout << "Hello object #" << _id << " for session `" << _name << "' destroyed" << endl;
+ 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;
+ cout << "Hello object #" << _id << " for session `" << _name << "' says:\n"
+ << "Hello " << _name << "!" << endl;
}
private:
@@ -55,7 +55,7 @@ SessionI::createHello(const Ice::Current& c)
Lock sync(*this);
if(_destroy)
{
- throw Ice::ObjectNotExistException(__FILE__, __LINE__);
+ throw Ice::ObjectNotExistException(__FILE__, __LINE__);
}
HelloPrx hello = HelloPrx::uncheckedCast(c.adapter->addWithUUID(new HelloI(_name, _nextId++)));
@@ -69,7 +69,7 @@ SessionI::refresh(const Ice::Current& c)
Lock sync(*this);
if(_destroy)
{
- throw Ice::ObjectNotExistException(__FILE__, __LINE__);
+ throw Ice::ObjectNotExistException(__FILE__, __LINE__);
}
_timestamp = IceUtil::Time::now();
@@ -81,7 +81,7 @@ SessionI::getName(const Ice::Current&) const
Lock sync(*this);
if(_destroy)
{
- throw Ice::ObjectNotExistException(__FILE__, __LINE__);
+ throw Ice::ObjectNotExistException(__FILE__, __LINE__);
}
return _name;
@@ -93,7 +93,7 @@ SessionI::destroy(const Ice::Current& c)
Lock sync(*this);
if(_destroy)
{
- throw Ice::ObjectNotExistException(__FILE__, __LINE__);
+ throw Ice::ObjectNotExistException(__FILE__, __LINE__);
}
_destroy = true;
@@ -101,16 +101,16 @@ SessionI::destroy(const Ice::Current& c)
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());
- }
+ 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.
+ // This method is called on shutdown of the server, in which
+ // case this exception is expected.
}
_objs.clear();
@@ -122,7 +122,7 @@ SessionI::timestamp() const
Lock sync(*this);
if(_destroy)
{
- throw Ice::ObjectNotExistException(__FILE__, __LINE__);
+ throw Ice::ObjectNotExistException(__FILE__, __LINE__);
}
return _timestamp;
}