60 // 2nd phase constructor. |
65 // 2nd phase constructor. |
61 // -------------------------------------------------------------------------- |
66 // -------------------------------------------------------------------------- |
62 // |
67 // |
63 void CPtpServer::ConstructL() |
68 void CPtpServer::ConstructL() |
64 { |
69 { |
65 __FLOG_OPEN(KMTPSubsystem, KPtpServerLog); |
70 OstTraceFunctionEntry0( CPTPSERVER_CONSTRUCTL_ENTRY ); |
66 __FLOG(_L8(">>>CPtpServer::ConstructL")); |
71 |
67 iFileMan = CFileMan::NewL(iFramework.Fs()); |
72 iFileMan = CFileMan::NewL(iFramework.Fs()); |
68 iPtpFolder = PathInfo::PhoneMemoryRootPath(); |
73 iPtpFolder = PathInfo::PhoneMemoryRootPath(); |
69 iPtpFolder.Append( PathInfo::ImagesPath()); |
74 iPtpFolder.Append( PathInfo::ImagesPath()); |
70 iPtpFolder.Append(KPtpFolder); |
75 iPtpFolder.Append(KPtpFolder); |
71 iFileMan->RmDir(iPtpFolder); |
76 iFileMan->RmDir(iPtpFolder); |
72 Framework().Fs().MkDirAll(iPtpFolder); |
77 Framework().Fs().MkDirAll(iPtpFolder); |
73 |
78 |
74 iPrinterP = CMTPPictBridgePrinter::NewL(*this); |
79 iPrinterP = CMTPPictBridgePrinter::NewL(*this); |
75 __FLOG(_L8("<<<CPtpServer::ConstructL")); |
80 OstTraceFunctionExit0( CPTPSERVER_CONSTRUCTL_EXIT ); |
76 } |
81 } |
77 |
82 |
78 |
83 |
79 // -------------------------------------------------------------------------- |
84 // -------------------------------------------------------------------------- |
80 // |
85 // |
81 // C++ destructor. |
86 // C++ destructor. |
82 // -------------------------------------------------------------------------- |
87 // -------------------------------------------------------------------------- |
83 // |
88 // |
84 CPtpServer::~CPtpServer() |
89 CPtpServer::~CPtpServer() |
85 { |
90 { |
86 __FLOG(_L8(">>>CPtpServer::~")); |
91 OstTraceFunctionEntry0( CPTPSERVER_CPTPSERVER_DES_ENTRY ); |
87 delete iPrinterP; |
92 delete iPrinterP; |
88 iPrinterP = NULL; |
93 iPrinterP = NULL; |
89 delete iFileMan; |
94 delete iFileMan; |
90 iFileMan = NULL; |
95 iFileMan = NULL; |
91 __FLOG(_L8("<<<CPtpServer::~")); |
96 OstTraceFunctionExit0( CPTPSERVER_CPTPSERVER_DES_EXIT ); |
92 __FLOG_CLOSE; |
|
93 } |
97 } |
94 |
98 |
95 |
99 |
96 // ---------------------------------------------------------------------------- |
100 // ---------------------------------------------------------------------------- |
97 // |
101 // |
99 // ---------------------------------------------------------------------------- |
103 // ---------------------------------------------------------------------------- |
100 // |
104 // |
101 CSession2* CPtpServer::NewSessionL(const TVersion& aVersion, |
105 CSession2* CPtpServer::NewSessionL(const TVersion& aVersion, |
102 const RMessage2& /*aMessage*/) const |
106 const RMessage2& /*aMessage*/) const |
103 { |
107 { |
104 __FLOG(_L8(">>>CPtpServer::NewSessionL")); |
108 OstTraceFunctionEntry0( CPTPSERVER_NEWSESSIONL_ENTRY ); |
105 TVersion v(KPtpServerVersionMajor, KPtpServerVersionMinor, 0); |
109 TVersion v(KPtpServerVersionMajor, KPtpServerVersionMinor, 0); |
106 if (!User::QueryVersionSupported(v,aVersion)) |
110 if (!User::QueryVersionSupported(v,aVersion)) |
107 { |
111 { |
108 __FLOG(_L8("!!!!Error: CPtpServer::NewSessionL version not support!")); |
112 OstTrace0( TRACE_ERROR, CPTPSERVER_NEWSESSIONL, "!!!!Error: version not support!" ); |
109 User::Leave(KErrNotSupported); |
113 User::Leave(KErrNotSupported); |
110 } |
114 } |
111 if (iNumSession>0) |
115 if (iNumSession>0) |
112 { |
116 { |
113 __FLOG(_L8("!!!!Error: CPtpServer::NewSessionL session is in use!")); |
117 OstTrace0( TRACE_ERROR, DUP1_CPTPSERVER_NEWSESSIONL, "!!!!Error: session is in use!" ); |
114 User::Leave(KErrInUse); |
118 User::Leave(KErrInUse); |
115 } |
119 } |
116 CPtpSession* session = CPtpSession::NewL(const_cast<CPtpServer*>(this)); |
120 CPtpSession* session = CPtpSession::NewL(const_cast<CPtpServer*>(this)); |
117 __FLOG(_L8("<<<CPtpServer::NewSessionL")); |
121 OstTraceFunctionExit0( CPTPSERVER_NEWSESSIONL_EXIT ); |
118 return session; |
122 return session; |
119 } |
123 } |
120 |
124 |
121 // -------------------------------------------------------------------------- |
125 // -------------------------------------------------------------------------- |
122 // CPtpServer::GetObjectHandleByNameL() |
126 // CPtpServer::GetObjectHandleByNameL() |
123 // Returns object handle |
127 // Returns object handle |
124 // -------------------------------------------------------------------------- |
128 // -------------------------------------------------------------------------- |
125 // |
129 // |
126 void CPtpServer::GetObjectHandleByNameL(const TDesC& aNameAndPath, TUint32& aHandle) |
130 void CPtpServer::GetObjectHandleByNameL(const TDesC& aNameAndPath, TUint32& aHandle) |
127 { |
131 { |
128 __FLOG_VA((_L16(">> CPtpServer::GetObjectHandleByNameL %S"), &aNameAndPath)); |
132 OstTraceFunctionEntry0( CPTPSERVER_GETOBJECTHANDLEBYNAMEL_ENTRY ); |
|
133 OstTraceExt1( TRACE_NORMAL, CPTPSERVER_GETOBJECTHANDLEBYNAMEL, "Name %S", aNameAndPath ); |
129 aHandle=Framework().ObjectMgr().HandleL(aNameAndPath); |
134 aHandle=Framework().ObjectMgr().HandleL(aNameAndPath); |
130 __FLOG_VA((_L16("<< CPtpServer::GetObjectHandleByNameL %S == 0x%x"), &aNameAndPath, aHandle)); |
135 OstTraceExt2( TRACE_NORMAL, DUP1_CPTPSERVER_GETOBJECTHANDLEBYNAMEL, |
|
136 "Name %S == Handle 0x%x", aNameAndPath, aHandle ); |
|
137 OstTraceFunctionExit0( CPTPSERVER_GETOBJECTHANDLEBYNAMEL_EXIT ); |
|
138 |
131 } |
139 } |
132 |
140 |
133 // -------------------------------------------------------------------------- |
141 // -------------------------------------------------------------------------- |
134 // CPtpServer::GetObjectNameByHandleL() |
142 // CPtpServer::GetObjectNameByHandleL() |
135 // Returns object name and path |
143 // Returns object name and path |
136 // -------------------------------------------------------------------------- |
144 // -------------------------------------------------------------------------- |
137 // |
145 // |
138 void CPtpServer::GetObjectNameByHandleL(TDes& aNameAndPath, |
146 void CPtpServer::GetObjectNameByHandleL(TDes& aNameAndPath, |
139 const TUint32 aHandle) |
147 const TUint32 aHandle) |
140 { |
148 { |
141 __FLOG(_L8(">> CPtpServer::GetObjectNameByHandleL")); |
149 OstTraceFunctionEntry0( CPTPSERVER_GETOBJECTNAMEBYHANDLEL_ENTRY ); |
142 TMTPTypeUint32 handle(aHandle); |
150 TMTPTypeUint32 handle(aHandle); |
143 CMTPObjectMetaData* objectP=CMTPObjectMetaData::NewL(); |
151 CMTPObjectMetaData* objectP=CMTPObjectMetaData::NewL(); |
144 CleanupStack::PushL(objectP); |
152 CleanupStack::PushL(objectP); |
145 TBool err = Framework().ObjectMgr().ObjectL(handle, *objectP); |
153 TBool err = Framework().ObjectMgr().ObjectL(handle, *objectP); |
146 if(EFalse == err) |
154 if(EFalse == err) |
147 { |
155 { |
148 __FLOG(_L8("!!!!Error: CPtpServer::GetObjectNameByHandleL ObjectL failed!")); |
156 OstTrace0( TRACE_ERROR, CPTPSERVER_GETOBJECTNAMEBYHANDLEL, "!!!!Error: ObjectL failed!" ); |
149 User::Leave(KErrBadHandle); |
157 User::Leave(KErrBadHandle); |
150 } |
158 } |
151 |
159 |
152 aNameAndPath=objectP->DesC(CMTPObjectMetaData::ESuid); |
160 aNameAndPath=objectP->DesC(CMTPObjectMetaData::ESuid); |
153 CleanupStack::PopAndDestroy(objectP); |
161 CleanupStack::PopAndDestroy(objectP); |
154 __FLOG(_L8("<< CPtpServer::GetObjectNameByHandleL")); |
162 OstTraceFunctionExit0( CPTPSERVER_GETOBJECTNAMEBYHANDLEL_EXIT ); |
155 } |
163 } |
156 |
164 |
157 |
165 |
158 // -------------------------------------------------------------------------- |
166 // -------------------------------------------------------------------------- |
159 // CPtpServer::SendEvent |
167 // CPtpServer::SendEvent |
160 // Requests Object send |
168 // Requests Object send |
161 // -------------------------------------------------------------------------- |
169 // -------------------------------------------------------------------------- |
162 // |
170 // |
163 void CPtpServer::SendEventL(TMTPTypeEvent& ptpEvent) |
171 void CPtpServer::SendEventL(TMTPTypeEvent& ptpEvent) |
164 { |
172 { |
165 __FLOG(_L8(">> CPtpServer::SendEventL")); |
173 OstTraceFunctionEntry0( CPTPSERVER_SENDEVENTL_ENTRY ); |
166 |
174 |
167 if(iPrinterP->Status()!=CMTPPictBridgePrinter::EConnected) |
175 if(iPrinterP->Status()!=CMTPPictBridgePrinter::EConnected) |
168 { |
176 { |
169 __FLOG(_L8(" CPtpServer::SendEventL, no printer connection")); |
177 OstTrace0( TRACE_ERROR, CPTPSERVER_SENDEVENTL, " no printer connection" ); |
170 User::Leave(KErrNotReady); |
178 User::Leave(KErrNotReady); |
171 } |
179 } |
172 Framework().SendEventL(ptpEvent, *(iPrinterP->ConnectionP())); |
180 Framework().SendEventL(ptpEvent, *(iPrinterP->ConnectionP())); |
173 |
181 |
174 __FLOG(_L8("<< CPtpServer::SendEventL")); |
182 OstTraceFunctionExit0( CPTPSERVER_SENDEVENTL_EXIT ); |
175 } |
183 } |
176 |
184 |
177 |
185 |
178 // -------------------------------------------------------------------------- |
186 // -------------------------------------------------------------------------- |
179 // |
187 // |
219 if(err) |
227 if(err) |
220 { |
228 { |
221 Framework().Fs().Delete(objectP->DesC(CMTPObjectMetaData::ESuid)); // not checking the return value since there is not much we can do with it |
229 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)); |
230 RemoveObjectL(objectP->DesC(CMTPObjectMetaData::ESuid)); |
223 delete objectP; |
231 delete objectP; |
224 __FLOG_VA((_L8(" CPtpServer::AddTemporaryObjectL, leaving %d"), err)); |
232 OstTrace1( TRACE_ERROR, CPTPSERVER_ADDTEMPORARYOBJECTL, " leaving %d", err); |
225 User::Leave(err); |
233 User::Leave(err); |
226 } |
234 } |
227 |
235 |
228 |
236 |
229 __FLOG_VA((_L8("<< CPtpServer::AddTemporaryObjectL"))); |
237 OstTraceFunctionExit0( CPTPSERVER_ADDTEMPORARYOBJECTL_EXIT ); |
230 } |
238 } |
231 |
239 |
232 // -------------------------------------------------------------------------- |
240 // -------------------------------------------------------------------------- |
233 // |
241 // |
234 // -------------------------------------------------------------------------- |
242 // -------------------------------------------------------------------------- |
235 // |
243 // |
236 void CPtpServer::RemoveTemporaryObjects() |
244 void CPtpServer::RemoveTemporaryObjects() |
237 { |
245 { |
238 __FLOG_VA((_L8(">> CPtpServer::RemoveTemporaryObjects %d"), iTemporaryObjects.Count())); |
246 OstTraceFunctionEntry0( CPTPSERVER_REMOVETEMPORARYOBJECTS_ENTRY ); |
|
247 OstTrace1( TRACE_NORMAL, CPTPSERVER_REMOVETEMPORARYOBJECTS, "plan to remove %d temporary objects", iTemporaryObjects.Count()); |
239 |
248 |
240 for (TInt i=0; i<iTemporaryObjects.Count();i++) |
249 for (TInt i=0; i<iTemporaryObjects.Count();i++) |
241 { |
250 { |
242 TInt err(KErrNone); |
251 TInt err(KErrNone); |
243 TRAP(err,RemoveObjectL(iTemporaryObjects[i]->DesC(CMTPObjectMetaData::ESuid))); |
252 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)); |
253 OstTraceExt2( TRACE_NORMAL, DUP1_CPTPSERVER_REMOVETEMPORARYOBJECTS, |
|
254 "removed object from db %S err=%d", iTemporaryObjects[i]->DesC(CMTPObjectMetaData::ESuid), err); |
245 err=Framework().Fs().Delete(iTemporaryObjects[i]->DesC(CMTPObjectMetaData::ESuid)); |
255 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)); |
256 OstTraceExt2( TRACE_NORMAL, DUP2_CPTPSERVER_REMOVETEMPORARYOBJECTS, |
247 |
257 "removed object from fs %S err=%d", iTemporaryObjects[i]->DesC(CMTPObjectMetaData::ESuid), err); |
248 } |
258 } |
249 iTemporaryObjects.ResetAndDestroy(); |
259 iTemporaryObjects.ResetAndDestroy(); |
250 __FLOG_VA((_L8("<< CPtpServer::RemoveTemporaryObjects %d"), iTemporaryObjects.Count())); |
260 OstTrace1( TRACE_NORMAL, DUP3CPTPSERVER_REMOVETEMPORARYOBJECTS, "%d temporary objects remain", iTemporaryObjects.Count()); |
|
261 OstTraceFunctionExit0( CPTPSERVER_REMOVETEMPORARYOBJECTS_EXIT ); |
251 } |
262 } |
252 |
263 |
253 // -------------------------------------------------------------------------- |
264 // -------------------------------------------------------------------------- |
254 // |
265 // |
255 // -------------------------------------------------------------------------- |
266 // -------------------------------------------------------------------------- |
256 // |
267 // |
257 void CPtpServer::RemoveObjectL(const TDesC& aSuid) |
268 void CPtpServer::RemoveObjectL(const TDesC& aSuid) |
258 { |
269 { |
259 __FLOG_VA((_L16(">> CPtpServer::RemoveObjectL %S"), &aSuid)); |
270 OstTraceFunctionEntry0( CPTPSERVER_REMOVEOBJECTL_ENTRY ); |
|
271 OstTraceExt1( TRACE_NORMAL, CPTPSERVER_REMOVEOBJECTL, "remove %S", aSuid ); |
260 Framework().ObjectMgr().RemoveObjectL(aSuid); |
272 Framework().ObjectMgr().RemoveObjectL(aSuid); |
261 __FLOG_VA((_L8("<< CPtpServer::RemoveObjectL"))); |
273 OstTraceFunctionExit0( CPTPSERVER_REMOVEOBJECTL_EXIT ); |
262 } |
274 } |
263 |
275 |
264 // -------------------------------------------------------------------------- |
276 // -------------------------------------------------------------------------- |
265 // -------------------------------------------------------------------------- |
277 // -------------------------------------------------------------------------- |
266 // |
278 // |