00001 /***************************** 00002 File: RemoteServer.h 00003 Language: C++ (header) 00004 Project: H3DNetworkingUtils 00005 The contents of this file are subject to the Mozilla Public License 00006 Version 1.1 (the "License"); you may not use this file except in 00007 compliance with the License. You may obtain a copy of the License at 00008 http://www.mozilla.org/MPL/ 00009 00010 Software distributed under the License is distributed on an "AS IS" 00011 basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the 00012 License for the specific language governing rights and limitations 00013 under the License. 00014 00015 The Original Code is H3DNetworkingUtils v1.0. 00016 00017 The Initial Developer of the Original Code is CSIRO. 00018 Portions created by the Initial Developer are Copyright (C) 1009 CSIRO. All Rights Reserved. 00019 Contributor(s): 00020 Chris Gunn <Chris.Gunn@csiro.au> <ChrisJGunn@gmail.com> 00021 ***************************/ 00022 00025 00026 #ifndef RemoteServer_H 00027 #define RemoteServer_H 00028 00029 // 00030 // <field "INPUT_OUTPUT" "listeningPort" "SFInt32" "9876"> 00031 // <field "INPUT_OUTPUT" "open" "SFBool" "FALSE"> 00032 00033 #include "H3DNetworkingUtils/RemoteConnection.h" 00034 00035 // This next line is needed because H3DAPI.dll instantiates this template but this class does not see the header with 00036 // the instantiation in it. So without the line, this class would instantiate an identical one and there would 00037 // be a multiply defined symbol in the link stage. 00038 template struct __declspec(dllimport) H3D::AutoUpdate <H3D::SFBool>; 00039 00040 namespace H3DNetworkingUtils { 00041 00054 00055 class H3D_NETWORKING_UTILS_DLL_SPEC RemoteServer : public RemoteConnection { 00056 public: 00057 00058 class OpenHandler; 00059 00061 RemoteServer( H3D::Inst<H3D::SFInt32> _listeningPort = 0, 00062 H3D::Inst<OpenHandler> _open = 0); 00063 00065 virtual ~RemoteServer(); 00066 00068 static H3D::H3DNodeDatabase database; 00069 00071 class H3D_NETWORKING_UTILS_DLL_SPEC OpenHandler : public H3D::AutoUpdate < H3D::SFBool > { 00072 public: 00073 OpenHandler() {value = false;} 00074 virtual void setValue(bool const & val, int id = 0); 00075 virtual void update(); 00076 }; 00077 00078 // Public fields 00079 00084 auto_ptr<H3D::SFInt32> listeningPort; 00085 00090 auto_ptr<OpenHandler> open; 00091 00092 virtual void initialize(); 00093 00094 00095 protected: 00096 00097 virtual void startServer(int port_number) = 0; 00098 // Supplied by sub-classes. 00099 00100 virtual bool doClosedActions(); 00101 // Do any actions that are required while the connection is closed. 00102 // The return value tells the receive loop whether top break out of the 00103 // loop. 00104 // This class returns true, to tell the receive loop to break out when 00105 // the connection is closed, so that the thread can be used for listening for 00106 // a new connection. 00107 00108 00109 private: 00110 00111 }; 00112 00113 } 00114 00115 #endif