cryptomgmtlibs/securitytestfw/test/sntpclient/sntpclientengine.h
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 #ifndef __SNTPCLIENTENGINE_H__
       
    18 #define __SNTPCLIENTENGINE_H__
       
    19 
       
    20 #include <e32base.h>
       
    21 #include <es_sock.h>
       
    22 #include <in_sock.h>
       
    23 
       
    24 #include "commandlineargs.h"
       
    25 
       
    26 enum TSNTPClientState {
       
    27 	EStateIdle = 0,
       
    28 	EStateResolve,
       
    29 	EStateWrite,
       
    30 	EStateRead,
       
    31 	EStateComplete,
       
    32 	EStateFailed,
       
    33 	EStateAborted
       
    34 	};
       
    35 
       
    36 class MTimeOutNotify
       
    37 	{
       
    38 public:
       
    39 	virtual void TimerExpired() = 0;
       
    40 	};
       
    41 	
       
    42 // timeout handler
       
    43 
       
    44 class CTimeOutTimer: public CTimer
       
    45 	{
       
    46 public:
       
    47 	static CTimeOutTimer* NewL(const TInt aPriority, MTimeOutNotify& aTimeOutNotify);
       
    48 	~CTimeOutTimer();
       
    49 
       
    50 protected:
       
    51     CTimeOutTimer(const TInt aPriority);
       
    52 	void ConstructL(MTimeOutNotify& aTimeOutNotify);
       
    53     virtual void RunL();
       
    54 
       
    55 private:
       
    56 	MTimeOutNotify* iNotify;
       
    57 	};
       
    58 	
       
    59 // The main client engine
       
    60 	
       
    61 class CSNTPClient : public CActive, public MTimeOutNotify
       
    62 	{
       
    63 
       
    64 public:
       
    65 	static CSNTPClient* NewL(TCommandLineArgs& aArgs);
       
    66 	static CSNTPClient* NewLC(TCommandLineArgs& aArgs);
       
    67 	
       
    68 	TSNTPClientState State();
       
    69 	void Start();
       
    70 	
       
    71 	~CSNTPClient();
       
    72 	
       
    73 private:
       
    74 	CSNTPClient(TCommandLineArgs& aArgs);
       
    75 
       
    76 	void ConstructL();
       
    77 	
       
    78 	/* CActive methods */
       
    79 	void RunL();
       
    80 	void DoCancel();
       
    81 	TInt RunError(TInt aError);
       
    82 	
       
    83 	/* MTimeOutNotify methods */
       
    84 	void TimerExpired();
       
    85 	
       
    86 	void SetTimeL(); 
       
    87 	
       
    88 private:
       
    89 	RSocketServ	iSockServ;
       
    90 	RSocket iSock;
       
    91 	RHostResolver iResolver;
       
    92 
       
    93 	TCommandLineArgs& iArgs;
       
    94 	TSNTPClientState iState;
       
    95 	TNameEntry iNameEntry;
       
    96 	
       
    97 	CTimeOutTimer* iTimer;
       
    98 	
       
    99 	// An NTP packet is exactly 48 bytes
       
   100 	TBuf8<48> iBuffer;
       
   101 	
       
   102 	TInt iServerIndex;
       
   103 	};
       
   104 
       
   105 
       
   106 
       
   107 #endif /* _SNTPCLIENTENGINE_H__ */