This repository has been archived by the owner on Feb 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPapyMemSystem.h
132 lines (118 loc) · 6.86 KB
/
PapyMemSystem.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/********************************************************************************/
/* */
/* Papyrus 3 library. */
/* This library constitutes a DICOM file system which helps reading and writing */
/* DICOM files and DICOMDIR files. */
/* */
/* Copyright (C) 2004 - Service of Medical Informatics - */
/* University Hospitals of Geneva (HUG), Geneva, Switzerland */
/* */
/* This library is a free software; you can redistribute it and/or modify it */
/* under the terms of the GNU Lesser General Public License as published by the */
/* Free Software Foundation; either version 2.1 of the License, or */
/* (at your option) any later version. */
/* */
/* This library is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */
/* See the GNU Lesser General Public License for more details. */
/* */
/* You should have received a copy of the GNU Lesser General Public License */
/* along with this library; if not, write to */
/* the Free Software Foundation, Inc., */
/* 59 Temple Place, Suite 330, */
/* Boston, MA 02111-1307 USA */
/* */
/* You can contact us for more information at [email protected] */
/* or by writing to Papyrus, */
/* Unite d'Imagerie Numerique / Service d'Informatique Medicale / HUG, */
/* 24, Micheli-du-Crest street, 1211 Geneva 14, Switzerland. */
/* */
/* The University Hopitals of Geneva, hereby disclaims all copyright interest */
/* in the library `Papyrus' (a library for reading and writing DICOM files). */
/* */
/* Geneva, april 2004 */
/* Antoine Geissbuhler, head of the Service of Medical Informatics, */
/* University Hospitals of Geneva, Switzerland */
/* */
/********************************************************************************/
/********************************************************************************/
/* */
/* Project : P A P Y R U S Toolkit */
/* File : PapyMemSystem.h */
/* Function : contains calls for asynchronous read */
/* Authors : Olivier Baujard */
/* */
/* History : 03.1997 version 3.1 */
/* 04.2001 version 3.7 */
/* 09.2001 version 3.7 on CVS */
/* */
/********************************************************************************/
#ifndef PapyMemSystem3H
#define PapyMemSystem3H
/* ------------------------- includes ------------------------------------------*/
#include <windows.h>
#include <process.h> /* _beginthread, _endthread */
#include <fcntl.h>
#ifdef __cplusplus
extern "C" {
int __cdecl _close(int);
long __cdecl _lseek(int, long, int);
int __cdecl _open(const char *, int, ...);
int __cdecl _read(int, void *, unsigned int);
int __cdecl _write(int, void *, unsigned int);
char* __cdecl sprintf(char*, char *, ...);
}
#endif
#ifdef __cplusplus /* C++ PapyMemSystem class and functions */
class PapyMemSystem {
public:
PapyMemSystem();
~PapyMemSystem();
int Open(char* aFilename,long aLength,long aChunkSize=10240L);
void Close();
int Read(char* aBuffer,int aLength);
long Seek(int aPosition,long anOffset);
int WaitSomethingToRead();
int WaitPlaceToWrite();
int IsMemoryAllocated();
static void ReadMemory(void* aPapyMemSystem); // function used in thread
private:
char* theBuffer; // Buffer to read from
long theLength; // Length of buffer
long theChunkSize; // Length of an element chunk read in thread
char* theFilename; // Filename to read from
unsigned long theReadingThread; // Handle to thread reading from filename to fill buffer
char* theFirstPosition; // Starting position of buffer
char* theLastPosition; // Last position in buffer
char* theCurrentRead; // Current position of buffer reading cursor
char* theCurrentWrite; // Current position of file reading cursor
HANDLE theReadEvent; // Event to synchronize file reading
HANDLE theReadMutex; // Mutex to synchronize buffer reading
HANDLE theWriteMutex; // Mutex to synchronize file reading
HANDLE theBooleanMutex; // Mutex to synchronize file reading
short theBoolean; // boolean to check if end of buffer has been reach by all threads
};
extern "C" {
int OpenMemSystem(char* aFilename,long aLength,long aChunk);
int ReadMemSystem(char* aBuffer,int aLength);
int SeekMemSystem(int aPosition,long anOffset);
int IsAllocated();
void CloseMemSystem();
}
#endif
#ifndef __cplusplus /* C API to PapyMemSystem class */
void* CreatePapyMemSystem();
int OpenPapyMemSystem(void* aPapyMemSystem,char* aFilename,long aLength,long aChunk);
void ClosePapyMemSystem(void* aPapyMemSystem);
int ReadPapyMemSystem(void* aPapyMemSystem,char* aBuffer,int aLength);
int SeekPapyMemSystem(void* aPapyMemSystem,int aPosition,long anOffset);
int IsMemoryAllocated(void* aPapyMemSystem);
void DeletePapyMemSystem(void* aPapyMemSystem);
int OpenMemSystem(char* aFilename,long aLength,long aChunk);
int ReadMemSystem(char* aBuffer,int aLength);
int SeekMemSystem(int aPosition,long anOffset);
int IsAllocated();
void CloseMemSystem();
#endif
#endif