|
1 /* |
|
2 * Copyright (c) 2003 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 |
|
19 #include "CdlClient.h" |
|
20 #include "CdlClientServer.h" |
|
21 #ifdef __CDLSERVER_NO_PROCESSES__ |
|
22 #include <e32math.h> |
|
23 #endif |
|
24 #include "CdlRefs.h" |
|
25 #include <f32file.h> |
|
26 |
|
27 static TInt StartServer() |
|
28 // |
|
29 // Start the server process or thread |
|
30 // |
|
31 { |
|
32 const TUidType serverUid(KNullUid,KNullUid,KServerUid3); |
|
33 |
|
34 #ifdef __CDLSERVER_NO_PROCESSES__ |
|
35 // |
|
36 // In EKA1 WINS the server is a DLL, the exported entrypoint returns a TInt |
|
37 // which represents the real entry-point for the server thread |
|
38 // |
|
39 RLibrary lib; |
|
40 TInt r=lib.Load(KCdlServerDllImg,serverUid); |
|
41 if (r!=KErrNone) |
|
42 return r; |
|
43 TLibraryFunction ordinal1=lib.Lookup(1); |
|
44 TThreadFunction serverFunc=reinterpret_cast<TThreadFunction>(ordinal1()); |
|
45 // |
|
46 // To deal with the unique thread (+semaphore!) naming in EPOC, and that we may |
|
47 // be trying to restart a server that has just exited we attempt to create a |
|
48 // unique thread name for the server. |
|
49 // This uses Math::Random() to generate a 32-bit random number for the name |
|
50 // |
|
51 TName name(KCdlServerName); |
|
52 name.AppendNum(Math::Random(),EHex); |
|
53 RThread server; |
|
54 r=server.Create(name,serverFunc, |
|
55 KCdlServerStackSize, |
|
56 NULL,&lib,NULL, |
|
57 KCdlServerInitHeapSize,KCdlServerMaxHeapSize,EOwnerProcess); |
|
58 lib.Close(); // if successful, server thread has handle to library now |
|
59 #else |
|
60 // |
|
61 // EPOC and EKA2 is easy, we just create a new server process. Simultaneous launching |
|
62 // of two such processes should be detected when the second one attempts to |
|
63 // create the server object, failing with KErrAlreadyExists. |
|
64 // |
|
65 RProcess server; |
|
66 TInt r=server.Create(KCdlServerExeImg,KNullDesC,serverUid); |
|
67 #endif |
|
68 if (r!=KErrNone) |
|
69 return r; |
|
70 TRequestStatus stat; |
|
71 server.Rendezvous(stat); |
|
72 if (stat!=KRequestPending) |
|
73 server.Kill(0); // abort startup |
|
74 else |
|
75 server.Resume(); // logon OK - start the server |
|
76 User::WaitForRequest(stat); // wait for start or death |
|
77 // we can't use the 'exit reason' if the server panicked as this |
|
78 // is the panic 'reason' and may be '0' which cannot be distinguished |
|
79 // from KErrNone |
|
80 r=(server.ExitType()==EExitPanic) ? KErrGeneral : stat.Int(); |
|
81 server.Close(); |
|
82 return r; |
|
83 } |
|
84 |
|
85 TInt RCdlSession::Connect() |
|
86 // |
|
87 // Connect to the server, attempting to start it if necessary |
|
88 // |
|
89 { |
|
90 TInt retry=2; |
|
91 for (;;) |
|
92 { |
|
93 TInt r=CreateSession(KCdlServerName,TVersion(0,0,0),1); |
|
94 if (r!=KErrNotFound && r!=KErrServerTerminated) |
|
95 return r; |
|
96 if (--retry==0) |
|
97 return r; |
|
98 r=StartServer(); |
|
99 if (r!=KErrNone && r!=KErrAlreadyExists) |
|
100 return r; |
|
101 } |
|
102 } |
|
103 |
|
104 void RCdlSession::RequestGetCustL(const CCdlUids& aUids, TInt& aCustSize) const |
|
105 { |
|
106 TPtrC8 ptr = aUids.Export(); |
|
107 TPckg<TInt> pckg(aCustSize); |
|
108 |
|
109 TIpcArgs p(&pckg, &ptr, ptr.Length()); |
|
110 User::LeaveIfError(SendReceive(ECdlServCmdRequestGetCust,p)); |
|
111 } |
|
112 |
|
113 TInt RCdlSession::GetCust(TDes8& aCust, TInt& aNewSize) const |
|
114 { |
|
115 TPckg<TInt> pckg(aNewSize); |
|
116 |
|
117 TIpcArgs p(&aCust, aCust.MaxLength(), &pckg); |
|
118 return SendReceive(ECdlServCmdGetCust,p); |
|
119 } |
|
120 |
|
121 void RCdlSession::SetUidsToNotifyL(const CCdlUids& aUids) |
|
122 { |
|
123 TPtrC8 ptr = aUids.Export(); |
|
124 |
|
125 TIpcArgs p(&ptr, ptr.Size()); |
|
126 User::LeaveIfError(SendReceive(ECdlServCmdSetUidsToNotify,p)); |
|
127 } |
|
128 |
|
129 void RCdlSession::NotifyChange(TRequestStatus& aStatus, TPckgBuf<SCdlServerChange>& aChange) |
|
130 { |
|
131 TIpcArgs p(&aChange); |
|
132 SendReceive(ECdlServCmdNotifyChange,p,aStatus); |
|
133 } |
|
134 |
|
135 void RCdlSession::CancelNotifyChange() const |
|
136 { |
|
137 SendReceive(ECdlServCmdCancelNotifyChange,TIpcArgs()); |
|
138 } |
|
139 |
|
140 void RCdlSession::SetCustL(const TDesC8& aCust) |
|
141 { |
|
142 TIpcArgs p(&aCust, aCust.Size()); |
|
143 User::LeaveIfError(SendReceive(ECdlServCmdSetCust,p)); |
|
144 } |
|
145 |
|
146 CCdlRefs* RCdlSession::FileContentsLC(const TDesC& aName) const |
|
147 { |
|
148 return GetRefsLC(KNullUid, aName, EFalse); |
|
149 } |
|
150 |
|
151 CCdlRefs* RCdlSession::FindInstancesLC(TUid aCdlUid) const |
|
152 { |
|
153 return GetRefsLC(aCdlUid, KNullDesC, ETrue); |
|
154 } |
|
155 |
|
156 CCdlRefs* RCdlSession::GetRefsLC(TUid aCdlUid, const TDesC& aName, TBool aByUid) const |
|
157 { |
|
158 TPckgBuf<TInt> refsSize; |
|
159 |
|
160 // get the server to export the refs to the temp buffer and return it's size. |
|
161 TIpcArgs p(&refsSize, aByUid ? 0 : &aName, aName.Length(), aCdlUid.iUid); |
|
162 User::LeaveIfError(SendReceive(ECdlServCmdGetRefsSize,p)); |
|
163 |
|
164 CCdlRefs* refs = CCdlRefs::NewLC(); |
|
165 |
|
166 // now get the temp buffer and import the refs. |
|
167 HBufC8* buf = GetTempBufLC(refsSize()); |
|
168 refs->ImportL(*buf); |
|
169 CleanupStack::PopAndDestroy(buf); |
|
170 |
|
171 return refs; |
|
172 } |
|
173 |
|
174 CCdlNames* RCdlSession::FindCustomisationFilesLC() const |
|
175 { |
|
176 TPckgBuf<TInt> namesSize; |
|
177 |
|
178 // get the server to export the files list to the temp buffer and return it's size |
|
179 TIpcArgs p(&namesSize); |
|
180 User::LeaveIfError(SendReceive(ECdlServCmdGetNamesSize,p)); |
|
181 |
|
182 CCdlNames* names = CCdlNames::NewLC(); |
|
183 |
|
184 // now get the temp buffer and import the names. |
|
185 HBufC8* buf = GetTempBufLC(namesSize()); |
|
186 names->ImportL(*buf); |
|
187 CleanupStack::PopAndDestroy(buf); |
|
188 |
|
189 return names; |
|
190 } |
|
191 |
|
192 // There are a number of commands that use a common temporary buffer in the server-side |
|
193 // session. This function gets that buffer. |
|
194 HBufC8* RCdlSession::GetTempBufLC(TInt aSize) const |
|
195 { |
|
196 HBufC8* buf = HBufC8::NewMaxLC(aSize); |
|
197 TPtr8 ptr = buf->Des(); |
|
198 TIpcArgs p(&ptr); |
|
199 User::LeaveIfError(SendReceive(ECdlServCmdGetTempBuf,p)); |
|
200 return buf; |
|
201 } |
|
202 |
|
203 CCdlRefs* RCdlSession::AllAvailableRefsLC() const |
|
204 { |
|
205 // get the server to export the refs to the temp buffer and return it's size. |
|
206 TPckgBuf<TInt> refsSize; |
|
207 TIpcArgs p(&refsSize); |
|
208 User::LeaveIfError(SendReceive(ECdlServCmdGetAllRefsSize,p)); |
|
209 |
|
210 CCdlRefs* refs = CCdlRefs::NewLC(); |
|
211 |
|
212 // now get the temp buffer and import the refs. |
|
213 HBufC8* buf = GetTempBufLC(refsSize()); |
|
214 refs->ImportL(*buf); |
|
215 CleanupStack::PopAndDestroy(buf); |
|
216 |
|
217 return refs; |
|
218 } |
|
219 |
|
220 TInt RCdlSession::IsPluginInRom(const TDesC& aFileName, TBool& aIsInRom) const |
|
221 { |
|
222 TPckg<TBool> isInRom(aIsInRom); |
|
223 TIpcArgs p(&aFileName, aFileName.Length(), &isInRom); |
|
224 return SendReceive(ECdlServCmdIsPluginInRom, p); |
|
225 } |
|
226 |
|
227 TInt RCdlSession::PluginDrive(const TDesC& aFileName, TDriveUnit& aDrive) const |
|
228 { |
|
229 TIpcArgs p(&aFileName, aFileName.Length()); |
|
230 TInt ret = SendReceive(ECdlServCmdPluginDrive, p); |
|
231 if (ret < KErrNone) |
|
232 return ret; |
|
233 aDrive = ret; |
|
234 return KErrNone; |
|
235 } |
|
236 |