Stimfit @PACKAGE_VERSION@
Loading...
Searching...
No Matches
csynch.hpp
Go to the documentation of this file.
1//***********************************************************************************************
2//
3// Copyright (c) 1993-1997 Axon Instruments.
4// All rights reserved.
5//
6//***********************************************************************************************
7// HEADER: CSYNCH.HPP
8// PURPOSE: Contains cclass definition for CSynch for creating and maintaining a Synch array.
9// AUTHOR: BHI May 1994
10//
11
12#ifndef INC_CSYNCH_HPP
13#define INC_CSYNCH_HPP
14
15#include "../Common/axodefn.h"
16#include "../Common/axodebug.h"
17
18//-----------------------------------------------------------------------------------------------
19// Local constants:
20
21#define SYNCH_BUFFER_SIZE 100 // buffer 100 synch entries at a time.
22
23// Synch structure definition.
30
31//-----------------------------------------------------------------------------------------------
32// CSynch class definition
33
34class CSynch
35{
36public:
38
39private: // Member variables.
40#if defined(_WINDOWS) && !defined(__MINGW32__)
41 char m_szFileName[_MAX_PATH]; // Filename for array virtualization
42#endif
43
44 FILEHANDLE m_hfSynchFile; // Handle to temporary file.
45 eMODE m_eMode; // Mode flag for buffering algorithm.
46
47 UINT m_uSynchCount; // Total count of entries in the synch array
48 UINT m_uCacheCount; // Count of entries in the cache
49 UINT m_uCacheStart; // Number of first entry in the cache.
50
51 Synch m_SynchBuffer[SYNCH_BUFFER_SIZE]; // Buffer for caching synch entries.
52 Synch m_LastEntry; // Last entry written (write only).
53
54private: // Declare but don't define copy constructor to prevent use of default
55 CSynch(const CSynch &CS);
56 const CSynch &operator=(const CSynch &CS);
57
58private: // Private member functions.
59 void _Initialize();
60 BOOL _Flush();
61/* BOOL _PackBuffer(UINT uAcquiredSamples, UINT &uEntries, UINT uSampleSize);
62// BOOL _Read(LPVOID lpBuf, DWORD dwBytesToRead);
63*/
64 BOOL Read(LPVOID lpBuf, DWORD dwFilePos, DWORD dwEntriesToRead);
65 BOOL _GetReadMode( UINT uFirstEntry, Synch *pSynch, UINT uEntries );
66 BOOL _GetWriteMode( UINT uFirstEntry, Synch *pSynch, UINT uEntries );
67 BOOL _IsFileOpen();
68
69public: // Public member functions
72 void Clone(CSynch *pCS);
73
75 void CloseFile();
76
77 void SetMode(eMODE eMode);
78
79 BOOL Put( UINT uStart, UINT uLength, UINT uOffset=0 );
80/* void UpdateLength( DWORD dwLength );
81 void IncreaseLastLength( DWORD dwIncrease );
82 BOOL GetLastEntry(Synch *pSynch);
83
84*/ BOOL Get( UINT uFirstEntry, Synch *pSynch, UINT uEntries );
85/* BOOL Update( UINT uEntry, const Synch *pSynch );
86*/ UINT GetCount() const;
87/*
88 BOOL Write( HANDLE hDataFile, UINT uAcquiredSamples, UINT *puSynchCount, UINT uSampleSize );
89*/
90};
91
92
93//===============================================================================================
94// PROCEDURE: GetCount
95// PURPOSE: Returns the current count of synch elements.
96//
97inline UINT CSynch::GetCount() const
98{
99// MEMBERASSERT();
100 return m_uSynchCount;
101}
102
103//===============================================================================================
104// PROCEDURE: Read
105// PURPOSE: Reads a block and returns FALSE on ERROR.
106//
107inline BOOL CSynch::Read(LPVOID lpBuf, DWORD dwFirstEntry, DWORD dwEntriesToRead)
108{
109// MEMBERASSERT();
110
111 DWORD dwBytesToRead= dwEntriesToRead * sizeof(Synch);
112// ARRAYASSERT(LPSTR(lpBuf), dwBytesToRead);
113
114 // Save the current file position and seek to the desired position.
115 DWORD dwCurrentPos = c_SetFilePointer( m_hfSynchFile, 0, NULL, FILE_CURRENT );
116
117 if (dwCurrentPos == INVALID_SEEK_VALUE)
118 return FALSE;
119
120 c_SetFilePointer( m_hfSynchFile, dwFirstEntry * sizeof(Synch), NULL, FILE_BEGIN );
121
122 DWORD dwBytesRead = 0;
123 BOOL bOK = c_ReadFile(m_hfSynchFile, lpBuf, dwBytesToRead, &dwBytesRead, NULL);
124
125 // Restore the original file.
126 c_SetFilePointer( m_hfSynchFile, dwCurrentPos, NULL, FILE_BEGIN );
127
128 // Debug error messages.
129 if( !bOK )
130 {
131 TRACE( (char*)"CSynch::Read - ReadFile failed");// with the following error:\n" );
132// SHOW_SYSTEM_ERROR( GetLastError() );
133 }
134
135 if( dwBytesRead != dwBytesToRead ) {
136// TRACE2( "CSynch::Read - error reading from file: dwBytesToRead %d, dwBytesRead %d.\n",
137// dwBytesToRead, dwBytesRead );
138 }
139 return (bOK && (dwBytesRead==dwBytesToRead));
140}
141
142//===============================================================================================
143// PROCEDURE: Get
144// PURPOSE: Retrieves synch entries from the virtualized array.
145//
146inline BOOL CSynch::Get( UINT uFirstEntry, Synch *pSynch, UINT uEntries )
147{
148// MEMBERASSERT();
149// ASSERT(uEntries > 0);
150// ARRAYASSERT(pSynch, uEntries);
151// ASSERT(uFirstEntry+uEntries <= m_uSynchCount);
152 if (m_eMode == eREADMODE)
153 return _GetReadMode( uFirstEntry, pSynch, uEntries );
154 else
155 return _GetWriteMode( uFirstEntry, pSynch, uEntries );
156}
157
158//===============================================================================================
159// PROCEDURE: _IsFileOpen
160// PURPOSE: Returns TRUE if the temp file was opened ok.
161//
162inline BOOL CSynch::_IsFileOpen()
163{
164 return (m_hfSynchFile != FILE_NULL);
165}
166
167#endif // INC_CSYNCH_HPP
#define TRACE(s)
Definition axodebug.h:198
BOOL Get(UINT uFirstEntry, Synch *pSynch, UINT uEntries)
Definition csynch.hpp:146
@ eREADMODE
Definition csynch.hpp:37
@ eWRITEMODE
Definition csynch.hpp:37
void Clone(CSynch *pCS)
BOOL OpenFile()
void CloseFile()
BOOL Put(UINT uStart, UINT uLength, UINT uOffset=0)
void SetMode(eMODE eMode)
UINT GetCount() const
Definition csynch.hpp:97
#define SYNCH_BUFFER_SIZE
Definition csynch.hpp:21
DWORD dwFileOffset
Definition csynch.hpp:28
DWORD dwLength
Definition csynch.hpp:27
DWORD dwStart
Definition csynch.hpp:26
BOOL WINAPI c_ReadFile(FILEHANDLE hFile, LPVOID buffer, DWORD bytesToRead, LPDWORD bytesRead, LPOVERLAPPED overlapped)
int BOOL
Definition unix.h:49
#define FILE_BEGIN
Definition unix.h:153
unsigned int UINT
Definition unix.h:47
FILE * FILEHANDLE
Definition unix.h:38
#define INVALID_SEEK_VALUE
Definition unix.h:8
#define FILE_CURRENT
Definition unix.h:154
#define _MAX_PATH
Definition unix.h:188
#define FILE_NULL
Definition unix.h:10
#define FALSE
Definition unix.h:172
void * LPVOID
Definition unix.h:52
unsigned ABFLONG DWORD
Definition unix.h:45
DWORD WINAPI c_SetFilePointer(FILEHANDLE hFile, LONG distance, LONG *highword, DWORD method)