/usr/share/cruisecontrol-bin-2.6.1/projects/qpid-trunk/cpp/src/qpid/client/Dispatcher.h

00001 /*
00002  *
00003  * Licensed to the Apache Software Foundation (ASF) under one
00004  * or more contributor license agreements.  See the NOTICE file
00005  * distributed with this work for additional information
00006  * regarding copyright ownership.  The ASF licenses this file
00007  * to you under the Apache License, Version 2.0 (the
00008  * "License"); you may not use this file except in compliance
00009  * with the License.  You may obtain a copy of the License at
00010  * 
00011  *   http://www.apache.org/licenses/LICENSE-2.0
00012  * 
00013  * Unless required by applicable law or agreed to in writing,
00014  * software distributed under the License is distributed on an
00015  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00016  * KIND, either express or implied.  See the License for the
00017  * specific language governing permissions and limitations
00018  * under the License.
00019  *
00020  */
00021 #ifndef _Dispatcher_
00022 #define _Dispatcher_
00023 
00024 #include <map>
00025 #include <memory>
00026 #include <string>
00027 #include <boost/shared_ptr.hpp>
00028 #include "qpid/client/Session.h"
00029 #include "qpid/sys/Mutex.h"
00030 #include "qpid/sys/Runnable.h"
00031 #include "qpid/sys/Thread.h"
00032 #include "MessageListener.h"
00033 #include "AckPolicy.h"
00034 
00035 namespace qpid {
00036 namespace client {
00037 
00038 class Subscriber : public MessageListener
00039 {
00040     Session& session;
00041     MessageListener* const listener;
00042     AckPolicy autoAck;
00043 
00044 public:
00045     typedef boost::shared_ptr<Subscriber> shared_ptr;
00046     Subscriber(Session& session, MessageListener* listener, AckPolicy);
00047     void received(Message& msg);
00048     
00049 };
00050 
00051 typedef framing::Handler<framing::FrameSet> FrameSetHandler;
00052 
00053 class Dispatcher : public sys::Runnable
00054 {
00055     typedef std::map<std::string, Subscriber::shared_ptr> Listeners;
00056     sys::Mutex lock;
00057     sys::Thread worker;
00058     Session& session;
00059     Demux::QueuePtr queue;
00060     bool running;
00061     bool autoStop;
00062     Listeners listeners;
00063     Subscriber::shared_ptr defaultListener;
00064     std::auto_ptr<FrameSetHandler> handler;
00065 
00066     Subscriber::shared_ptr find(const std::string& name);
00067     bool isStopped();
00068 
00069 public:
00070     Dispatcher(Session& session, const std::string& queue = "");
00071 
00072     void start();
00073     void run();
00074     void stop();
00075     void setAutoStop(bool b);
00076 
00077     void listen(MessageListener* listener, AckPolicy autoAck=AckPolicy());
00078     void listen(const std::string& destination, MessageListener* listener, AckPolicy autoAck=AckPolicy());
00079     void cancel(const std::string& destination);
00080 };
00081 
00082 }}
00083 
00084 #endif

Generated on Thu Apr 10 11:08:18 2008 for Qpid by  doxygen 1.4.7