|
1 /* |
|
2 * Copyright (c) 2003 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 |
|
19 #include "CdlServer.h" |
|
20 |
|
21 CCdlDllsWatcherBase::CCdlDllsWatcherBase(RFs& aFs) |
|
22 : CActive(CActive::EPriorityStandard), iFs(aFs) |
|
23 { |
|
24 CActiveScheduler::Add(this); |
|
25 } |
|
26 |
|
27 |
|
28 CCdlServer::CCdlServer() |
|
29 :CServer2(0) |
|
30 {} |
|
31 |
|
32 CCdlServer::~CCdlServer() |
|
33 { |
|
34 delete iDllWatcher; |
|
35 delete iAllRefs; |
|
36 delete iState; |
|
37 delete iEngRef; |
|
38 iFs.Close(); |
|
39 } |
|
40 |
|
41 CServer2* CCdlServer::NewLC() |
|
42 { |
|
43 CCdlServer* self=new(ELeave) CCdlServer; |
|
44 CleanupStack::PushL(self); |
|
45 self->ConstructL(); |
|
46 return self; |
|
47 } |
|
48 |
|
49 // |
|
50 // 2nd phase construction - ensure the timer and server objects are running |
|
51 // |
|
52 void CCdlServer::ConstructL() |
|
53 { |
|
54 StartL(KCdlServerName); |
|
55 iShutdown.ConstructL(); |
|
56 // ensure that the server still exits even if the 1st client fails to connect |
|
57 iShutdown.Start(); |
|
58 User::LeaveIfError(iFs.Connect()); |
|
59 iEngRef = CdlServerEngine::CreateCdlEngineL(); |
|
60 iState = CCdlRefs::NewL(); |
|
61 iAllRefs = CCdlRefs::NewL(); |
|
62 CCdlDllsWatcherBase::NewL(iDllWatcher, iFs, this); |
|
63 } |
|
64 |
|
65 |
|
66 // |
|
67 // Create a new client session. This should really check the version number. |
|
68 // |
|
69 CSession2* CCdlServer::NewSessionL(const TVersion& /*aVersion*/,const RMessage2& /*aMessage*/) const |
|
70 { |
|
71 return new(ELeave) CCdlSession(); |
|
72 } |
|
73 |
|
74 // |
|
75 // A new session is being created |
|
76 // Cancel the shutdown timer if it was running |
|
77 // |
|
78 void CCdlServer::AddSession() |
|
79 { |
|
80 ++iSessionCount; |
|
81 iShutdown.Cancel(); |
|
82 } |
|
83 |
|
84 // |
|
85 // A session is being destroyed |
|
86 // Start the shutdown timer if it is the last session. |
|
87 // |
|
88 void CCdlServer::DropSession() |
|
89 { |
|
90 if (--iSessionCount==0) |
|
91 iShutdown.Start(); |
|
92 } |
|
93 |
|
94 // |
|
95 // Handle an error from CCdlSession::ServiceL() |
|
96 // A bad descriptor error implies a badly programmed client, so panic it; |
|
97 // otherwise report the error to the client |
|
98 // |
|
99 TInt CCdlServer::RunError(TInt aError) |
|
100 { |
|
101 if (aError == KErrBadDescriptor) |
|
102 PanicClient(Message(),EPanicBadDescriptor); |
|
103 else if (aError == KErrArgument) |
|
104 PanicClient(Message(), EPanicParamOutOfRange); |
|
105 else |
|
106 Message().Complete(aError); |
|
107 // |
|
108 // The leave will result in an early return from CServer::RunL(), skipping |
|
109 // the call to request another message. So do that now in order to keep the |
|
110 // server running. |
|
111 ReStart(); |
|
112 return KErrNone; // handled the error fully |
|
113 } |
|
114 |
|
115 CCdlRefs* CCdlServer::GetStateLC(const CCdlUids& aUids) const |
|
116 { |
|
117 return iState->SubsetByUidsLC(aUids); |
|
118 } |
|
119 |
|
120 void CCdlServer::SetStateL(CCdlRefs* aState) |
|
121 { |
|
122 CCdlUids* uids = aState->UidsLC(); |
|
123 iState->MergeAndReplaceL(*aState); |
|
124 |
|
125 iSessionIter.SetToFirst(); |
|
126 CSession2* s; |
|
127 while ((s = iSessionIter++) != 0) |
|
128 static_cast<CCdlSession*>(s)->HandleCustChangeL(*uids); |
|
129 |
|
130 CleanupStack::PopAndDestroy(uids); |
|
131 } |
|
132 |
|
133 void CCdlServer::McdoPrepareForChangesL() |
|
134 { |
|
135 } |
|
136 |
|
137 void CCdlServer::McdoFileAddedL(const TDesC& aFile) |
|
138 { |
|
139 CCdlRefCollection* refs = FileContentsLC(aFile); |
|
140 iAllRefs->AppendL(*refs); |
|
141 CleanupStack::PopAndDestroy(refs); |
|
142 } |
|
143 |
|
144 void CCdlServer::McdoFileRemovedL(const TDesC& aFile) |
|
145 { |
|
146 iAllRefs->Delete(aFile); |
|
147 } |
|
148 |
|
149 void CCdlServer::McdoChangesCompleteL() |
|
150 { |
|
151 iSessionIter.SetToFirst(); |
|
152 CSession2* s; |
|
153 while ((s = iSessionIter++) != 0) |
|
154 static_cast<CCdlSession*>(s)->HandleRefsChangeL(); |
|
155 } |
|
156 |
|
157 const CCdlRefs& CCdlServer::AllRefs() const |
|
158 { |
|
159 return *iAllRefs; |
|
160 } |
|
161 |
|
162 TInt CCdlServer::IsPluginInRom(const TDesC& aFileName, TBool& aIsInRom) |
|
163 { |
|
164 return iDllWatcher->IsPluginInRom(aFileName, aIsInRom); |
|
165 } |
|
166 |
|
167 TInt CCdlServer::PluginDrive(const TDesC& aFileName, TDriveUnit& aDrive) |
|
168 { |
|
169 return iDllWatcher->PluginDrive(aFileName, aDrive); |
|
170 } |