|
1 /* |
|
2 * Copyright (c) 2006-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 #include <e32std.h> |
|
20 #include "tintegrityservicesclientserver.h" |
|
21 #include "tintegrityservicesserver.h" |
|
22 #include "log.h" |
|
23 #include <e32uid.h> |
|
24 #include <e32debug.h> |
|
25 |
|
26 using namespace Swi; |
|
27 using namespace Swi::Test; |
|
28 |
|
29 // |
|
30 // Starts the IntegrityServices Server in a new process |
|
31 // |
|
32 static TInt StartIntegrityServicesServer() |
|
33 { |
|
34 const TUidType serverUid(KExecutableImageUid, KNullUid, KIntegrityServicesServerUid3); |
|
35 RProcess server; |
|
36 TInt err = server.Create(KIntegrityServicesServerImage, KNullDesC); |
|
37 |
|
38 if (err != KErrNone) |
|
39 { |
|
40 RDebug::Print(_L("StartIntegrityServicesServer: %d"), err); |
|
41 return err; |
|
42 } |
|
43 |
|
44 TRequestStatus stat; |
|
45 server.Rendezvous(stat); |
|
46 |
|
47 if (stat != KRequestPending) |
|
48 { |
|
49 server.Kill(0); // abort startup |
|
50 } |
|
51 else |
|
52 { |
|
53 server.Resume(); // logon OK, start the server |
|
54 } |
|
55 |
|
56 User::WaitForRequest(stat); // wait for start or death |
|
57 // We can't use the 'exit reason' if the server panicked as this is the |
|
58 // panic 'reason' and may be 0 which cannot be distinguished from KErrNone. |
|
59 err = (server.ExitType() == EExitPanic) ? KErrGeneral : stat.Int(); |
|
60 server.Close(); |
|
61 return err; |
|
62 } |
|
63 |
|
64 EXPORT_C TInt RIntegrityServicesServerSession::Connect() |
|
65 { |
|
66 TInt retry = 2; |
|
67 RDebug::Print(_L("RIntegrityServicesServerSession::Connect:")); |
|
68 // DEBUG_PRINTF(_L("RIntegrityServicesServerSession::Connect:")); |
|
69 for(;;) |
|
70 { |
|
71 TInt err = CreateSession(KIntegrityServicesServerName, TVersion(0,0,0), 1); |
|
72 if (err != KErrNotFound && err != KErrServerTerminated) |
|
73 { |
|
74 RDebug::Print(_L("RIntegrityServicesServerSession::Connect: %d"), err); |
|
75 return err; |
|
76 } |
|
77 |
|
78 if (--retry == 0) |
|
79 { |
|
80 return err; |
|
81 } |
|
82 |
|
83 err = StartIntegrityServicesServer(); |
|
84 if (err != KErrNone && err != KErrAlreadyExists) |
|
85 { |
|
86 return err; |
|
87 } |
|
88 } |
|
89 } |
|
90 |
|
91 EXPORT_C void RIntegrityServicesServerSession::AddL(const TDesC& aFileName) |
|
92 { |
|
93 RDebug::Print(_L("RIntegrityServicesServerSession::AddL: %S"), &aFileName); |
|
94 |
|
95 User::LeaveIfError(SendReceive(EAdd, TIpcArgs(&aFileName))); |
|
96 } |
|
97 |
|
98 EXPORT_C void RIntegrityServicesServerSession::RemoveL(const TDesC& aFileName) |
|
99 { |
|
100 RDebug::Print(_L("RIntegrityServicesServerSession::Remove: %S"), &aFileName); |
|
101 |
|
102 User::LeaveIfError(SendReceive(ERemove, TIpcArgs(&aFileName))); |
|
103 } |
|
104 |
|
105 EXPORT_C void RIntegrityServicesServerSession::TemporaryL(const TDesC& aFileName) |
|
106 { |
|
107 RDebug::Print(_L("RIntegrityServicesServerSession::TemporaryL: %S"), &aFileName); |
|
108 |
|
109 User::LeaveIfError(SendReceive(ETemporary, TIpcArgs(&aFileName))); |
|
110 } |
|
111 |
|
112 EXPORT_C void RIntegrityServicesServerSession::CommitL() |
|
113 { |
|
114 DEBUG_PRINTF(_L("RIntegrityServicesServerSession::CommitL: ")); |
|
115 |
|
116 User::LeaveIfError(SendReceive(ECommit)); |
|
117 } |
|
118 |
|
119 EXPORT_C void RIntegrityServicesServerSession::RollBackL(TBool aAllTransactions) |
|
120 { |
|
121 RDebug::Print(_L("RIntegrityServicesServerSession::RollBackL: %d"), aAllTransactions); |
|
122 TPckg<TBool> all(aAllTransactions); |
|
123 |
|
124 User::LeaveIfError(SendReceive(ERollBack, TIpcArgs(&all))); |
|
125 } |
|
126 |
|
127 EXPORT_C void RIntegrityServicesServerSession::SetSimulatedFailure(TPtrC aFailType, TPtrC aFailPosition, TPtrC aFileName) |
|
128 { |
|
129 RDebug::Print(_L("RIntegrityServicesServerSession::SetSimulatedFailure: %S %S %S"), &aFailType, &aFailPosition, &aFileName); |
|
130 |
|
131 User::LeaveIfError(SendReceive(ESetSimulatedFailure, TIpcArgs(&aFailType, &aFailPosition, &aFileName))); |
|
132 } |
|
133 |
|
134 EXPORT_C void RIntegrityServicesServerSession::CreateNewTestFileL(const TDesC& aFileName) |
|
135 { |
|
136 RDebug::Print(_L("RIntegrityServicesServerSession::CreateNewTestFileL: %S"), &aFileName); |
|
137 |
|
138 User::LeaveIfError(SendReceive(ECreateNewTestFile, TIpcArgs(&aFileName))); |
|
139 } |
|
140 |
|
141 EXPORT_C void RIntegrityServicesServerSession::CreateTempTestFileL(const TDesC& aFileName) |
|
142 { |
|
143 RDebug::Print(_L("RIntegrityServicesServerSession::CreateTempTestFileL: %S"), &aFileName); |
|
144 |
|
145 User::LeaveIfError(SendReceive(ECreateTempTestFile, TIpcArgs(&aFileName))); |
|
146 } |