Alternate e697dbe9c5997e35395fe158628dd8c5209481da
for Visual Studio 2022 and Windows 11.
読み取り中…
検索中…
一致する文字列を見つけられません
WorkerTemplate.hpp
[詳解]
1// ----------------------------------------------------------------------------
2// WorkerTemplate.hpp:
3// ----------------------------------------------------------------------------
4#pragma once
5
6#include "CriticalSection.h"
7
8namespace alt
9{
10 enum class WorkerStatus
11 {
13 Created,
14
19
23 Started,
24
29
34
38 Stopped,
39
43 Exited
44 };
45
46 class Message
47 {
48 public:
50 {
51 _from = -1;
52 _to = -1;
53 _command = -1;
54 };
55
56 virtual ~Message () {};
57
58 int GetFrom () { return _from; };
59 void SetFrom (int from) { _from = from; };
60
61 int GetTo () { return _to; };
62 void SetTo (int to) { _to = to; };
63
64 int GetCommand () { return _command; };
65 void SetCommand (int command) { _command = command; };
66
67 private:
68 int _from;
69 int _to;
71 };
72
73 class Data
74 {
75 public:
76 Data (DWORD dwMaxSize)
77 {
78 _dwMaxSize = dwMaxSize;
80 _lpbyData = new BYTE[_dwMaxSize];
81 ZeroMemory (_lpbyData, _dwMaxSize);
82 };
83
84 Data (const Data& data)
85 {
88 _lpbyData = new BYTE[data._dwMaxSize];
89 CopyMemory (_lpbyData, data._lpbyData, data._dwMaxSize);
90 };
91 virtual ~Data () { delete[] _lpbyData; };
92
93 LPBYTE GetByte () { return _lpbyData; };
94 DWORD GetMaxSize () { return _dwMaxSize; };
95 DWORD GetCurrentSize () { return _dwCurrentSize; };
96
97 void SetByte (LPBYTE pbyData, DWORD dwSize)
98 {
99 if (dwSize <= _dwMaxSize)
100 {
101 CopyMemory (_lpbyData, pbyData, dwSize);
102 _dwCurrentSize = dwSize;
103 }
104 };
105
106 private:
108 {
109 _dwMaxSize = 0;
110 _dwCurrentSize = 0;
111 _lpbyData = nullptr;
112 };
113 LPBYTE _lpbyData;
116 };
117
119 {
120 public:
123 {
125 }
126
128 virtual ~WorkerTemplate () {};
129
131 template <typename Function>
132 bool Init (Function function)
133 {
135
136 bool ret = this->CriticalAction (function);
137
139
140 return ret;
141 }
142
144 template <typename Function>
145 bool Start (Function function)
146 {
148
149 bool ret = this->CriticalAction (function);
150
152
153 return ret;
154 }
155
157 template <typename Function>
158 bool Command (Function function, Message message)
159 {
161
162 bool ret = this->CriticalCommand (function, message);
163
165
166 return ret;
167 }
168
170 template <typename Function>
171 Data Process (Function function, Data data)
172 {
174
175 Data ret = this->CriticalProcess (function, data);
176
178
179 return ret;
180 }
181
183 template <typename Function>
184 bool Stop (Function function)
185 {
187
188 bool ret = this->CriticalAction (function);
189
191
192 return ret;
193 }
194
196 template <typename Function>
197 bool Exit (Function function)
198 {
200
201 bool ret = this->CriticalAction (function);
202
204
205 return ret;
206 }
207
210
211 protected:
213 template <typename Function>
214 bool CriticalAction (Function function)
215 {
217
218 bool ret = function ();
219
221
222 return ret;
223 }
224
226 template <typename Function>
227 bool CriticalCommand (Function function, Message message)
228 {
230
231 bool ret = function (message);
232
234
235 return ret;
236 }
237
239 template <typename Function>
240 Data CriticalProcess (Function function, Data data)
241 {
243
244 Data ret = function (data);
245
247
248 return ret;
249 }
250
251 private:
254 };
255}
CriticalSectionに関するWindowsAPIを集約したクラス
CriticalSectionに関するWindowsAPIを集約したクラス
VOID APIENTRY Enter()
排他処理開始
VOID APIENTRY Leave()
排他処理終了
LPBYTE GetByte()
LPBYTE _lpbyData
virtual ~Data()
Data(DWORD dwMaxSize)
DWORD GetMaxSize()
void SetByte(LPBYTE pbyData, DWORD dwSize)
DWORD _dwCurrentSize
Data(const Data &data)
DWORD GetCurrentSize()
void SetTo(int to)
void SetFrom(int from)
void SetCommand(int command)
virtual ~Message()
Data CriticalProcess(Function function, Data data)
Process処理
bool Stop(Function function)
終了処理
WorkerStatus GetStatus()
状態取得
bool Start(Function function)
開始処理
bool CriticalAction(Function function)
排他処理共通
CriticalSection _criticalSection
virtual ~WorkerTemplate()
デストラクタ
bool Exit(Function function)
退出処理
bool Init(Function function)
初期化処理
bool Command(Function function, Message message)
コマンド処理
WorkerStatus _workerStatus
Data Process(Function function, Data data)
プロセス処理
bool CriticalCommand(Function function, Message message)
Command処理
WorkerTemplate()
コンストラクタ
Definition: DBLibrary.h:12
@ Created
生成直後
@ Executed
コマンド実行語
@ BeforeExit
終了前
@ Initialized
初期化後
@ BeforeStop
停止前
@ Started
スタート後
@ BeforeExecute
コマンド実行前
@ BeforeStart
スタート前
@ Stopped
停止後
@ BeforeProcess
プロセス処理前
@ Processed
プロセス処理後
@ BeforeInitialize
初期化前