00001 // -*- C++ -*- 00002 // 00003 // This is a side-class to Connection which is used solely for listening for 00004 // incoming connections. A Listener will call the get_incoming() method of 00005 // the BiDirConn it was constructed to manage, and will take the returned 00006 // Connections and invoke the ConnEventHandler on them. This ConnEventHandler 00007 // class will perform whatever sort of initialization/cross-connection that 00008 // is desired for the newly created [incoming] Connections. 00009 // 00010 // ***** BEGIN LICENSE BLOCK ***** 00011 // Version: MPL 1.1/GPL 2.0/LGPL 2.1 00012 // 00013 // The contents of this file are subject to the Mozilla Public License 00014 // Version 1.1 (the "License"); you may not use this file except in 00015 // compliance with the License. You may obtain a copy of the License at 00016 // http://www.mozilla.org/MPL/ 00017 // 00018 // Software distributed under the License is distributed on an "AS IS" 00019 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00020 // the License for the specific language governing rights and limitations 00021 // under the License. 00022 // 00023 // The Original Code is the consmgr network/serial-line monitoring package. 00024 // 00025 // The Initial Developer of the Original Code is Chris P. Ross. 00026 // Portions created by the Initial Developer are Copyright (C) 2000-2008 00027 // the Initial Developer. All Rights Reserved. 00028 // 00029 // Contributor(s): 00030 // 00031 // Alternatively, the contents of this file may be used under the terms of 00032 // either the GNU General Public License Version 2 or later (the "GPL"), or 00033 // the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 00034 // in which case the provisions of the GPL or the LGPL are applicable instead 00035 // of those above. If you wish to allow use of your version of this file only 00036 // under the terms of either the GPL or the LGPL, and not to allow others to 00037 // use your version of this file under the terms of the MPL, indicate your 00038 // decision by deleting the provisions above and replace them with the notice 00039 // and other provisions required by the GPL or the LGPL. If you do not delete 00040 // the provisions above, a recipient may use your version of this file under 00041 // the terms of any one of the MPL, the GPL or the LGPL. 00042 // 00043 // ***** END LICENSE BLOCK ***** 00044 00045 #ifndef __INCOMING_H 00046 #define __INCOMING_H 00047 00048 #include <vector> 00049 00050 #include "connection.h" 00051 #include "listener.h" 00052 #include "bidirconn.h" 00053 00065 class ConnEventHandler { 00066 public: 00067 // Construct an empty ConnEventHandler 00068 ConnEventHandler(); 00069 // A special-case constructor for the common-case of "connect incoming 00070 // connections to this one other thing." 00071 ConnEventHandler(const Connection *other_side); 00072 #define CONNECT_TO_ONE(p) (ConnEventHandler((p))) 00073 00074 void add_peer(const Connection *peer); 00075 00076 void operator ()(Connection*); 00077 00078 private: 00079 // A list of Connections that need to be connected to the BiDirConn 00080 // that's accepted/created/incoming. 00081 std::vector<Connection*> peers; 00082 typedef std::vector<Connection*>::iterator peer_iterator; 00083 00084 }; 00085 00091 class Incoming : protected Messageable 00092 { 00093 public: 00094 Incoming(ListenerP l, ConnEventHandler ceh); 00095 ~Incoming(); 00096 00097 std::string get_id(void) const; 00098 00099 private: 00101 void start_listening(); 00102 00104 static void *listener_thread(void *); 00105 00107 ListenerP base; 00109 ConnEventHandler handler; 00110 00112 pthread_t tid_listener; 00113 }; 00114 00115 #endif /* __INCOMING_H */