- Main Page
- Classes
- Files

- Search for |

# RemoteClient.h

Go to the documentation of this file.

    00001 /*****************************
    00002 File:      RemoteClient.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 RemoteClient_H
    00027 #define RemoteClient_H
    00028
    00029
    00030 #include "H3DNetworkingUtils/RemoteConnection.h"
    00031 #include "H3DNetworkingUtils/RemoteField.h"
    00032 //#include "Macro.h"
    00033 #include "H3DNetworkingUtils/sockwrap.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 H3D {
    00041   H3D_VALUE_EXCEPTION( const char *, CantConnect );
    00042 }
    00043
    00044 namespace H3DNetworkingUtils {
    00045
    00055
    00056 class H3D_NETWORKING_UTILS_DLL_SPEC RemoteClient : public RemoteConnection {
    00057 public:
    00058
    00060    struct H3D_NETWORKING_UTILS_DLL_SPEC OpenHandler : public H3D::AutoUpdate<H3D::SFBool> {
    00061       virtual void setValue(bool const & val, int id = 0);
    00062       virtual void update();
    00063   };
    00064
    00066    RemoteClient( string socket_type = "TCP",
    00067                 H3D::Inst<H3D::SFString> remoteHost = 0,
    00068                 H3D::Inst<H3D::SFInt32> remotePort = 0,
    00069                 H3D::Inst<OpenHandler>  open = 0,
    00070                 H3D::Inst<H3D::SFBool>  autoReconnect = 0);
    00071
    00072   static H3D::H3DNodeDatabase database;
    00073
    00074   virtual void initialize();
    00075
    00080    auto_ptr<H3D::SFString> remoteHost;
    00081
    00086    auto_ptr<H3D::SFInt32>  remotePort;
    00087
    00093    auto_ptr<OpenHandler>   open;
    00094
    00102    auto_ptr<H3D::SFBool>   autoReconnect;
    00103
    00104 protected:
    00105
    00106   bool openedBefore() const {return opened_once;}
    00107   // Returns true if the client socket has been opened before.
    00108
    00109   virtual void startClient(string host, int port_number);
    00110   // Connects the client to the server.
    00111
    00112   void requestRestart() {restart_requested = true;}
    00113   // Signals the reading thread to reconnect its socket.
    00114
    00115   virtual void restartClient() = 0;
    00116   // Restarts the client reading and writing to a new socket.
    00117   // Provided by sub-classes.
    00118
    00119   virtual bool doClosedActions();
    00120   // Do any actions that are required while the connection is closed.
    00121   // This class returns false, to tell the receive loop not to break out when
    00122   // the connection is closed.
    00123
    00124   virtual void close();
    00125   // Close the client.
    00126
    00127   bool restart_requested;
    00128
    00129   char addr[80];
    00130
    00131 private:
    00132   bool opened_once;
    00133   string socket_type;
    00134   bool start_called;
    00135 };
    00136
    00137 }
    00138
    00139 #endif