00001 /* Open SoundControl kit in C++ */ 00002 /* Copyright (C) 2002-2004 libOSC++ contributors. See AUTHORS */ 00003 /* */ 00004 /* This library is free software; you can redistribute it and/or */ 00005 /* modify it under the terms of the GNU Lesser General Public */ 00006 /* License as published by the Free Software Foundation; either */ 00007 /* version 2.1 of the License, or (at your option) any later version. */ 00008 /* */ 00009 /* This library is distributed in the hope that it will be useful, */ 00010 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ 00011 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */ 00012 /* Lesser General Public License for more details. */ 00013 /* */ 00014 /* You should have received a copy of the GNU Lesser General Public */ 00015 /* License along with this library; if not, write to the Free Software */ 00016 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00017 /* */ 00018 /* For questions regarding this program contact */ 00019 /* Daniel Holth <dholth@fastmail.fm> or visit */ 00020 /* http://wiretap.stetson.edu/ */ 00021 00022 /* 00023 * This class was written by Martin Rumori (martin@rumori.de) 00024 */ 00025 00026 #ifndef LIBOSC_INETTCPMASTER_H 00027 #define LIBOSC_INETTCPMASTER_H 00028 00029 00030 #ifdef __CYGWIN__ 00031 #include <w32api/winsock2.h> 00032 #include <w32api/ws2tcpip.h> 00033 #define SOL_TCP 6 00034 #else 00035 #include <sys/types.h> 00036 #include <netinet/tcp.h> 00037 #endif 00038 00039 #include "InetMaster.h" 00040 #include "InetTransportManager.h" 00041 00042 #include <vector> 00043 #include <algorithm> 00044 #include <sstream> 00045 #include <iosfwd> 00046 00047 class InetTCPSlave; // compiler food 00048 00062 class InetTCPMaster : public InetMaster 00063 { 00064 public: 00071 InetTCPMaster (InetOSCAddrType addrType = OSC_IN_IPv4); 00072 00074 virtual ~InetTCPMaster (); 00075 00080 bool handle (); 00081 00101 bool transmit(const std::string& data); 00102 00107 const int getHandle () const; 00108 00116 bool process (const std::string& data, Transmit *reply); 00117 00134 InetTCPSlave *const newconnection (const std::string& host, 00135 const short port, 00136 const InetOSCAddrType addrType = OSC_IN_IPv4); 00137 00151 bool disconnectAll (); 00152 00163 bool startlisten (const short port); 00164 00172 bool stoplisten (); 00173 00180 bool registerSlave (InetTCPSlave *slave); 00181 00188 bool deregisterSlave (InetTCPSlave *slave); 00189 00200 bool setTransportManager (InetTransportManager *const transMan); 00201 00206 void setProcessor (Processor *processor); 00207 00212 bool isListening (); 00213 00218 const int getConnectedSlavesNum (void) const; 00219 00231 void setSlavesMaxHandleCycles (const int cycles = -1); 00232 00237 const int getSlavesMaxHandleCycles (void) const; 00238 00243 const std::string getStatusString (void); 00244 00249 virtual std::string getName (); 00250 00251 00252 protected: 00253 00261 bool setSocketTcpNodelay (int *const sd, bool nodelay = true); 00262 00263 00264 private: 00265 00267 std::vector<InetTCPSlave *> _slaves; 00268 00270 InetTransportManager *_transMan; 00271 00273 Processor *_processor; 00274 00276 bool _listening; 00277 00279 short _port; 00280 00282 int _slavesMaxHandleCycles; 00283 00284 }; 00285 00286 #endif // #ifndef LIBOSC_INETTCPMASTER_H