sl@0: #ifndef __SNTPCLIENTENGINE_H__ sl@0: #define __SNTPCLIENTENGINE_H__/* sl@0: * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include "commandlineargs.h" sl@0: sl@0: enum TSNTPClientState { sl@0: EStateIdle = 0, sl@0: EStateResolve, sl@0: EStateWrite, sl@0: EStateRead, sl@0: EStateComplete, sl@0: EStateFailed, sl@0: EStateAborted sl@0: }; sl@0: sl@0: class MTimeOutNotify sl@0: { sl@0: public: sl@0: virtual void TimerExpired() = 0; sl@0: }; sl@0: sl@0: // timeout handler sl@0: sl@0: class CTimeOutTimer: public CTimer sl@0: { sl@0: public: sl@0: static CTimeOutTimer* NewL(const TInt aPriority, MTimeOutNotify& aTimeOutNotify); sl@0: ~CTimeOutTimer(); sl@0: sl@0: protected: sl@0: CTimeOutTimer(const TInt aPriority); sl@0: void ConstructL(MTimeOutNotify& aTimeOutNotify); sl@0: virtual void RunL(); sl@0: sl@0: private: sl@0: MTimeOutNotify* iNotify; sl@0: }; sl@0: sl@0: // The main client engine sl@0: sl@0: class CSNTPClient : public CActive, public MTimeOutNotify sl@0: { sl@0: sl@0: public: sl@0: static CSNTPClient* NewL(TCommandLineArgs& aArgs); sl@0: static CSNTPClient* NewLC(TCommandLineArgs& aArgs); sl@0: sl@0: TSNTPClientState State(); sl@0: void Start(); sl@0: sl@0: ~CSNTPClient(); sl@0: sl@0: private: sl@0: CSNTPClient(TCommandLineArgs& aArgs); sl@0: sl@0: void ConstructL(); sl@0: sl@0: /* CActive methods */ sl@0: void RunL(); sl@0: void DoCancel(); sl@0: TInt RunError(TInt aError); sl@0: sl@0: /* MTimeOutNotify methods */ sl@0: void TimerExpired(); sl@0: sl@0: void SetTimeL(); sl@0: sl@0: private: sl@0: RSocketServ iSockServ; sl@0: RSocket iSock; sl@0: RHostResolver iResolver; sl@0: sl@0: TCommandLineArgs& iArgs; sl@0: TSNTPClientState iState; sl@0: TNameEntry iNameEntry; sl@0: sl@0: CTimeOutTimer* iTimer; sl@0: sl@0: // An NTP packet is exactly 48 bytes sl@0: TBuf8<48> iBuffer; sl@0: sl@0: TInt iServerIndex; sl@0: }; sl@0: sl@0: sl@0: sl@0: #endif /* _SNTPCLIENTENGINE_H__ */