|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 */ |
|
19 |
|
20 #include <amastartcli.h> |
|
21 #include "amastartconst.h" |
|
22 #include "amastartsrv.h" |
|
23 |
|
24 |
|
25 |
|
26 EXPORT_C RAmaStartSession::RAmaStartSession() |
|
27 : RSessionBase(), iVersion( KAmaStartCliVersionMajor, KAmaStartCliVersionMinor, KAmaStartCliVersionBuild ), iClientStatus( NULL ) |
|
28 { |
|
29 DEBUGPRINT1A( ">RAmaStartSession::RAmaStartSession> (Empty constructor)"); |
|
30 } //lint !e1401 not initialized by constructor (iSpare) |
|
31 |
|
32 |
|
33 |
|
34 /** |
|
35 * Connect to the AmaStart server. If the server is not found, this function will attempt to start it |
|
36 * and then connect. |
|
37 */ |
|
38 EXPORT_C TInt RAmaStartSession::Connect() |
|
39 { |
|
40 DEBUGPRINT1A( ">RAmaStartSession::Connect") ; |
|
41 |
|
42 TInt err = CreateSession(KAmaStartSrvName, iVersion, KAmaStartSrvMsgSlots); |
|
43 if( (KErrNotFound == err) || (KErrServerTerminated == err) ) |
|
44 { |
|
45 err = CAmaStartServer::StartAmaStartSrv(); |
|
46 if (err != KErrNone) |
|
47 { |
|
48 DEBUGPRINT1A( "RAmaStartSession::Connect> (Error starting server thread)") ; |
|
49 return err; |
|
50 } |
|
51 |
|
52 err = CreateSession(KAmaStartSrvName, iVersion, KAmaStartSrvMsgSlots); |
|
53 } |
|
54 |
|
55 DEBUGPRINT1A( "RAmaStartSession::Connect>") ; |
|
56 return err; |
|
57 } |
|
58 |
|
59 |
|
60 |
|
61 EXPORT_C void RAmaStartSession::Close() |
|
62 { |
|
63 DEBUGPRINT1A( ">RAmaStartSession::Close") ; |
|
64 // Guard against illegal operations if non-open. |
|
65 if( Handle() ) |
|
66 { |
|
67 StartDscCancel(); |
|
68 } |
|
69 |
|
70 RSessionBase::Close(); |
|
71 DEBUGPRINT1A( "RAmaStartSession::Close>") ; |
|
72 } |
|
73 |
|
74 |
|
75 |
|
76 /** |
|
77 * Sends the UID of a DSC to the server for its items to be launched. |
|
78 * The system currently only supports one call per client session. |
|
79 * |
|
80 * @param aDscId The UID for the DSC to be launched. |
|
81 * @param aStatus The TRequestStatus which will be completed by server-side code when |
|
82 * list execution is complete. KErrNone if list execution is successful. A system-wide error code |
|
83 * in case of error. KErrCancel if a call is made to StartDscCancel() during list processing. |
|
84 */ |
|
85 EXPORT_C void RAmaStartSession::StartDsc( const TUid& aDscId, TRequestStatus& aStatus ) |
|
86 { |
|
87 DEBUGPRINT1A( ">RAmaStartSession::StartDsc") ; |
|
88 iClientStatus = &aStatus; |
|
89 |
|
90 TBool dscExists = ETrue; |
|
91 |
|
92 TRAPD(err, dscExists = CheckDscExistsL(aDscId)); |
|
93 if (KErrNone != err) |
|
94 { |
|
95 User::RequestComplete(iClientStatus, err); |
|
96 DEBUGPRINT1A( "RAmaStartSession::StartDsc> (Error checking that DSC exists") ; |
|
97 return; |
|
98 } |
|
99 if (!dscExists) |
|
100 { |
|
101 User::RequestComplete(iClientStatus, KErrArgument); |
|
102 DEBUGPRINT1A( "RAmaStartSession::StartDsc> (DSC does not exist)") ; |
|
103 return; |
|
104 } |
|
105 |
|
106 |
|
107 |
|
108 TIpcArgs args( aDscId.iUid ); |
|
109 SendReceive( EAmaStartSrvStartDsc, args, aStatus ); |
|
110 |
|
111 DEBUGPRINT1A( "RAmaStartSession::StartDsc>") ; |
|
112 } |
|
113 |
|
114 |
|
115 |
|
116 /** |
|
117 * Cancels a currently executing DSC. |
|
118 * |
|
119 * @see StartDscL() |
|
120 */ |
|
121 EXPORT_C void RAmaStartSession::StartDscCancel() |
|
122 { |
|
123 DEBUGPRINT1A( ">RAmaStartSession::StartDscCancel") ; |
|
124 __ASSERT_DEBUG( Handle(), User::Panic( KAmaStartHandleNotOpen, KAmaStartSrvHandleNotOpen) ); |
|
125 |
|
126 if( iClientStatus && (iClientStatus->Int() == KRequestPending) && Handle() ) |
|
127 { |
|
128 SendReceive( EAmaStartSrvStartDscCancel ); |
|
129 } |
|
130 |
|
131 iClientStatus = NULL; |
|
132 |
|
133 DEBUGPRINT1A( "RAmaStartSession::StartDscCancel>") ; |
|
134 } |
|
135 |
|
136 TBool RAmaStartSession::CheckDscExistsL(const TUid& aDscId) |
|
137 { |
|
138 DEBUGPRINT1A( ">RAmaStartSession::CheckDscExistsL") ; |
|
139 |
|
140 RDscStore store; |
|
141 store.OpenL(); |
|
142 CleanupClosePushL(store); |
|
143 TBool result = store.DscExistsL(aDscId); |
|
144 CleanupStack::PopAndDestroy(/*store*/); |
|
145 |
|
146 DEBUGPRINT1A( "RAmaStartSession::CheckDscExistsL>"); |
|
147 return result; |
|
148 } |