-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathBarcodeFileReader.h
More file actions
168 lines (151 loc) · 3.54 KB
/
BarcodeFileReader.h
File metadata and controls
168 lines (151 loc) · 3.54 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#pragma once
#include <vector>
#include <string>
#include <list>
#include <map>
#include <fstream>
#include <sstream>
#if defined(_WIN64) || defined(_WIN32)
#include <io.h>
#include <direct.h>
#define sleep _sleep
#else
#ifdef DM_ARM
#include <sys/uio.h>
#else
#include <sys/io.h>
#endif
#include <dirent.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#endif
#include "BarcodeStatisticsRecorder.h"
#ifndef SAFE_DELETE
#define SAFE_DELETE(obj) if(obj!=NULL){ delete obj;obj=NULL;}
#endif
using namespace std;
struct PathInfo
{
char* name;
bool isDir;
const string strDir;
#if defined(_WIN64) || defined(_WIN32)
_finddata_t findData;
intptr_t handle;
#else
struct dirent* pDirent;
struct stat s_buf;
DIR* pDir;
#endif
PathInfo(const string& sDir) :strDir(sDir)
{}
};
static bool ReadNext(PathInfo& pathInfo)
{
#if defined(_WIN64) || defined(_WIN32)
if (_findnext(pathInfo.handle, &pathInfo.findData) == 0)
{
pathInfo.name = pathInfo.findData.name;
pathInfo.isDir = ((pathInfo.findData.attrib & _A_SUBDIR) != 0);
return true;
}
#else
pathInfo.pDirent = readdir(pathInfo.pDir);
if (pathInfo.pDirent != NULL)
{
pathInfo.name = pathInfo.pDirent->d_name;
string strTmpDir = pathInfo.strDir + "/" + pathInfo.name;
stat(strTmpDir.c_str(), &pathInfo.s_buf);
pathInfo.isDir = S_ISDIR(pathInfo.s_buf.st_mode);
return true;
}
#endif
return false;
}
static bool OpenDirectory(PathInfo& pathInfo)
{
#if defined(_WIN64) || defined(_WIN32)
string strTmpDir = pathInfo.strDir + "\\*.*";
pathInfo.handle = _findfirst(strTmpDir.c_str(), &pathInfo.findData);
if (pathInfo.handle == -1)
return false;
pathInfo.name = pathInfo.findData.name;
pathInfo.isDir = ((pathInfo.findData.attrib & _A_SUBDIR) != 0);
#else
stat(pathInfo.strDir.c_str(), &pathInfo.s_buf);
pathInfo.pDir = opendir(pathInfo.strDir.c_str());
if (!pathInfo.pDir)
return false;
if (!ReadNext(pathInfo))
return false;
#endif
return true;
}
static int CloseDirectory(PathInfo& pathInfo)
{
#if defined(_WIN64) || defined(_WIN32)
return _findclose(pathInfo.handle);
#else
return closedir(pathInfo.pDir);
#endif
}
class CBarcodeStatisticsRecorder;
class CBarcodeFileReader
{
public:
CBarcodeFileReader();
~CBarcodeFileReader();
typedef enum _emOutputType
{
OUTPUT_CONSOLE,
OUTPUT_FILE,
}OUTPUT_TYPE;
typedef enum _enBarcodeFormat {
ALL_BARCODE,
ONED_BARCODE,
CODE39_BARCODE,
CODE128_BARCODE,
CODE93_BARCODE,
CODABAR_BARCODE,
ITF_BARCODE,
EAN13_BARCODE,
EAN8_BARCODE,
UPC_A_BARCODE,
UPC_E_BARCODE,
INDUSTRIAL_25_BARCODE,
PDF417_BARCODE,
DATAMATRIX_BARCODE,
AZTEC_BARCODE,
}BARCODE_FORMAT;
private:
typedef enum _enReaderState
{
READER_STOPPED,
READER_RUNNING,
READER_PAUSE,
}READER_STATE;
private:
string m_barcodeFilesDir;
string m_decodeResultOutputDir;
OUTPUT_TYPE m_outputType;
READER_STATE m_readerState; //0:stopped 1:running 2:pause
protected:
string m_currentOutputFileName;
CBarcodeStatisticsRecorder* m_pBarcodeStatisticsRecorder;
public:
void LoadBarcodeFiles(const char *strBarcodeFilesDir);
void SetOutputType(OUTPUT_TYPE outputType);
void SetOutputFileDir(const char *strOutputDir);
virtual void Run();
void Pause();
void Stop();
protected:
virtual bool ReadFileBarcodes(const string strBarcodeFilePath, CBarcodeStatisticsRecorder::DecodeResultInfo &decodeResultInfo)= 0;
string GetCurrentTimeString();
string ToHexString(unsigned char* bytes, const int byteLength);
private:
void ProcessBarcodeFileRead();
void ScanBarcodeFilesDir(string dir);
void CreateOutputFileDir(string strOutputFilePath);
};