1 /* |
|
2 * Copyright (c) 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 "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: CSconSyncServer implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "sconsyncserver.h" |
|
20 #include "sconsyncclientserver.h" |
|
21 |
|
22 #include "sconsyncsession.h" |
|
23 #include "debug.h" |
|
24 |
|
25 const TInt KSConPCConnServerUid = 0x101F99F6; |
|
26 |
|
27 // Security policy |
|
28 const TUint KServerPolicyRangeCount = 2; |
|
29 |
|
30 const TInt KServerPolicyRanges[KServerPolicyRangeCount] = |
|
31 { |
|
32 0, // range is 0 inclusive |
|
33 EMaxService // range is 1-KMaxTInt inclusive |
|
34 }; |
|
35 |
|
36 const TUint8 KServerPolicyElementsIndex[KServerPolicyRangeCount] = |
|
37 { |
|
38 0, // applies to 0th range |
|
39 CPolicyServer::ENotSupported // applies to 1st range |
|
40 }; |
|
41 |
|
42 const CPolicyServer::TPolicyElement KServerPolicyElements[] = |
|
43 { |
|
44 { _INIT_SECURITY_POLICY_S0(KSConPCConnServerUid) /*_INIT_SECURITY_POLICY_C1(ECapabilityReadDeviceData)*/, CPolicyServer::EFailClient } |
|
45 }; |
|
46 |
|
47 const CPolicyServer::TPolicy KServerPolicy = |
|
48 { |
|
49 0 /*CPolicyServer::EAlwaysPass*/, // specifies all connect attempts should pass |
|
50 KServerPolicyRangeCount, |
|
51 KServerPolicyRanges, |
|
52 KServerPolicyElementsIndex, |
|
53 KServerPolicyElements |
|
54 }; |
|
55 |
|
56 |
|
57 CSconSyncServer* CSconSyncServer::NewL() |
|
58 { |
|
59 CSconSyncServer* self = NewLC(); |
|
60 CleanupStack::Pop(self); |
|
61 return self; |
|
62 } |
|
63 |
|
64 CSconSyncServer* CSconSyncServer::NewLC() |
|
65 { |
|
66 CSconSyncServer* self = new(ELeave) CSconSyncServer(); |
|
67 CleanupStack::PushL(self); |
|
68 self->ConstructL(); |
|
69 return self; |
|
70 } |
|
71 |
|
72 CSconSyncServer::CSconSyncServer() : |
|
73 CPolicyServer(EPriorityStandard, KServerPolicy, ESharableSessions) |
|
74 { |
|
75 } |
|
76 |
|
77 void CSconSyncServer::ConstructL() |
|
78 { |
|
79 TRACE_FUNC_ENTRY; |
|
80 TInt error = Start(KSconSyncServerName); |
|
81 |
|
82 if (error != KErrNone) |
|
83 { |
|
84 User::Panic(KSconSyncServerName, error); |
|
85 } |
|
86 TRACE_FUNC_EXIT; |
|
87 } |
|
88 |
|
89 CSconSyncServer::~CSconSyncServer() |
|
90 { |
|
91 TRACE_FUNC; |
|
92 } |
|
93 |
|
94 CSession2* CSconSyncServer::NewSessionL(const TVersion& aVersion, const RMessage2& /*aMessage*/) const |
|
95 { |
|
96 TRACE_FUNC; |
|
97 TVersion v(1,0,0); |
|
98 if ( !User::QueryVersionSupported(v,aVersion) ) |
|
99 { |
|
100 TVersionName vname = aVersion.Name(); |
|
101 LOGGER_WRITE_1("Client has wrong version: %S", &vname); |
|
102 User::Leave( KErrNotSupported ); |
|
103 } |
|
104 |
|
105 return CSconSyncSession::NewL(); |
|
106 } |
|
107 |
|
108 TInt CSconSyncServer::RunError(TInt aError) |
|
109 { |
|
110 TRACE_FUNC_ENTRY; |
|
111 LOGGER_WRITE_1("aError: %d", aError); |
|
112 // Bad descriptor implies bad client |
|
113 if (aError == KErrBadDescriptor) |
|
114 { |
|
115 Message().Panic(KSconSyncServerName, aError); |
|
116 } |
|
117 else |
|
118 { |
|
119 Message().Complete(aError); |
|
120 } |
|
121 |
|
122 // Continue handling requests |
|
123 ReStart(); |
|
124 TRACE_FUNC_EXIT; |
|
125 return KErrNone; |
|
126 } |
|
127 |
|
128 void CSconSyncServer::AddSession() |
|
129 { |
|
130 ++iSessionCount; |
|
131 LOGGER_WRITE_1("CSconSyncServer::AddSession(), iSessionCount: %d", iSessionCount); |
|
132 } |
|
133 |
|
134 void CSconSyncServer::RemoveSession() |
|
135 { |
|
136 --iSessionCount; |
|
137 LOGGER_WRITE_1("CSconSyncServer::RemoveSession(), iSessionCount: %d", iSessionCount); |
|
138 if (iSessionCount == 0) |
|
139 { |
|
140 CActiveScheduler::Stop(); |
|
141 } |
|
142 } |
|
143 |
|
144 LOCAL_C void ExeMainL() |
|
145 { |
|
146 TRACE_FUNC_ENTRY; |
|
147 // Install active scheduler |
|
148 CActiveScheduler* scheduler = new(ELeave) CActiveScheduler; |
|
149 CleanupStack::PushL(scheduler); |
|
150 CActiveScheduler::Install(scheduler); |
|
151 |
|
152 CSconSyncServer::NewLC(); |
|
153 |
|
154 User::LeaveIfError(User::RenameThread(KSconSyncServerName)); |
|
155 RProcess::Rendezvous(KErrNone); |
|
156 |
|
157 CActiveScheduler::Start(); |
|
158 |
|
159 CleanupStack::PopAndDestroy(); // CSconSyncServer |
|
160 CleanupStack::PopAndDestroy(); // CActiveScheduler |
|
161 TRACE_FUNC_EXIT; |
|
162 } |
|
163 |
|
164 GLDEF_C TInt E32Main() |
|
165 { |
|
166 TRACE_FUNC_ENTRY; |
|
167 __UHEAP_MARK; |
|
168 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
169 |
|
170 TRAPD(error, ExeMainL()); |
|
171 __ASSERT_ALWAYS(!error, User::Panic(KSconSyncServerName, error)); |
|
172 |
|
173 delete cleanup; |
|
174 __UHEAP_MARKEND; |
|
175 TRACE_FUNC_EXIT; |
|
176 return 0; |
|
177 } |
|