FileWin.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 FILEWIN_H
  19. #define FILEWIN_H
  20. //////////////////////////////////////////////////////////////////////////////
  21. // Headers
  22. //////////////////////////////////////////////////////////////////////////////
  23. #include "btime.h"
  24. #include "file.h"
  25. //////////////////////////////////////////////////////////////////////////////
  26. // Macros.
  27. //////////////////////////////////////////////////////////////////////////////
  28. // Status flags.
  29. #define STATUS_WAITING 0x0001 // Waiting for user to advance a pane.
  30. #define ERROR_FILEACCESS 0x0002 // Error reading file.
  31. #define STATUS_EOF 0x0004 // EOF has been reached.
  32. //////////////////////////////////////////////////////////////////////////////
  33. // Typedefs.
  34. //////////////////////////////////////////////////////////////////////////////
  35. // Access into window.
  36. typedef struct
  37. {
  38. UCHAR *puc; // Pane data.
  39. long lSize; // Size of pane.
  40. long lPos; // Pane's position in Window.
  41. } PANE, *PPANE;
  42. // User callback.
  43. typedef void (*FWFUNC)(PPANE ppane, long lUser);
  44. typedef long (*FILEWIN_TIMEFUNC)(long lUserTime);
  45. class CFileWin
  46. {
  47. public: // Construction/Destruction.
  48. // Default constructor.
  49. CFileWin();
  50. // Destructor.
  51. ~CFileWin();
  52. public: // Methods.
  53. // Sets size of window, i/o pane, and user pane.
  54. // Returns 0 on success.
  55. short SetSize(long lWinSize, long lIOPaneSize, long lUserPaneSize);
  56. // Sets interval between input access.
  57. void SetInputInterval(long lInputInterval)
  58. { m_lInputInterval = lInputInterval; }
  59. // Opens a window into pszFile. Read only!
  60. // Returns 0 on success.
  61. short Open(char* pszFile);
  62. // Closes the currently open file.
  63. // Returns 0 on success.
  64. short Close(void);
  65. // Move to next user pane.
  66. // Returns 0 on success.
  67. short NextPane(void);
  68. // Start reading.
  69. // Returns 0 on success.
  70. short Start(void);
  71. // Suspend reading.
  72. // Returns 0 on success.
  73. short Suspend(void);
  74. // Clear status flag.
  75. void ClearStatus(void)
  76. { m_usStatus = 0; }
  77. // Set time function. Set to NULL to clear.
  78. void SetTimeFunc(FILEWIN_TIMEFUNC fnTime, long lTimeUser)
  79. { m_fnTime = fnTime; m_lTimeUser = lTimeUser; }
  80. public: // Querries.
  81. // Returns ptr to user access pane.
  82. PPANE GetCurPane(void)
  83. {
  84. return &m_paneUser;
  85. }
  86. // Returns TRUE if next user pane is ready; FALSE otherwise.
  87. short IsNextPaneReady(void);
  88. // Returns TRUE if next i/o pane is ready; FALSE otherwise.
  89. short IsNextInputPaneReady(void);
  90. // Current callback status.
  91. USHORT GetStatus(void)
  92. { return m_usStatus; }
  93. // Get time based on user handler or blue.
  94. long GetTime(void)
  95. { return (m_fnTime == NULL ? Blu_GetTime() : (*m_fnTime)(m_lTimeUser) ); }
  96. // Returns TRUE if critical handler is Blue's critical list.
  97. short IsActive(void)
  98. { return m_sActive; }
  99. protected: // Internal methods.
  100. // Sets variables for the first time.
  101. void Set(void);
  102. // Resets variables.
  103. void Reset(void);
  104. // Allocates the file window of size lSize.
  105. // Returns 0 on success.
  106. short Alloc(long lSize);
  107. // Frees the file window.
  108. void Free(void);
  109. // Implied this version of CriticalStatic.
  110. void Critical(void);
  111. // Called by Blue every time Blu_System is called. Reads file.
  112. static void CriticalStatic(CFileWin* pfw);
  113. // Move to next i/o pane.
  114. // Returns 0 on success.
  115. short NextIOPane(void);
  116. public: // Members.
  117. long m_lUser; // Set this to whatever you want!
  118. FWFUNC m_call; // User callback (point wherever you want).
  119. protected: // Members.
  120. CNFile m_file; // File object use to read data.
  121. UCHAR* m_pucWindow; // Window into file.
  122. long m_lWinSize; // Size of window.
  123. long m_lInputInterval; // Time between pane input accesses.
  124. long m_lNextTime; // Time of next pane input.
  125. PANE m_paneIn; // Window pane for input.
  126. PANE m_paneUser; // Window pane for user access.
  127. USHORT m_usStatus; // Current status.
  128. FILEWIN_TIMEFUNC m_fnTime;// Custom time handler.
  129. long m_lTimeUser; // User value for time handler.
  130. short m_sActive; // TRUE if critical is active, FALSE
  131. // otherwise.
  132. short m_sSuspend; // Number of calls to suspend w/o matching
  133. // start.
  134. };
  135. #endif // FILEWIN_H
  136. //////////////////////////////////////////////////////////////////////////////
  137. // EOF
  138. //////////////////////////////////////////////////////////////////////////////