res.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. #ifndef RES_H
  19. #define RES_H
  20. //////////////////////////////////////////////////////////////////////////////
  21. // Headers.
  22. //////////////////////////////////////////////////////////////////////////////
  23. #include "dispatch.h"
  24. #include "resitem.h"
  25. #include "list.h"
  26. //////////////////////////////////////////////////////////////////////////////
  27. // Macros.
  28. //////////////////////////////////////////////////////////////////////////////
  29. // Size of hash range. To get an idea of overhead for this value: multiply
  30. // HASH_SIZE * sizeof(CList <CResItem>) (currently 20 bytes for an empty list).
  31. // Currently the hash function is dependent on the HASH_SIZE being 256. To
  32. // change this value, YOU MUST REDEFINE THE HASH FUNCTION.
  33. #define HASH_SIZE 256
  34. //////////////////////////////////////////////////////////////////////////////
  35. // Typedefs.
  36. //////////////////////////////////////////////////////////////////////////////
  37. class CRes
  38. {
  39. public: // Construction/Destruction.
  40. // Default constructor.
  41. CRes();
  42. // Destructor.
  43. ~CRes();
  44. public: // Methods.
  45. // Set filter.
  46. void SetDispatcher(CDispatch* pDispatch);
  47. // Free all remaining resources and nodes.
  48. void FreeAll(void);
  49. // If sFreeOnClose is TRUE, resources opened by the open hook
  50. // will be freed by the close hook if they are not additionally locked.
  51. void SetFreeOnClose(short sFreeOnClose)
  52. { m_sFreeOnClose = sFreeOnClose; }
  53. public: // Querries.
  54. // Retrieves the resource identified by pszName.
  55. // Returns ptr to CResItem on succes, NULL otherwise.
  56. PRESITEM GetResource(char* pszName);
  57. // Releases a resource.
  58. void FreeResource(PRESITEM pri);
  59. protected: // Internal methods.
  60. // Sets members w/o regard for current value.
  61. void Set(void);
  62. // Resets members. Deallocates memory if necessary.
  63. void Reset(void);
  64. // Returns a resource item based on it's hash value.
  65. PRESITEM GetResItem(char* pszName);
  66. // Handles data callbacks from dispatch.
  67. short UseCall( UCHAR* puc, long lSize, USHORT usType, UCHAR ucFlags,
  68. long lTime);
  69. // Callback dispatcher (calls the implied this version).
  70. static short UseCallStatic(UCHAR* puc, long lSize, USHORT usType,
  71. UCHAR ucFlags,
  72. long lTime, long l_pRes);
  73. // Handles alloc callbacks from dispatch.
  74. UCHAR* AllocCall(long lSize, USHORT usType, UCHAR ucFlags);
  75. // Callback dispatcher (calls the implied this version).
  76. static UCHAR* AllocCallStatic(long lSize,
  77. USHORT usType, UCHAR ucFlags,
  78. long l_pRes);
  79. // Handles free callbacks from filter.
  80. void FreeCall(UCHAR* puc, USHORT usType, UCHAR ucFlags);
  81. // Callback dispatcher (calls the implied this version).
  82. static void FreeCallStatic(UCHAR* puc, USHORT usType, UCHAR ucFlags,
  83. long l_pRes);
  84. // Hooks calls to CNFile's file Open (NOT memory opens).
  85. // Returns 0 if file found.
  86. static short FileOpenHook( CNFile* pfile, char* pszFileName,
  87. char* pszFlags, short sEndian, long lUser);
  88. // Hooks calls to CNFile's Close.
  89. // Returns 0 if close was taken care of by this hook.
  90. static short FileCloseHook(CNFile* pfile, long lUser);
  91. public: // Members.
  92. protected: // Members.
  93. CDispatch* m_pDispatch; // CDispatch.
  94. CList <CResItem> m_alistRes[HASH_SIZE]; // Uh..De ja vus.
  95. short m_sFreeOnClose; // If TRUE, the close hook
  96. // will free the resource
  97. // if it's not locked.
  98. // Static members.
  99. static CList<CRes> ms_listRes; // List of all CRes objects.
  100. };
  101. #endif // RES_H
  102. //////////////////////////////////////////////////////////////////////////////
  103. // EOF
  104. //////////////////////////////////////////////////////////////////////////////