Guiliani  Version 2.5 revision 7293 (documentation build 13)
GUIResourceFileHandler.h
1/*
2* Copyright (C) TES Electronic Solutions GmbH,
3* All Rights Reserved.
4* Contact: info@guiliani.de
5*
6* This file is part of the Guiliani HMI framework
7* for the development of graphical user interfaces on embedded systems.
8*/
9
10#ifndef GUIRESOURCEFILE_HANDLER__H_
11#define GUIRESOURCEFILE_HANDLER__H_
12
13#include "eC_Types.h"
14#include "eC_TList_doubleLinked.h"
15#include "eC_String.h"
16
17#include "GUIComponentManager.h"
18
19class eC_File;
20
22#define GETRESHANDLER CGUIComponentManager::GetInstance().GetResourceFileHandler()
23
25
195{
196 friend class CGUIComponentManager;
197
198public:
201 {
204 };
205
208 {
212 };
213
214public:
217 static void CreateInstance();
218
221 static void DeleteInstance();
222
226 void DeInit();
227
238 eC_File* Open(const eC_String& kPath, const BufferingStrategy_t eBufferingStrategy = BUFFERING_DEFAULT);
239
247 eC_Bool Close(eC_File* file);
248
256 eC_Bool SetResourceData(const eC_UByte* pubResourceData);
257
262 eC_Bool RemoveResourceData(const eC_UByte* pubResourceData);
263
271 eC_Bool SetResourceFile(const eC_String& rkResourceFilePath, const eC_Bool& bEmulateROMFile = false);
272
277 eC_Bool RemoveResourceFile(const eC_String& rkResourceFilePath);
278
284
296 eC_Bool AddMemoryResource(const eC_String& kResourceName, const eC_UInt uiResourceSize, eC_UByte* pubResourceLocation);
297
303 eC_Bool RemoveMemoryResource(const eC_String& kResourceName);
304
312 eC_Bool GetFileInformation(const eC_String& kPath, eC_UInt &uiFileSize, const eC_UByte** ppubData);
313
319 void SetResourcePathPrefix(const eC_String& kResourcePrefix);
320
324 inline const eC_String& GetResourcePathPrefix() const { return m_kResourcePrefix; }
325
329 inline void SetFileOpenOrder(const FileOpenOrder_t eFileOpenOrder) { m_eFileOpenOrder = eFileOpenOrder; }
330
335 inline void SetDiskBuffering(eC_Bool bBufferFileFromDisk) { m_bBufferFileFromDisk = bBufferFileFromDisk; }
336
341 inline void SetHeaderBuffering(eC_Bool bBufferHeader) { m_bBufferHeader = bBufferHeader; }
342
343private:
344 //struct of resource header
345 struct ResourceFileHeader_t
346 {
347 ResourceFileHeader_t() :
348 uiResourceVersion(0),
349 uiHeaderLength(0),
350 uiFileCnt(0),
351 uiFileSize(0),
352 uiAlignmentBytes(0),
353 uiReserved1(0),
354 uiReserved2(0),
355 uiReserved3(0)
356 {}
357
358 eC_UInt uiResourceVersion;
359 eC_UInt uiHeaderLength;
360 eC_UInt uiFileCnt;
361 eC_UInt uiFileSize;
362 eC_UInt uiAlignmentBytes;
363 eC_UInt uiReserved1;
364 eC_UInt uiReserved2;
365 eC_UInt uiReserved3;
366 };
367
368 struct ResourceFileInfo_t
369 {
370 ResourceFileInfo_t() :
371 kResourceFileHeader(),
372 pkResourceFileHandle(NULL),
373 pkResourceFileName(NULL),
374 pubResourceData(NULL),
375 ubSegmentIndex(0)
376 {}
377
378 ResourceFileHeader_t kResourceFileHeader; // header information of resource-file
379 eC_File* pkResourceFileHandle; // file handle to either memory-file or platform-file
380 const eC_String* pkResourceFileName; // name of resource-file if container was loaded
381 const eC_UByte* pubResourceData; // resource-data in memory from statically linked byte-array
382 eC_UByte ubSegmentIndex; // segment-index of file
383 };
384
385 // struct to handle memory locations and treat them as files
386 // the actual pointer and size of the data is managed by eC_MemoryFile
387 struct MemoryFileInfo_t
388 {
389 MemoryFileInfo_t() :
390 pkMemoryFileName(NULL),
391 uiMemoryFileSize(0),
392 pubMemoryFileLocation(NULL)
393 {}
394
395 const eC_String* pkMemoryFileName; // name of resource-file to identify it
396 eC_UInt uiMemoryFileSize; // size of attached memory-file
397 eC_UByte* pubMemoryFileLocation; // pointer to memory-location
398 };
399
400 //struct of pointers to header info for each file in ResourceFile
401 struct FileSearchEntry_t
402 {
403 FileSearchEntry_t() :
404 kPath(""),
405 uiFileSize(0),
406 uiArrayOffset(0),
407 ubSegmentIndex(0)
408 {}
409
410 eC_String kPath; // full name of file as given during Resourcefile creation. This is used for search.
411 eC_UInt uiFileSize; // size of file in bytes
412 eC_UInt uiArrayOffset; // offset in bytes from beginning of ResourceData to the first byte of the given file's data
413 eC_UByte ubSegmentIndex; // used to identify the segment within the resources
414 };
415
416 // each opened file has some management informations
417 struct FileHandleEntry_t
418 {
419 FileHandleEntry_t() :
420#ifdef DEBUG_OPENED_FILES
421 kPath(""),
422#endif
423 pkFileHandle(NULL),
424 pubFileBuffer(NULL),
425 iIndexInAvailableFiles(-1),
426 ubSegmentIndex(0xFF)
427 {}
428
429#ifdef DEBUG_OPENED_FILES
430 eC_String kPath; // path of the opened file
431#endif
432 eC_File* pkFileHandle; // The FileHandle which was returned when it was opened.
433 eC_UByte* pubFileBuffer; // The buffer where the file is loaded in ResouceFile mode
434 eC_Int iIndexInAvailableFiles; // Used to check if file was opened before (-1 = not)
435 eC_UByte ubSegmentIndex; // index of segment (0xFF = no segment)
436 eC_Bool operator==(const FileHandleEntry_t& rhs) const { return pkFileHandle == rhs.pkFileHandle; }
437 };
438
439 // returned when searching for a file
440 struct FileSearchResult_t
441 {
442 FileSearchResult_t() :
443 iFileIndex(FILE_NOT_FOUND_INDEX),
444 ubSegmentIndex(0)
445 {}
446
447 eC_Int iFileIndex;
448 eC_UByte ubSegmentIndex;
449 };
450
451private:
455
459
466
473 CGUIResourceFileHandler& operator=(const CGUIResourceFileHandler& kSource);
474
475 // comparator function for FileSearchEntry_t
476 static int FileSearchEntryComparator(const void* first, const void* second)
477 {
478 const FileSearchEntry_t *firstEntry = static_cast<const FileSearchEntry_t*>(first);
479 const FileSearchEntry_t *secondEntry = static_cast<const FileSearchEntry_t*>(second);
480
481 if (firstEntry->kPath < secondEntry->kPath)
482 return -1;
483 else if (firstEntry->kPath > secondEntry->kPath)
484 return 1;
485 else
486 return 0;
487 }
488
493 ResourceFileHeader_t ReadResourceHeader(eC_File* pkHeaderFile);
494
499 void SetupSearchTable(const ResourceFileInfo_t& rkFileInfo);
500
501 void RemoveSegmentFromSearchTable(const ResourceFileInfo_t& rkFileInfo);
502
509 FileSearchResult_t SearchForFile(const eC_String& kFilePath);
510
518 eC_Int OpenFileFromDisk(const eC_String& kPath, FileHandleEntry_t& newFile, const BufferingStrategy_t eBufferingStrategy);
519
527 eC_Int OpenFileFromResourceFile(const eC_String& kPath, FileHandleEntry_t& newFile, const BufferingStrategy_t eBufferingStrategy);
528
534 eC_File* GetMemoryResource(const eC_String& kResourceName);
535
542 eC_Int OpenFileFromMemory(const eC_String& kPath, FileHandleEntry_t& newFile);
543
544 void RemoveResourceEntry(const eC_UInt& uiIndex);
545
546private:
555 enum GUIResourceMode_t {RESOURCE_NONE, RESOURCE_HEADER, RESOURCE_FILE};
556
557 // Return codes for OpenFileFromResourceFile
558 enum
559 {
560 FILE_OPEN_SUCCESS = 0,
561 FILE_OPEN_FAILURE = -1
562 };
563
564 enum
565 {
566 FILE_NOT_FOUND_INDEX = -1,
567 RESOURCE_READ_BUFFER_SIZE = 256
568 };
569
570private:
571 FileOpenOrder_t m_eFileOpenOrder; // opening order (resource-file first or last)
572 eC_TArray<ResourceFileInfo_t> m_kResourceFileInfo; // information for each loaded segment
573 eC_TListDoubleLinked<MemoryFileInfo_t> m_kListMemoryFileInfo; // lookup-table for all loaded memory locations
574 FileSearchEntry_t* m_pkFileSearchTable; // table sorted by filename for searching individual files
575 eC_UInt m_uiFileSearchEntryCount; // number of search entries stored in array
576 eC_String m_kResourcePrefix; // The resource prefix which is prepended to all file-open operations
577 eC_TListDoubleLinked<FileHandleEntry_t> m_kListOfOpenedFiles; // list of opened files
578 eC_UByte m_ubLoadedSegmentCount; // number of loaded segments
579 eC_Bool m_bBufferFileFromDisk; // loading strategy for data resided on disk
580 eC_Bool m_bBufferHeader; // loading strategy for data in header-files
581};
582
583#endif
central component-manager
Definition: GUIComponentManager.h:62
Class for file handling in Guiliani.
Definition: GUIResourceFileHandler.h:195
eC_Bool GetFileInformation(const eC_String &kPath, eC_UInt &uiFileSize, const eC_UByte **ppubData)
eC_File * Open(const eC_String &kPath, const BufferingStrategy_t eBufferingStrategy=BUFFERING_DEFAULT)
void SetDiskBuffering(eC_Bool bBufferFileFromDisk)
Definition: GUIResourceFileHandler.h:335
const eC_String & GetResourcePathPrefix() const
Definition: GUIResourceFileHandler.h:324
eC_Bool SetResourceData(const eC_UByte *pubResourceData)
eC_Bool SetResourceFile(const eC_String &rkResourceFilePath, const eC_Bool &bEmulateROMFile=false)
static void CreateInstance()
eC_Bool Close(eC_File *file)
eC_Bool RemoveResourceData(const eC_UByte *pubResourceData)
void SetHeaderBuffering(eC_Bool bBufferHeader)
Definition: GUIResourceFileHandler.h:341
FileOpenOrder_t
Enumeration for the order in which files are opened.
Definition: GUIResourceFileHandler.h:201
@ RESOURCE_FILE_FIRST
First try opening from resource file.
Definition: GUIResourceFileHandler.h:202
@ RESOURCE_FILE_LAST
First try opening from disk.
Definition: GUIResourceFileHandler.h:203
BufferingStrategy_t
Enumeration for the buffering strategy to use when opening a file.
Definition: GUIResourceFileHandler.h:208
@ BUFFERING_OFF
Do not use buffering.
Definition: GUIResourceFileHandler.h:209
@ BUFFERING_ALWAYS
Always use.
Definition: GUIResourceFileHandler.h:210
@ BUFFERING_DEFAULT
Use previously set buffering strategy.
Definition: GUIResourceFileHandler.h:211
void SetResourcePathPrefix(const eC_String &kResourcePrefix)
eC_Bool AddMemoryResource(const eC_String &kResourceName, const eC_UInt uiResourceSize, eC_UByte *pubResourceLocation)
static void DeleteInstance()
void SetFileOpenOrder(const FileOpenOrder_t eFileOpenOrder)
Definition: GUIResourceFileHandler.h:329
eC_Bool RemoveMemoryResource(const eC_String &kResourceName)
eC_Bool RemoveResourceFile(const eC_String &rkResourceFilePath)
bool operator==(const NSmartPtr::SharedPtr< C1 > &a, const NSmartPtr::SharedPtr< C2 > &b)
Definition: SharedPtr.h:240