|
1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 |
|
17 #include <mtp/tmtptypeevent.h> |
|
18 #include <mtp/tmtptypeuint32.h> |
|
19 #include <mtp/mmtpdataproviderframework.h> |
|
20 #include <mtp/mmtpobjectmgr.h> |
|
21 #include <mtp/mmtpstoragemgr.h> |
|
22 #include <mtp/cmtpobjectmetadata.h> |
|
23 #include <mtp/mmtpconnection.h> |
|
24 |
|
25 #include "ptpdef.h" |
|
26 #include "cptpserver.h" |
|
27 #include "mtppictbridgedpconst.h" |
|
28 #include "cmtppictbridgeprinter.h" |
|
29 |
|
30 _LIT(KPtpFolder, "_Ptp\\"); |
|
31 |
|
32 // -------------------------------------------------------------------------- |
|
33 // |
|
34 // 2-phased constructor. |
|
35 // -------------------------------------------------------------------------- |
|
36 // |
|
37 CPtpServer* CPtpServer::NewL(MMTPDataProviderFramework& aFramework, CMTPPictBridgeDataProvider& aDataProvider) |
|
38 { |
|
39 CPtpServer* self = new (ELeave) CPtpServer(aFramework, aDataProvider); |
|
40 CleanupStack::PushL(self); |
|
41 self->ConstructL(); |
|
42 self->StartL( KPTPServer ); |
|
43 CleanupStack::Pop(self); |
|
44 return self; |
|
45 } |
|
46 |
|
47 // -------------------------------------------------------------------------- |
|
48 // |
|
49 // C++ constructor. |
|
50 // -------------------------------------------------------------------------- |
|
51 // |
|
52 CPtpServer::CPtpServer(MMTPDataProviderFramework& aFramework, CMTPPictBridgeDataProvider& aDataProvider) : CServer2(EPriorityStandard), |
|
53 iFramework(aFramework), |
|
54 iDataProvider(aDataProvider) |
|
55 { |
|
56 } |
|
57 |
|
58 // -------------------------------------------------------------------------- |
|
59 // |
|
60 // 2nd phase constructor. |
|
61 // -------------------------------------------------------------------------- |
|
62 // |
|
63 void CPtpServer::ConstructL() |
|
64 { |
|
65 __FLOG_OPEN(KMTPSubsystem, KPtpServerLog); |
|
66 __FLOG(_L8(">>>CPtpServer::ConstructL")); |
|
67 iFileMan = CFileMan::NewL(iFramework.Fs()); |
|
68 iPtpFolder = PathInfo::PhoneMemoryRootPath(); |
|
69 iPtpFolder.Append( PathInfo::ImagesPath()); |
|
70 iPtpFolder.Append(KPtpFolder); |
|
71 iFileMan->RmDir(iPtpFolder); |
|
72 Framework().Fs().MkDirAll(iPtpFolder); |
|
73 |
|
74 iPrinterP = CMTPPictBridgePrinter::NewL(*this); |
|
75 __FLOG(_L8("<<<CPtpServer::ConstructL")); |
|
76 } |
|
77 |
|
78 |
|
79 // -------------------------------------------------------------------------- |
|
80 // |
|
81 // C++ destructor. |
|
82 // -------------------------------------------------------------------------- |
|
83 // |
|
84 CPtpServer::~CPtpServer() |
|
85 { |
|
86 __FLOG(_L8(">>>CPtpServer::~")); |
|
87 delete iPrinterP; |
|
88 iPrinterP = NULL; |
|
89 delete iFileMan; |
|
90 iFileMan = NULL; |
|
91 __FLOG(_L8("<<<CPtpServer::~")); |
|
92 __FLOG_CLOSE; |
|
93 } |
|
94 |
|
95 |
|
96 // ---------------------------------------------------------------------------- |
|
97 // |
|
98 // from CServer2, creates a new session. |
|
99 // ---------------------------------------------------------------------------- |
|
100 // |
|
101 CSession2* CPtpServer::NewSessionL(const TVersion& aVersion, |
|
102 const RMessage2& /*aMessage*/) const |
|
103 { |
|
104 __FLOG(_L8(">>>CPtpServer::NewSessionL")); |
|
105 TVersion v(KPtpServerVersionMajor, KPtpServerVersionMinor, 0); |
|
106 if (!User::QueryVersionSupported(v,aVersion)) |
|
107 { |
|
108 __FLOG(_L8("!!!!Error: CPtpServer::NewSessionL version not support!")); |
|
109 User::Leave(KErrNotSupported); |
|
110 } |
|
111 if (iNumSession>0) |
|
112 { |
|
113 __FLOG(_L8("!!!!Error: CPtpServer::NewSessionL session is in use!")); |
|
114 User::Leave(KErrInUse); |
|
115 } |
|
116 CPtpSession* session = CPtpSession::NewL(const_cast<CPtpServer*>(this)); |
|
117 __FLOG(_L8("<<<CPtpServer::NewSessionL")); |
|
118 return session; |
|
119 } |
|
120 |
|
121 // -------------------------------------------------------------------------- |
|
122 // CPtpServer::GetObjectHandleByNameL() |
|
123 // Returns object handle |
|
124 // -------------------------------------------------------------------------- |
|
125 // |
|
126 void CPtpServer::GetObjectHandleByNameL(const TDesC& aNameAndPath, TUint32& aHandle) |
|
127 { |
|
128 __FLOG_VA((_L16(">> CPtpServer::GetObjectHandleByNameL %S"), &aNameAndPath)); |
|
129 aHandle=Framework().ObjectMgr().HandleL(aNameAndPath); |
|
130 __FLOG_VA((_L16("<< CPtpServer::GetObjectHandleByNameL %S == 0x%x"), &aNameAndPath, aHandle)); |
|
131 } |
|
132 |
|
133 // -------------------------------------------------------------------------- |
|
134 // CPtpServer::GetObjectNameByHandleL() |
|
135 // Returns object name and path |
|
136 // -------------------------------------------------------------------------- |
|
137 // |
|
138 void CPtpServer::GetObjectNameByHandleL(TDes& aNameAndPath, |
|
139 const TUint32 aHandle) |
|
140 { |
|
141 __FLOG(_L8(">> CPtpServer::GetObjectNameByHandleL")); |
|
142 TMTPTypeUint32 handle(aHandle); |
|
143 CMTPObjectMetaData* objectP=CMTPObjectMetaData::NewL(); |
|
144 CleanupStack::PushL(objectP); |
|
145 TBool err = Framework().ObjectMgr().ObjectL(handle, *objectP); |
|
146 if(EFalse == err) |
|
147 { |
|
148 __FLOG(_L8("!!!!Error: CPtpServer::GetObjectNameByHandleL ObjectL failed!")); |
|
149 User::Leave(KErrBadHandle); |
|
150 } |
|
151 |
|
152 aNameAndPath=objectP->DesC(CMTPObjectMetaData::ESuid); |
|
153 CleanupStack::PopAndDestroy(objectP); |
|
154 __FLOG(_L8("<< CPtpServer::GetObjectNameByHandleL")); |
|
155 } |
|
156 |
|
157 |
|
158 // -------------------------------------------------------------------------- |
|
159 // CPtpServer::SendEvent |
|
160 // Requests Object send |
|
161 // -------------------------------------------------------------------------- |
|
162 // |
|
163 void CPtpServer::SendEventL(TMTPTypeEvent& ptpEvent) |
|
164 { |
|
165 __FLOG(_L8(">> CPtpServer::SendEventL")); |
|
166 |
|
167 if(iPrinterP->Status()!=CMTPPictBridgePrinter::EConnected) |
|
168 { |
|
169 __FLOG(_L8(" CPtpServer::SendEventL, no printer connection")); |
|
170 User::Leave(KErrNotReady); |
|
171 } |
|
172 Framework().SendEventL(ptpEvent, *(iPrinterP->ConnectionP())); |
|
173 |
|
174 __FLOG(_L8("<< CPtpServer::SendEventL")); |
|
175 } |
|
176 |
|
177 |
|
178 // -------------------------------------------------------------------------- |
|
179 // |
|
180 // |
|
181 // -------------------------------------------------------------------------- |
|
182 // |
|
183 MMTPDataProviderFramework& CPtpServer::Framework() const |
|
184 { |
|
185 return iFramework; |
|
186 } |
|
187 |
|
188 |
|
189 // -------------------------------------------------------------------------- |
|
190 // -------------------------------------------------------------------------- |
|
191 // |
|
192 const TDesC& CPtpServer::PtpFolder() |
|
193 { |
|
194 return iPtpFolder; |
|
195 } |
|
196 |
|
197 |
|
198 // -------------------------------------------------------------------------- |
|
199 // |
|
200 // -------------------------------------------------------------------------- |
|
201 // |
|
202 void CPtpServer::AddTemporaryObjectL(const TDesC& aPathAndFileName, TUint32& aHandle) |
|
203 { |
|
204 __FLOG_VA((_L8(">> CPtpServer::AddTemporaryObjectL"))); |
|
205 |
|
206 // always using the default storage for this |
|
207 |
|
208 CMTPObjectMetaData* objectP(CMTPObjectMetaData::NewLC(Framework().DataProviderId(), |
|
209 EMTPFormatCodeScript, // we only support sending DPS scripts |
|
210 Framework().StorageMgr().DefaultStorageId(), |
|
211 aPathAndFileName)); |
|
212 |
|
213 // since this object is temporary, we will not add any other details for it |
|
214 |
|
215 Framework().ObjectMgr().InsertObjectL(*objectP); |
|
216 aHandle=objectP->Uint(CMTPObjectMetaData::EHandle); |
|
217 CleanupStack::Pop(objectP); |
|
218 TInt err=iTemporaryObjects.Append(objectP); |
|
219 if(err) |
|
220 { |
|
221 Framework().Fs().Delete(objectP->DesC(CMTPObjectMetaData::ESuid)); // not checking the return value since there is not much we can do with it |
|
222 RemoveObjectL(objectP->DesC(CMTPObjectMetaData::ESuid)); |
|
223 delete objectP; |
|
224 __FLOG_VA((_L8(" CPtpServer::AddTemporaryObjectL, leaving %d"), err)); |
|
225 User::Leave(err); |
|
226 } |
|
227 |
|
228 |
|
229 __FLOG_VA((_L8("<< CPtpServer::AddTemporaryObjectL"))); |
|
230 } |
|
231 |
|
232 // -------------------------------------------------------------------------- |
|
233 // |
|
234 // -------------------------------------------------------------------------- |
|
235 // |
|
236 void CPtpServer::RemoveTemporaryObjects() |
|
237 { |
|
238 __FLOG_VA((_L8(">> CPtpServer::RemoveTemporaryObjects %d"), iTemporaryObjects.Count())); |
|
239 |
|
240 for (TInt i=0; i<iTemporaryObjects.Count();i++) |
|
241 { |
|
242 TInt err(KErrNone); |
|
243 TRAP(err,RemoveObjectL(iTemporaryObjects[i]->DesC(CMTPObjectMetaData::ESuid))); |
|
244 __FLOG_VA((_L16("removed object from db %S err=%d"), &(iTemporaryObjects[i]->DesC(CMTPObjectMetaData::ESuid)), err)); |
|
245 err=Framework().Fs().Delete(iTemporaryObjects[i]->DesC(CMTPObjectMetaData::ESuid)); |
|
246 __FLOG_VA((_L16("removed object from fs %S err=%d"), &(iTemporaryObjects[i]->DesC(CMTPObjectMetaData::ESuid)), err)); |
|
247 |
|
248 } |
|
249 iTemporaryObjects.ResetAndDestroy(); |
|
250 __FLOG_VA((_L8("<< CPtpServer::RemoveTemporaryObjects %d"), iTemporaryObjects.Count())); |
|
251 } |
|
252 |
|
253 // -------------------------------------------------------------------------- |
|
254 // |
|
255 // -------------------------------------------------------------------------- |
|
256 // |
|
257 void CPtpServer::RemoveObjectL(const TDesC& aSuid) |
|
258 { |
|
259 __FLOG_VA((_L16(">> CPtpServer::RemoveObjectL %S"), &aSuid)); |
|
260 Framework().ObjectMgr().RemoveObjectL(aSuid); |
|
261 __FLOG_VA((_L8("<< CPtpServer::RemoveObjectL"))); |
|
262 } |
|
263 |
|
264 // -------------------------------------------------------------------------- |
|
265 // -------------------------------------------------------------------------- |
|
266 // |
|
267 void CPtpServer::MtpSessionClosed() |
|
268 { |
|
269 iMtpSessionOpen = EFalse; |
|
270 RemoveTemporaryObjects(); |
|
271 iTemporaryObjects.Close(); |
|
272 } |
|
273 |
|
274 // -------------------------------------------------------------------------- |
|
275 // -------------------------------------------------------------------------- |
|
276 // |
|
277 void CPtpServer::MtpSessionOpened() |
|
278 { |
|
279 iMtpSessionOpen=ETrue; |
|
280 if(iSessionOpenNotifyClientP) |
|
281 { |
|
282 iSessionOpenNotifyClientP->MTPSessionOpened(); |
|
283 iSessionOpenNotifyClientP=NULL; |
|
284 } |
|
285 } |
|
286 |
|
287 // -------------------------------------------------------------------------- |
|
288 // -------------------------------------------------------------------------- |
|
289 // |
|
290 void CPtpServer::CancelNotifyOnMtpSessionOpen(CPtpSession* /*aSessionP*/) |
|
291 { |
|
292 iSessionOpenNotifyClientP=NULL; |
|
293 } |
|
294 |
|
295 // -------------------------------------------------------------------------- |
|
296 // -------------------------------------------------------------------------- |
|
297 // |
|
298 void CPtpServer::NotifyOnMtpSessionOpen(CPtpSession* aSession) |
|
299 { |
|
300 iSessionOpenNotifyClientP=aSession; |
|
301 } |
|
302 |