|
1 /* |
|
2 * Copyright (c) 2005 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: RXcapCache |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "XcapCache.h" |
|
21 #include "CommonDefines.h" |
|
22 |
|
23 |
|
24 //CLASS DECLARATION |
|
25 EXPORT_C RXcapCache::RXcapCache() : iConnected( EFalse ) |
|
26 { |
|
27 } |
|
28 |
|
29 // ---------------------------------------------------- |
|
30 // RXcapCache::Store |
|
31 // |
|
32 // ---------------------------------------------------- |
|
33 // |
|
34 EXPORT_C void RXcapCache::Store( const TDesC8& aETag, |
|
35 const TDesC& aDocumentName, |
|
36 const TDesC8& aRootLocation, |
|
37 const TDesC8& aResponseData ) |
|
38 { |
|
39 SendReceive( EXcapCacheStore, TIpcArgs( &aDocumentName, &aRootLocation, &aETag, &aResponseData ) ); |
|
40 } |
|
41 |
|
42 // ---------------------------------------------------- |
|
43 // RXcapCache::Delete |
|
44 // |
|
45 // ---------------------------------------------------- |
|
46 // |
|
47 EXPORT_C TInt RXcapCache::Delete( const TDesC& aDocumentName, |
|
48 const TDesC8& aRootLocation ) |
|
49 { |
|
50 TCacheEntryInfo entryInfo; |
|
51 entryInfo.iRootUri = CONST_CAST( TDesC8*, &aRootLocation ); |
|
52 entryInfo.iDocumentUri = CONST_CAST( TDesC*, &aDocumentName ); |
|
53 TPckgC<TCacheEntryInfo> package( entryInfo ); |
|
54 return SendReceive( EXcapCacheDelete, TIpcArgs( &package ) ); |
|
55 } |
|
56 |
|
57 // ---------------------------------------------------- |
|
58 // RXcapCache::FetchDocumentInfo |
|
59 // |
|
60 // ---------------------------------------------------- |
|
61 // |
|
62 EXPORT_C TInt RXcapCache::FetchDocumentInfo( TDes8& aETagDescriptor, |
|
63 const TDesC& aDocumentName, |
|
64 const TDesC8& aRootLocation, |
|
65 TCacheEntryInfo& aEntryInfo ) |
|
66 { |
|
67 TPckg<TCacheEntryInfo> package( aEntryInfo ); |
|
68 return SendReceive( EXcapCacheFetchInfo, TIpcArgs( &package, &aETagDescriptor, |
|
69 &aDocumentName, &aRootLocation ) ); |
|
70 } |
|
71 |
|
72 // ---------------------------------------------------- |
|
73 // RXcapCache::FetchDocumentContent |
|
74 // |
|
75 // ---------------------------------------------------- |
|
76 // |
|
77 EXPORT_C void RXcapCache::FetchDocumentContent( TDes8& aContentDescriptor, |
|
78 const TDesC& aDocumentName, |
|
79 const TDesC8& aRootLocation ) |
|
80 { |
|
81 SendReceive( EXcapCacheFetchData, TIpcArgs( |
|
82 &aDocumentName, &aRootLocation, &aContentDescriptor ) ); |
|
83 } |
|
84 |
|
85 // ---------------------------------------------------- |
|
86 // RXcapCache::IsCurrent |
|
87 // |
|
88 // ---------------------------------------------------- |
|
89 // |
|
90 EXPORT_C TInt RXcapCache::IsCurrent( const TDesC8& aETag, |
|
91 const TDesC& aDocumentName, |
|
92 const TDesC8& aRootLocation ) |
|
93 { |
|
94 return SendReceive( EXcapCacheCheckValidity, TIpcArgs( |
|
95 &aETag, &aDocumentName, &aRootLocation ) ); |
|
96 } |
|
97 |
|
98 // ---------------------------------------------------- |
|
99 // RXcapCache::Flush |
|
100 // |
|
101 // ---------------------------------------------------- |
|
102 // |
|
103 EXPORT_C void RXcapCache::Flush() |
|
104 { |
|
105 SendReceive( EXcapCacheFlush ); |
|
106 } |
|
107 |
|
108 // ---------------------------------------------------- |
|
109 // RXcapCache::Version |
|
110 // |
|
111 // ---------------------------------------------------- |
|
112 // |
|
113 EXPORT_C TVersion RXcapCache::Version() const |
|
114 { |
|
115 return TVersion( KCacheServerMajorVersionNumber, |
|
116 KCacheServerMinorVersionNumber, |
|
117 KCacheServerBuildVersionNumber ); |
|
118 } |
|
119 |
|
120 // ---------------------------------------------------- |
|
121 // RXcapCache::~RXcapCache |
|
122 // |
|
123 // ---------------------------------------------------- |
|
124 // |
|
125 EXPORT_C RXcapCache::~RXcapCache() |
|
126 { |
|
127 } |
|
128 |
|
129 // ---------------------------------------------------- |
|
130 // RXcapCache::Connect() |
|
131 // |
|
132 // ---------------------------------------------------- |
|
133 // |
|
134 EXPORT_C TInt RXcapCache::Connect() |
|
135 { |
|
136 TInt ret = KErrNone; |
|
137 if( !iConnected ) |
|
138 { |
|
139 ret = StartServer(); |
|
140 if( ret == KErrNone || ret == KErrAlreadyExists ) |
|
141 { |
|
142 ret = CreateSession( KXcapCacheServerLib, Version(), KTTDefaultMessageSlots ); |
|
143 iConnected = ( ret == KErrNone ); |
|
144 } |
|
145 } |
|
146 return ret; |
|
147 } |
|
148 |
|
149 // ---------------------------------------------------- |
|
150 // RXcapCache::StartServer |
|
151 // |
|
152 // ---------------------------------------------------- |
|
153 // |
|
154 TInt RXcapCache::StartServer() |
|
155 { |
|
156 TInt ret = KErrNone; |
|
157 TRequestStatus status = KRequestPending; |
|
158 if ( !IsRunning() ) |
|
159 { |
|
160 RProcess server; |
|
161 ret = server.Create( KXcapCacheServerExe, KNullDesC ); |
|
162 if( ret != KErrNone ) |
|
163 return ret; |
|
164 server.Rendezvous( status ); |
|
165 status != KRequestPending ? server.Kill( 0 ) : server.Resume(); |
|
166 //Wait for start or death |
|
167 User::WaitForRequest( status ); |
|
168 ret = server.ExitType() == EExitPanic ? KErrGeneral : status.Int(); |
|
169 server.Close(); |
|
170 } |
|
171 return ret; |
|
172 } |
|
173 |
|
174 // ---------------------------------------------------- |
|
175 // RXcapCache::IsRunning |
|
176 // |
|
177 // ---------------------------------------------------- |
|
178 // |
|
179 TBool RXcapCache::IsRunning() |
|
180 { |
|
181 TFindServer findServer( KXcapCacheServerName ); |
|
182 TFullName name; |
|
183 return ( findServer.Next( name ) == KErrNone ); |
|
184 } |
|
185 |
|
186 // End of File |
|
187 |
|
188 |