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