|
1 /* |
|
2 * Copyright (c) 2007 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: Candidate store |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include "natcandidatestore.h" |
|
22 |
|
23 #include "natfwcandidate.h" |
|
24 #include <s32file.h> |
|
25 |
|
26 #include "natcandidatestoreitem.h" |
|
27 |
|
28 _LIT( KFileName, "E:\\natfwcandidates.bin" ); |
|
29 |
|
30 // --------------------------------------------------------------------------- |
|
31 // CNATCandidateStore::CNATCandidateStore |
|
32 // --------------------------------------------------------------------------- |
|
33 // |
|
34 CNATCandidateStore::CNATCandidateStore() |
|
35 { |
|
36 } |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // CNATCandidateStore::ConstructL |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 void CNATCandidateStore::ConstructL() |
|
43 { |
|
44 User::LeaveIfError( iFileServer.Connect() ); |
|
45 } |
|
46 |
|
47 // --------------------------------------------------------------------------- |
|
48 // CNATCandidateStore::NewL |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 CNATCandidateStore* CNATCandidateStore::NewL() |
|
52 { |
|
53 CNATCandidateStore* self = CNATCandidateStore::NewLC(); |
|
54 CleanupStack::Pop( self ); |
|
55 return self; |
|
56 } |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 // CNATCandidateStore::NewLC |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 CNATCandidateStore* CNATCandidateStore::NewLC() |
|
63 { |
|
64 CNATCandidateStore* self = new( ELeave ) CNATCandidateStore(); |
|
65 CleanupStack::PushL( self ); |
|
66 self->ConstructL(); |
|
67 return self; |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // CNATCandidateStore::~CNATCandidateStore |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 CNATCandidateStore::~CNATCandidateStore() |
|
75 { |
|
76 iFileServer.Close(); |
|
77 } |
|
78 |
|
79 // --------------------------------------------------------------------------- |
|
80 // CNATCandidateStore::WriteL |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 void CNATCandidateStore::WriteL( const RPointerArray<CNATFWCandidate>& aCandidates ) |
|
84 { |
|
85 CNATCandidateStoreItem* item = CNATCandidateStoreItem::NewLC(); |
|
86 |
|
87 RFileWriteStream outstream; |
|
88 outstream.PushL(); |
|
89 |
|
90 User::LeaveIfError( outstream.Replace( |
|
91 iFileServer, KFileName, EFileStream | EFileWrite ) ); |
|
92 |
|
93 TInt itemCount = aCandidates.Count(); |
|
94 |
|
95 outstream.WriteInt32L( itemCount ); |
|
96 |
|
97 for ( TInt i( 0 ); i < itemCount; i++ ) |
|
98 { |
|
99 item->SetNATCandidate( *aCandidates[i] ); |
|
100 outstream << *item; |
|
101 } |
|
102 outstream.CommitL(); |
|
103 outstream.Pop(); |
|
104 outstream.Close(); |
|
105 CleanupStack::PopAndDestroy( item ); |
|
106 } |
|
107 |
|
108 // --------------------------------------------------------------------------- |
|
109 // CNATCandidateStore::ReadL |
|
110 // --------------------------------------------------------------------------- |
|
111 // |
|
112 void CNATCandidateStore::ReadL( RPointerArray<CNATFWCandidate>& aCandidates ) |
|
113 { |
|
114 CNATCandidateStoreItem* item = CNATCandidateStoreItem::NewLC(); |
|
115 |
|
116 RFileReadStream instream; |
|
117 instream.PushL(); |
|
118 |
|
119 User::LeaveIfError( instream.Open( |
|
120 iFileServer, KFileName, EFileStream | EFileRead ) ); |
|
121 |
|
122 TInt itemCount = instream.ReadInt32L(); |
|
123 |
|
124 for ( TInt i ( 0 ); i < itemCount; i++ ) |
|
125 { |
|
126 instream >> *item; |
|
127 aCandidates.AppendL( CNATFWCandidate::NewLC( item->NATCandidate() ) ); |
|
128 CleanupStack::Pop( 1 ); |
|
129 } |
|
130 instream.Pop(); |
|
131 instream.Close(); |
|
132 CleanupStack::PopAndDestroy( item ); |
|
133 } |