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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <e32cmn.h> |
|
19 #include "stubclient.h" |
|
20 #include "stubclientsrv.h" |
|
21 |
|
22 _LIT(KStubSrvExe, "stubsrv.exe"); |
|
23 static TInt ClientStart() |
|
24 { |
|
25 RProcess server; |
|
26 TInt r = server.Create(KStubSrvExe, KNullDesC, TUidType(KNullUid, KNullUid, KStubSrvUid3)); |
|
27 if (r!=KErrNone) |
|
28 return r; |
|
29 TRequestStatus stat; |
|
30 server.Rendezvous(stat); |
|
31 if (stat != KRequestPending) |
|
32 server.Kill(0); |
|
33 else |
|
34 server.Resume(); |
|
35 User::WaitForRequest(stat); |
|
36 r = (server.ExitType() == EExitPanic) ? KErrGeneral : stat.Int(); |
|
37 server.Close(); |
|
38 return r; |
|
39 } |
|
40 |
|
41 void RStubClient::EnqueBehavior(const TApiBehavior& aBeh, TInt aExeDuration) |
|
42 { |
|
43 CheckSession(); |
|
44 TApiBehaviorPckgBuf buf(aBeh); |
|
45 (void) SendReceive(EStubSrvEnqueApiBehavior, TIpcArgs(&buf, aExeDuration)); |
|
46 } |
|
47 |
|
48 void RStubClient::DeleteBehaviors(TUint aLib, TUint aApi) |
|
49 { |
|
50 CheckSession(); |
|
51 (void) SendReceive(EStubSrvDeleteApiBehaviors, TIpcArgs(aLib, aApi)); |
|
52 } |
|
53 |
|
54 void RStubClient::InvokeApi(TApiBehaviorPckg& aBehPckg, TApiInvokeMode aMode) |
|
55 { |
|
56 CheckSession(); |
|
57 (void) SendReceive(EStubSrvInvokeApi, TIpcArgs(&aBehPckg, aMode, 0)); |
|
58 } |
|
59 |
|
60 void RStubClient::InvokeApiL(TApiBehaviorPckg& aBehPckg, TRequestStatus& aStatus, TApiInvokeMode aMode) |
|
61 { |
|
62 CheckSession(); |
|
63 TInt transctionId = 0; |
|
64 TPckg<TInt> transpckg(transctionId); |
|
65 TInt err = SendReceive(EStubSrvGetApiCompletionCode, TIpcArgs(aBehPckg().iLib, aBehPckg().iApi, &transpckg)); |
|
66 if (err) |
|
67 { |
|
68 User::Leave(err); |
|
69 } |
|
70 SendReceive(EStubSrvInvokeApi, TIpcArgs(&aBehPckg, aMode, transctionId), aStatus); |
|
71 } |
|
72 |
|
73 void RStubClient::InvokeApiCancel(TUint aLib, TUint aApi) |
|
74 { |
|
75 CheckSession(); |
|
76 (void) SendReceive(EStubSrvInvokeApiCancel, TIpcArgs(aLib, aApi)); |
|
77 } |
|
78 |
|
79 TInt RStubClient::Connect() |
|
80 { |
|
81 TInt retVal = CreateSession(KStubSrvName, Version()); |
|
82 if (retVal) |
|
83 { |
|
84 retVal = ClientStart(); |
|
85 if (!retVal) |
|
86 retVal = CreateSession(KStubSrvName, Version()); |
|
87 } |
|
88 return retVal; |
|
89 } |
|
90 |
|
91 TVersion RStubClient::Version() const |
|
92 { |
|
93 return(TVersion(KStubSrvMajorVersionNumber, KStubSrvMinorVersionNumber, KStubSrvBuildNumber)); |
|
94 } |
|
95 |
|
96 _LIT(KPanicCat, "!Stubsrv"); |
|
97 |
|
98 void RStubClient::CheckSession() |
|
99 { |
|
100 if (!Handle()) |
|
101 User::Panic(KPanicCat, KErrBadHandle); |
|
102 } |
|