Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

CascadeSNTPClient.h

Go to the documentation of this file.
00001 // CascadeSNTPClient.h : interface of class CascadeSNTPClient
00002 //
00003 // Copyright (c) 2005, Roku, LLC.  All rights reserved.
00004 //
00006 
00007 #ifndef _ROKU_INCLUDE_CASCADE_NET_CASCADESNTPCLIENT_H
00008 #define _ROKU_INCLUDE_CASCADE_NET_CASCADESNTPCLIENT_H
00009 
00010 #include <cascade/CascadeObject.h>
00011 #include <cascade/util/CascadeTime.h>
00012 
00014 // class CascadeSNTPClient - an easy to use socket for client connections
00015 class CascadeSNTPClient : public CascadeObject
00016 {
00017 #ifndef DOXY_SKIP
00018 public:
00019     struct InternetTimeStruct;
00020 #endif
00021     
00022 public:
00023     CascadeSNTPClient();
00024     virtual ~CascadeSNTPClient();
00025 
00026 public:
00027     enum { kDefaultTimeout = 5000 };
00028     bool FetchInternetTime(const char * pServerName, InternetTimeStruct & timeStructToSet, u32 nTimeoutMS = kDefaultTimeout);
00029     
00030 public:
00031     struct TimeStamp
00032     {
00033     public:
00034         inline bool operator == (const TimeStamp & that) const { return ((m_seconds == that.m_seconds) && (m_fractional == that.m_fractional)) ? true : false; }
00035         inline bool operator != (const TimeStamp & that) const { return ((m_seconds != that.m_seconds) || (m_fractional != that.m_fractional)) ? true : false; }
00036     public:
00037         unsigned long m_seconds;
00038         unsigned long m_fractional;
00039     };
00040     
00041     struct Packet
00042     {
00043     public:
00044         unsigned char m_flags;
00045         unsigned char m_stratum;
00046         unsigned char m_poll;
00047         unsigned char m_precision;
00048         unsigned long m_rootDelay;
00049         unsigned long m_rootDispersion;
00050         unsigned long m_refID;
00051         TimeStamp     m_refTimeStamp;
00052         TimeStamp     m_originateTimeStamp;
00053         TimeStamp     m_receiveTimeStamp;
00054         TimeStamp     m_transmitTimeStamp;      
00055     };
00056     
00057     struct InternetTimeStruct
00058     {
00059     public:
00060         CascadeTime::TimeBase m_timeBase;
00061             // the interesting part: you can use m_timeBase in a call
00062             // to CascadeTime::SetSystemClockTimeBase()
00063             // to set the system clock time based on this InternetTimeStruct
00064             // you probably should gather more than one of these
00065             // from different servers, normalize their time bases and
00066             // average them before so doing.  In practice, I, RokuDon, will
00067             // do this from a daemon in the Cascade process so don't actually
00068             // call CascadeTime::SetSystemClockTimeBase() because my daemon will overwrite
00069             // you at some point in the future!
00070         u32 m_nRoundTripDelayMilliseconds;
00071             // calculated RoundTrip delay in milliseconds
00072         Packet m_packetSent;
00073             // the entire SNTP packet that was sent should you care to examine
00074         Packet m_packetReceived;
00075             // the entire SNTP packet that was received should you care to examine
00076     };
00077     
00078     enum
00079     {
00080         kFlagsLeapIndicatorMask     = 0xC0,
00081         kFlagsLeapIndicatorNone     = 0x00,
00082         kFlagsLeapIndicatorLong     = 0x40,
00083         kFlagsLeapIndicatorShort    = 0x80,
00084         kFlagsLeapIndicatorAlarm    = 0xC0,
00085         kFlagsVersionMask           = 0x38,
00086         kFlagsVersion1              = 0x08,
00087         kFlagsVersion2              = 0x10,
00088         kFlagsVersion3              = 0x18,
00089         kFlagsModeMask              = 0x07,
00090         kFlagsModeActive            = 0x01,
00091         kFlagsModePassive           = 0x02,
00092         kFlagsModeClient            = 0x03,
00093         kFlagsModeServer            = 0x04,
00094         kFlagsModeBroadcast         = 0x05,
00095         kFlagsModeControl           = 0x06,
00096     };
00097     
00098 private:
00099     class Client;
00100     Client * m_pClient;
00101 };
00102 
00103 #endif // #ifndef _ROKU_INCLUDE_CASCADE_NET_CASCADESNTPCLIENT_H
00104 
00106 //      LOG 
00108 //  18-May-05   dwoodward   created
00109 

Generated on Sun Jul 24 14:27:17 2005 for Cascade Library by  doxygen 1.4.1