diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2006-11-16 17:31:10 +0000 |
---|---|---|
committer | Dwayne Boone <dwayne@zeroc.com> | 2006-11-16 17:31:10 +0000 |
commit | 51b5c23482df36ac145c82d58e9ccdef9728f935 (patch) | |
tree | 15a62e43b132ebdd721ec13a0d6b664133d00e3a /cpp/demo/Ice/async/QueueI.cpp | |
parent | Remove debug code (diff) | |
download | ice-51b5c23482df36ac145c82d58e9ccdef9728f935.tar.bz2 ice-51b5c23482df36ac145c82d58e9ccdef9728f935.tar.xz ice-51b5c23482df36ac145c82d58e9ccdef9728f935.zip |
Added async demo
Diffstat (limited to 'cpp/demo/Ice/async/QueueI.cpp')
-rw-r--r-- | cpp/demo/Ice/async/QueueI.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/cpp/demo/Ice/async/QueueI.cpp b/cpp/demo/Ice/async/QueueI.cpp new file mode 100644 index 00000000000..a2255c3d83f --- /dev/null +++ b/cpp/demo/Ice/async/QueueI.cpp @@ -0,0 +1,69 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2006 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 <QueueI.h> + +using namespace std; + +void +QueueI::get_async(const Demo::AMD_Queue_getPtr& getCB, const Ice::Current&) +{ + IceUtil::Mutex::Lock lock(*this); + + // + // If there is already a message in the message queue, send the + // response immediately. Otherwise add the callback to the + // request queue. + // + if(_messageQueue.size() != 0) + { + try + { + getCB->ice_response(_messageQueue.front()); + _messageQueue.pop_front(); + } + catch(const Ice::Exception& ex) + { + cout << ex << endl; + } + } + else + { + _requestQueue.push_back(getCB); + } +} + +void +QueueI::add(const ::std::string& message, const Ice::Current&) +{ + IceUtil::Mutex::Lock lock(*this); + + // + // If there is an outstanding request in the request queue, + // send a response. Otherwise add the message to the message + // queue. + // + if(_requestQueue.size() != 0) + { + try + { + _requestQueue.front()->ice_response(message); + } + catch(const Ice::Exception& ex) + { + _messageQueue.push_back(message); + cout << ex << endl; + } + _requestQueue.pop_front(); + } + else + { + _messageQueue.push_back(message); + } +} |