|
1 /* |
|
2 * Copyright (c) 2010 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: IETF SIMPLE Protocol implementation for XIMP Framework |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <aknutils.h> |
|
20 #include "presencepluginlocalstore.h" |
|
21 #include "presencelogger.h" |
|
22 |
|
23 _LIT( KContactId, "ContactId" ); |
|
24 _LIT( KContactTable, "Contacts" ); |
|
25 _LIT( KStorageExtn, ".db"); |
|
26 _LIT( KDbPath, "c:\\" ); |
|
27 |
|
28 |
|
29 // ======== MEMBER FUNCTIONS ======== |
|
30 |
|
31 // --------------------------------------------------------------------------- |
|
32 // CPresencePluginLocalstore::CPresencePluginLocalstore |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 CPresencePluginLocalstore::CPresencePluginLocalstore() |
|
36 { |
|
37 } |
|
38 |
|
39 |
|
40 // --------------------------------------------------------------------------- |
|
41 // CPresencePluginLocalstore::ConstructL() |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 void CPresencePluginLocalstore::ConstructL( const TDesC& aServiceName ) |
|
45 { |
|
46 DP_SDA( "CPresencePluginLocalstore::ConstructL -Start" ); |
|
47 |
|
48 iLocalDBName = |
|
49 HBufC::NewL( aServiceName.Length()+ KStorageExtn().Length() ); |
|
50 TPtr localDBNamePtr = iLocalDBName->Des(); |
|
51 localDBNamePtr.Append( aServiceName ); |
|
52 |
|
53 _LIT( KSpecialChar, "/\\:*?<>\"" ); |
|
54 AknTextUtils::StripCharacters( localDBNamePtr, KSpecialChar ); |
|
55 localDBNamePtr.Append( KStorageExtn() ); |
|
56 |
|
57 DP_SDA2( "CPresencePluginLocalstore::ConstructL -localDBName: %S" , &localDBNamePtr ); |
|
58 |
|
59 User::LeaveIfError( iFs.Connect() ); |
|
60 if ( DbExists() ) |
|
61 { |
|
62 DP_SDA( "CPresencePluginLocalstore::ConstructL -DB exists" ); |
|
63 OpenDbL(); |
|
64 } |
|
65 else |
|
66 { |
|
67 DP_SDA( "CPresencePluginLocalstore::ConstructL -DB does not exists LEAVE!" ); |
|
68 User::Leave( KErrNotReady ); |
|
69 } |
|
70 |
|
71 User::LeaveIfError( iTable.Open( iDb, KContactTable ) ); |
|
72 iColset = iDb.ColSetL( KContactTable ); |
|
73 |
|
74 DP_SDA( "CPresencePluginLocalstore::ConstructL -End" ); |
|
75 } |
|
76 |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // CPresencePluginLocalstore::NewL() |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 CPresencePluginLocalstore* CPresencePluginLocalstore::NewL( |
|
83 const TDesC& aServiceName ) |
|
84 { |
|
85 CPresencePluginLocalstore* self = |
|
86 CPresencePluginLocalstore::NewLC( aServiceName ); |
|
87 CleanupStack::Pop( self ); |
|
88 return self; |
|
89 } |
|
90 |
|
91 |
|
92 // --------------------------------------------------------------------------- |
|
93 // CPresencePluginLocalstore::NewLC() |
|
94 // --------------------------------------------------------------------------- |
|
95 // |
|
96 CPresencePluginLocalstore* CPresencePluginLocalstore::NewLC( |
|
97 const TDesC& aServiceName ) |
|
98 { |
|
99 CPresencePluginLocalstore* self = |
|
100 new( ELeave ) CPresencePluginLocalstore(); |
|
101 CleanupStack::PushL( self ); |
|
102 self->ConstructL( aServiceName ); |
|
103 return self; |
|
104 } |
|
105 |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // CPresencePluginLocalstore::~CPresencePluginLocalstore() |
|
109 // --------------------------------------------------------------------------- |
|
110 // |
|
111 CPresencePluginLocalstore::~CPresencePluginLocalstore() |
|
112 { |
|
113 DP_SDA( "CPresencePluginLocalstore::~CPresencePluginLocalstore -Start" ); |
|
114 |
|
115 delete iLocalDBName; |
|
116 delete iFileStore; |
|
117 delete iColset; |
|
118 |
|
119 iTable.Close(); |
|
120 iDb.Close(); |
|
121 iFs.Close(); |
|
122 |
|
123 DP_SDA( "CPresencePluginLocalstore::~CPresencePluginLocalstore -End" ); |
|
124 } |
|
125 |
|
126 |
|
127 // --------------------------------------------------------------------------- |
|
128 // CPresencePluginLocalstore::OpenDbL |
|
129 // --------------------------------------------------------------------------- |
|
130 // |
|
131 void CPresencePluginLocalstore::OpenDbL() |
|
132 { |
|
133 DP_SDA( "CPresencePluginLocalstore::OpenDbL() Start" ); |
|
134 |
|
135 TBuf< KMaxPath > storagePath; |
|
136 storagePath.Append( KDbPath ); |
|
137 storagePath.Append( *iLocalDBName ); |
|
138 iFileStore = CPermanentFileStore::OpenL( iFs, storagePath, |
|
139 EFileShareReadersOrWriters|EFileWrite ); |
|
140 iFileStore->SetTypeL( iFileStore->Layout() ); |
|
141 iDb.OpenL( iFileStore, iFileStore->Root() ); |
|
142 |
|
143 DP_SDA( "CPresencePluginLocalstore::OpenDbL() End" ); |
|
144 } |
|
145 |
|
146 |
|
147 // --------------------------------------------------------------------------- |
|
148 // CPresencePluginLocalstore::DbExists |
|
149 // --------------------------------------------------------------------------- |
|
150 // |
|
151 TBool CPresencePluginLocalstore::DbExists() |
|
152 { |
|
153 DP_SDA( "CPresencePluginLocalstore::DbExists() Start" ); |
|
154 |
|
155 TBool ret( ETrue ); |
|
156 RFile temp; |
|
157 TBuf< KMaxPath > storagePath; |
|
158 storagePath.Append( KDbPath ); |
|
159 storagePath.Append( *iLocalDBName ); |
|
160 |
|
161 TInt err( temp.Open( iFs, *( &storagePath ), |
|
162 EFileShareReadersOrWriters|EFileRead ) ); |
|
163 TInt size( 0 ); |
|
164 |
|
165 if ( KErrNone == err ) |
|
166 { |
|
167 temp.Size( size ); |
|
168 } |
|
169 |
|
170 temp.Close(); |
|
171 |
|
172 if ( ( 0 == size ) || ( KErrNone != err ) ) |
|
173 { |
|
174 ret = EFalse; |
|
175 } |
|
176 |
|
177 DP_SDA( "CPresencePluginLocalstore::DbExists() End" ); |
|
178 return ret; |
|
179 } |
|
180 |
|
181 |
|
182 // --------------------------------------------------------------------------- |
|
183 // CPresencePluginLocalstore::SeekRowL() |
|
184 // --------------------------------------------------------------------------- |
|
185 // |
|
186 TBool CPresencePluginLocalstore::SeekRowAtContactColL( |
|
187 TInt32& aIdentifier ) |
|
188 { |
|
189 DP_SDA( "CPresencePluginLocalstore::SeekRowAtContactColL() Start" ); |
|
190 |
|
191 TBool ret( EFalse ); |
|
192 TDbColNo colNo = iColset->ColNo( KContactId ); |
|
193 iTable.BeginningL(); |
|
194 |
|
195 while ( iTable.NextL() ) |
|
196 { |
|
197 DP_SDA( "CPresencePluginLocalstore::SeekRowAtContactColL() - next found" ); |
|
198 iTable.GetL(); |
|
199 if ( iTable.ColInt32( colNo ) == aIdentifier ) |
|
200 { |
|
201 ret = ETrue; |
|
202 break; |
|
203 } |
|
204 } |
|
205 |
|
206 DP_SDA2( "CPresencePluginLocalstore::SeekRowAtContactColL() End - ret = %d", ret ); |
|
207 return ret; |
|
208 } |