-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathThreadData.h
77 lines (67 loc) · 2.63 KB
/
ThreadData.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
#pragma once
#include <Windows.h>
#include <TextOutputDev.h>
#include <PDFDoc.h>
/**
* @file
* Declarations of constants and structures used in threads
*/
/**
* @defgroup handles ThreadData::handles indexes
* @{ */
constexpr auto THREAD_HANDLE = 0; /**< thread handle index in ThreadData::handles[] */
constexpr auto CONSUMER_HANDLE = 1; /**< consumer event handle index in ThreadData::handles[] */
constexpr auto PRODUCER_HANDLE = 2; /**< producer event handle index in ThreadData::handles[] */
/** @} */
#if 0
constexpr auto CONSUMER_TIMEOUT = INFINITE;
constexpr auto PRODUCER_TIMEOUT = 100U;
#else
/**
* wait for 10 s for producer to produce data (form PDF)
* wait for 100 ms for consumer (TC) to consume data and ask for more,
* on timeout close PDF file
* it is a bad idea to wait for infinite
*/
constexpr auto CONSUMER_TIMEOUT = 10000U; /**< time for one data extraction */
constexpr auto PRODUCER_TIMEOUT = 100U;/**< extractor waits for next request from TC, or closes PDF document */
#endif
constexpr auto DEFAULT_FIELD_CB = 4096U;/**< size of Request.fieldValue, if not provided form TC */
constexpr auto sizeOfWchar = sizeof(wchar_t);/**< sizeof wchar_t */
/**
* Request status enumeration
*/
enum request_status
{
closed, /**< PDF document is closed */
active, /**< data extraction form PDF document in progress */
complete, /**< data extraction form PDF document complete */
canceled /**< data extraction is cancelled, waiting to close document */
};
/**
* PDF extraction request related data
*/
struct Request
{
int fieldIndex; /**< field index to extract */
int unitIndex; /**< unit index */
int cbfieldValue; /**< size of fieldValue in BYTES!!! */
int flags; /**< flags from TC */
int result; /**< result of an extraction */
bool allocated; /**< true=fieldValue is allocated in this class */
DWORD timeout; /**< time to wait in text extraction procedure */
volatile LONG status; /**< request status, @see request_status */
void* fieldValue; /**< extracted data buffer */
void* ptr; /**< pointer to end of extracted data, offset pointer to fieldValue */
const wchar_t* fileName; /**< name of PDF document */
};
/**
* Extraction thread related data
*/
struct ThreadData
{
volatile LONG active; /**< thread status, 1 when active */
CRITICAL_SECTION lock; /**< lock to protect Request while exchanging data */
HANDLE handles[3U]; /**< thread, producer and consumer event handles */
Request request; /**< extraction request */
};