1 /* |
|
2 * Copyright (c) 2005-2006 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: This class implemets the Default App Client API |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <apgcli.h> |
|
21 |
|
22 |
|
23 #include <das_client.h> |
|
24 #include "das_service.h" |
|
25 |
|
26 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
27 #include <apaid.h> |
|
28 #else |
|
29 #include <apaid.h> |
|
30 #include <apaidpartner.h> // new file introduced by xSymbian |
|
31 #endif |
|
32 |
|
33 const TUid KDefaultAppServiceUid = { 0x10281B9D }; |
|
34 |
|
35 |
|
36 |
|
37 // ======== MEMBER FUNCTIONS ======== |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // CDefaultAppClient::NewL() |
|
41 // |
|
42 // |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 EXPORT_C CDefaultAppClient* CDefaultAppClient::NewL( MAknServerAppExitObserver* aObserver ) |
|
46 { |
|
47 CDefaultAppClient* self = CDefaultAppClient::NewLC( aObserver ); |
|
48 CleanupStack::Pop( self ); |
|
49 return self; |
|
50 } |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // CDefaultAppClient::NewLC() |
|
54 // |
|
55 // |
|
56 // --------------------------------------------------------------------------- |
|
57 // |
|
58 EXPORT_C CDefaultAppClient* CDefaultAppClient::NewLC( MAknServerAppExitObserver* aObserver ) |
|
59 { |
|
60 CDefaultAppClient* self = new ( ELeave ) CDefaultAppClient; |
|
61 CleanupStack::PushL( self ); |
|
62 self->ConstructL( aObserver ); |
|
63 return self; |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // CDefaultAppClient::CDefaultAppClient() |
|
68 // Default constructor |
|
69 // |
|
70 // --------------------------------------------------------------------------- |
|
71 // |
|
72 CDefaultAppClient::CDefaultAppClient() |
|
73 { |
|
74 iServerAppUid.iUid = 0; |
|
75 } |
|
76 |
|
77 // --------------------------------------------------------------------------- |
|
78 // CDefaultAppClient::ConstructL() |
|
79 // |
|
80 // |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 void CDefaultAppClient::ConstructL( MAknServerAppExitObserver* aObserver ) |
|
84 { |
|
85 iObserver=aObserver; |
|
86 iService = new (ELeave) RDefaultAppService; |
|
87 } |
|
88 |
|
89 // --------------------------------------------------------------------------- |
|
90 // CDefaultAppClient::~CDefaultAppClient |
|
91 // |
|
92 // |
|
93 // --------------------------------------------------------------------------- |
|
94 // |
|
95 EXPORT_C CDefaultAppClient::~CDefaultAppClient() |
|
96 { |
|
97 if(iMonitor) |
|
98 { |
|
99 iMonitor->Cancel(); |
|
100 delete iMonitor; |
|
101 }; |
|
102 if(iService) |
|
103 { |
|
104 iService->Close(); |
|
105 delete iService; |
|
106 }; |
|
107 |
|
108 |
|
109 |
|
110 // iObserver is not owned |
|
111 } |
|
112 |
|
113 |
|
114 // --------------------------------------------------------------------------- |
|
115 // Function to check if a server is present in the system. If the |
|
116 // server is present, the subsequent functions should not fail due |
|
117 // to server unavailability. |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 EXPORT_C TBool CDefaultAppClient::ServiceAvailable(TInt& aErrorCode) |
|
121 { |
|
122 TRAP(aErrorCode,GetServiceParamsL(NULL)); |
|
123 if(aErrorCode != KErrNone) return EFalse; |
|
124 return ETrue; |
|
125 } |
|
126 |
|
127 // --------------------------------------------------------------------------- |
|
128 // Function to check the number of Service & MIME pairs the server would display if the |
|
129 // ChangeDefaultsL() would be called. The purpose of this function |
|
130 // is to allow the client application not to display an entry for starting the server, in the |
|
131 // Options menu, in case the Server's list of Service & MIME pairs is empty. |
|
132 // |
|
133 // Please note that the function may return a higher number than the actual number |
|
134 // of pairs, because it does not check for MIMEs with System priority (that would not be |
|
135 // displayed). |
|
136 // --------------------------------------------------------------------------- |
|
137 // |
|
138 EXPORT_C TInt CDefaultAppClient::PairsToDisplayL() |
|
139 { |
|
140 RApaLsSession ls; |
|
141 TInt i,j; |
|
142 TInt pairs=0; |
|
143 |
|
144 //Get own UID |
|
145 TUid clientAppUid = User::Identity(); |
|
146 |
|
147 //connect |
|
148 User::LeaveIfError(ls.Connect()); |
|
149 |
|
150 //we are connected, so some initialization |
|
151 CleanupClosePushL( ls ); |
|
152 User::LeaveIfError(ls.GetAllApps()); |
|
153 |
|
154 //get all services & MIMEs supported by our application |
|
155 CApaAppServiceInfoArray* servicesAndDataTypes=ls.GetAppServicesLC(clientAppUid); |
|
156 |
|
157 for(i=0; i<servicesAndDataTypes->Array().Count(); i++ ) |
|
158 { |
|
159 const TApaAppServiceInfo currentServiceInfo = servicesAndDataTypes->Array()[i]; |
|
160 for ( j = 0 ; j < currentServiceInfo.DataTypes().Count() ; j++ ) |
|
161 { |
|
162 //check if there are more than one applications supporting this Service & MIME pair |
|
163 CApaAppServiceInfoArray* apps=ls.GetServiceImplementationsLC(currentServiceInfo.Uid(),currentServiceInfo.DataTypes()[j].iDataType); |
|
164 |
|
165 if(apps->Array().Count()>1) |
|
166 { |
|
167 //more that one app handles this Service & MIME |
|
168 pairs++; |
|
169 }; |
|
170 |
|
171 CleanupStack::PopAndDestroy(apps); |
|
172 }; |
|
173 }; |
|
174 |
|
175 //clean |
|
176 CleanupStack::PopAndDestroy(servicesAndDataTypes); |
|
177 CleanupStack::PopAndDestroy(); // closes RApaLsSession |
|
178 |
|
179 return pairs; |
|
180 } |
|
181 |
|
182 // --------------------------------------------------------------------------- |
|
183 // This function launches the server, as a chained application. The client application will not be |
|
184 // available to the user until the server does not exit. |
|
185 // When the server exits, the client application gains control again. The observer (if specified |
|
186 // during instantiation (NewL) is notified that the server has exited. |
|
187 // --------------------------------------------------------------------------- |
|
188 // |
|
189 EXPORT_C void CDefaultAppClient::ChangeDefaultsL( TInt aFlags ) |
|
190 { |
|
191 if(iServerAppUid.iUid == 0) |
|
192 GetServiceParamsL( &iServerAppUid ); |
|
193 |
|
194 iService->ConnectChainedAppL(iServerAppUid); |
|
195 |
|
196 if(iObserver) |
|
197 iMonitor = CApaServerAppExitMonitor::NewL(*iService, *iObserver, CActive::EPriorityStandard); |
|
198 else |
|
199 aFlags|=EFlagNoObserver; |
|
200 |
|
201 iService->SetDefault(aFlags); |
|
202 } |
|
203 |
|
204 |
|
205 |
|
206 // --------------------------------------------------------------------------- |
|
207 // This function finds out the uid of the Default Application Server |
|
208 // (the application registered to handle the DefaultApp service) |
|
209 // --------------------------------------------------------------------------- |
|
210 // |
|
211 void CDefaultAppClient::GetServiceParamsL( TUid *aServerAppUid) |
|
212 { |
|
213 CApaAppServiceInfoArray* services = NULL; |
|
214 RApaLsSession ls; |
|
215 TInt count = 0; //number of services found so far. |
|
216 |
|
217 User::LeaveIfError(ls.Connect()); |
|
218 CleanupClosePushL( ls ); |
|
219 |
|
220 User::LeaveIfError(ls.GetServerApps( KDefaultAppServiceUid )); |
|
221 |
|
222 services = ls.GetServiceImplementationsLC( KDefaultAppServiceUid ); |
|
223 |
|
224 if( services ) |
|
225 { |
|
226 count = services->Array().Count(); |
|
227 // get the server's Uid |
|
228 if( aServerAppUid ) |
|
229 aServerAppUid->iUid = services->Array()[0].Uid().iUid; |
|
230 }; |
|
231 CleanupStack::PopAndDestroy( 2 ); // destroys services + closes RApaLsSession |
|
232 |
|
233 if ( count == 0) User::Leave(KErrNotFound); |
|
234 if ( count > 1) User::Leave(KErrNotSupported); |
|
235 |
|
236 // if we are here, it means that we have a single server handling the defaults |
|
237 } |
|
238 |
|
239 |
|
240 |
|
241 |
|