|
1 /* |
|
2 * Copyright (c) 2007-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 |
|
18 #ifndef __SNTPCLIENTENGINE_H__ |
|
19 #define __SNTPCLIENTENGINE_H__ |
|
20 |
|
21 #include <e32base.h> |
|
22 #include <es_sock.h> |
|
23 #include <in_sock.h> |
|
24 |
|
25 #include "commandlineargs.h" |
|
26 |
|
27 enum TSNTPClientState { |
|
28 EStateIdle = 0, |
|
29 EStateResolve, |
|
30 EStateWrite, |
|
31 EStateRead, |
|
32 EStateComplete, |
|
33 EStateFailed, |
|
34 EStateAborted |
|
35 }; |
|
36 |
|
37 class MTimeOutNotify |
|
38 { |
|
39 public: |
|
40 virtual void TimerExpired() = 0; |
|
41 }; |
|
42 |
|
43 // timeout handler |
|
44 |
|
45 class CTimeOutTimer: public CTimer |
|
46 { |
|
47 public: |
|
48 static CTimeOutTimer* NewL(const TInt aPriority, MTimeOutNotify& aTimeOutNotify); |
|
49 ~CTimeOutTimer(); |
|
50 |
|
51 protected: |
|
52 CTimeOutTimer(const TInt aPriority); |
|
53 void ConstructL(MTimeOutNotify& aTimeOutNotify); |
|
54 virtual void RunL(); |
|
55 |
|
56 private: |
|
57 MTimeOutNotify* iNotify; |
|
58 }; |
|
59 |
|
60 // The main client engine |
|
61 |
|
62 class CSNTPClient : public CActive, public MTimeOutNotify |
|
63 { |
|
64 |
|
65 public: |
|
66 static CSNTPClient* NewL(TCommandLineArgs& aArgs); |
|
67 static CSNTPClient* NewLC(TCommandLineArgs& aArgs); |
|
68 |
|
69 TSNTPClientState State(); |
|
70 void Start(); |
|
71 |
|
72 ~CSNTPClient(); |
|
73 |
|
74 private: |
|
75 CSNTPClient(TCommandLineArgs& aArgs); |
|
76 |
|
77 void ConstructL(); |
|
78 |
|
79 /* CActive methods */ |
|
80 void RunL(); |
|
81 void DoCancel(); |
|
82 TInt RunError(TInt aError); |
|
83 |
|
84 /* MTimeOutNotify methods */ |
|
85 void TimerExpired(); |
|
86 |
|
87 void SetTimeL(); |
|
88 |
|
89 private: |
|
90 RSocketServ iSockServ; |
|
91 RSocket iSock; |
|
92 RHostResolver iResolver; |
|
93 |
|
94 TCommandLineArgs& iArgs; |
|
95 TSNTPClientState iState; |
|
96 TNameEntry iNameEntry; |
|
97 |
|
98 CTimeOutTimer* iTimer; |
|
99 |
|
100 // An NTP packet is exactly 48 bytes |
|
101 TBuf8<48> iBuffer; |
|
102 |
|
103 TInt iServerIndex; |
|
104 }; |
|
105 |
|
106 |
|
107 |
|
108 #endif /* _SNTPCLIENTENGINE_H__ */ |