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 /*! \file oscl_file_io.cpp
19 \brief This file contains file io APIs
20 */
21
22 #include "oscl_file_io.h"
23 #include "oscl_dll.h"
24 #include "oscl_mem.h"
25 #include "oscl_file_native.h"
26 #include "oscl_file_handle.h"
27 #include "oscl_file_cache.h"
28 #include "pvlogger.h"
29 #include "oscl_string_containers.h"
30 #include "oscl_file_stats.h"
31 #include "oscl_file_async_read.h"
32
33 #ifndef OSCL_COMBINED_DLL
OSCL_DLL_ENTRY_POINT_DEFAULT()34 OSCL_DLL_ENTRY_POINT_DEFAULT()
35 #endif
36
37
38 OSCL_EXPORT_REF Oscl_File::Oscl_File()
39 {
40 Construct();
41
42 //for back-compatibility, set the old compile-time defaults.
43 OldCacheDefaults();
44 }
45
Construct()46 void Oscl_File::Construct()
47 {
48 iOpenFileHandle = NULL;
49 iLogger = NULL;
50 iStatsLogger = NULL;
51 iNativeLogger = NULL;
52 iAsyncLogger = NULL;
53 iFileStats = NULL;
54 iNativeFile = NULL;
55 iFileCache = NULL;
56 iIsOpen = false;
57 iNativeBufferSize = 0;
58 iNativeAccessMode = 0;
59 iPVCacheSize = 0;
60 iAsyncReadBufferSize = 0;
61 iAsyncFile = NULL;
62
63 //Create the native file I/O implementation
64 int32 err;
65 OSCL_TRY(err, iNativeFile = OSCL_NEW(OsclNativeFile, ()););
66 }
67
68 //For back-compatibility, this sets cache defaults using the
69 //compile-switches (if defined).
OldCacheDefaults()70 void Oscl_File::OldCacheDefaults()
71 {
72
73 //native file cache enable chooses RFileBuf mode over RFile mode
74 //for symbian.
75
76 SetNativeAccessMode(ESymbianAccessMode_RfileBuf);
77
78 #if defined(OSCL_FILE_BUFFER_MAX_SIZE)
79 //native buffer size defaults to max buffer size
80
81 SetNativeBufferSize(OSCL_FILE_BUFFER_MAX_SIZE);
82 #endif
83
84 #if defined(OSCL_ASYNC_READ_BUFFER_SIZE)
85 // enable async file read operation
86
87 SetAsyncReadBufferSize(OSCL_ASYNC_READ_BUFFER_SIZE);
88 #endif
89
90
91 }
92
93 //For back-compatibility constructors.
94 //This sets the cache settings using a combination of the input value
95 //and the compile-time settings (if defined).
OldCacheSelect(uint32 aCacheSize)96 void Oscl_File::OldCacheSelect(uint32 aCacheSize)
97 {
98 uint32 cacheSize = aCacheSize;
99
100 //file buffer max limits the actual cache size when defined.
101 #if defined(OSCL_FILE_BUFFER_MAX_SIZE)
102 if (cacheSize > OSCL_FILE_BUFFER_MAX_SIZE)
103 cacheSize = OSCL_FILE_BUFFER_MAX_SIZE;
104 #endif
105
106
107 //cache option is "off" (or not defined)
108
109 //cache option is "on"
110 SetNativeBufferSize(cacheSize);
111
112 }
113
114 //This constructor is deprecated, but present for back-compatibility.
Oscl_File(uint32 cacheSize)115 OSCL_EXPORT_REF Oscl_File::Oscl_File(uint32 cacheSize)
116 {
117 Construct();
118 OldCacheDefaults();
119 OldCacheSelect(cacheSize);
120 }
121
122 //This constructor is deprecated, but present for back-compatibility.
Oscl_File(uint32 cacheSize,OsclFileHandle * aHandle)123 OSCL_EXPORT_REF Oscl_File::Oscl_File(uint32 cacheSize, OsclFileHandle* aHandle)
124 {
125 Construct();
126 OldCacheDefaults();
127 OldCacheSelect(cacheSize);
128 SetFileHandle(aHandle);
129 }
130
~Oscl_File()131 OSCL_EXPORT_REF Oscl_File::~Oscl_File()
132 {
133 if (iIsOpen)
134 Close();
135
136 if (iOpenFileHandle)
137 OSCL_DELETE(iOpenFileHandle);
138 iOpenFileHandle = NULL;
139
140 if (iFileCache)
141 OSCL_DELETE(iFileCache);
142 iFileCache = NULL;
143
144 if (iAsyncFile)
145 OsclAsyncFile::Delete(iAsyncFile);
146 iAsyncFile = NULL;
147
148 if (iNativeFile)
149 OSCL_DELETE(iNativeFile);
150 iNativeFile = NULL;
151
152 if (iFileStats)
153 OSCL_DELETE(iFileStats);
154 iFileStats = NULL;
155 }
156
SetPVCacheSize(uint32 aSize)157 OSCL_EXPORT_REF void Oscl_File::SetPVCacheSize(uint32 aSize)
158 {
159 //just save the value now-- it will take effect on the next open.
160 iPVCacheSize = aSize;
161 }
162
SetAsyncReadBufferSize(uint32 aSize)163 OSCL_EXPORT_REF void Oscl_File::SetAsyncReadBufferSize(uint32 aSize)
164 {
165 //just save the value now-- it will take effect on the next open.
166 iAsyncReadBufferSize = aSize;
167
168 }
169
SetLoggingEnable(bool aEnable)170 OSCL_EXPORT_REF void Oscl_File::SetLoggingEnable(bool aEnable)
171 {
172 if (aEnable)
173 {
174 iLogger = PVLogger::GetLoggerObject("Oscl_File");
175 iNativeLogger = PVLogger::GetLoggerObject("OsclNativeFile");
176 iAsyncLogger = PVLogger::GetLoggerObject("OsclAsyncFile");
177 }
178 else
179 {
180 iLogger = NULL;
181 iNativeLogger = NULL;
182 iAsyncLogger = NULL;
183 }
184 }
185
SetSummaryStatsLoggingEnable(bool aEnable)186 OSCL_EXPORT_REF void Oscl_File::SetSummaryStatsLoggingEnable(bool aEnable)
187 {
188 if (aEnable)
189 {
190 iStatsLogger = PVLogger::GetLoggerObject("OsclFileStats");
191 }
192 else
193 {
194 iStatsLogger = NULL;
195 }
196 CreateFileStats();
197 }
198
CreateFileStats()199 void Oscl_File::CreateFileStats()
200 {
201 if (iFileStats)
202 OSCL_DELETE(iFileStats);
203 iFileStats = NULL;
204 if (iStatsLogger)
205 {
206 int32 err;
207 OSCL_TRY(err, iFileStats = OSCL_NEW(OsclFileStats, (this)););
208 }
209 }
210
211
SetNativeAccessMode(uint32 aMode)212 OSCL_EXPORT_REF void Oscl_File::SetNativeAccessMode(uint32 aMode)
213 {
214 //just save the value now-- it will take effect on the next open.
215 iNativeAccessMode = aMode;
216 }
217
SetNativeBufferSize(int32 aSize)218 OSCL_EXPORT_REF void Oscl_File::SetNativeBufferSize(int32 aSize)
219 {
220 //just save the value now-- it will take effect on the next open.
221 iNativeBufferSize = aSize;
222 }
223
SetFileHandle(OsclFileHandle * aHandle)224 OSCL_EXPORT_REF int32 Oscl_File::SetFileHandle(OsclFileHandle* aHandle)
225 {
226 if (iIsOpen)
227 return -1;//can't reset file handle when file is open.
228
229 if (iOpenFileHandle)
230 OSCL_DELETE(iOpenFileHandle);
231 iOpenFileHandle = NULL;
232
233 //make a copy to avoid memory persistence issues
234 if (aHandle)
235 {
236 int32 err;
237 OSCL_TRY(err, iOpenFileHandle = OSCL_NEW(OsclFileHandle, (*aHandle)););
238 if (!iOpenFileHandle)
239 return (-1);//allocation failed.
240 }
241
242 return 0;
243 }
244
245
246 #include "pvlogger.h"
247
OpenFileCacheOrAsyncBuffer(const char * filename,const oscl_wchar * wfilename,uint32 mode,const OsclNativeFileParams & params,Oscl_FileServer & fileserv)248 int32 Oscl_File::OpenFileCacheOrAsyncBuffer(const char *filename
249 , const oscl_wchar* wfilename
250 , uint32 mode
251 , const OsclNativeFileParams& params
252 , Oscl_FileServer& fileserv)
253 //open pv cache or async file implementation for the given open mode.
254 //if cache is not enabled, then cleanup any old implementation.
255 {
256 //use async buffer when read-only mode and iAsyncReadBufferSize is > 0
257 bool asyncEnable = ((mode == MODE_READ || mode == MODE_READ + MODE_BINARY) && iAsyncReadBufferSize > 0);
258
259 //use cache when *not* using async file and iPVCacheSize is > 0
260 bool cacheEnable = !asyncEnable && (iPVCacheSize > 0);
261
262 if (cacheEnable)
263 {
264 //create file cache implementation if needed.
265 if (!iFileCache)
266 {
267 int32 err;
268 OSCL_TRY(err, iFileCache = OSCL_NEW(OsclFileCache, (*this)););
269 if (!iFileCache)
270 return -1;//allocation failed
271 }
272 }
273 else
274 {
275 //cleanup any old implementation of file cache
276 if (iFileCache)
277 OSCL_DELETE(iFileCache);
278 iFileCache = NULL;
279 }
280
281 if (asyncEnable)
282 {
283 //async file implementation isn't reusable so destroy
284 //& re-create it
285 if (iAsyncFile)
286 OsclAsyncFile::Delete(iAsyncFile);
287 iAsyncFile = NULL;
288 int32 err;
289 OSCL_TRY(err, iAsyncFile = OsclAsyncFile::NewL(*iNativeFile, iAsyncReadBufferSize, iAsyncLogger););
290 if (!iAsyncFile)
291 return -1;//allocation failed
292 }
293 else
294 {
295 //cleanup any old implementation of async file.
296 if (iAsyncFile)
297 OsclAsyncFile::Delete(iAsyncFile);
298 iAsyncFile = NULL;
299 }
300
301 //at this point we have either iFileCache, iAsyncFile, or neither.
302
303 if (iFileCache)
304 {
305 return iFileCache->Open(mode, iPVCacheSize);
306 }
307 else if (iAsyncFile)
308 {
309 if (filename)
310 return iAsyncFile->Open(filename, mode, params, fileserv);
311 else if (wfilename)
312 return iAsyncFile->Open(wfilename, mode, params, fileserv);
313 else
314 return -1;
315 }
316 else
317 {
318 return 0;
319 }
320 }
321
Open(const oscl_wchar * filename,uint32 mode,Oscl_FileServer & fileserv)322 OSCL_EXPORT_REF int32 Oscl_File::Open(const oscl_wchar *filename, uint32 mode, Oscl_FileServer& fileserv)
323 {
324 if (iLogger)
325 {
326 OSCL_wHeapString<OsclMemAllocator> wstr(filename);
327 OSCL_HeapString<OsclMemAllocator> str;
328 char buf[2];
329 buf[1] = '\0';
330 for (uint32 i = 0; i < wstr.get_size(); i++)
331 {
332 buf[0] = (char)wstr[i];
333 str += buf;
334 }
335 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
336 (0, "Oscl_File(0x%x)::Open IN name '%s' mode %d serv 0x%x", this, str.get_cstr(), mode, &fileserv));
337 }
338
339 int32 result = (-1);
340
341 uint32 ticks = 0;
342 if (iFileStats)
343 iFileStats->Start(ticks);
344
345 //protect against duplicate open calls
346 if (iIsOpen)
347 goto ErrorExit;
348
349 //do native open or attach
350 {
351 OsclNativeFileParams params(iNativeAccessMode, iNativeBufferSize, iAsyncReadBufferSize);
352 if (iOpenFileHandle)
353 result = CallNativeOpen(*iOpenFileHandle, mode, params, fileserv);
354 else
355 result = CallNativeOpen(filename, mode , params, fileserv);
356
357 if (result != 0)
358 goto ErrorExit;
359
360 //create cache implementation if needed.
361 result = OpenFileCacheOrAsyncBuffer(NULL, filename, mode, params, fileserv);
362 }
363 if (result != 0)
364 goto ErrorExit;
365
366 ErrorExit:
367
368 if (result == 0)
369 iIsOpen = true;
370
371 if (iFileStats
372 && result == 0)
373 iFileStats->End(EOsclFileOp_Open, ticks);
374
375 if (iLogger)
376 {
377 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
378 (0, "Oscl_File(0x%x)::Open OUT result %d", this, result));
379 }
380
381 return result;
382 }
383
384
Open(const char * filename,uint32 mode,Oscl_FileServer & fileserv)385 OSCL_EXPORT_REF int32 Oscl_File::Open(const char *filename, uint32 mode, Oscl_FileServer& fileserv)
386 {
387 if (iLogger)
388 {
389 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
390 (0, "Oscl_File(0x%x)::Open IN name '%s' mode %d serv 0x%x", this, filename, mode, &fileserv));
391 }
392
393 int32 result = (-1);
394
395 uint32 ticks = 0;
396 if (iFileStats)
397 iFileStats->Start(ticks);
398
399 //protect against duplicate open calls
400 if (iIsOpen)
401 goto ErrorExit;
402
403 //do native open or attach
404 {
405 OsclNativeFileParams params(iNativeAccessMode, iNativeBufferSize, iAsyncReadBufferSize);
406 if (iOpenFileHandle)
407 result = CallNativeOpen(*iOpenFileHandle, mode, params, fileserv);
408 else
409 result = CallNativeOpen(filename, mode , params, fileserv);
410
411 if (result != 0)
412 goto ErrorExit;
413
414 //create file cache implementation if needed
415 result = OpenFileCacheOrAsyncBuffer(filename, NULL, mode, params, fileserv);
416 }
417 if (result != 0)
418 goto ErrorExit;
419
420 ErrorExit:
421
422 if (result == 0)
423 iIsOpen = true;
424
425 if (iFileStats
426 && result == 0)
427 iFileStats->End(EOsclFileOp_Open, ticks);
428
429 if (iLogger)
430 {
431 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
432 (0, "Oscl_File(0x%x)::Open OUT result %d", this, result));
433 }
434
435 return result;
436 }
437
Close()438 OSCL_EXPORT_REF int32 Oscl_File::Close()
439 {
440 if (iLogger)
441 {
442 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
443 (0, "Oscl_File(0x%x)::Close IN", this));
444 }
445
446 uint32 ticks = 0;
447 if (iFileStats)
448 iFileStats->Start(ticks);
449
450 int32 result = (-1);
451
452 if (iIsOpen)
453 {
454 if (iFileCache)
455 iFileCache->Close();
456 else if (iAsyncFile)
457 iAsyncFile->Close();
458
459 result = CallNativeClose();
460 }
461
462 iIsOpen = false;
463
464 if (iFileStats
465 && result == 0)
466 {
467 iFileStats->End(EOsclFileOp_Close, ticks);
468 iFileStats->LogAll(iStatsLogger, PVLOGMSG_DEBUG);
469 }
470
471 if (iLogger)
472 {
473 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
474 (0, "Oscl_File(0x%x)::Close OUT result %d", this, result));
475 }
476
477 return result;
478 }
479
480
Read(OsclAny * buffer,uint32 size,uint32 numelements)481 OSCL_EXPORT_REF uint32 Oscl_File::Read(OsclAny *buffer, uint32 size, uint32 numelements)
482 {
483 if (iLogger)
484 {
485 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
486 (0, "Oscl_File(0x%x)::Read IN size %d num %d", this, size, numelements));
487 }
488
489 if (!size || !numelements || !buffer)
490 {
491 OSCL_LEAVE(OsclErrArgument);
492 }
493
494 uint32 ticks = 0;
495 if (iFileStats)
496 iFileStats->Start(ticks);
497
498 uint32 result = 0;
499
500 if (iIsOpen)
501 {
502 if (iFileCache)
503 result = iFileCache->Read(buffer, size, numelements);
504 else if (iAsyncFile)
505 result = iAsyncFile->Read(buffer, size, numelements);
506 else
507 result = CallNativeRead(buffer, size, numelements);
508 }
509
510 if (iFileStats
511 && result > 0)
512 iFileStats->End(EOsclFileOp_Read, ticks, result*size);
513
514 if (iLogger)
515 {
516 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
517 (0, "Oscl_File(0x%x)::Read OUT result %d", this, result));
518 }
519 return result;
520 }
521
522
Write(const OsclAny * buffer,uint32 size,uint32 numelements)523 OSCL_EXPORT_REF uint32 Oscl_File::Write(const OsclAny *buffer, uint32 size, uint32 numelements)
524 {
525 if (iLogger)
526 {
527 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
528 (0, "Oscl_File(0x%x)::Write IN size %d num %d", this, size, numelements));
529 }
530
531 uint32 ticks = 0;
532 if (iFileStats)
533 iFileStats->Start(ticks);
534
535 uint32 result = 0;
536
537 if (iIsOpen)
538 {
539 if (iFileCache)
540 result = iFileCache->Write(buffer, size, numelements);
541 else if (iAsyncFile)
542 return iAsyncFile->Write(buffer, size, numelements);
543 else
544 result = CallNativeWrite(buffer, size, numelements);
545 }
546
547 if (iFileStats
548 && result > 0)
549 iFileStats->End(EOsclFileOp_Write, ticks, result*size);
550
551 if (iLogger)
552 {
553 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
554 (0, "Oscl_File(0x%x)::Write OUT result %d", this, result));
555 }
556 return result;
557 }
558
Seek(TOsclFileOffset offset,seek_type origin)559 OSCL_EXPORT_REF int32 Oscl_File::Seek(TOsclFileOffset offset, seek_type origin)
560 {
561 if (iLogger)
562 {
563 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
564 (0, "Oscl_File(0x%x)::Seek IN offset %d origin %d", this, offset, origin));
565 }
566
567 uint32 ticks = 0;
568 if (iFileStats)
569 iFileStats->Start(ticks);
570
571 int32 result = (-1);
572
573 if (iIsOpen)
574 {
575 if (iFileCache)
576 result = iFileCache->Seek(offset, origin);
577 else if (iAsyncFile)
578 result = iAsyncFile->Seek(offset, origin);
579 else
580 result = CallNativeSeek(offset, origin);
581 }
582
583 if (iFileStats
584 && result == 0)
585 iFileStats->End(EOsclFileOp_Seek, ticks, origin, offset);
586
587 if (iLogger)
588 {
589 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
590 (0, "Oscl_File(0x%x)::Seek OUT result %d", this, result));
591 }
592 return result;
593 }
594
595
Tell()596 OSCL_EXPORT_REF TOsclFileOffset Oscl_File::Tell()
597 {
598 if (iLogger)
599 {
600 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
601 (0, "Oscl_File(0x%x)::Tell IN", this));
602 }
603
604 uint32 ticks = 0;
605 if (iFileStats)
606 iFileStats->Start(ticks);
607
608 TOsclFileOffset result = (-1);
609
610 if (iIsOpen)
611 {
612 if (iFileCache)
613 result = iFileCache->Tell();
614 else if (iAsyncFile)
615 result = iAsyncFile->Tell();
616 else
617 result = CallNativeTell();
618 }
619
620 if (iFileStats
621 && result == 0)
622 iFileStats->End(EOsclFileOp_Tell, ticks);
623
624 if (iLogger)
625 {
626 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
627 (0, "Oscl_File(0x%x)::Tell OUT result %d", this, result));
628 }
629 return result;
630 }
631
Flush()632 OSCL_EXPORT_REF int32 Oscl_File::Flush()
633 {
634 if (iLogger)
635 {
636 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
637 (0, "Oscl_File(0x%x)::Flush IN", this));
638 }
639
640 uint32 ticks = 0;
641 if (iFileStats)
642 iFileStats->Start(ticks);
643
644 int32 result = (-1);
645
646 if (iIsOpen)
647 {
648 if (iFileCache)
649 result = iFileCache->Flush();
650 else if (iAsyncFile)
651 return iAsyncFile->Flush();
652 else
653 result = CallNativeFlush();
654 }
655
656 if (iFileStats
657 && result == 0)
658 iFileStats->End(EOsclFileOp_Flush, ticks);
659
660 if (iLogger)
661 {
662 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
663 (0, "Oscl_File(0x%x)::Flush OUT result %d", this, result));
664 }
665 return result;
666 }
667
668
EndOfFile()669 OSCL_EXPORT_REF int32 Oscl_File::EndOfFile()
670 {
671 if (iLogger)
672 {
673 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
674 (0, "Oscl_File(0x%x)::EndOfFile IN", this));
675 }
676
677 uint32 ticks = 0;
678 if (iFileStats)
679 iFileStats->Start(ticks);
680
681 int32 result = (-1);
682 if (iIsOpen)
683 {
684 if (iFileCache)
685 result = iFileCache->EndOfFile();
686 else if (iAsyncFile)
687 result = iAsyncFile->EndOfFile();
688 else
689 result = CallNativeEndOfFile();
690 }
691
692 if (iFileStats
693 && result != (-1))
694 iFileStats->End(EOsclFileOp_EndOfFile, ticks);
695
696 if (iLogger)
697 {
698 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
699 (0, "Oscl_File(0x%x)::EndOfFile OUT result %d", this, result));
700 }
701 return result;
702 }
703
Size()704 OSCL_EXPORT_REF TOsclFileOffset Oscl_File::Size()
705 {
706 if (iLogger)
707 {
708 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
709 (0, "Oscl_File(0x%x)::Size IN"));
710 }
711
712 uint32 ticks = 0;
713 if (iFileStats)
714 iFileStats->Start(ticks);
715
716 TOsclFileOffset result = (-1);
717
718 if (iIsOpen)
719 {
720 if (iFileCache)
721 result = iFileCache->FileSize();
722 else if (iAsyncFile)
723 result = iAsyncFile->Size();
724 else
725 result = CallNativeSize();
726 }
727
728 if (iFileStats
729 && result != (-1))
730 iFileStats->End(EOsclFileOp_Size, ticks);
731
732 if (iLogger)
733 {
734 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
735 (0, "Oscl_File(0x%x)::Size OUT result %d", this, result));
736 }
737 return result;
738 }
739
GetError()740 OSCL_EXPORT_REF int32 Oscl_File::GetError()
741 {
742 return CallNativeGetError();
743 }
744
CallNativeOpen(const OsclFileHandle & handle,uint32 mode,const OsclNativeFileParams & params,Oscl_FileServer & fileserv)745 int32 Oscl_File::CallNativeOpen(const OsclFileHandle& handle, uint32 mode
746 , const OsclNativeFileParams& params
747 , Oscl_FileServer& fileserv)
748 {
749 if (iNativeLogger)
750 {
751 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iNativeLogger, PVLOGMSG_DEBUG,
752 (0, "OsclNativeFile(0x%x)::Open IN handle 0x%x mode %d serv 0x%x", this, &handle, mode, &fileserv));
753 }
754
755 uint32 ticks = 0;
756 if (iFileStats)
757 iFileStats->Start(ticks);
758
759 int32 result = (-1);
760
761 if (iNativeFile)
762 result = iNativeFile->Open(handle, mode, params, fileserv);
763
764 if (iFileStats
765 && result == 0)
766 iFileStats->End(EOsclFileOp_NativeOpen, ticks);
767
768 if (iNativeLogger)
769 {
770 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iNativeLogger, PVLOGMSG_DEBUG,
771 (0, "OsclNativeFile(0x%x)::Open OUT result %d", this, result));
772 }
773
774 return result;
775 }
776
CallNativeOpen(const oscl_wchar * filename,uint32 mode,const OsclNativeFileParams & params,Oscl_FileServer & fileserv)777 int32 Oscl_File::CallNativeOpen(const oscl_wchar *filename, uint32 mode
778 , const OsclNativeFileParams& params
779 , Oscl_FileServer& fileserv)
780 {
781 OSCL_UNUSED_ARG(params);
782
783 if (iNativeLogger)
784 {
785 OSCL_wHeapString<OsclMemAllocator> wstr(filename);
786 OSCL_HeapString<OsclMemAllocator> str;
787 char buf[2];
788 buf[1] = '\0';
789 for (uint32 i = 0; i < wstr.get_size(); i++)
790 {
791 buf[0] = (char)wstr[i];
792 str += buf;
793 }
794 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iNativeLogger, PVLOGMSG_DEBUG,
795 (0, "OsclNativeFile(0x%x)::Open IN name '%s' mode %d serv 0x%x", this, str.get_cstr(), mode, &fileserv));
796 }
797
798 uint32 ticks = 0;
799 if (iFileStats)
800 iFileStats->Start(ticks);
801
802 int32 result = (-1);
803
804 {
805 OsclNativeFileParams params(iNativeAccessMode, iNativeBufferSize, iAsyncReadBufferSize);
806 if (iNativeFile)
807 result = iNativeFile->Open(filename, mode, params, fileserv);
808 }
809
810 if (iFileStats
811 && result == 0)
812 iFileStats->End(EOsclFileOp_NativeOpen, ticks);
813
814 if (iNativeLogger)
815 {
816 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iNativeLogger, PVLOGMSG_DEBUG,
817 (0, "OsclNativeFile(0x%x)::Open OUT result %d", this, result));
818 }
819
820 return result;
821 }
822
CallNativeOpen(const char * filename,uint32 mode,const OsclNativeFileParams & params,Oscl_FileServer & fileserv)823 int32 Oscl_File::CallNativeOpen(const char *filename, uint32 mode
824 , const OsclNativeFileParams& params
825 , Oscl_FileServer& fileserv)
826 {
827 OSCL_UNUSED_ARG(params);
828
829 if (iNativeLogger)
830 {
831 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iNativeLogger, PVLOGMSG_DEBUG,
832 (0, "OsclNativeFile(0x%x)::Open IN name '%s' mode %d serv 0x%x", this, filename, mode, &fileserv));
833 }
834
835 uint32 ticks = 0;
836 if (iFileStats)
837 iFileStats->Start(ticks);
838
839 int32 result = (-1);
840
841 {
842 OsclNativeFileParams params(iNativeAccessMode, iNativeBufferSize, iAsyncReadBufferSize);
843 if (iNativeFile)
844 result = iNativeFile->Open(filename, mode, params, fileserv);
845 }
846
847 if (iFileStats
848 && result == 0)
849 iFileStats->End(EOsclFileOp_NativeOpen, ticks);
850
851 if (iNativeLogger)
852 {
853 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iNativeLogger, PVLOGMSG_DEBUG,
854 (0, "OsclNativeFile(0x%x)::Open OUT result %d", this, result));
855 }
856
857 return result;
858 }
859
CallNativeRead(OsclAny * buffer,uint32 size,uint32 numelements)860 uint32 Oscl_File::CallNativeRead(OsclAny *buffer, uint32 size, uint32 numelements)
861 {
862 if (iNativeLogger)
863 {
864 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iNativeLogger, PVLOGMSG_DEBUG,
865 (0, "OsclNativeFile(0x%x)::Read IN size %d numelements %d", this, size, numelements));
866 }
867
868 uint32 ticks = 0;
869 if (iFileStats)
870 iFileStats->Start(ticks);
871
872 int32 result = 0;
873
874 if (iNativeFile)
875 result = iNativeFile->Read(buffer, size, numelements);
876
877 if (iFileStats
878 && result > 0)
879 iFileStats->End(EOsclFileOp_NativeRead, ticks, result*size);
880
881 if (iNativeLogger)
882 {
883 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iNativeLogger, PVLOGMSG_DEBUG,
884 (0, "OsclNativeFile(0x%x)::Read OUT result %d", this, result));
885 }
886
887 return result;
888 }
889
CallNativeWrite(const OsclAny * buffer,uint32 size,uint32 numelements)890 uint32 Oscl_File::CallNativeWrite(const OsclAny *buffer, uint32 size, uint32 numelements)
891 {
892 if (iNativeLogger)
893 {
894 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iNativeLogger, PVLOGMSG_DEBUG,
895 (0, "OsclNativeFile(0x%x)::Write IN size %d numelements %d", this, size, numelements));
896 }
897
898 uint32 ticks = 0;
899 if (iFileStats)
900 iFileStats->Start(ticks);
901
902 int32 result = 0;
903
904 if (iNativeFile)
905 result = iNativeFile->Write(buffer, size, numelements);
906
907 if (iFileStats
908 && result > 0)
909 iFileStats->End(EOsclFileOp_NativeWrite, ticks, result*size);
910
911 if (iNativeLogger)
912 {
913 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iNativeLogger, PVLOGMSG_DEBUG,
914 (0, "OsclNativeFile(0x%x)::Write OUT result %d", this, result));
915 }
916
917 return result;
918 }
919
CallNativeSeek(TOsclFileOffset offset,Oscl_File::seek_type origin)920 int32 Oscl_File::CallNativeSeek(TOsclFileOffset offset, Oscl_File::seek_type origin)
921 {
922 if (iNativeLogger)
923 {
924 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iNativeLogger, PVLOGMSG_DEBUG,
925 (0, "OsclNativeFile(0x%x)::Seek IN offset %d origin %d", this, offset, origin));
926 }
927
928 uint32 ticks = 0;
929 if (iFileStats)
930 iFileStats->Start(ticks);
931
932 int32 result = (-1);
933
934 if (iNativeFile)
935 result = iNativeFile->Seek(offset, origin);
936
937 if (iFileStats
938 && result == 0)
939 iFileStats->End(EOsclFileOp_NativeSeek, ticks, origin, offset);
940
941 if (iNativeLogger)
942 {
943 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iNativeLogger, PVLOGMSG_DEBUG,
944 (0, "OsclNativeFile(0x%x)::Seek OUT result %d", this, result));
945 }
946
947 return result;
948 }
949
CallNativeTell()950 TOsclFileOffset Oscl_File::CallNativeTell()
951 {
952 if (iNativeLogger)
953 {
954 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iNativeLogger, PVLOGMSG_DEBUG,
955 (0, "OsclNativeFile(0x%x)::Tell IN", this));
956 }
957
958 uint32 ticks = 0;
959 if (iFileStats)
960 iFileStats->Start(ticks);
961
962 TOsclFileOffset result = (-1);
963
964 if (iNativeFile)
965 result = iNativeFile->Tell();
966
967 if (iFileStats
968 && result == 0)
969 iFileStats->End(EOsclFileOp_NativeTell, ticks);
970
971 if (iNativeLogger)
972 {
973 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iNativeLogger, PVLOGMSG_DEBUG,
974 (0, "OsclNativeFile(0x%x)::Tell OUT result %d", this, result));
975 }
976
977 return result;
978 }
979
980
CallNativeFlush()981 int32 Oscl_File::CallNativeFlush()
982 {
983 if (iNativeLogger)
984 {
985 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iNativeLogger, PVLOGMSG_DEBUG,
986 (0, "OsclNativeFile(0x%x)::Flush IN", this));
987 }
988
989 uint32 ticks = 0;
990 if (iFileStats)
991 iFileStats->Start(ticks);
992
993 int32 result = (-1);
994
995 if (iNativeFile)
996 result = iNativeFile->Flush();
997
998 if (iFileStats
999 && result == 0)
1000 iFileStats->End(EOsclFileOp_NativeFlush, ticks);
1001
1002 if (iNativeLogger)
1003 {
1004 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iNativeLogger, PVLOGMSG_DEBUG,
1005 (0, "OsclNativeFile(0x%x)::Flush OUT result", this, result));
1006 }
1007
1008 return result;
1009 }
1010
CallNativeEndOfFile()1011 int32 Oscl_File::CallNativeEndOfFile()
1012 {
1013 if (iNativeLogger)
1014 {
1015 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iNativeLogger, PVLOGMSG_DEBUG,
1016 (0, "OsclNativeFile(0x%x)::EndOfFile IN", this));
1017 }
1018
1019 uint32 ticks = 0;
1020 if (iFileStats)
1021 iFileStats->Start(ticks);
1022
1023 int32 result = (-1);
1024
1025 if (iNativeFile)
1026 result = iNativeFile->EndOfFile();
1027
1028 if (iFileStats
1029 && result == 0)
1030 iFileStats->End(EOsclFileOp_NativeEndOfFile, ticks);
1031
1032 if (iNativeLogger)
1033 {
1034 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iNativeLogger, PVLOGMSG_DEBUG,
1035 (0, "OsclNativeFile(0x%x)::EndOfFile OUT result", this, result));
1036 }
1037
1038 return result;
1039 }
1040
CallNativeSize()1041 TOsclFileOffset Oscl_File::CallNativeSize()
1042 {
1043 if (iNativeLogger)
1044 {
1045 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iNativeLogger, PVLOGMSG_DEBUG,
1046 (0, "OsclNativeFile(0x%x)::Size IN", this));
1047 }
1048
1049 uint32 ticks = 0;
1050 if (iFileStats)
1051 iFileStats->Start(ticks);
1052
1053 TOsclFileOffset result = (-1);
1054
1055 if (iNativeFile)
1056 result = iNativeFile->Size();
1057
1058 if (iFileStats
1059 && result >= 0)
1060 iFileStats->End(EOsclFileOp_NativeSize, ticks);
1061
1062 if (iNativeLogger)
1063 {
1064 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iNativeLogger, PVLOGMSG_DEBUG,
1065 (0, "OsclNativeFile(0x%x)::Size OUT result", this, result));
1066 }
1067
1068 return result;
1069 }
1070
CallNativeClose()1071 int32 Oscl_File::CallNativeClose()
1072 {
1073 if (iNativeLogger)
1074 {
1075 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iNativeLogger, PVLOGMSG_DEBUG,
1076 (0, "OsclNativeFile(0x%x)::Close IN", this));
1077 }
1078
1079 uint32 ticks = 0;
1080 if (iFileStats)
1081 iFileStats->Start(ticks);
1082
1083 int32 result = (-1);
1084
1085 if (iNativeFile)
1086 result = iNativeFile->Close();
1087
1088 if (iFileStats
1089 && result >= 0)
1090 iFileStats->End(EOsclFileOp_NativeClose, ticks);
1091
1092 if (iNativeLogger)
1093 {
1094 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iNativeLogger, PVLOGMSG_DEBUG,
1095 (0, "OsclNativeFile(0x%x)::Close OUT result", this, result));
1096 }
1097
1098 return result;
1099 }
1100
CallNativeMode()1101 uint32 Oscl_File::CallNativeMode()
1102 {
1103 int32 result = (-1);
1104
1105 if (iNativeFile)
1106 result = iNativeFile->Mode();
1107
1108 return result;
1109 }
1110
CallNativeGetError()1111 int32 Oscl_File::CallNativeGetError()
1112 {
1113 int32 result = (-1);
1114
1115 if (iNativeFile)
1116 result = iNativeFile->GetError();
1117
1118 return result;
1119 }
1120
GetAsyncFileNumOfRun()1121 OSCL_EXPORT_REF uint32 Oscl_File::GetAsyncFileNumOfRun()
1122 {
1123 if (iAsyncFile)
1124 return iAsyncFile->iNumOfRun;
1125 else
1126 return 0;
1127 }
1128
GetAsyncFileNumOfRunError()1129 OSCL_EXPORT_REF uint32 Oscl_File::GetAsyncFileNumOfRunError()
1130 {
1131 if (iAsyncFile)
1132 return iAsyncFile->iNumOfRunErr;
1133 else
1134 return 0;
1135 }
1136
1137