1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13 * express or implied.
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
17 */
18 /**
19 * File Buffer Data Stream (FBDS) class will act as the data pipe between the
20 * protocol engine node and the file format parsing node.
21 * This will write the data from the protocol engine in a file for later reading by the
22 * file format parsing node.
23 */
24
25 #ifndef OSCL_EXCEPTION_H_INCLUDED
26 #include "oscl_exception.h"
27 #endif
28 #ifndef PVMF_FILEBUFFERDATASTREAM_FACTORY_H_INCLUDED
29 #include "pvmf_filebufferdatastream_factory.h"
30 #endif
31
32 // Logging #define
33 #define LOGDEBUG(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG,iLogger,PVLOGMSG_VERBOSE,m);
34
35 //////////////////////////////////////////////////////////////////////
36 // PVMFFileBufferDataStreamReadDataStreamFactoryImpl
37 //////////////////////////////////////////////////////////////////////
38 OSCL_EXPORT_REF
PVMFFileBufferDataStreamReadDataStreamFactoryImpl(OSCL_wString & aFileName)39 PVMFFileBufferDataStreamReadDataStreamFactoryImpl::PVMFFileBufferDataStreamReadDataStreamFactoryImpl(OSCL_wString& aFileName)
40 {
41 iFileName = aFileName;
42 iDownloadComplete = false;
43 }
44
45 OSCL_EXPORT_REF void
SetWriteDataStreamPtr(PVInterface * aWriteDataStream)46 PVMFFileBufferDataStreamReadDataStreamFactoryImpl::SetWriteDataStreamPtr(PVInterface* aWriteDataStream)
47 {
48 if (aWriteDataStream)
49 {
50 iWriteDataStream = OSCL_STATIC_CAST(PVMFFileBufferWriteDataStreamImpl*, aWriteDataStream);
51 }
52 }
53
54 OSCL_EXPORT_REF PVMFStatus
QueryAccessInterfaceUUIDs(Oscl_Vector<PVUuid,OsclMemAllocator> & aUuids)55 PVMFFileBufferDataStreamReadDataStreamFactoryImpl::QueryAccessInterfaceUUIDs(Oscl_Vector<PVUuid, OsclMemAllocator>& aUuids)
56 {
57 aUuids.push_back(PVMIDataStreamSyncInterfaceUuid);
58 return PVMFSuccess;
59 }
60
61 OSCL_EXPORT_REF PVInterface*
CreatePVMFCPMPluginAccessInterface(PVUuid & aUuid)62 PVMFFileBufferDataStreamReadDataStreamFactoryImpl::CreatePVMFCPMPluginAccessInterface(PVUuid& aUuid)
63 {
64 // Create a new PVMFFileBufferDataStreamReadDataStreamFactoryImpl for each request.
65 if (aUuid == PVMIDataStreamSyncInterfaceUuid)
66 {
67 PVMFFileBufferReadDataStreamImpl* ReadStream = NULL;
68 ReadStream = OSCL_NEW(PVMFFileBufferReadDataStreamImpl, (iWriteDataStream, iFileName));
69 if (ReadStream == NULL)
70 {
71 OSCL_LEAVE(OsclErrNoMemory);
72 }
73 ReadStream->iDownloadComplete = iDownloadComplete;
74 iReadStreamVec.push_back(ReadStream);
75 return OSCL_STATIC_CAST(PVInterface*, ReadStream);
76 }
77 return NULL;
78 }
79
80 OSCL_EXPORT_REF void
DestroyPVMFCPMPluginAccessInterface(PVUuid & aUuid,PVInterface * aPtr)81 PVMFFileBufferDataStreamReadDataStreamFactoryImpl::DestroyPVMFCPMPluginAccessInterface(PVUuid& aUuid,
82 PVInterface* aPtr)
83 {
84 // Destroy the incoming object only if it uses the right UUID and has a vaild pointer
85 if ((aUuid == PVMIDataStreamSyncInterfaceUuid) && (aPtr))
86 {
87 // Cast the incoming ptr to the correct type, then delete
88 PVMFFileBufferReadDataStreamImpl* iReadStream = NULL;
89 iReadStream = OSCL_STATIC_CAST(PVMFFileBufferReadDataStreamImpl*, aPtr);
90
91 Oscl_Vector<PVMFFileBufferReadDataStreamImpl*, OsclMemAllocator>::iterator it;
92 it = iReadStreamVec.begin();
93 while (it != iReadStreamVec.end())
94 {
95 if (*it == aPtr)
96 {
97 iReadStreamVec.erase(it);
98 break;
99 }
100 else
101 {
102 it++;
103 }
104 }
105 OSCL_DELETE(iReadStream);
106 }
107 }
108
109 OSCL_EXPORT_REF void
NotifyDownloadComplete()110 PVMFFileBufferDataStreamReadDataStreamFactoryImpl::NotifyDownloadComplete()
111 {
112 iDownloadComplete = true;
113 Oscl_Vector<PVMFFileBufferReadDataStreamImpl*, OsclMemAllocator>::iterator it;
114 for (it = iReadStreamVec.begin(); it != iReadStreamVec.end(); it++)
115 {
116 (*it)->NotifyDownloadComplete();
117 }
118 }
119
120
121 //////////////////////////////////////////////////////////////////////
122 // PVMFFileBufferDataStreamWriteDataStreamFactoryImpl
123 //////////////////////////////////////////////////////////////////////
124 OSCL_EXPORT_REF
PVMFFileBufferDataStreamWriteDataStreamFactoryImpl(OSCL_wString & aFileName)125 PVMFFileBufferDataStreamWriteDataStreamFactoryImpl::PVMFFileBufferDataStreamWriteDataStreamFactoryImpl(OSCL_wString& aFileName)
126 {
127 // Init to NULL for later creation
128 iWriteDataStream = NULL;
129 // Set the Filename to pass
130 iFileName = aFileName;
131 iDownloadComplete = false;
132 }
133
134 OSCL_EXPORT_REF
~PVMFFileBufferDataStreamWriteDataStreamFactoryImpl()135 PVMFFileBufferDataStreamWriteDataStreamFactoryImpl::~PVMFFileBufferDataStreamWriteDataStreamFactoryImpl()
136 {
137 if (iWriteDataStream)
138 {
139 OSCL_DELETE(iWriteDataStream);
140 }
141 }
142
143 OSCL_EXPORT_REF PVMFStatus
QueryAccessInterfaceUUIDs(Oscl_Vector<PVUuid,OsclMemAllocator> & aUuids)144 PVMFFileBufferDataStreamWriteDataStreamFactoryImpl::QueryAccessInterfaceUUIDs(Oscl_Vector<PVUuid, OsclMemAllocator>& aUuids)
145 {
146 aUuids.push_back(PVMIDataStreamSyncInterfaceUuid);
147 return PVMFSuccess;
148 }
149
150 OSCL_EXPORT_REF PVInterface*
CreatePVMFCPMPluginAccessInterface(PVUuid & aUuid)151 PVMFFileBufferDataStreamWriteDataStreamFactoryImpl::CreatePVMFCPMPluginAccessInterface(PVUuid& aUuid)
152 {
153 if (aUuid == PVMIDataStreamSyncInterfaceUuid)
154 {
155 // iWriteDataStream should have only one instance.
156 if (!iWriteDataStream)
157 {
158 // It does not exist so allocate
159 iWriteDataStream = OSCL_NEW(PVMFFileBufferWriteDataStreamImpl, (iFileName));
160 if (iWriteDataStream == NULL)
161 {
162 OSCL_LEAVE(OsclErrNoMemory);
163 }
164 }
165
166 // Return the ptr to the iWriteDataStream
167 return OSCL_STATIC_CAST(PVInterface*, iWriteDataStream);
168 }
169 return NULL;
170 }
171
172 OSCL_EXPORT_REF void
DestroyPVMFCPMPluginAccessInterface(PVUuid & aUuid,PVInterface * aPtr)173 PVMFFileBufferDataStreamWriteDataStreamFactoryImpl::DestroyPVMFCPMPluginAccessInterface(PVUuid& aUuid,
174 PVInterface* aPtr)
175 {
176 // Do nothing
177 OSCL_UNUSED_ARG(aUuid);
178 OSCL_UNUSED_ARG(aPtr);
179 }
180
181 PvmiDataStreamStatus
GetStreamReadCapacity(uint32 & aCapacity)182 PVMFFileBufferDataStreamWriteDataStreamFactoryImpl::GetStreamReadCapacity(uint32& aCapacity)
183 {
184 aCapacity = 0;
185 if (iWriteDataStream != NULL)
186 {
187 //id does not matter
188 PvmiDataStreamSession id = 0;
189 return (iWriteDataStream->QueryReadCapacity(id, aCapacity));
190 }
191 return PVDS_FAILURE;
192 }
193
194 //////////////////////////////////////////////////////////////////////
195 // PVMFFileBufferReadDataStreamImpl
196 //////////////////////////////////////////////////////////////////////
197 OSCL_EXPORT_REF
PVMFFileBufferReadDataStreamImpl(PVMFFileBufferWriteDataStreamImpl * aWriteDataStream,OSCL_wString & aFileName)198 PVMFFileBufferReadDataStreamImpl::PVMFFileBufferReadDataStreamImpl(PVMFFileBufferWriteDataStreamImpl* aWriteDataStream, OSCL_wString& aFileName)
199 {
200 iDownloadComplete = false;
201 iWriteDataStream = aWriteDataStream;
202 iFileHandle = NULL;
203 iFileObject = NULL;
204 iFileNumBytes = 0;
205 iSessionID = 0;
206 iFileName = aFileName;
207 iFs.Connect();
208 iLogger = PVLogger::GetLoggerObject("PVMFFileBufferReadDataStreamImpl");
209 LOGDEBUG((0, "PVMFFileBufferReadDataStreamImpl::PVMFFileBufferReadDataStreamImpl"));
210 }
211
212 OSCL_EXPORT_REF
~PVMFFileBufferReadDataStreamImpl()213 PVMFFileBufferReadDataStreamImpl::~PVMFFileBufferReadDataStreamImpl()
214 {
215 LOGDEBUG((0, "PVMFFileBufferReadDataStreamImpl::~PVMFFileBufferReadDataStreamImpl"));
216 if (iFileObject)
217 OSCL_DELETE(iFileObject);
218 iFileObject = NULL;
219 iLogger = NULL;
220 iFs.Close();
221 }
222
223 OSCL_EXPORT_REF bool
queryInterface(const PVUuid & uuid,PVInterface * & iface)224 PVMFFileBufferReadDataStreamImpl::queryInterface(const PVUuid& uuid,
225 PVInterface*& iface)
226 {
227 iface = NULL;
228 LOGDEBUG((0, "PVMFFileBufferReadDataStreamImpl::queryInterface"));
229 if (uuid == PVMIDataStreamSyncInterfaceUuid)
230 {
231 PVMIDataStreamSyncInterface* myInterface
232 = OSCL_STATIC_CAST(PVMIDataStreamSyncInterface*, this);
233 iface = OSCL_STATIC_CAST(PVInterface*, myInterface);
234 return true;
235 }
236 return false;
237 }
238
239 OSCL_EXPORT_REF PvmiDataStreamStatus
OpenSession(PvmiDataStreamSession & aSessionID,PvmiDataStreamMode aMode,bool nonblocking)240 PVMFFileBufferReadDataStreamImpl::OpenSession(PvmiDataStreamSession& aSessionID,
241 PvmiDataStreamMode aMode,
242 bool nonblocking)
243 {
244 OSCL_UNUSED_ARG(nonblocking);
245 int32 result = -1;
246 LOGDEBUG((0, "PVMFFileBufferReadDataStreamImpl::OpenSession"));
247
248 // Check to see if we have an open file object.
249 if (!iFileObject)
250 {
251 // Only open the file.
252 #if (defined(PVMF_PDL_DATASTREAM_ENABLE_READ_FILECACHE_DURING_PDL))
253 iFileObject = OSCL_NEW(Oscl_File, (OSCL_FILE_BUFFER_MAX_SIZE, iFileHandle));
254 #else
255 iFileObject = OSCL_NEW(Oscl_File, (0, iFileHandle));
256 #endif
257 // Should have a file object now
258 if (iFileObject)
259 {
260 switch (aMode)
261 {
262 case PVDS_READ_ONLY:
263 {
264 result = iFileObject->Open(iFileName.get_cstr(), Oscl_File::MODE_READ, iFs);
265 LOGDEBUG((0, "PVMFFileBufferReadDataStreamImpl::OpenSession - File opened returning %d iFileObject %x", result, iFileObject));
266 aSessionID = 0;
267 return (result == 0 ? PVDS_SUCCESS : PVDS_FAILURE);
268 }
269 // break; This statement was removed to avoid compiler warning for Unreachable Code
270 default:
271 // Attempt to open in an unsported mode.
272 // Have a iFileObject so clean it up and report PVDS_UNSUPPORTED_MODE
273 int32 result = iFileObject->Close();
274 if (result != 0)
275 LOGDEBUG((0, "PVMFFileBufferReadDataStreamImpl::OpenSession PVDS_UNSUPPORTED_MODE returning %d", result));
276 OSCL_DELETE(iFileObject);
277 iFileObject = NULL;
278 return PVDS_UNSUPPORTED_MODE;
279 }
280 }
281 else
282 return PVDS_FAILURE; // Failed to create a file object.
283 }
284 // Already have a iFileObject, dont allow a second call to OpenSession.
285 return PVDS_FAILURE;
286 }
287
288 OSCL_EXPORT_REF PvmiDataStreamStatus
CloseSession(PvmiDataStreamSession aSessionID)289 PVMFFileBufferReadDataStreamImpl::CloseSession(PvmiDataStreamSession aSessionID)
290 {
291 OSCL_UNUSED_ARG(aSessionID);
292 if (!iFileObject)
293 {
294 // Either OpenSession was never called or we already called CloseSession
295 // Tell the user and return failure.
296 LOGDEBUG((0, "PVMFFileBufferReadDataStreamImpl::CloseSession returning %d", -1));
297 return PVDS_FAILURE;
298 }
299
300 // Have a iFileObject so cleanup.
301 int32 result = iFileObject->Close();
302 LOGDEBUG((0, "PVMFFileBufferReadDataStreamImpl::CloseSession returning %d iFileObject %x", result, iFileObject));
303 OSCL_DELETE(iFileObject);
304 iFileObject = NULL;
305 if (result == 0)
306 return PVDS_SUCCESS;
307
308 // If result != 0, then return failure
309 return PVDS_FAILURE;
310 }
311
312 OSCL_EXPORT_REF PvmiDataStreamRandomAccessType
QueryRandomAccessCapability()313 PVMFFileBufferReadDataStreamImpl::QueryRandomAccessCapability()
314 {
315 return PVDS_FULL_RANDOM_ACCESS;
316 }
317
318 OSCL_EXPORT_REF PvmiDataStreamStatus
QueryReadCapacity(PvmiDataStreamSession aSessionID,uint32 & capacity)319 PVMFFileBufferReadDataStreamImpl::QueryReadCapacity(PvmiDataStreamSession aSessionID,
320 uint32& capacity)
321 {
322 int32 result = -1;
323 if (!iFileObject)
324 {
325 // No iFileObject to work with, return failure
326 return PVDS_FAILURE;
327 }
328 // Get the current file position
329 uint32 currFilePosition = GetCurrentPointerPosition(aSessionID);
330
331 // for projects on Symbian using RFileBuf cache enabled
332 // we need to reload the filecache in symbian, since oscl fileio
333 // does not have a sync / reload API we cheat by calling flush
334 // It so happens that the flush impl on symbian does a "synch"
335 iFileObject->Flush();
336
337 // since the behaviour of fflush is undefined for read-only files
338 // file pos may not be preserved. So seek back
339 iFileObject->Seek((int32)(currFilePosition), Oscl_File::SEEKSET);
340
341 uint32 lastFilePosition = 0;
342 // Determine the file size from write datastream.
343 result = iWriteDataStream->QueryReadCapacity(iSessionID, lastFilePosition);
344 if (result != 0)
345 {
346 LOGDEBUG((0, "PVMFFileBufferReadDataStreamImpl::QueryReadCapacity - iWriteDataStream->QueryReadCapacity ret %d", result));
347 return PVDS_FAILURE;
348 }
349
350 // Calculate the capacity from these two positions.
351 capacity = (lastFilePosition - currFilePosition);
352
353 if (iDownloadComplete == true)
354 {
355 return PVDS_END_OF_STREAM;
356 }
357 return PVDS_SUCCESS;
358 }
359
360 OSCL_EXPORT_REF PvmiDataStreamCommandId
RequestReadCapacityNotification(PvmiDataStreamSession aSessionID,PvmiDataStreamObserver & observer,uint32 capacity,OsclAny * aContextData)361 PVMFFileBufferReadDataStreamImpl::RequestReadCapacityNotification(PvmiDataStreamSession aSessionID,
362 PvmiDataStreamObserver& observer,
363 uint32 capacity,
364 OsclAny* aContextData)
365 {
366 OSCL_UNUSED_ARG(aSessionID);
367 PvmiDataStreamStatus result;
368
369 if (iDownloadComplete == true)
370 {
371 OSCL_LEAVE(OsclErrInvalidState);
372 }
373
374 // Check for an open session...
375 if (iSessionID == 0)
376 {
377 // No open session, open one now
378 result = iWriteDataStream->OpenSession(iSessionID, PVDS_READ_ONLY, false);
379
380 if (result != PVDS_SUCCESS)
381 {
382 // No READ sessions left
383 OSCL_LEAVE(OsclErrNoResources);
384 return 0;
385 }
386 }
387
388 //get current write datastream pos
389 //the capacity passed here means that the entity using the read datastream
390 //wants "capacity" number of bytes FROM its CURRENT location
391 //Read datastream's current read location cannot exceed write datastream's
392 //current location (cant read beyond what is written), therefore subtract
393 //writedatastream's current position from capacity, before making the request
394 uint32 currwritepos = iWriteDataStream->GetCurrentPointerPosition(iSessionID);
395 uint32 currreadpos = GetCurrentPointerPosition(0);
396 uint32 finalreadpositionforthisrequest = currreadpos + capacity;
397 if (currwritepos >= finalreadpositionforthisrequest)
398 {
399 //this request should never have been sent
400 //there is enough data in the datastream to be read
401 OSCL_LEAVE(OsclErrArgument);
402 return 0;
403 }
404 //these many bytes are yet to be written, so ask the writedatastream
405 //to notify when they become available
406 uint32 requestsize = finalreadpositionforthisrequest - currwritepos;
407
408 PvmiDataStreamCommandId iCommandID = 0;
409 int32 error = 0;
410
411 // Trap the error from the RequestReadCapacityNotification
412 OSCL_TRY(error, iCommandID = iWriteDataStream->RequestReadCapacityNotification(
413 iSessionID,
414 observer,
415 requestsize,
416 aContextData));
417 if (error)
418 {
419 // If we have an error, report it to the observer.
420 OSCL_LEAVE(error);
421 return iCommandID;
422 }
423
424 // Else everything worked ok, return the command ID
425 return iCommandID;
426 }
427
428 OSCL_EXPORT_REF PvmiDataStreamStatus
QueryWriteCapacity(PvmiDataStreamSession aSessionID,uint32 & capacity)429 PVMFFileBufferReadDataStreamImpl::QueryWriteCapacity(PvmiDataStreamSession aSessionID,
430 uint32& capacity)
431 {
432 OSCL_UNUSED_ARG(aSessionID);
433 OSCL_UNUSED_ARG(capacity);
434 return PVDS_NOT_SUPPORTED;
435 }
436
437 OSCL_EXPORT_REF PvmiDataStreamCommandId
RequestWriteCapacityNotification(PvmiDataStreamSession aSessionID,PvmiDataStreamObserver & observer,uint32 capacity,OsclAny * aContextData)438 PVMFFileBufferReadDataStreamImpl::RequestWriteCapacityNotification(PvmiDataStreamSession aSessionID,
439 PvmiDataStreamObserver& observer,
440 uint32 capacity,
441 OsclAny* aContextData)
442 {
443 OSCL_UNUSED_ARG(aSessionID);
444 OSCL_UNUSED_ARG(observer);
445 OSCL_UNUSED_ARG(capacity);
446 OSCL_UNUSED_ARG(aContextData);
447
448 OSCL_LEAVE(OsclErrNotSupported);
449 return 0;
450 }
451
452 OSCL_EXPORT_REF PvmiDataStreamCommandId
CancelNotification(PvmiDataStreamSession aSessionID,PvmiDataStreamObserver & observer,PvmiDataStreamCommandId aID,OsclAny * aContextData)453 PVMFFileBufferReadDataStreamImpl::CancelNotification(PvmiDataStreamSession aSessionID,
454 PvmiDataStreamObserver& observer,
455 PvmiDataStreamCommandId aID,
456 OsclAny* aContextData)
457 {
458 OSCL_UNUSED_ARG(aSessionID);
459
460 PvmiDataStreamCommandId iCommandID = 0;
461 int32 error = 0;
462
463 // Trap the error from the CancelNotification
464 OSCL_TRY(error, iCommandID = iWriteDataStream->CancelNotification(iSessionID,
465 observer,
466 aID,
467 aContextData));
468 if (error)
469 {
470 OSCL_LEAVE(error);
471 // return iCommandID; This statement was removed to avoid compiler warning for Unreachable Code
472 }
473
474 // No error return the Command ID
475 return iCommandID;
476 }
477
478
479 OSCL_EXPORT_REF PvmiDataStreamStatus
CancelNotificationSync(PvmiDataStreamSession aSessionID)480 PVMFFileBufferReadDataStreamImpl::CancelNotificationSync(PvmiDataStreamSession aSessionID)
481 {
482 OSCL_UNUSED_ARG(aSessionID);
483
484 return iWriteDataStream->CancelNotificationSync(iSessionID);
485 }
486
487
488 OSCL_EXPORT_REF PvmiDataStreamStatus
Read(PvmiDataStreamSession aSessionID,uint8 * buffer,uint32 size,uint32 & numelements)489 PVMFFileBufferReadDataStreamImpl::Read(PvmiDataStreamSession aSessionID,
490 uint8* buffer,
491 uint32 size,
492 uint32& numelements)
493 {
494 OSCL_UNUSED_ARG(aSessionID);
495
496 if (!iFileObject)
497 {
498 // No iFileObject to work with, return failure
499 return PVDS_FAILURE;
500 }
501
502 // Read the requested information from the file.
503 uint32 read_result = iFileObject->Read(buffer, size, numelements);
504 //LOGDEBUG((0,"PVMFFileBufferReadDataStreamImpl::Read iFileObject %x request size %d numelems %d returning %d", iFileObject, size, numelements, read_result));
505 numelements = read_result;
506
507 return PVDS_SUCCESS;
508 }
509
510 OSCL_EXPORT_REF PvmiDataStreamStatus
Write(PvmiDataStreamSession aSessionID,uint8 * buffer,uint32 size,uint32 & numelements)511 PVMFFileBufferReadDataStreamImpl::Write(PvmiDataStreamSession aSessionID,
512 uint8* buffer,
513 uint32 size,
514 uint32& numelements)
515 {
516 OSCL_UNUSED_ARG(aSessionID);
517 OSCL_UNUSED_ARG(buffer);
518 OSCL_UNUSED_ARG(size);
519 OSCL_UNUSED_ARG(numelements);
520 // Write not supported in the PVMFFileBufferReadDataStreamImpl object
521 return PVDS_NOT_SUPPORTED;
522 }
523
524 OSCL_EXPORT_REF PvmiDataStreamStatus
Write(PvmiDataStreamSession aSessionID,OsclRefCounterMemFrag * aFrag,uint32 & aNumElements)525 PVMFFileBufferReadDataStreamImpl::Write(PvmiDataStreamSession aSessionID, OsclRefCounterMemFrag* aFrag, uint32& aNumElements)
526 {
527 OSCL_UNUSED_ARG(aSessionID);
528 OSCL_UNUSED_ARG(aFrag);
529 OSCL_UNUSED_ARG(aNumElements);
530 // Write not supported in the PVMFMemoryBufferReadDataStreamImpl object
531 return PVDS_NOT_SUPPORTED;
532 }
533
534 OSCL_EXPORT_REF PvmiDataStreamStatus
Seek(PvmiDataStreamSession aSessionID,int32 offset,PvmiDataStreamSeekType origin)535 PVMFFileBufferReadDataStreamImpl::Seek(PvmiDataStreamSession aSessionID,
536 int32 offset,
537 PvmiDataStreamSeekType origin)
538 {
539 OSCL_UNUSED_ARG(aSessionID);
540
541 if (!iFileObject)
542 return PVDS_FAILURE; // No iFileObject to work with, return failure
543
544 // Peform the Seek the user requested
545 Oscl_File::seek_type seekType = Oscl_File::SEEKSET;
546 if (origin == PVDS_SEEK_SET)
547 {
548 seekType = Oscl_File::SEEKSET;
549 }
550 if (origin == PVDS_SEEK_CUR)
551 {
552 seekType = Oscl_File::SEEKCUR;
553 }
554 if (origin == PVDS_SEEK_END)
555 {
556 seekType = Oscl_File::SEEKEND;
557 }
558 int32 result = iFileObject->Seek(offset, seekType);
559 LOGDEBUG((0, "PVMFFileBufferReadDataStreamImpl::SeekContent iFileObject %x offset %d origin %d returning %d", iFileObject, offset, origin, result));
560 if (result != 0)
561 {
562 return PVDS_FAILURE;
563 }
564 return PVDS_SUCCESS;
565 }
566
567 OSCL_EXPORT_REF uint32
GetCurrentPointerPosition(PvmiDataStreamSession aSessionID)568 PVMFFileBufferReadDataStreamImpl::GetCurrentPointerPosition(PvmiDataStreamSession aSessionID)
569 {
570 OSCL_UNUSED_ARG(aSessionID);
571
572 if (!iFileObject)
573 return 0; // No iFileObject to work with, return zero
574 int32 result = (TOsclFileOffsetInt32)iFileObject->Tell();
575 LOGDEBUG((0, "PVMFFileBufferReadDataStreamImpl::GetCurrentContentPosition returning %d", result));
576 return (uint32)(result);
577 }
578
579 OSCL_EXPORT_REF PvmiDataStreamStatus
Flush(PvmiDataStreamSession aSessionID)580 PVMFFileBufferReadDataStreamImpl::Flush(PvmiDataStreamSession aSessionID)
581 {
582 OSCL_UNUSED_ARG(aSessionID);
583
584 if (!iFileObject)
585 {
586 // No iFileObject to work with, return failure
587 LOGDEBUG((0, "PVMFFileBufferReadDataStreamImpl::Flush returning %d", -1));
588 return PVDS_FAILURE;
589 }
590
591 // Perform the flush
592 int32 result = iFileObject->Flush();
593 if (result != 0)
594 LOGDEBUG((0, "PVMFFileBufferReadDataStreamImpl::Flush returning %d", result));
595 return PVDS_SUCCESS;
596 }
597
598 OSCL_EXPORT_REF void
NotifyDownloadComplete()599 PVMFFileBufferReadDataStreamImpl::NotifyDownloadComplete()
600 {
601 iDownloadComplete = true;
602 if (iWriteDataStream != NULL)
603 {
604 iWriteDataStream->NotifyDownloadComplete();
605 }
606 }
607
608 //////////////////////////////////////////////////////////////////////
609 // PVMFFileBufferWriteDataStreamImpl
610 //////////////////////////////////////////////////////////////////////
611 OSCL_EXPORT_REF
PVMFFileBufferWriteDataStreamImpl(OSCL_wString & aFileName)612 PVMFFileBufferWriteDataStreamImpl::PVMFFileBufferWriteDataStreamImpl(OSCL_wString& aFileName)
613 {
614 iDownloadComplete = false;
615 iFileHandle = NULL;
616 iFileObject = NULL;
617 iFileNumBytes = 0;
618 iSessionID = 0;
619 iFileName = aFileName;
620
621 for (uint32 i = 0; i < MAX_NUMBER_OF_READ_CONNECTIONS; i++)
622 {
623 iReadNotifications[i].ReadStructValid = false;
624 }
625 iLastSessionID = 0;
626
627 iFs.Connect();
628 iLogger = PVLogger::GetLoggerObject("PVMFFileBufferWriteDataStreamImpl");
629 LOGDEBUG((0, "PVMFFileBufferWriteDataStreamImpl::PVMFFileBufferWriteDataStreamImpl"));
630 }
631
632 OSCL_EXPORT_REF
~PVMFFileBufferWriteDataStreamImpl()633 PVMFFileBufferWriteDataStreamImpl::~PVMFFileBufferWriteDataStreamImpl()
634 {
635 LOGDEBUG((0, "PVMFFileBufferWriteDataStreamImpl::~PVMFFileBufferWriteDataStreamImpl"));
636 if (iFileObject)
637 OSCL_DELETE(iFileObject);
638 iFileObject = NULL;
639 iLogger = NULL;
640 iFs.Close();
641 }
642
643 OSCL_EXPORT_REF bool
queryInterface(const PVUuid & uuid,PVInterface * & iface)644 PVMFFileBufferWriteDataStreamImpl::queryInterface(const PVUuid& uuid,
645 PVInterface*& iface)
646 {
647 iface = NULL;
648 LOGDEBUG((0, "PVMFFileBufferWriteDataStreamImpl::queryInterface"));
649 if (uuid == PVMIDataStreamSyncInterfaceUuid)
650 {
651 PVMIDataStreamSyncInterface* myInterface
652 = OSCL_STATIC_CAST(PVMIDataStreamSyncInterface*, this);
653 iface = OSCL_STATIC_CAST(PVInterface*, myInterface);
654 return true;
655 }
656 return false;
657 }
658
659 OSCL_EXPORT_REF PvmiDataStreamStatus
OpenSession(PvmiDataStreamSession & aSessionID,PvmiDataStreamMode aMode,bool nonblocking)660 PVMFFileBufferWriteDataStreamImpl::OpenSession(PvmiDataStreamSession& aSessionID,
661 PvmiDataStreamMode aMode,
662 bool nonblocking)
663 {
664 OSCL_UNUSED_ARG(nonblocking);
665
666 // This function assumes that the WRITE mode will be requested first!
667
668 int32 result = -1;
669
670 LOGDEBUG((0, "PVMFFileBufferWriteDataStreamImpl::OpenSession"));
671
672 // Check to see if we have an open file object.
673 if ((!iFileObject) && (aMode != PVDS_READ_ONLY))
674 {
675 // Only open the file.
676 iFileObject = OSCL_NEW(Oscl_File, ());
677
678 // Should have a file object now
679 if (iFileObject)
680 {
681 //since we flush the file after each write, cache is not helpful.
682 iFileObject->SetPVCacheSize(0);
683 iFileObject->SetFileHandle(iFileHandle);
684 //iFileObject->SetLoggingEnable(true);
685 switch (aMode)
686 {
687 case PVDS_WRITE_ONLY:
688 case PVDS_READ_WRITE:
689 {
690 result = iFileObject->Open(iFileName.get_cstr(), Oscl_File::MODE_READWRITE, iFs);
691 LOGDEBUG((0, "PVMFFileBufferWriteDataStreamImpl::OpenSession - File opened returning %d", result));
692 }
693 break;
694 case PVDS_READ_PLUS:
695 {
696
697 result = iFileObject->Open(iFileName.get_cstr(), Oscl_File::MODE_READ_PLUS, iFs);
698 LOGDEBUG((0, "PVMFFileBufferWriteDataStreamImpl::OpenSession - File opened returning %d", result));
699
700 }
701 break;
702 case PVDS_APPEND:
703 {
704 result = iFileObject->Open(iFileName.get_cstr(), Oscl_File::MODE_APPEND, iFs);
705 LOGDEBUG((0, "PVMFFileBufferWriteDataStreamImpl::OpenSession - File opened returning %d", result));
706 }
707 break;
708 case PVDS_REWRITE:
709 {
710 result = iFs.Oscl_DeleteFile(iFileName.get_cstr());
711 LOGDEBUG((0, "PVMFFileBufferWriteDataStreamImpl::OpenSession - File deleted returning %d", result));
712 if (result != 0)
713 {
714 return PVDS_FAILURE;
715 }
716 result = iFileObject->Open(iFileName.get_cstr(), Oscl_File::MODE_READWRITE, iFs);
717 LOGDEBUG((0, "PVMFFileBufferWriteDataStreamImpl::OpenSession - File opened returning %d", result));
718 }
719 break;
720 default:
721 // Attempt to open in an unsported mode.
722 // Have a iFileObject so clean it up and report PVDS_UNSUPPORTED_MODE
723 int32 result = iFileObject->Close();
724 if (result != 0)
725 LOGDEBUG((0, "PVMFFileBufferReadDataStreamImpl::OpenSession PVDS_UNSUPPORTED_MODE returning %d", result));
726 OSCL_DELETE(iFileObject);
727 iFileObject = NULL;
728 return PVDS_UNSUPPORTED_MODE;
729 }
730 // file has been opened- update byte count
731 aSessionID = 0;
732 if (result == 0)
733 {
734 const int32 filesize = (TOsclFileOffsetInt32)iFileObject->Size();
735 if (filesize >= 0)
736 this->iFileNumBytes = filesize;
737 }
738 return (result == 0 ? PVDS_SUCCESS : PVDS_FAILURE);
739 }
740 else
741 return PVDS_FAILURE; // Failed to create a file object.
742 }
743
744 if (aMode == PVDS_READ_ONLY)
745 {
746 // Check to see if we have free READ connections before setting one.
747 if (iLastSessionID < MAX_NUMBER_OF_READ_CONNECTIONS)
748 {
749 iReadNotifications[iLastSessionID].ReadStructValid = true;
750 iReadNotifications[iLastSessionID].iReadSessionID =
751 iLastSessionID + MAX_NUMBER_OF_WRITE_CONNECTIONS;
752 iReadNotifications[iLastSessionID].iReadObserver = NULL;
753 iReadNotifications[iLastSessionID].iFilePosition = 0;
754 iReadNotifications[iLastSessionID].iReadCapacity = 0;
755 iReadNotifications[iLastSessionID].iContextData = NULL;
756 iReadNotifications[iLastSessionID].iCommandID = 0;
757 iReadNotifications[iLastSessionID].iCurrentCommandID = 0;
758 aSessionID = iReadNotifications[iLastSessionID].iReadSessionID;
759 iLastSessionID++;
760 return PVDS_SUCCESS;
761 }
762 }
763
764 // We got here becuase:
765 // 1) We already have an iFileObject (IE we opened once WRITE mode)
766 // 2) We have all the iReadNotifications filled.
767 return PVDS_INVALID_REQUEST;
768
769 }
770
771 OSCL_EXPORT_REF PvmiDataStreamStatus
CloseSession(PvmiDataStreamSession aSessionID)772 PVMFFileBufferWriteDataStreamImpl::CloseSession(PvmiDataStreamSession aSessionID)
773 {
774 // Check for the WRITE session
775 if (aSessionID == 0)
776 {
777 // Check to make sure we dont close the write session twice
778 if (!iFileObject)
779 {
780 // Either OpenSession was never called or we already called CloseSession
781 // Tell the user and return failure.
782 LOGDEBUG((0, "PVMFFileBufferWriteDataStreamImpl::CloseSession no valid iFileObject returning %d", -1));
783 return PVDS_FAILURE;
784 }
785
786 // Have a iFileObject so clean it up
787 int32 result = iFileObject->Close();
788 LOGDEBUG((0, "PVMFFileBufferWriteDataStreamImpl::CloseSession returning %d", result));
789 OSCL_DELETE(iFileObject);
790 iFileObject = NULL;
791 if (result == 0)
792 return PVDS_SUCCESS;
793
794 // If result != 0, then return failure
795 return PVDS_FAILURE;
796 }
797 else
798 {
799 // Close the READ sessions
800 if ((aSessionID > (MAX_NUMBER_OF_READ_CONNECTIONS + MAX_NUMBER_OF_WRITE_CONNECTIONS)) ||
801 (iReadNotifications[aSessionID-MAX_NUMBER_OF_WRITE_CONNECTIONS].ReadStructValid != true))
802 {
803 return PVDS_INVALID_SESSION;
804 }
805
806 // Have a valid READ session so close it by setting the flag to invalid
807 iReadNotifications[aSessionID-MAX_NUMBER_OF_WRITE_CONNECTIONS].ReadStructValid = false;
808 iLastSessionID--;
809 return PVDS_SUCCESS;
810 }
811 }
812
813 OSCL_EXPORT_REF PvmiDataStreamRandomAccessType
QueryRandomAccessCapability()814 PVMFFileBufferWriteDataStreamImpl::QueryRandomAccessCapability()
815 {
816 return PVDS_FULL_RANDOM_ACCESS;
817 }
818
819 OSCL_EXPORT_REF PvmiDataStreamStatus
QueryReadCapacity(PvmiDataStreamSession aSessionID,uint32 & capacity)820 PVMFFileBufferWriteDataStreamImpl::QueryReadCapacity(PvmiDataStreamSession aSessionID,
821 uint32& capacity)
822 {
823 OSCL_UNUSED_ARG(aSessionID);
824 OSCL_UNUSED_ARG(capacity);
825 //return number of bytes written thus far
826 capacity = iFileNumBytes;
827 return PVDS_SUCCESS;
828 }
829
830 OSCL_EXPORT_REF PvmiDataStreamCommandId
RequestReadCapacityNotification(PvmiDataStreamSession aSessionID,PvmiDataStreamObserver & observer,uint32 capacity,OsclAny * aContextData)831 PVMFFileBufferWriteDataStreamImpl::RequestReadCapacityNotification(PvmiDataStreamSession aSessionID,
832 PvmiDataStreamObserver& observer,
833 uint32 capacity,
834 OsclAny* aContextData)
835 {
836 // Check if the aSessionID is a valid SessionID
837 // Check that the aSessionID is not the WRITE session
838 // Check that the aSessionID is valid
839 if ((aSessionID > (MAX_NUMBER_OF_READ_CONNECTIONS + MAX_NUMBER_OF_WRITE_CONNECTIONS)) ||
840 (aSessionID == 0) ||
841 (iReadNotifications[aSessionID-MAX_NUMBER_OF_WRITE_CONNECTIONS].ReadStructValid != true))
842 {
843 OSCL_LEAVE(OsclErrArgument);
844 return 0;
845 }
846 else
847 {
848 // Read SessionID index is MAX_NUMBER_OF_WRITE_CONNECTIONS less than the aSessionID passed in
849 PvmiDataStreamSession temp_session = aSessionID - MAX_NUMBER_OF_WRITE_CONNECTIONS;
850
851 // Its valid, so save the read notification
852 iReadNotifications[temp_session].iReadObserver = &observer;
853 iReadNotifications[temp_session].iFilePosition = GetCurrentPointerPosition(0);
854 iReadNotifications[temp_session].iReadCapacity = capacity;
855 iReadNotifications[temp_session].iContextData = aContextData;
856 iReadNotifications[temp_session].iCommandID =
857 iReadNotifications[temp_session].iCurrentCommandID++;
858 return iReadNotifications[temp_session].iCommandID;
859 }
860 }
861
862 OSCL_EXPORT_REF PvmiDataStreamStatus
QueryWriteCapacity(PvmiDataStreamSession sessionID,uint32 & capacity)863 PVMFFileBufferWriteDataStreamImpl::QueryWriteCapacity(PvmiDataStreamSession sessionID,
864 uint32& capacity)
865 {
866 OSCL_UNUSED_ARG(sessionID);
867 capacity = 0xFFFFFFFF; // for file write, write capacity would be infinite.
868 return PVDS_SUCCESS;
869 }
870
871 OSCL_EXPORT_REF PvmiDataStreamCommandId
RequestWriteCapacityNotification(PvmiDataStreamSession sessionID,PvmiDataStreamObserver & observer,uint32 capacity,OsclAny * aContextData)872 PVMFFileBufferWriteDataStreamImpl::RequestWriteCapacityNotification(PvmiDataStreamSession sessionID,
873 PvmiDataStreamObserver& observer,
874 uint32 capacity,
875 OsclAny* aContextData)
876 {
877 OSCL_UNUSED_ARG(sessionID);
878 OSCL_UNUSED_ARG(observer);
879 OSCL_UNUSED_ARG(capacity);
880 OSCL_UNUSED_ARG(aContextData);
881
882 OSCL_LEAVE(OsclErrNotSupported);
883 return 0;
884 }
885
886 OSCL_EXPORT_REF PvmiDataStreamCommandId
CancelNotification(PvmiDataStreamSession aSessionID,PvmiDataStreamObserver & observer,PvmiDataStreamCommandId aID,OsclAny * aContextData)887 PVMFFileBufferWriteDataStreamImpl::CancelNotification(PvmiDataStreamSession aSessionID,
888 PvmiDataStreamObserver& observer,
889 PvmiDataStreamCommandId aID,
890 OsclAny* aContextData)
891 {
892 OSCL_UNUSED_ARG(observer);
893 OSCL_UNUSED_ARG(aID);
894 OSCL_UNUSED_ARG(aContextData);
895
896 // Check if the aSessionID is a valid number
897 // Check that the aSessionID is not the WRITE session
898 // Check that the aSessionID is valid
899 if ((aSessionID > (MAX_NUMBER_OF_READ_CONNECTIONS + MAX_NUMBER_OF_WRITE_CONNECTIONS)) ||
900 (aSessionID == 0) ||
901 (iReadNotifications[aSessionID-MAX_NUMBER_OF_WRITE_CONNECTIONS].ReadStructValid != true))
902 {
903 OSCL_LEAVE(OsclErrArgument);
904 }
905
906 PvmiDataStreamSession temp_sessionID = aSessionID - MAX_NUMBER_OF_WRITE_CONNECTIONS;
907 // SessionID is valid, so zero out the notification info
908 iReadNotifications[temp_sessionID].iReadObserver = NULL;
909 iReadNotifications[temp_sessionID].iFilePosition = 0;
910 iReadNotifications[temp_sessionID].iReadCapacity = 0;
911 iReadNotifications[temp_sessionID].iContextData = NULL;
912 iReadNotifications[temp_sessionID].iCommandID = 0;
913 return iReadNotifications[temp_sessionID].iCurrentCommandID++;
914 }
915
916
917 OSCL_EXPORT_REF PvmiDataStreamStatus
CancelNotificationSync(PvmiDataStreamSession aSessionID)918 PVMFFileBufferWriteDataStreamImpl::CancelNotificationSync(PvmiDataStreamSession aSessionID)
919 {
920 // Check if the aSessionID is a valid number
921 // Check that the aSessionID is not the WRITE session
922 // Check that the aSessionID is valid
923 PvmiDataStreamStatus status = PVDS_SUCCESS;
924 if ((aSessionID > (MAX_NUMBER_OF_READ_CONNECTIONS + MAX_NUMBER_OF_WRITE_CONNECTIONS)) ||
925 (aSessionID == 0) ||
926 (iReadNotifications[aSessionID - MAX_NUMBER_OF_WRITE_CONNECTIONS].ReadStructValid != true))
927 {
928 status = PVDS_FAILURE;
929 }
930 else
931 {
932 // zero out the notification info
933 PvmiDataStreamSession temp_sessionID = aSessionID - MAX_NUMBER_OF_WRITE_CONNECTIONS;
934 iReadNotifications[temp_sessionID].iReadObserver = NULL;
935 iReadNotifications[temp_sessionID].iFilePosition = 0;
936 iReadNotifications[temp_sessionID].iReadCapacity = 0;
937 iReadNotifications[temp_sessionID].iContextData = NULL;
938 iReadNotifications[temp_sessionID].iCommandID = 0;
939 }
940 return status;
941 }
942
943 OSCL_EXPORT_REF PvmiDataStreamStatus
Read(PvmiDataStreamSession aSessionID,uint8 * buffer,uint32 size,uint32 & numelements)944 PVMFFileBufferWriteDataStreamImpl::Read(PvmiDataStreamSession aSessionID,
945 uint8* buffer,
946 uint32 size,
947 uint32& numelements)
948 {
949 OSCL_UNUSED_ARG(aSessionID);
950 OSCL_UNUSED_ARG(buffer);
951 OSCL_UNUSED_ARG(size);
952 OSCL_UNUSED_ARG(numelements);
953 // Read not supported in the PVMFFileBufferWriteDataStreamImpl object
954 return PVDS_NOT_SUPPORTED;
955 }
956
957
958 OSCL_EXPORT_REF PvmiDataStreamStatus
Write(PvmiDataStreamSession aSessionID,OsclRefCounterMemFrag * aFrag,uint32 & aNumElements)959 PVMFFileBufferWriteDataStreamImpl::Write(PvmiDataStreamSession aSessionID, OsclRefCounterMemFrag* aFrag, uint32& aNumElements)
960 {
961 aNumElements = aFrag->getMemFragSize();
962 return Write(aSessionID, (uint8*)(aFrag->getMemFragPtr()), sizeof(uint8), aNumElements);
963 }
964
965 OSCL_EXPORT_REF PvmiDataStreamStatus
Write(PvmiDataStreamSession aSessionID,uint8 * buffer,uint32 size,uint32 & numelements)966 PVMFFileBufferWriteDataStreamImpl::Write(PvmiDataStreamSession aSessionID,
967 uint8* buffer,
968 uint32 size,
969 uint32& numelements)
970 {
971 if ((!iFileObject) || (aSessionID != 0))
972 {
973 // No iFileObject or valid write session to work with, return failure
974 return PVDS_FAILURE;
975 }
976
977 uint32 result = iFileObject->Write(buffer, size, numelements);
978 Flush(0);
979 iFileNumBytes += (size * numelements);
980
981 // LOGDEBUG((0,"PVMFFileBufferWriteDataStreamImpl::Write returning %d",result));
982 numelements = result;
983
984 // Loop through the iReadNotifications for a Read Notification
985 for (uint32 i = 0; i < MAX_NUMBER_OF_READ_CONNECTIONS; i++)
986 {
987 // If we have a valid iReadNotifications element
988 // AND the iReadObserver != NULL
989 if ((iReadNotifications[i].ReadStructValid == true) &&
990 (iReadNotifications[i].iReadObserver != NULL))
991 {
992 uint32 currFilePosition = GetCurrentPointerPosition(0);
993
994 PVMFStatus status;
995 if ((currFilePosition -
996 iReadNotifications[i].iFilePosition) >
997 iReadNotifications[i].iReadCapacity)
998 {
999 status = PVMFSuccess;
1000 PvmiDataStreamObserver* copy_observer = iReadNotifications[i].iReadObserver;
1001 OsclAny* copy_ContextData = iReadNotifications[i].iContextData;
1002 PvmiDataStreamCommandId copy_aID = iReadNotifications[i].iCommandID;
1003
1004 // Reset the iReadNotifications for the next notification
1005 iReadNotifications[i].iReadObserver = NULL;
1006 iReadNotifications[i].iReadCapacity = 0;
1007 iReadNotifications[i].iFilePosition = 0;
1008 iReadNotifications[i].iCommandID = 0;
1009 iReadNotifications[i].iContextData = NULL;
1010
1011 // Form a command response.
1012 PVMFCmdResp resp(copy_aID,
1013 copy_ContextData,
1014 status,
1015 NULL,
1016 NULL);
1017
1018 // Make the Command Complete notification.
1019 copy_observer->DataStreamCommandCompleted(resp);
1020 }
1021 else
1022 {
1023 if (iDownloadComplete == true)
1024 {
1025 status = PVMFFailure;
1026 PvmiDataStreamObserver* copy_observer = iReadNotifications[i].iReadObserver;
1027 OsclAny* copy_ContextData = iReadNotifications[i].iContextData;
1028 PvmiDataStreamCommandId copy_aID = iReadNotifications[i].iCommandID;
1029
1030 // Reset the iReadNotifications for the next notification
1031 iReadNotifications[i].iReadObserver = NULL;
1032 iReadNotifications[i].iReadCapacity = 0;
1033 iReadNotifications[i].iFilePosition = 0;
1034 iReadNotifications[i].iCommandID = 0;
1035 iReadNotifications[i].iContextData = NULL;
1036
1037 // Form a command response.
1038 PVMFCmdResp resp(copy_aID,
1039 copy_ContextData,
1040 status,
1041 NULL,
1042 NULL);
1043
1044 // Make the Command Complete notification.
1045 copy_observer->DataStreamCommandCompleted(resp);
1046 }
1047 }
1048 }
1049 }
1050
1051 return PVDS_SUCCESS;
1052 }
1053
1054 OSCL_EXPORT_REF PvmiDataStreamStatus
Seek(PvmiDataStreamSession aSessionID,int32 offset,PvmiDataStreamSeekType origin)1055 PVMFFileBufferWriteDataStreamImpl::Seek(PvmiDataStreamSession aSessionID,
1056 int32 offset,
1057 PvmiDataStreamSeekType origin)
1058 {
1059 OSCL_UNUSED_ARG(aSessionID);
1060
1061 if (!iFileObject)
1062 return PVDS_FAILURE; // No iFileObject to work with, return failure
1063
1064 // Peform the Seek the user requested
1065 Oscl_File::seek_type seekType = Oscl_File::SEEKSET;
1066 if (origin == PVDS_SEEK_SET)
1067 {
1068 seekType = Oscl_File::SEEKSET;
1069 }
1070 if (origin == PVDS_SEEK_CUR)
1071 {
1072 seekType = Oscl_File::SEEKCUR;
1073 }
1074 if (origin == PVDS_SEEK_END)
1075 {
1076 seekType = Oscl_File::SEEKEND;
1077 }
1078 int32 result = iFileObject->Seek(offset, seekType);
1079 LOGDEBUG((0, "PVMFFileBufferWriteDataStreamImpl::SeekContent returning %d", result));
1080 if (result != 0)
1081 {
1082 return PVDS_FAILURE;
1083 }
1084 return PVDS_SUCCESS;
1085 }
1086
1087 OSCL_EXPORT_REF uint32
GetCurrentPointerPosition(PvmiDataStreamSession aSessionID)1088 PVMFFileBufferWriteDataStreamImpl::GetCurrentPointerPosition(PvmiDataStreamSession aSessionID)
1089 {
1090 OSCL_UNUSED_ARG(aSessionID);
1091
1092 if (!iFileObject)
1093 return 0; // No iFileObject to work with, return zero
1094 int32 result = (TOsclFileOffsetInt32)iFileObject->Tell();
1095 LOGDEBUG((0, "PVMFFileBufferWriteDataStreamImpl::GetCurrentContentPosition returning %d", result));
1096 return (uint32)(result);
1097 }
1098
1099 OSCL_EXPORT_REF PvmiDataStreamStatus
Flush(PvmiDataStreamSession aSessionID)1100 PVMFFileBufferWriteDataStreamImpl::Flush(PvmiDataStreamSession aSessionID)
1101 {
1102 OSCL_UNUSED_ARG(aSessionID);
1103
1104 if (!iFileObject)
1105 {
1106 // No iFileObject to work with, return failure
1107 LOGDEBUG((0, "PVMFFileBufferWriteDataStreamImpl::Flush returning %d", -1));
1108 return PVDS_FAILURE;
1109 }
1110
1111 // Perform the flush
1112 int32 result = iFileObject->Flush();
1113 if (result != 0)
1114 LOGDEBUG((0, "PVMFFileBufferWriteDataStreamImpl::Flush returning %d", result));
1115 return PVDS_SUCCESS;
1116 }
1117
1118 OSCL_EXPORT_REF void
NotifyDownloadComplete()1119 PVMFFileBufferWriteDataStreamImpl::NotifyDownloadComplete()
1120 {
1121 iDownloadComplete = true;
1122 // Loop through the iReadNotifications for a Read Notification
1123 for (uint32 i = 0; i < MAX_NUMBER_OF_READ_CONNECTIONS; i++)
1124 {
1125 // If we have a valid iReadNotifications element
1126 // AND the iReadObserver != NULL
1127 if ((iReadNotifications[i].ReadStructValid == true) &&
1128 (iReadNotifications[i].iReadObserver != NULL))
1129 {
1130 uint32 currFilePosition = GetCurrentPointerPosition(0);
1131
1132 PVMFStatus status;
1133 if ((currFilePosition -
1134 iReadNotifications[i].iFilePosition) >
1135 iReadNotifications[i].iReadCapacity)
1136 {
1137 status = PVMFSuccess;
1138 }
1139 else
1140 {
1141 //fail the request - no more data is possible
1142 status = PVMFFailure;
1143 }
1144 PvmiDataStreamObserver* copy_observer = iReadNotifications[i].iReadObserver;
1145 OsclAny* copy_ContextData = iReadNotifications[i].iContextData;
1146 PvmiDataStreamCommandId copy_aID = iReadNotifications[i].iCommandID;
1147
1148 // Reset the iReadNotifications for the next notification
1149 iReadNotifications[i].iReadObserver = NULL;
1150 iReadNotifications[i].iReadCapacity = 0;
1151 iReadNotifications[i].iFilePosition = 0;
1152 iReadNotifications[i].iCommandID = 0;
1153 iReadNotifications[i].iContextData = NULL;
1154
1155 // Form a command response.
1156 PVMFCmdResp resp(copy_aID,
1157 copy_ContextData,
1158 status,
1159 NULL,
1160 NULL);
1161
1162 // Make the Command Complete notification.
1163 copy_observer->DataStreamCommandCompleted(resp);
1164 }
1165 }
1166 }
1167
1168
1169 //////////////////////////////////////////////////////////////////////
1170 // PVMFFileBufferDataStream
1171 //////////////////////////////////////////////////////////////////////
1172 OSCL_EXPORT_REF
PVMFFileBufferDataStream(OSCL_wString & aFileName)1173 PVMFFileBufferDataStream::PVMFFileBufferDataStream(OSCL_wString& aFileName)
1174 {
1175 // Create the two factories
1176 iWriteDataStreamFactory = OSCL_NEW(PVMFFileBufferDataStreamWriteDataStreamFactoryImpl, (aFileName));
1177 iReadDataStreamFactory = OSCL_NEW(PVMFFileBufferDataStreamReadDataStreamFactoryImpl, (aFileName));
1178
1179 // Now create a iWriteDataStream and set the pointer in the iReadDataStreamFactory
1180 PVUuid uuid = PVMIDataStreamSyncInterfaceUuid;
1181 iWriteDataStream = iWriteDataStreamFactory->CreatePVMFCPMPluginAccessInterface(uuid);
1182 iReadDataStreamFactory->SetWriteDataStreamPtr(iWriteDataStream);
1183 }
1184
1185 OSCL_EXPORT_REF
~PVMFFileBufferDataStream()1186 PVMFFileBufferDataStream::~PVMFFileBufferDataStream()
1187 {
1188 // Destroy the instance of the iWriteDataStream
1189 //OSCL_DELETE(iWriteDataStream);
1190 //iWriteDataStream = NULL;
1191
1192 // Delete the two DataStreamFactories
1193 OSCL_DELETE(iWriteDataStreamFactory);
1194 OSCL_DELETE(iReadDataStreamFactory);
1195 }
1196
1197 OSCL_EXPORT_REF PVMFDataStreamFactory*
GetReadDataStreamFactoryPtr()1198 PVMFFileBufferDataStream::GetReadDataStreamFactoryPtr()
1199 {
1200 return OSCL_STATIC_CAST(PVMFDataStreamFactory*, iReadDataStreamFactory);
1201 }
1202
1203 OSCL_EXPORT_REF PVMFDataStreamFactory*
GetWriteDataStreamFactoryPtr()1204 PVMFFileBufferDataStream::GetWriteDataStreamFactoryPtr()
1205 {
1206 return OSCL_STATIC_CAST(PVMFDataStreamFactory*, iWriteDataStreamFactory);
1207 }
1208
1209 OSCL_EXPORT_REF void
NotifyDownloadComplete()1210 PVMFFileBufferDataStream::NotifyDownloadComplete()
1211 {
1212 if (iReadDataStreamFactory != NULL)
1213 {
1214 iReadDataStreamFactory->NotifyDownloadComplete();
1215 }
1216 }
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227