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

00001 #ifndef _sys_Poller_h
00002 #define _sys_Poller_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 "Time.h"
00026 #include "Socket.h"
00027 
00028 #include <stdint.h>
00029 
00030 #include <boost/shared_ptr.hpp>
00031 
00032 namespace qpid {
00033 namespace sys {
00034 
00038 class Poller;
00039 class PollerHandlePrivate;
00040 class PollerHandle {
00041     friend class Poller;
00042 
00043     PollerHandlePrivate* const impl;
00044     const Socket& socket;
00045 
00046 public:
00047     PollerHandle(const Socket& s);
00048     
00049     // Usual way to delete (will defer deletion until we
00050     // can't be returned from a Poller::wait any more)
00051     void deferDelete();
00052     
00053     // Class clients shouldn't ever use this
00054     virtual ~PollerHandle();
00055     
00056     const Socket& getSocket() const {return socket;}
00057 };
00058 
00063 class PollerPrivate;
00064 class Poller {
00065     PollerPrivate* const impl;
00066 
00067 public:
00068     typedef boost::shared_ptr<Poller> shared_ptr;
00069 
00070     enum Direction {
00071         NONE = 0,
00072         IN,
00073         OUT,
00074         INOUT
00075     };
00076 
00077     enum EventType {
00078         INVALID = 0,
00079         READABLE,
00080         WRITABLE,
00081         READ_WRITABLE,
00082         DISCONNECTED,
00083         SHUTDOWN,
00084         TIMEOUT
00085     };
00086 
00087     struct Event {
00088         PollerHandle* handle;
00089         EventType type;
00090         
00091         Event(PollerHandle* handle0, EventType type0) :
00092           handle(handle0),
00093           type(type0) {
00094         }
00095     };
00096     
00097     Poller();
00098     ~Poller();
00100     void shutdown();
00101 
00102     void addFd(PollerHandle& handle, Direction dir);
00103     void delFd(PollerHandle& handle);
00104     void modFd(PollerHandle& handle, Direction dir);
00105     void rearmFd(PollerHandle& handle);
00106     Event wait(Duration timeout = TIME_INFINITE);
00107 };
00108 
00109 }}
00110 #endif // _sys_Poller_h

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