00001 /*---------------------------------------------------------------------------*\ 00002 * OpenSG * 00003 * * 00004 * * 00005 * Copyright (C) 2000-2002 by the OpenSG Forum * 00006 * * 00007 * www.opensg.org * 00008 * * 00009 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de * 00010 * * 00011 \*---------------------------------------------------------------------------*/ 00012 /*---------------------------------------------------------------------------*\ 00013 * License * 00014 * * 00015 * This library is free software; you can redistribute it and/or modify it * 00016 * under the terms of the GNU Library General Public License as published * 00017 * by the Free Software Foundation, version 2. * 00018 * * 00019 * This library is distributed in the hope that it will be useful, but * 00020 * WITHOUT ANY WARRANTY; without even the implied warranty of * 00021 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00022 * Library General Public License for more details. * 00023 * * 00024 * You should have received a copy of the GNU Library General Public * 00025 * License along with this library; if not, write to the Free Software * 00026 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * 00027 * * 00028 \*---------------------------------------------------------------------------*/ 00029 /*---------------------------------------------------------------------------*\ 00030 * Changes * 00031 * * 00032 * * 00033 * * 00034 * * 00035 * * 00036 * * 00037 \*---------------------------------------------------------------------------*/ 00038 00039 00040 #ifndef _GROUPSOCKCONNECTION_H_ 00041 #define _GROUPSOCKCONNECTION_H_ 00042 #ifdef __sgi 00043 #pragma once 00044 #endif 00045 00046 //--------------------------------------------------------------------------- 00047 // Includes 00048 //--------------------------------------------------------------------------- 00049 00050 #include <string> 00051 #include <OSGBase.h> 00052 #include <OSGBaseTypes.h> 00053 #include <OSGGroupConnection.h> 00054 #include <OSGTime.h> 00055 #include <OSGStreamSocket.h> 00056 00057 OSG_BEGIN_NAMESPACE 00058 00059 class PointSockConnection; 00060 00061 class OSG_BASE_DLLMAPPING GroupSockConnection : public GroupConnection 00062 { 00063 /*========================== PUBLIC =================================*/ 00064 public: 00065 00066 /*---------------------------------------------------------------------*/ 00070 GroupSockConnection ( void ); 00071 virtual ~GroupSockConnection ( void ); 00072 00074 /*---------------------------------------------------------------------*/ 00078 virtual const ConnectionType *getType (void); 00079 00081 /*---------------------------------------------------------------------*/ 00085 virtual Channel connectPoint(const std::string &address, 00086 Time timeout=-1 ); 00087 virtual void disconnect ( Channel channel ); 00088 virtual Channel acceptPoint ( Time timeout=-1 ); 00089 virtual std::string bind (const std::string &interf ); 00090 00092 /*---------------------------------------------------------------------*/ 00096 virtual void setParams(const std::string ¶ms); 00097 00099 /*---------------------------------------------------------------------*/ 00103 virtual Channel selectChannel (Time timeout=-1) throw (ReadError); 00104 00106 /*---------------------------------------------------------------------*/ 00110 static GroupConnection *create(void); 00111 00114 /*========================= PROTECTED ===============================*/ 00115 protected: 00116 00117 /*---------------------------------------------------------------------*/ 00121 struct SocketBufferHeader { 00122 UInt32 size; 00123 }; 00124 00126 /*---------------------------------------------------------------------*/ 00130 virtual void read (MemoryHandle mem, UInt32 size); 00131 virtual void readBuffer (void); 00132 virtual void write (MemoryHandle mem, UInt32 size); 00133 virtual void writeBuffer (void); 00134 00136 /*---------------------------------------------------------------------*/ 00140 StreamSocket _acceptSocket; 00141 std::vector<StreamSocket> _sockets; 00142 ChannelIndex _readIndex; 00143 std::vector<UInt8> _socketReadBuffer; 00144 std::vector<UInt8> _socketWriteBuffer; 00145 00147 /*---------------------------------------------------------------------*/ 00151 virtual bool wait (Time timeout) throw (ReadError); 00152 virtual void signal(void ) throw (WriteError); 00153 00156 /*========================== PRIVATE ================================*/ 00157 private: 00158 00159 friend class PointSockConnection; 00160 00161 /*---------------------------------------------------------------------*/ 00165 static ConnectionType _type; 00166 00168 /*---------------------------------------------------------------------*/ 00172 static bool connectSocket(StreamSocket &socket, 00173 std::string address, 00174 Time timeout); 00175 static bool acceptSocket (StreamSocket &accept, 00176 StreamSocket &from, 00177 Time timeout); 00178 00181 typedef GroupConnection Inherited; 00182 00183 // prohibit default functions (move to 'public' if you need one) 00184 GroupSockConnection(const GroupSockConnection &source); 00185 GroupSockConnection& operator =(const GroupSockConnection &source); 00186 }; 00187 00188 //--------------------------------------------------------------------------- 00189 // Exported Types 00190 //--------------------------------------------------------------------------- 00191 00192 // class pointer 00193 00194 typedef GroupSockConnection *GroupSockConnectionP; 00195 00196 OSG_END_NAMESPACE 00197 00198 #define OSG_GROUPSOCKCONNECTION_HEADER_CVSID "@(#)$Id: $" 00199 00200 #endif /* _GROUPSOCKCONNECTION_H_ */
1.4.3