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

00001 #ifndef _sys_Dispatcher_h
00002 #define _sys_Dispatcher_h
00003 
00004 /*
00005  *
00006  * Licensed to the Apache Software Foundation (ASF) under one
00007  * or more contributor license agreements.  See the NOTICE file
00008  * distributed with this work for additional information
00009  * regarding copyright ownership.  The ASF licenses this file
00010  * to you under the Apache License, Version 2.0 (the
00011  * "License"); you may not use this file except in compliance
00012  * with the License.  You may obtain a copy of the License at
00013  * 
00014  *   http://www.apache.org/licenses/LICENSE-2.0
00015  * 
00016  * Unless required by applicable law or agreed to in writing,
00017  * software distributed under the License is distributed on an
00018  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00019  * KIND, either express or implied.  See the License for the
00020  * specific language governing permissions and limitations
00021  * under the License.
00022  *
00023  */
00024 
00025 #include "Poller.h"
00026 #include "Runnable.h"
00027 #include "Mutex.h"
00028 
00029 #include <memory>
00030 #include <queue>
00031 #include <boost/function.hpp>
00032 
00033 #include <assert.h>
00034 
00035 
00036 namespace qpid {
00037 namespace sys {
00038 
00039 class Dispatcher;
00040 class DispatchHandle : public PollerHandle {
00041     friend class Dispatcher;
00042 public:
00043     typedef boost::function1<void, DispatchHandle&> Callback;
00044 
00045 private:
00046     Callback readableCallback;
00047     Callback writableCallback;
00048     Callback disconnectedCallback;
00049     Poller::shared_ptr poller;
00050     Mutex stateLock;
00051     enum {
00052         IDLE, INACTIVE, ACTIVE_R, ACTIVE_W, ACTIVE_RW,
00053         DELAYED_IDLE, DELAYED_INACTIVE, DELAYED_R, DELAYED_W, DELAYED_RW,
00054         DELAYED_DELETE
00055     } state;
00056 
00057 public:
00058     DispatchHandle(const Socket& s, Callback rCb, Callback wCb, Callback dCb) :
00059       PollerHandle(s),
00060       readableCallback(rCb),
00061       writableCallback(wCb),
00062       disconnectedCallback(dCb),
00063       state(IDLE)
00064     {}
00065 
00066     ~DispatchHandle();
00067 
00068     void startWatch(Poller::shared_ptr poller);
00069     void rewatch();
00070     void rewatchRead();
00071     void rewatchWrite();
00072     void unwatch();
00073     void unwatchRead();
00074     void unwatchWrite();
00075     void stopWatch();
00076     
00077 protected:
00078     void doDelete();
00079 
00080 private:
00081     void dispatchCallbacks(Poller::EventType dir);
00082 };
00083 
00084 class Dispatcher : public Runnable {
00085     const Poller::shared_ptr poller;
00086 
00087 public:
00088     Dispatcher(Poller::shared_ptr poller);
00089     ~Dispatcher();
00090     
00091     void run();
00092 };
00093 
00094 }}
00095 
00096 #endif // _sys_Dispatcher_h

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