os/security/cryptomgmtlibs/securitytestfw/test/sntpclient/sntpclientengine.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 #ifndef __SNTPCLIENTENGINE_H__
     2 #define __SNTPCLIENTENGINE_H__/*
     3 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     4 * All rights reserved.
     5 * This component and the accompanying materials are made available
     6 * under the terms of the License "Eclipse Public License v1.0"
     7 * which accompanies this distribution, and is available
     8 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     9 *
    10 * Initial Contributors:
    11 * Nokia Corporation - initial contribution.
    12 *
    13 * Contributors:
    14 *
    15 * Description: 
    16 *
    17 */
    18 
    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__ */