|
1 /* |
|
2 * Copyright (c) 2008 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef NSPTESTCONSOLECENREP_H |
|
19 #define NSPTESTCONSOLECENREP_H |
|
20 |
|
21 #include <centralrepository.h> |
|
22 #include <unsafprotocolscrkeys.h> |
|
23 |
|
24 class TCenrepKeys |
|
25 { |
|
26 public: // Methods |
|
27 |
|
28 inline TUint32 DomainKey() |
|
29 { |
|
30 return KUNSAFProtocolsDomainMask; |
|
31 } |
|
32 |
|
33 inline TUint32 IapKey() |
|
34 { |
|
35 return KUNSAFProtocolsIAPIdMask; |
|
36 } |
|
37 |
|
38 inline TUint32 DomainSpecificAprotocol() |
|
39 { |
|
40 return KUNSAFProtocolsUsedNATProtocolMask; |
|
41 } |
|
42 |
|
43 inline TUint32 DomainSpecificStunSrvAddr() |
|
44 { |
|
45 return KUNSAFProtocolsSTUNServerMask; |
|
46 } |
|
47 |
|
48 inline TUint32 DomainSpecificStunSrvPort() |
|
49 { |
|
50 return KUNSAFProtocolsSTUNServerPortMask; |
|
51 } |
|
52 }; |
|
53 |
|
54 class TCenrepReader : private TCenrepKeys |
|
55 { |
|
56 public: // Methods |
|
57 |
|
58 inline TCenrepReader( CRepository& aCenrep ) |
|
59 : iCenrep( aCenrep ) |
|
60 { |
|
61 } |
|
62 |
|
63 inline CRepository& Cenrep() |
|
64 { |
|
65 return iCenrep; |
|
66 } |
|
67 |
|
68 inline void ReadDomainL( TDes& aBuffer ) |
|
69 { |
|
70 TBuf8<255> buffer; |
|
71 ReadDomainL( buffer ); |
|
72 aBuffer.Copy( buffer ); |
|
73 } |
|
74 |
|
75 inline void ReadDomainL( TDes8& aBuffer ) |
|
76 { |
|
77 if ( KErrNotFound == iCenrep.Get( DomainKey(), aBuffer ) ) |
|
78 { |
|
79 aBuffer.Zero(); |
|
80 User::LeaveIfError( iCenrep.Create( DomainKey(), aBuffer ) ); |
|
81 } |
|
82 } |
|
83 |
|
84 inline void ReadIapL( TUint32& aIap ) |
|
85 { |
|
86 TInt value( 0 ); |
|
87 |
|
88 if ( KErrNotFound == iCenrep.Get( IapKey(), value ) ) |
|
89 { |
|
90 aIap = 0; |
|
91 User::LeaveIfError( iCenrep.Create( IapKey(), value ) ); |
|
92 } |
|
93 |
|
94 aIap = (TUint32) value; |
|
95 } |
|
96 |
|
97 inline void ReadAProtocolL( TDes& aBuffer ) |
|
98 { |
|
99 TBuf8<255> buffer; |
|
100 ReadAProtocolL( buffer ); |
|
101 aBuffer.Copy( buffer ); |
|
102 } |
|
103 |
|
104 inline void ReadAProtocolL( TDes8& aBuffer ) |
|
105 { |
|
106 const TUint32 key = DomainSpecificAprotocol(); |
|
107 |
|
108 if ( KErrNotFound == iCenrep.Get( key, aBuffer ) ) |
|
109 { |
|
110 aBuffer.Zero(); |
|
111 User::LeaveIfError( iCenrep.Create( key, aBuffer ) ); |
|
112 } |
|
113 } |
|
114 |
|
115 inline void ReadStunSrvAddrL( TDes& aBuffer ) |
|
116 { |
|
117 TBuf8<255> buffer; |
|
118 ReadStunSrvAddrL( buffer ); |
|
119 aBuffer.Copy( buffer ); |
|
120 } |
|
121 |
|
122 inline void ReadStunSrvAddrL( TDes8& aBuffer ) |
|
123 { |
|
124 const TUint32 key = DomainSpecificStunSrvAddr(); |
|
125 |
|
126 if ( KErrNotFound == iCenrep.Get( key, aBuffer ) ) |
|
127 { |
|
128 aBuffer.Zero(); |
|
129 User::LeaveIfError( iCenrep.Create( key, aBuffer ) ); |
|
130 } |
|
131 } |
|
132 |
|
133 inline void ReadStunSrvPortL( TUint& aPort ) |
|
134 { |
|
135 const TUint32 key = DomainSpecificStunSrvPort(); |
|
136 TInt value( 0 ); |
|
137 |
|
138 if ( KErrNotFound == iCenrep.Get( key, value ) ) |
|
139 { |
|
140 aPort = 0; |
|
141 User::LeaveIfError( iCenrep.Create( key, value ) ); |
|
142 } |
|
143 |
|
144 aPort = (TUint) value; |
|
145 } |
|
146 |
|
147 private: // data |
|
148 |
|
149 CRepository& iCenrep; |
|
150 }; |
|
151 |
|
152 class TCenrepWriter : private TCenrepKeys |
|
153 { |
|
154 public: // Methods |
|
155 |
|
156 inline TCenrepWriter( CRepository& aCenrep ) |
|
157 : iCenrep( aCenrep ) |
|
158 { |
|
159 } |
|
160 |
|
161 inline CRepository& Cenrep() |
|
162 { |
|
163 return iCenrep; |
|
164 } |
|
165 |
|
166 inline void WriteDomainL( const TDesC& aBuffer ) |
|
167 { |
|
168 TBuf8<255> buffer; |
|
169 buffer.Copy( aBuffer ); |
|
170 WriteDomainL( buffer ); |
|
171 } |
|
172 |
|
173 inline void WriteDomainL( const TDesC8& aBuffer ) |
|
174 { |
|
175 if ( KErrNotFound == iCenrep.Set( DomainKey(), aBuffer ) ) |
|
176 { |
|
177 User::LeaveIfError( iCenrep.Create( DomainKey(), aBuffer ) ); |
|
178 } |
|
179 } |
|
180 |
|
181 inline void WriteIapL( TUint32 aIap ) |
|
182 { |
|
183 TInt value = (TInt) aIap; |
|
184 |
|
185 if ( KErrNotFound == iCenrep.Set( IapKey(), value ) ) |
|
186 { |
|
187 User::LeaveIfError( iCenrep.Create( IapKey(), value ) ); |
|
188 } |
|
189 } |
|
190 |
|
191 inline void WriteAProtocolL( const TDesC& aBuffer ) |
|
192 { |
|
193 TBuf8<255> buffer; |
|
194 buffer.Copy( aBuffer ); |
|
195 WriteAProtocolL( buffer ); |
|
196 } |
|
197 |
|
198 inline void WriteAProtocolL( const TDesC8& aBuffer ) |
|
199 { |
|
200 const TUint32 key = DomainSpecificAprotocol(); |
|
201 |
|
202 if ( KErrNotFound == iCenrep.Set( key, aBuffer ) ) |
|
203 { |
|
204 User::LeaveIfError( iCenrep.Create( key, aBuffer ) ); |
|
205 } |
|
206 } |
|
207 |
|
208 inline void WriteStunSrvAddrL( const TDesC& aBuffer ) |
|
209 { |
|
210 TBuf8<255> buffer; |
|
211 buffer.Copy( aBuffer ); |
|
212 WriteStunSrvAddrL( buffer ); |
|
213 } |
|
214 |
|
215 inline void WriteStunSrvAddrL( const TDesC8& aBuffer ) |
|
216 { |
|
217 const TUint32 key = DomainSpecificStunSrvAddr(); |
|
218 |
|
219 if ( KErrNotFound == iCenrep.Set( key, aBuffer ) ) |
|
220 { |
|
221 User::LeaveIfError( iCenrep.Create( key, aBuffer ) ); |
|
222 } |
|
223 } |
|
224 |
|
225 inline void WriteStunSrvPortL( TUint aPort ) |
|
226 { |
|
227 const TUint32 key = DomainSpecificStunSrvPort(); |
|
228 TInt value = (TInt) aPort; |
|
229 |
|
230 if ( KErrNotFound == iCenrep.Set( key, value ) ) |
|
231 { |
|
232 User::LeaveIfError( iCenrep.Create( key, value ) ); |
|
233 } |
|
234 } |
|
235 |
|
236 private: // data |
|
237 |
|
238 CRepository& iCenrep; |
|
239 }; |
|
240 |
|
241 #endif // NSPTESTCONSOLECENREP_H |