|
1 /* |
|
2 * Copyright (c) 2005-2009 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 the License "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 /** |
|
20 @file |
|
21 */ |
|
22 |
|
23 #include "sishelperclient.h" |
|
24 #include "sishelper.h" |
|
25 |
|
26 #include <e32base.h> |
|
27 #include <f32file.h> |
|
28 #include <e32math.h> |
|
29 |
|
30 void MainL(); |
|
31 |
|
32 using namespace Swi; |
|
33 |
|
34 GLDEF_D TInt E32Main() |
|
35 { |
|
36 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
37 if(cleanup == NULL) |
|
38 { |
|
39 return KErrNoMemory; |
|
40 } |
|
41 |
|
42 TRAPD(err,MainL()); |
|
43 delete cleanup; |
|
44 return err; |
|
45 } |
|
46 |
|
47 HBufC* GetDesParameterL(TInt aParam) |
|
48 { |
|
49 // Get buffer from parameter passed |
|
50 TInt length=User::ParameterLength(aParam); |
|
51 User::LeaveIfError(length); |
|
52 |
|
53 HBufC* des=HBufC::NewLC(length); |
|
54 TPtr desPtr=des->Des(); |
|
55 User::LeaveIfError(User::GetDesParameter(aParam, desPtr)); |
|
56 |
|
57 CleanupStack::Pop(des); |
|
58 return des; |
|
59 } |
|
60 |
|
61 TInt SisHelperThreadFunction(TAny *aPtr) |
|
62 { |
|
63 if (aPtr==NULL) |
|
64 return KErrArgument; |
|
65 |
|
66 __UHEAP_MARK; |
|
67 CTrapCleanup* cleanup = CTrapCleanup::New(); // get clean-up stack |
|
68 |
|
69 TSisHelperStartParams* params= |
|
70 static_cast<TSisHelperStartParams*>(aPtr); |
|
71 |
|
72 CActiveScheduler* scheduler=new CActiveScheduler; |
|
73 |
|
74 CActiveScheduler::Install(scheduler); |
|
75 CSisHelperServer* server=NULL; |
|
76 |
|
77 TRAPD(err, server=CSisHelperServer::NewL(*params)); |
|
78 |
|
79 if (err==KErrNone) |
|
80 { |
|
81 // only continue launching the server if no error |
|
82 RThread::Rendezvous(KErrNone); |
|
83 scheduler->Start(); |
|
84 CActiveScheduler::Install(NULL); |
|
85 } |
|
86 |
|
87 delete server; |
|
88 delete scheduler; |
|
89 delete cleanup; // destroy clean-up stack |
|
90 __UHEAP_MARKEND; |
|
91 |
|
92 return err; |
|
93 } |
|
94 |
|
95 TInt StartSisHelper(TSisHelperStartParams& aParams) |
|
96 { |
|
97 // To deal with the unique thread (+semaphore!) naming in Symbian OS, and |
|
98 // that we may be trying to restart a server that has just exited we |
|
99 // attempt to create a unique thread name for the server |
|
100 TName name(KSisHelperServerName); |
|
101 name.AppendNum(Math::Random(), EHex); |
|
102 RThread server; |
|
103 const TInt KSisHelperServerStackSize=0x2000; |
|
104 const TInt KSisHelperServerInitHeapSize=0x1000; |
|
105 const TInt KSisHelperServerMaxHeapSize=0x1000000; |
|
106 TInt err=server.Create(name, SisHelperThreadFunction, |
|
107 KSisHelperServerStackSize, KSisHelperServerInitHeapSize, |
|
108 KSisHelperServerMaxHeapSize, static_cast<TAny*>(&aParams), |
|
109 EOwnerProcess); |
|
110 if (err!=KErrNone && err!=KErrAlreadyExists) |
|
111 return err; |
|
112 |
|
113 // The following code is the same whether the server runs in a new thread |
|
114 // or process |
|
115 TRequestStatus stat; |
|
116 server.Rendezvous(stat); |
|
117 if (stat!=KRequestPending) |
|
118 server.Kill(0); // abort startup |
|
119 else |
|
120 server.Resume(); // logon OK, start the server |
|
121 User::WaitForRequest(stat); // wait for start or death |
|
122 |
|
123 RProcess::Rendezvous(stat.Int()); |
|
124 if (stat.Int()==KErrNone) |
|
125 { |
|
126 server.Logon(stat); |
|
127 User::WaitForRequest(stat); |
|
128 } |
|
129 |
|
130 // we can't use the 'exit reason' if the server panicked as this is the |
|
131 // panic 'reason' and may be 0 which cannot be distinguished from KErrNone |
|
132 err=(server.ExitType()==EExitPanic) ? KErrGeneral : stat.Int(); |
|
133 server.Close(); |
|
134 return err; |
|
135 } |
|
136 |
|
137 void MainL() |
|
138 { |
|
139 HBufC* fileName=GetDesParameterL(7); |
|
140 CleanupStack::PushL(fileName); |
|
141 TSisHelperStartParams params(*fileName); |
|
142 User::LeaveIfError(StartSisHelper(params)); |
|
143 CleanupStack::PopAndDestroy(fileName); |
|
144 } |