|
1 /* |
|
2 * Copyright (c) 2006 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 "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: Implementation of CNcdServerAddress |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32math.h> |
|
20 |
|
21 #include "ncdserveraddress.h" |
|
22 |
|
23 #include "catalogsdebug.h" |
|
24 #include "catalogsutils.h" |
|
25 #include "ncdproviderdefines.h" |
|
26 |
|
27 |
|
28 // --------------------------------------------------------------------------- |
|
29 // NewL |
|
30 // --------------------------------------------------------------------------- |
|
31 // |
|
32 CNcdServerAddress* CNcdServerAddress::NewL( const TDesC& aAddress, |
|
33 const TInt64& aValidity ) |
|
34 { |
|
35 CNcdServerAddress* self = CNcdServerAddress::NewLC( aAddress, aValidity ); |
|
36 CleanupStack::Pop( self ); |
|
37 return self; |
|
38 } |
|
39 |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // NewL |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 CNcdServerAddress* CNcdServerAddress::NewL( RReadStream& aStream ) |
|
46 { |
|
47 CNcdServerAddress* self = new ( ELeave ) CNcdServerAddress( 0 ); |
|
48 CleanupStack::PushL( self ); |
|
49 self->InternalizeL( aStream ); |
|
50 CleanupStack::Pop( self ); |
|
51 return self; |
|
52 } |
|
53 |
|
54 // --------------------------------------------------------------------------- |
|
55 // NewLC |
|
56 // --------------------------------------------------------------------------- |
|
57 // |
|
58 CNcdServerAddress* CNcdServerAddress::NewLC( const TDesC& aAddress, |
|
59 const TInt64& aValidity ) |
|
60 { |
|
61 CNcdServerAddress* self = new( ELeave ) CNcdServerAddress( aValidity ); |
|
62 CleanupStack::PushL( self ); |
|
63 self->ConstructL( aAddress ); |
|
64 return self; |
|
65 } |
|
66 |
|
67 |
|
68 // --------------------------------------------------------------------------- |
|
69 // Destructor |
|
70 // --------------------------------------------------------------------------- |
|
71 // |
|
72 CNcdServerAddress::~CNcdServerAddress() |
|
73 { |
|
74 delete iAddress; |
|
75 } |
|
76 |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // Address getter |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 const TDesC& CNcdServerAddress::Address() const |
|
83 { |
|
84 return *iAddress; |
|
85 } |
|
86 |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // Validity as TInt64 |
|
90 // --------------------------------------------------------------------------- |
|
91 // |
|
92 TInt64 CNcdServerAddress::Validity() const |
|
93 { |
|
94 return iValidity; |
|
95 } |
|
96 |
|
97 |
|
98 // --------------------------------------------------------------------------- |
|
99 // Validity checker |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 TBool CNcdServerAddress::IsValid() const |
|
103 { |
|
104 DLTRACEIN(("")); |
|
105 if ( iUseValidity ) |
|
106 { |
|
107 |
|
108 TTime validTime( iValidity ); |
|
109 |
|
110 TTime currentTime; |
|
111 currentTime.HomeTime(); |
|
112 DLTRACEOUT(("cur: %Li, validity: %Li, Is valid: %d", currentTime.Int64(), |
|
113 validTime.Int64(), (currentTime < validTime) )); |
|
114 return currentTime < validTime; |
|
115 } |
|
116 // Always valid if not using validity |
|
117 return ETrue; |
|
118 } |
|
119 |
|
120 |
|
121 // --------------------------------------------------------------------------- |
|
122 // Set use validity |
|
123 // --------------------------------------------------------------------------- |
|
124 // |
|
125 void CNcdServerAddress::SetUseValidity( TBool aUseValidity ) |
|
126 { |
|
127 iUseValidity = aUseValidity; |
|
128 } |
|
129 |
|
130 // --------------------------------------------------------------------------- |
|
131 // ExternalizeL |
|
132 // --------------------------------------------------------------------------- |
|
133 // |
|
134 void CNcdServerAddress::ExternalizeL( RWriteStream& aStream ) |
|
135 { |
|
136 ExternalizeDesL( *iAddress, aStream ); |
|
137 aStream << iValidity; |
|
138 aStream.WriteInt32L( iUseValidity ); |
|
139 } |
|
140 |
|
141 |
|
142 // --------------------------------------------------------------------------- |
|
143 // InternalizeL |
|
144 // --------------------------------------------------------------------------- |
|
145 // |
|
146 void CNcdServerAddress::InternalizeL( RReadStream& aStream ) |
|
147 { |
|
148 InternalizeDesL( iAddress, aStream ); |
|
149 aStream >> iValidity; |
|
150 iUseValidity = aStream.ReadInt32L(); |
|
151 } |
|
152 |
|
153 |
|
154 |
|
155 // --------------------------------------------------------------------------- |
|
156 // Constructor |
|
157 // --------------------------------------------------------------------------- |
|
158 // |
|
159 CNcdServerAddress::CNcdServerAddress( const TInt64& aValidity ) |
|
160 : iValidity( aValidity ) |
|
161 { |
|
162 // Enable validity check if validity != 0 |
|
163 if ( iValidity ) |
|
164 { |
|
165 iUseValidity = ETrue; |
|
166 } |
|
167 } |
|
168 |
|
169 |
|
170 // --------------------------------------------------------------------------- |
|
171 // ConstructL |
|
172 // --------------------------------------------------------------------------- |
|
173 // |
|
174 void CNcdServerAddress::ConstructL( const TDesC& aAddress ) |
|
175 { |
|
176 iAddress = aAddress.AllocL(); |
|
177 } |