- Main Page
- Classes
- Files

- Search for |

# RemoteSync.h

Go to the documentation of this file.

    00001 /*****************************
    00002 File:     RemoteSunc.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 RemoteSync_H
    00027 #define RemoteSync_H
    00028
    00029 #include "H3DNetworkingUtils/Config.h"
    00030 #include <H3D/Group.h>
    00031 #include <H3D/TimeSensor.h>
    00032 #include "H3DNetworkingUtils/TimePacket.h"
    00033 #include "H3DNetworkingUtils/RemoteTimePacket.h"
    00034 #include "H3DNetworkingUtils/PacketSequenceChecker.h"
    00035 #include <vector>
    00036
    00037 namespace H3DNetworkingUtils {
    00038
    00041
    00042 class H3D_NETWORKING_UTILS_DLL_SPEC RemoteSync : public H3D::Group {
    00043 public:
    00044
    00045    // Forward references
    00046    class ClockOffset;
    00047    struct TimePacketCollector;
    00048    typedef H3D::TypedSFNode<RemoteTimePacket> SFRemoteTimePacket;
    00049
    00051    RemoteSync( H3D::Inst<ClockOffset > _clockOffset = 0,
    00052                H3D::Inst< TimePacketCollector > _timePacketReceived = 0,
    00053                H3D::Inst< SFRemoteTimePacket> _remoteTimePacket = 0);
    00054
    00056    static H3D::H3DNodeDatabase database;
    00057
    00059    virtual void initialize();
    00060
    00061    struct H3D_NETWORKING_UTILS_DLL_SPEC TimePacker :
    00062                          public H3D::TypedField< H3D::SField< TimePacket >,
    00063                                                       H3D::SFTime > {
    00064       virtual void update();
    00065    };
    00066
    00067
    00068    struct H3D_NETWORKING_UTILS_DLL_SPEC TimePacketCollector : public H3D::AutoUpdate <
    00069                                 H3D::TypedField<H3D::Field, H3D::SField<TimePacket> > > {
    00070      TimePacketCollector() : remote_syncP (0) {}
    00071      virtual void update() {
    00072         H3D::SField<TimePacket> * packet = static_cast<H3D::SField<TimePacket> *>(event.ptr);
    00073         remote_syncP->appendResult(packet->getValue());
    00074      }
    00075      RemoteSync * remote_syncP;
    00076    };
    00077
    00078    class H3D_NETWORKING_UTILS_DLL_SPEC ClockOffset : public H3D::PeriodicUpdate< H3D::SFTime > {
    00079    public:
    00080       ClockOffset(): rs( 0 ) {
    00081          startup = true;
    00082       }
    00083       virtual void update();
    00084       RemoteSync *rs;
    00085    private:
    00086       bool startup;
    00087    };
    00088
    00089
    00090    // Public fields
    00091
    00095    auto_ptr< ClockOffset          > clockOffset;
    00096
    00100    auto_ptr< TimePacketCollector  > timePacketReceived;
    00101
    00105    auto_ptr< SFRemoteTimePacket   > remoteTimePacket;
    00106
    00107    H3D::AutoRef< H3D::TimeSensor > timer;
    00108    std::vector< TimePacket > results;
    00109
    00110 protected:
    00111    virtual void appendResult(TimePacket const & packet) {
    00112       if (packet.state)
    00113          results.push_back(packet);
    00114    }
    00115
    00116    auto_ptr< TimePacker > time_packer;
    00117
    00118 };
    00119
    00120 }
    00121
    00122 #endif