• R/O
  • SSH
  • HTTPS

wincs: Commit


Commit MetaInfo

Revisão8 (tree)
Hora2010-02-11 03:16:29
Autorsho1get

Mensagem de Log

(mensagem de log vazia)

Mudança Sumário

  • delete: WcsAPI/stdafx.h
  • delete: WcsAPI/Plugin.cpp
  • delete: WcsAPI/WcsAPI.vcproj.shoichi-PC.shoichi.user
  • delete: WcsAPI/WcsAPI.vcproj.shoichi-PC.Normal.user
  • delete: WcsAPI/Stopwatch.h
  • delete: WcsAPI/WcsAPI.aps
  • delete: WcsAPI/WcsAPI.vcproj
  • delete: WcsAPI/Interlocked.h
  • delete: WcsAPI/targetver.h
  • delete: WcsAPI/stdafx.cpp
  • delete: WcsAPI/Types.h
  • delete: WcsAPI/WcsAPI.h
  • delete: WcsAPI/StringConvert.h
  • delete: WcsAPI

Diff

--- WcsAPI/Stopwatch.h (revision 7)
+++ WcsAPI/Stopwatch.h (nonexistent)
@@ -1,63 +0,0 @@
1-#pragma once
2-
3-//////////////////////////////////////////////////////////////////////////
4-
5-class CStopwatch
6-{
7-private:
8- LARGE_INTEGER m_liPerfFreq;
9- LARGE_INTEGER m_liPerfStart;
10-
11-public:
12- CStopwatch()
13- {
14- QueryPerformanceFrequency(&m_liPerfFreq);
15- }
16-
17- virtual ~CStopwatch() {}
18-
19- void Start()
20- {
21- QueryPerformanceCounter(&m_liPerfStart);
22- }
23-
24- INT64 NowByMillisecond() const
25- {
26- LARGE_INTEGER liPerfNow;
27- QueryPerformanceCounter(&liPerfNow);
28- return (INT64)(((liPerfNow.QuadPart - m_liPerfStart.QuadPart) * 1000)
29- / m_liPerfFreq.QuadPart);
30- }
31-
32- INT64 NowByMicrosecond() const
33- {
34- LARGE_INTEGER liPerfNow;
35- QueryPerformanceCounter(&liPerfNow);
36- return (INT64)(((liPerfNow.QuadPart - m_liPerfStart.QuadPart) * 1000000)
37- / m_liPerfFreq.QuadPart);
38- }
39-
40- double NowBySecond() const
41- {
42- return static_cast<double>(NowByMicrosecond() / 1000000);
43- }
44-
45- void GetHMS(CString &cs)
46- {
47- LARGE_INTEGER liPerfNow;
48- UINT uHour, uMinute, uSecond;
49- INT64 liNowTime;
50-
51- QueryPerformanceCounter(&liPerfNow);
52- liNowTime = (INT64)((liPerfNow.QuadPart - m_liPerfStart.QuadPart)
53- / m_liPerfFreq.QuadPart);
54-
55- uHour = static_cast<UINT>(liNowTime / 3600);
56- uMinute = static_cast<UINT>((liNowTime - uHour * 3600) / 60);
57- uSecond = static_cast<UINT>(liNowTime - (uHour * 3600 + uMinute * 60));
58-
59- cs.Format(_T("%02d:%02d:%02d"), uHour, uMinute, uSecond);
60- }
61-};
62-
63-//////////////////////////////////////////////////////////////////////////
\ No newline at end of file
--- WcsAPI/Interlocked.h (revision 7)
+++ WcsAPI/Interlocked.h (nonexistent)
@@ -1,330 +0,0 @@
1-#pragma once
2-
3-///////////////////////////////////////////////////////////////////////////////
4-
5-class CLock
6-{
7-public:
8- CLock()
9- {
10- InitializeCriticalSection(&m_cs);
11- m_lRefCnt = 0;
12- }
13-
14- virtual ~CLock()
15- {
16- DeleteCriticalSection(&m_cs);
17- }
18-
19- void Enter()
20- {
21- EnterCriticalSection(&m_cs);
22- m_lRefCnt++;
23- }
24-
25- BOOL TryEnter()
26- {
27- BOOL fRet = TryEnterCriticalSection(&m_cs);
28- if (fRet)
29- {
30- m_lRefCnt++;
31- }
32- return fRet;
33- }
34-
35- void Leave()
36- {
37- m_lRefCnt--;
38- LeaveCriticalSection(&m_cs);
39- }
40-
41- BOOL IsLocked() const
42- {
43- return (m_lRefCnt > 0);
44- }
45-
46-protected:
47- CRITICAL_SECTION m_cs;
48- long m_lRefCnt;
49-};
50-
51-
52-// Instances of this class will be accessed by multiple threads. So,
53-// all members of this class (except the constructor and destructor)
54-// must be thread-safe.
55-class CResGuard
56-{
57-public:
58- CResGuard() { m_lGrdCnt = 0; InitializeCriticalSection(&m_cs); }
59- ~CResGuard() { DeleteCriticalSection(&m_cs); }
60-
61- // IsGuarded is used for debugging
62- BOOL IsGuarded() const { return (m_lGrdCnt > 0); }
63-
64-public:
65- class CGuard
66- {
67- public:
68- CGuard(CResGuard& rg) : m_rg(rg) { m_rg.Guard(); };
69- ~CGuard() { m_rg.Unguard(); }
70-
71- private:
72- CResGuard& m_rg;
73- };
74-
75-private:
76- void Guard() { EnterCriticalSection(&m_cs); m_lGrdCnt++; }
77- void Unguard() { m_lGrdCnt--; LeaveCriticalSection(&m_cs); }
78-
79- // Guard/Unguard can only be accessed by the nested CGuard class.
80- friend class CResGuard::CGuard;
81-
82-private:
83- CRITICAL_SECTION m_cs;
84- long m_lGrdCnt; // # of EnterCriticalSection calls
85-};
86-
87-
88-///////////////////////////////////////////////////////////////////////////////
89-
90-
91-// Instances of this class will be accessed by multiple threads. So,
92-// all members of this class (except the constructor and destructor)
93-// must be thread-safe.
94-template <class TYPE>
95-class CInterlockedType
96-{
97-public: // Public member functions
98- // Note: Constructors & destructors are always thread safe
99- CInterlockedType() {}
100- CInterlockedType(const TYPE& TVal) { m_TVal = TVal; }
101- virtual ~CInterlockedType() {}
102-
103- // Cast operator to make writing code that uses
104- // thread-safe data type easier
105- operator TYPE() const
106- {
107- CResGuard::CGuard x(m_rg);
108- return GetVal();
109- }
110-
111-protected: // Protected function to be called by derived class
112- TYPE& GetVal()
113- {
114- return m_TVal;
115- }
116-
117- const TYPE& GetVal() const
118- {
119- return m_TVal;
120- }
121-
122- TYPE SetVal(const TYPE& TNewVal)
123- {
124- TYPE& TVal = GetVal();
125- if (TVal != TNewVal)
126- {
127- TYPE TPrevVal = TVal;
128- TVal = TNewVal;
129- OnValChanged(TNewVal, TPrevVal);
130- }
131- return TVal;
132- }
133-
134-protected: // Overridable functions
135- virtual void OnValChanged(
136- const TYPE& TNewVal, const TYPE& TPrevVal) const
137- {
138- // Nothing to do here
139- }
140-
141-protected:
142- // Protected guard for use by derived class functions
143- mutable CResGuard m_rg;
144-
145-private: // Private data members
146- TYPE m_TVal;
147-};
148-
149-///////////////////////////////////////////////////////////////////////////////
150-
151-// Instances of this class will be accessed by multiple threads. So,
152-// all members of this class (except the constructor and destructor)
153-// must be thread-safe.
154-template <class TYPE>
155-class CInterlockedScalar : protected CInterlockedType<TYPE>
156-{
157-public:
158- CInterlockedScalar(TYPE TVal = 0) : CInterlockedType<TYPE>(TVal) {}
159- ~CInterlockedScalar() { /* Nothing to do */ }
160-
161- // C++ does not allow operator cast to be inherited.
162- operator TYPE() const
163- {
164- return (CInterlockedType<TYPE>::operator TYPE());
165- }
166-
167- TYPE operator=(TYPE TVal)
168- {
169- CResGuard::CGuard x(m_rg);
170- return SetVal(TVal);
171- }
172-
173- TYPE operator++(int) // Postfix increment operator
174- {
175- CResGuard::CGuard x(m_rg);
176- TYPE TPrevVal = GetVal();
177- SetVal((TYPE) (TPrevVal + 1));
178- return TPrevVal; // Return value BEFORE increment
179- }
180-
181- TYPE operator--(int) // Postfix decrement operator.
182- {
183- CResGuard::CGuard x(m_rg);
184- TYPE TPrevVal = GetVal();
185- SetVal((TYPE) (TPrevVal - 1));
186- return TPrevVal; // Return value BEFORE decrement
187- }
188-
189- TYPE operator += (TYPE op)
190- { CResGuard::CGuard x(m_rg); return SetVal(GetVal() + op); }
191- TYPE operator++()
192- { CResGuard::CGuard x(m_rg); return SetVal(GetVal() + 1); }
193- TYPE operator -= (TYPE op)
194- { CResGuard::CGuard x(m_rg); return SetVal(GetVal() - op); }
195- TYPE operator--()
196- { CResGuard::CGuard x(m_rg); return SetVal(GetVal() - 1); }
197- TYPE operator *= (TYPE op)
198- { CResGuard::CGuard x(m_rg); return SetVal(GetVal() * op); }
199- TYPE operator /= (TYPE op)
200- { CResGuard::CGuard x(m_rg); return SetVal(GetVal() / op); }
201- TYPE operator %= (TYPE op)
202- { CResGuard::CGuard x(m_rg); return SetVal(GetVal() % op); }
203- TYPE operator ^= (TYPE op)
204- { CResGuard::CGuard x(m_rg); return SetVal(GetVal() ^ op); }
205- TYPE operator &= (TYPE op)
206- { CResGuard::CGuard x(m_rg); return SetVal(GetVal() & op); }
207- TYPE operator |= (TYPE op)
208- { CResGuard::CGuard x(m_rg); return SetVal(GetVal() | op); }
209- TYPE operator <<=(TYPE op)
210- { CResGuard::CGuard x(m_rg); return SetVal(GetVal() << op); }
211- TYPE operator >>=(TYPE op)
212- { CResGuard::CGuard x(m_rg); return SetVal(GetVal() >> op); }
213-};
214-
215-///////////////////////////////////////////////////////////////////////////////
216-
217-// Instances of this class will be accessed by multiple threads. So,
218-// all members of this class (except the constructor and destructor)
219-// must be thread-safe.
220-template <class TYPE>
221-class CZeroEvent : public CInterlockedScalar<TYPE>
222-{
223-public:
224- CZeroEvent(TYPE TVal = 0, BOOL fManualReset = TRUE)
225- : CInterlockedScalar<TYPE>(TVal)
226- {
227- // The event should be signaled if TVal is 0
228- m_hevtZero = CreateEvent(NULL, fManualReset, (TVal == 0), NULL);
229-
230- // The event should be signaled if TVal is NOT 0
231- m_hevtNotZero = CreateEvent(NULL, fManualReset, (TVal != 0), NULL);
232- }
233-
234- ~CZeroEvent()
235- {
236- CloseHandle(m_hevtZero);
237- CloseHandle(m_hevtNotZero);
238- }
239-
240- // C++ does not allow operator= to be inherited.
241- TYPE operator=(TYPE x)
242- {
243- return (CInterlockedScalar<TYPE>::operator=(x));
244- }
245-
246- // Return handle to event signaled when value is zero
247- operator HANDLE() const { return m_hevtZero; }
248-
249- // Return handle to event signaled when value is zero
250- HANDLE GetZeroHandle() const { return m_hevtZero; }
251-
252- // Return handle to event signaled when value is not zero
253- HANDLE GetNotZeroHandle() const { return m_hevtNotZero; }
254-
255- // C++ does not allow operator cast to be inherited.
256- operator TYPE() const
257- {
258- return (CInterlockedScalar<TYPE>::operator TYPE());
259- }
260-
261-protected:
262- void OnValChanged(const TYPE& TNewVal, const TYPE& TPrevVal) const
263- {
264- // For best performance, avoid jumping to
265- // kernel mode if we don't have to
266- if ((TNewVal == 0) && (TPrevVal != 0))
267- {
268- SetEvent(m_hevtZero);
269- ResetEvent(m_hevtNotZero);
270- }
271- if ((TNewVal != 0) && (TPrevVal == 0))
272- {
273- ResetEvent(m_hevtZero);
274- SetEvent(m_hevtNotZero);
275- }
276- }
277-
278-private:
279- HANDLE m_hevtZero; // Signaled when data value is 0
280- HANDLE m_hevtNotZero; // Signaled when data value is not 0
281-};
282-
283-///////////////////////////////////////////////////////////////////////////////
284-
285-template <class TYPE>
286-class CAtomic
287-{
288-public:
289- CAtomic() {}
290- CAtomic(const TYPE& TVal) { m_TVal = TVal; }
291- virtual ~CAtomic() {}
292-
293- operator TYPE() const
294- {
295- CResGuard::CGuard x(m_rg);
296- return GetVal();
297- }
298-
299- TYPE operator = (TYPE TVal)
300- {
301- CResGuard::CGuard x(m_rg);
302- return SetVal(TVal);
303- }
304-
305-protected:
306- TYPE& GetVal()
307- {
308- return m_TVal;
309- }
310-
311- const TYPE& GetVal() const
312- {
313- return m_TVal;
314- }
315-
316- TYPE SetVal(const TYPE& TNewVal)
317- {
318- TYPE& TVal = GetVal();
319- TVal = TNewVal;
320- return TVal;
321- }
322-
323-protected:
324- mutable CResGuard m_rg;
325-
326-protected:
327- TYPE m_TVal;
328-};
329-
330-//////////////////////////////// End of File //////////////////////////////////
--- WcsAPI/targetver.h (revision 7)
+++ WcsAPI/targetver.h (nonexistent)
@@ -1,17 +0,0 @@
1-#pragma once
2-
3-#ifndef WINVER
4-#define WINVER 0x0600
5-#endif
6-
7-#ifndef _WIN32_WINNT
8-#define _WIN32_WINNT 0x0600
9-#endif
10-
11-#ifndef _WIN32_WINDOWS
12-#define _WIN32_WINDOWS 0x0410
13-#endif
14-
15-#ifndef _WIN32_IE
16-#define _WIN32_IE 0x0700
17-#endif
--- WcsAPI/stdafx.cpp (revision 7)
+++ WcsAPI/stdafx.cpp (nonexistent)
@@ -1 +0,0 @@
1-#include "stdafx.h"
--- WcsAPI/Types.h (revision 7)
+++ WcsAPI/Types.h (nonexistent)
@@ -1,153 +0,0 @@
1-#pragma once
2-
3-#define WCS_PLUGIN_TYPE_GRAPHICS 1
4-#define WCS_PLUGIN_TYPE_CONSOLE 2
5-
6-#define WCS_BUILD_TYPE_RELEASE 1
7-#define WCS_BUILD_TYPE_DEBUG 2
8-
9-//////////////////////////////////////////////////////////////////////////
10-
11-typedef struct _BM_DATA
12-{
13- WORD wNodeID;
14- DWORD dwAddress;
15- DWORD dwProcessors;
16- DWORD dwIterations;
17- double dbRlt1;
18- double dbRlt2;
19- double dbRlt3;
20- double dbRlt4;
21- double dbRltAvg;
22- double dbRuntime;
23- BOOL fSet;
24-}
25-BM_DATA, *LPBM_DATA;
26-
27-typedef struct _NODE_DATA
28-{
29- DWORD dwAddress;
30- WORD wPort;
31- WORD wNodeID;
32- WORD wNodeType;
33- WORD wNodeState;
34- DWORD dwProcessors;
35- BM_DATA bm;
36-}
37-NODE_DATA, *LPNODE_DATA;
38-
39-typedef struct _PLUGIN_INFO
40-{
41- WORD wPluginID;
42- WORD wType;
43- WORD wVersion;
44- UINT nBuildType;
45- DWORD dwTimeout;
46- TCHAR szText[512];
47-}
48-PLUGIN_INFO, *LPPLUGIN_INFO;
49-
50-typedef struct _MASTER_SETTING
51-{
52- BOOL fInternet;
53- BOOL fRtRendering;
54- BOOL fLogPlugin;
55- UINT nConnections;
56- UINT nProcessors;
57- UINT nRecvCount;
58- UINT nTotalCount;
59-}
60-MASTER_SETTING, *LPMASTER_SETTING;
61-
62-typedef struct _SLAVE_SETTING
63-{
64- BOOL fAutoDownload;
65- UINT nProcessors;
66-}
67-SLAVE_SETTING, *LPSLAVE_SETTING;
68-
69-typedef struct _CALCREPORT
70-{
71- WORD wNodeID;
72- WORD wSubID;
73- DWORD dwAddress;
74- double dbRuntime;
75-}
76-CALCREPORT, *LPCALCREPORT;
77-
78-typedef struct _CALCSIZE
79-{
80- UINT nWidth;
81- UINT nHeight;
82- UINT nRange;
83-}
84-CALCSIZE, *LPCALCSIZE;
85-
86-typedef struct _NODEINIT
87-{
88- int nIndex;
89- int nYInit;
90- int nStep;
91- int nRange;
92- WORD wNodeID;
93- WORD wSubID;
94- BOOL fEnd;
95- DWORD dwAddress;
96- double dbRuntime;
97-}
98-NODEINIT, *LPNODEINIT;
99-
100-//////////////////////////////////////////////////////////////////////////
101-
102-typedef unsigned (__stdcall *PTHREAD_START)(void *); // Thread
103-
104-typedef CArray<NODE_DATA> NodeDataList;
105-typedef CArray<HANDLE> HandleList;
106-typedef CArray<DWORD> DWORDList;
107-typedef CArray<CALCREPORT> CalcReportList;
108-typedef CArray<NODEINIT> NodeInitList;
109-
110-typedef struct _MASTER_PLUGIN
111-{
112- WORD wNodeID;
113- DWORD dwAddress;
114- DWORD dwProcessors;
115- BOOL bSystem;
116- BOOL bFront;
117- UINT nPluginType;
118- CString csWndName;
119- NodeDataList list;
120-}
121-MASTER_PLUGIN, *LPMASTER_PLUGIN;
122-
123-typedef struct _SLAVE_PLUGIN
124-{
125- WORD wNodeID;
126- DWORD dwProcessors;
127- double dbRuntime;
128-}
129-SLAVE_PLUGIN, *LPSLAVE_PLUGIN;
130-
131-//////////////////////////////////////////////////////////////////////////
132-
133-typedef CInterlockedType<HANDLE> ATM_HANDLE;
134-typedef CInterlockedScalar<WORD> ATM_WORD;
135-typedef CInterlockedScalar<DWORD> ATM_DWORD;
136-typedef CInterlockedScalar<double> ATM_DOUBLE;
137-
138-//////////////////////////////////////////////////////////////////////////
139-
140-#define MC_MINSIZE(x, y) \
141- (sizeof(x) < sizeof(y)) ? sizeof(x) : sizeof(y)
142-
143-#define MC_BEGINTHREADEX(psa, cbStack, pfnStartAddr, \
144- pvParam, fdwCreate, pdwThreadId) \
145- ((HANDLE)_beginthreadex( \
146- (void *) (psa), \
147- (unsigned) (cbStack), \
148- (PTHREAD_START) (pfnStartAddr), \
149- (void *) (pvParam), \
150- (unsigned) (fdwCreate), \
151- (unsigned *) (pdwThreadId)))
152-
153-//////////////////////////////////////////////////////////////////////////
--- WcsAPI/WcsAPI.h (revision 7)
+++ WcsAPI/WcsAPI.h (nonexistent)
@@ -1,282 +0,0 @@
1-#pragma once
2-
3-//////////////////////////////////////////////////////////////////////////
4-
5-#include "Interlocked.h"
6-#include "Types.h"
7-#include "Stopwatch.h"
8-#include "StringConvert.h"
9-#include <afxmt.h>
10-#include <process.h> // For _beginthreadex
11-
12-//////////////////////////////////////////////////////////////////////////
13-
14-class CWcsAPI
15-{
16-public:
17- CWcsAPI() {}
18- virtual ~CWcsAPI() {}
19-
20-public:
21- // WinCS API
22- virtual BOOL API_StartPlugin(WORD wPluginID, const CByteArray &arg)
23- { return FALSE; }
24- virtual BOOL API_StopPlugin(double dbRuntime) // For Single mode or Slave
25- { return FALSE; }
26- virtual BOOL API_StopPlugin(const CalcReportList &list) // For System mode
27- { return FALSE; }
28- virtual BOOL API_Broadcast(const CByteArray &data)
29- { return FALSE; }
30- virtual BOOL API_SendToMaster(const CByteArray &data)
31- { return FALSE; }
32- virtual BOOL API_CreateGraphWindow(const CString &csName, int cx, int cy, BOOL bFront)
33- { return FALSE;}
34- virtual BOOL API_SetPixel(int x, int y, COLORREF color)
35- { return FALSE;}
36- virtual BOOL API_SetXLine(int y, int cx, LPCOLORREF lpColor)
37- { return FALSE;}
38- virtual BOOL API_SetYLine(int x, int cy, LPCOLORREF lpColor)
39- { return FALSE;}
40- virtual BOOL API_SetTaskSchedule(const NodeInitList &list)
41- { return FALSE; }
42- virtual void API_SetProgress(DWORD dwIndex, int nPoint)
43- {}
44- virtual void API_InitProgress(DWORD dwProcessors)
45- {}
46- virtual void API_SetGraphWindowSize(int cx, int cy, int x, int y)
47- {}
48- virtual void API_SetCenterWindow()
49- {}
50- virtual void API_ResetWindow()
51- {}
52- virtual void API_StartTimer()
53- {}
54- virtual void API_StopTimer()
55- {}
56-};
57-
58-//////////////////////////////////////////////////////////////////////////
59-
60-// Base class
61-class CPlugin : public CStringConvert
62-{
63-protected:
64- explicit CPlugin();
65- virtual ~CPlugin();
66-
67-public:
68- // Override function
69- virtual BOOL LoadInitialize() { return TRUE; }
70- virtual void ReceiveCallBack(const CByteArray &data) {}
71-
72- virtual BOOL MasterInitialize(const NodeDataList &list, BOOL fSystem) { return TRUE; }
73- virtual BOOL MasterFinalize() { return TRUE; }
74- virtual DWORD MasterTransaction(LPVOID lpParams = NULL);
75-
76- virtual BOOL SlaveInitialize(const SLAVE_PLUGIN &init);
77- virtual BOOL SlaveFinalize() { return TRUE; }
78- virtual DWORD SlaveTransaction(LPVOID lpParams = NULL);
79-
80-public:
81- BOOL StartPlugin(const CByteArray &arg);
82- BOOL CancelPlugin(DWORD dwTimeout);
83- void GetPluginInfo(LPPLUGIN_INFO lpInfo);
84- void SetAPI(CWcsAPI *pAPI) { m_pAPI = pAPI; }
85- void SetCalcSize(CALCSIZE size) { m_CalcSize = size; }
86- void GetCalcSize(CALCSIZE &size) { size = m_CalcSize; }
87- BOOL IsMaster() { return m_fMaster; }
88-
89- // WinCS API wrapper
90- // Master function
91- BOOL API_StartPlugin(WORD wPluginID, const CByteArray &arg);
92- BOOL API_StopPlugin(double dbRuntime);
93- BOOL API_StopPlugin(const CalcReportList &list);
94- BOOL API_Broadcast(const CByteArray &data);
95- BOOL API_CreateGraphWindow(const CString &csName, int cx, int cy, BOOL bFront = FALSE);
96- BOOL API_SetPixel(int x, int y, COLORREF color);
97- BOOL API_SetXLine(int y, int cx, LPCOLORREF lpColor);
98- BOOL API_SetYLine(int x, int cy, LPCOLORREF lpColor);
99- BOOL API_SetTaskSchedule(const NodeInitList &list);
100- void API_SetGraphWindowSize(int cx, int cy, int x = 0, int y = 0);
101- void API_SetCenterWindow();
102- void API_ResetWindow();
103- void API_StartTimer();
104- void API_StopTimer();
105-
106- // Slave function
107- BOOL API_SendToMaster(const CByteArray &data);
108- void API_SetProgress(DWORD dwIndex, int nPoint);
109- void API_InitProgress(DWORD dwProcessors);
110-
111-protected:
112- typedef CZeroEvent<SHORT> ZeroEvent;
113- typedef CArray<ZeroEvent> EventList;
114-
115- void SetCalcReport(DWORD dwIndex, double dbRuntime);
116- BOOL doCreateWindow(const MASTER_PLUGIN &init);
117- static DWORD WINAPI doMasterTransaction(LPVOID lpParams);
118- static DWORD WINAPI doSlaveTransaction(LPVOID lpParams);
119-
120-private:
121- void CloseHandleList(BOOL fWait = FALSE, DWORD dwMilliseconds = INFINITE);
122- void ThreadFinish();
123-
124-protected:
125- typedef struct _PLUGIN_PARAMS
126- {
127- CPlugin *obj;
128- DWORD dwIndex;
129- DWORD dwAffinity;
130- DWORD dwThdCount;
131- BOOL fAlive;
132- BOOL fSystem;
133- CByteArray arg;
134- }
135- PLUGIN_PARAMS, *LPPLUGIN_PARAMS;
136-
137- typedef struct _THREAD_COUNT
138- {
139- ATM_DWORD dwCount;
140- ATM_DWORD dwFinish;
141- }
142- THREAD_COUNT, *LPTHREAD_COUNT;
143-
144- typedef struct _CALCCOUNT
145- {
146- ATM_DWORD dwFinCount;
147- ATM_DWORD dwAllCount;
148- }
149- CALCCOUNT, *LPCALCCOUNT;
150-
151- typedef CArray<PLUGIN_PARAMS> PlgPrmList;
152-
153- CCriticalSection m_NetLock;
154- CalcReportList m_Reportlist; // For Single mode
155- NodeInitList m_NodeInitList; // For System mode
156- PLUGIN_INFO m_PlgInfo;
157- CByteArray m_Argument;
158- CStopwatch m_Stopwatch;
159- PlgPrmList m_PlgPrmList;
160- HandleList m_ThdList;
161- DWORDList m_ThdIDList;
162- EventList m_EventList;
163- CALCCOUNT m_CalcCount;
164- CALCSIZE m_CalcSize;
165- BOOL m_fRunning;
166- BOOL m_fMaster;
167- BOOL m_fSystem;
168-
169- MASTER_PLUGIN m_MasterPlugin;
170- SLAVE_PLUGIN m_SlavePlugin;
171-
172-private:
173- CCriticalSection m_ThdLock;
174- THREAD_COUNT m_ThdCount;
175- CWcsAPI *m_pAPI;
176-};
177-
178-//////////////////////////////////////////////////////////////////////////
179-
180-inline BOOL CPlugin::API_StartPlugin(WORD wPluginID, const CByteArray &arg)
181-{
182- ASSERT(m_pAPI);
183- return m_pAPI->API_StartPlugin(wPluginID, arg);
184-}
185-
186-inline BOOL CPlugin::API_StopPlugin(double dbRuntime)
187-{
188- ASSERT(m_pAPI);
189- return m_pAPI->API_StopPlugin(dbRuntime);
190-}
191-
192-inline BOOL CPlugin::API_StopPlugin(const CalcReportList &list)
193-{
194- ASSERT(m_pAPI);
195- return m_pAPI->API_StopPlugin(list);
196-}
197-
198-inline BOOL CPlugin::API_Broadcast(const CByteArray &data)
199-{
200- ASSERT(m_pAPI);
201- return m_pAPI->API_Broadcast(data);
202-}
203-
204-inline BOOL CPlugin::API_SendToMaster(const CByteArray &data)
205-{
206- ASSERT(m_pAPI);
207- return m_pAPI->API_SendToMaster(data);
208-}
209-
210-inline BOOL CPlugin::API_CreateGraphWindow(const CString &csName, int cx, int cy, BOOL bFront)
211-{
212- ASSERT(m_pAPI);
213- return m_pAPI->API_CreateGraphWindow(csName, cx, cy, bFront);
214-}
215-
216-inline BOOL CPlugin::API_SetPixel(int x, int y, COLORREF color)
217-{
218- ASSERT(m_pAPI);
219- return m_pAPI->API_SetPixel(x, y, color);
220-}
221-
222-inline BOOL CPlugin::API_SetXLine(int y, int cx, LPCOLORREF lpColor)
223-{
224- ASSERT(m_pAPI);
225- return m_pAPI->API_SetXLine(y, cx, lpColor);
226-}
227-
228-inline BOOL CPlugin::API_SetYLine(int x, int cy, LPCOLORREF lpColor)
229-{
230- ASSERT(m_pAPI);
231- return m_pAPI->API_SetYLine(x, cy, lpColor);
232-}
233-
234-inline BOOL CPlugin::API_SetTaskSchedule(const NodeInitList &list)
235-{
236- ASSERT(m_pAPI);
237- return m_pAPI->API_SetTaskSchedule(list);
238-}
239-
240-inline void CPlugin::API_SetProgress(DWORD dwIndex, int nPoint)
241-{
242- ASSERT(m_pAPI);
243- m_pAPI->API_SetProgress(dwIndex, nPoint);
244-}
245-
246-inline void CPlugin::API_InitProgress(DWORD dwProcessors)
247-{
248- ASSERT(m_pAPI);
249- m_pAPI->API_InitProgress(dwProcessors);
250-}
251-
252-inline void CPlugin::API_SetGraphWindowSize(int cx, int cy, int x, int y)
253-{
254- ASSERT(m_pAPI);
255- m_pAPI->API_SetGraphWindowSize(cx, cy, x, y);
256-}
257-
258-inline void CPlugin::API_SetCenterWindow()
259-{
260- ASSERT(m_pAPI);
261- m_pAPI->API_SetCenterWindow();
262-}
263-
264-inline void CPlugin::API_ResetWindow()
265-{
266- ASSERT(m_pAPI);
267- m_pAPI->API_ResetWindow();
268-}
269-
270-inline void CPlugin::API_StartTimer()
271-{
272- ASSERT(m_pAPI);
273- m_pAPI->API_StartTimer();
274-}
275-
276-inline void CPlugin::API_StopTimer()
277-{
278- ASSERT(m_pAPI);
279- m_pAPI->API_StopTimer();
280-}
281-
282-//////////////////////////////////////////////////////////////////////////
--- WcsAPI/StringConvert.h (revision 7)
+++ WcsAPI/StringConvert.h (nonexistent)
@@ -1,106 +0,0 @@
1-#pragma once
2-
3-#include <afxwin.h>
4-
5-//////////////////////////////////////////////////////////////////////////
6-
7-class CStringConvert
8-{
9-public:
10- CStringConvert() {}
11- virtual ~CStringConvert() {}
12-
13- CString DwToIPAddress(DWORD dwAddress)
14- {
15- CString cs;
16- dwAddress = htonl(dwAddress);
17- cs.Format(_T("%d.%d.%d.%d"),
18- (dwAddress >> 24) & 0xff,
19- (dwAddress >> 16) & 0xff,
20- (dwAddress >> 8) & 0xff,
21- dwAddress & 0xff);
22- return cs;
23- }
24-
25- CString DwToString(DWORD dwNumber)
26- {
27- CString cs;
28- cs.Format(_T("%d"), dwNumber);
29- return cs;
30- }
31-
32- CString DbToString(double dwNumber)
33- {
34- CString cs;
35- cs.Format(_T("%10.4lf"), dwNumber);
36- return cs;
37- }
38-
39- CString DbToHMSTime(double dbTime)
40- {
41- CString cs;
42- UINT uHour, uMinute, uSecond;
43-
44- uHour = static_cast<UINT>(dbTime / 3600);
45- uMinute = static_cast<UINT>((dbTime - uHour * 3600) / 60);
46- uSecond = static_cast<UINT>(dbTime - (uHour * 3600 + uMinute * 60));
47- cs.Format(_T("%02d:%02d:%02d"), uHour, uMinute, uSecond);
48-
49- return cs;
50- }
51-
52- CString GetNowTime()
53- {
54- CString cs;
55- SYSTEMTIME st;
56-
57- GetLocalTime(&st);
58- cs.Format(_T("%04d/%02d/%02d %02d:%02d:%02d"),
59- st.wYear, st.wMonth, st.wDay,
60- st.wHour, st.wMinute, st.wSecond);
61-
62- return cs;
63- }
64-
65- void BigNumToString(CString &csParam)
66- {
67- NUMBERFMT nf;
68- TCHAR szBuf[100];
69-
70- lstrcpy(szBuf, csParam.GetBuffer(100));
71- csParam.ReleaseBuffer();
72- nf.NumDigits = 0;
73- nf.LeadingZero = FALSE;
74- nf.Grouping = 3;
75- nf.lpDecimalSep = _T(".");
76- nf.lpThousandSep = _T(",");
77- nf.NegativeOrder = 0;
78- GetNumberFormat(LOCALE_USER_DEFAULT,
79- 0,
80- szBuf,
81- &nf,
82- csParam.GetBuffer(),
83- 100);
84- csParam.ReleaseBuffer();
85- }
86-
87- void StringToByteArray(CString &cs, CByteArray &data)
88- {
89- LPBYTE lpData;
90- UINT nLength;
91-
92- nLength = cs.GetLength();
93- lpData = reinterpret_cast<LPBYTE>(static_cast<LPTSTR>(cs.GetBuffer()));
94- data.SetSize(cs.GetLength() * sizeof(TCHAR));
95- CopyMemory(data.GetData(), lpData, data.GetSize());
96- cs.ReleaseBuffer();
97- data.FreeExtra();
98- }
99-
100- void ByteArrayToString(CByteArray &data, CString &cs)
101- {
102- cs.SetString(reinterpret_cast<LPTSTR>(data.GetData()), data.GetSize() / sizeof(TCHAR));
103- }
104-};
105-
106-//////////////////////////////////////////////////////////////////////////
\ No newline at end of file
--- WcsAPI/stdafx.h (revision 7)
+++ WcsAPI/stdafx.h (nonexistent)
@@ -1,22 +0,0 @@
1-#pragma once
2-
3-//////////////////////////////////////////////////////////////////////////
4-
5-#include "targetver.h"
6-
7-#define WIN32_LEAN_AND_MEAN
8-#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS
9-
10-#ifndef VC_EXTRALEAN
11-#define VC_EXTRALEAN
12-#endif
13-
14-#include <afx.h>
15-#include <afxwin.h>
16-#include <afxtempl.h> // For CArray
17-#include <afxmt.h> // For Critialsection
18-
19-//////////////////////////////////////////////////////////////////////////
20-
21-
22-
--- WcsAPI/Plugin.cpp (revision 7)
+++ WcsAPI/Plugin.cpp (nonexistent)
@@ -1,277 +0,0 @@
1-#include "StdAfx.h"
2-#include "WcsAPI.h"
3-
4-//////////////////////////////////////////////////////////////////////////
5-// Common
6-
7-CPlugin::CPlugin() :
8- m_pAPI(NULL),
9- m_fMaster(FALSE),
10- m_fSystem(FALSE),
11- m_fRunning(FALSE)
12-{
13- ZeroMemory(&m_SlavePlugin, sizeof(m_SlavePlugin));
14- ZeroMemory(&m_CalcSize, sizeof(m_CalcSize));
15-}
16-
17-CPlugin::~CPlugin()
18-{
19-}
20-
21-void CPlugin::GetPluginInfo(LPPLUGIN_INFO lpInfo)
22-{
23- CopyMemory(lpInfo, &m_PlgInfo, sizeof(PLUGIN_INFO));
24-}
25-
26-BOOL CPlugin::StartPlugin(const CByteArray &arg)
27-{
28- CSingleLock sl(&m_ThdLock, TRUE);
29- DWORD dwCount;
30-
31- m_Argument.RemoveAll();
32- m_Argument.Copy(arg);
33- m_fRunning = TRUE;
34-
35- if (m_fMaster)
36- {
37- m_MasterPlugin.wNodeID = m_MasterPlugin.list[0].wNodeID;
38- m_MasterPlugin.dwAddress = m_MasterPlugin.list[0].dwAddress;
39- m_MasterPlugin.dwProcessors = m_fSystem ? 1 : m_MasterPlugin.list[0].dwProcessors;
40- dwCount = m_MasterPlugin.dwProcessors;
41-
42- if (!m_fSystem)
43- {
44- m_Reportlist.RemoveAll();
45- m_Reportlist.SetSize(dwCount);
46- }
47- }
48- else
49- {
50- dwCount = m_SlavePlugin.dwProcessors;
51- }
52-
53- m_ThdCount.dwCount = dwCount;
54- m_ThdCount.dwFinish = 0;
55-
56- m_ThdList.SetSize(dwCount);
57- m_ThdIDList.SetSize(dwCount);
58- m_PlgPrmList.SetSize(dwCount);
59-
60- for (UINT i = 0; i < dwCount; i++)
61- {
62- m_PlgPrmList[i].obj = this;
63- m_PlgPrmList[i].dwIndex = i;
64- m_PlgPrmList[i].dwAffinity = (0x0001 << i);
65- m_PlgPrmList[i].dwThdCount = dwCount;
66- m_PlgPrmList[i].fAlive = TRUE;
67- m_PlgPrmList[i].fSystem = m_fSystem;
68- m_PlgPrmList[i].arg.Copy(arg);
69-
70- m_ThdList[i] = MC_BEGINTHREADEX(NULL,
71- 0,
72- (m_fMaster ? doMasterTransaction : doSlaveTransaction),
73- &m_PlgPrmList[i],
74- CREATE_SUSPENDED,
75- &m_ThdIDList[i]);
76- }
77-
78- // Start thread
79- for (UINT i = 0; i < dwCount; i++)
80- {
81- ResumeThread(m_ThdList[i]);
82- }
83-
84- for (UINT i = 0; i < dwCount; i++)
85- {
86- if (m_ThdList[i] == NULL)
87- {
88- return FALSE;
89- }
90- }
91-
92- return TRUE;
93-}
94-
95-void CPlugin::ThreadFinish()
96-{
97- ++m_ThdCount.dwFinish;
98-
99- if (m_ThdCount.dwCount == m_ThdCount.dwFinish)
100- {
101- if (m_fMaster)
102- {
103- MasterFinalize();
104- }
105- else
106- {
107- SlaveFinalize();
108- }
109-
110- CloseHandleList();
111- m_fRunning = FALSE;
112- }
113-}
114-
115-BOOL CPlugin::CancelPlugin(DWORD dwTimeout)
116-{
117- CSingleLock sl(&m_ThdLock, TRUE);
118- UINT nSize = m_ThdIDList.GetSize();
119- DWORD dwRet;
120-
121- if (nSize > 0)
122- {
123- m_fRunning = FALSE;
124- dwRet = WaitForMultipleObjects(nSize, m_ThdList.GetData(), TRUE, dwTimeout);
125-
126- if (dwRet != WAIT_FAILED)
127- {
128- m_ThdList.RemoveAll();
129- m_ThdIDList.RemoveAll();
130- m_PlgPrmList.RemoveAll();
131- return TRUE;
132- }
133- }
134-
135- return FALSE;
136-}
137-
138-//////////////////////////////////////////////////////////////////////////
139-// Master
140-
141-DWORD CPlugin::MasterTransaction(LPVOID lpParams)
142-{
143- if (!m_fSystem)
144- {
145- // Single mode
146- ThreadFinish();
147- }
148-
149- return 0;
150-}
151-
152-BOOL CPlugin::doCreateWindow(const MASTER_PLUGIN &init)
153-{
154- m_CalcCount.dwAllCount = 0;
155- m_CalcCount.dwFinCount = 0;
156- m_MasterPlugin.csWndName = init.csWndName;
157- m_MasterPlugin.bFront = init.bFront;
158- m_MasterPlugin.list.Copy(init.list);
159- m_fMaster = TRUE;
160- m_fSystem = init.bSystem;
161- m_NodeInitList.RemoveAll();
162- CloseHandleList();
163-
164- CString csName = m_MasterPlugin.csWndName;
165- BOOL bFront = m_MasterPlugin.bFront;
166- int cx = m_CalcSize.nWidth;
167- int cy = m_CalcSize.nHeight;
168-
169- if (API_CreateGraphWindow(csName, cx, cy, bFront))
170- {
171- API_SetCenterWindow();
172- return TRUE;
173- }
174-
175- return FALSE;
176-}
177-
178-DWORD WINAPI CPlugin::doMasterTransaction(LPVOID lpParams)
179-{
180- // Master single mode
181- LPPLUGIN_PARAMS p = (LPPLUGIN_PARAMS)lpParams;
182- HANDLE hCurrent = GetCurrentThread();
183-
184- // Set Affinity
185- if (SetThreadAffinityMask(hCurrent, p->dwAffinity) == 0)
186- {
187- TRACE2("***** ERROR: SetThreadAffinityMask(%d) Processor(%d)", GetLastError(), p->dwIndex);
188- return 0;
189- }
190- /*if (SetThreadIdealProcessor(hCurrent, p->dwAffinity) == -1)
191- {
192- TRACE2("***** ERROR: SetThreadIdealProcessor(%d) Processor(%d)", GetLastError(), p->dwIndex);
193- return 0;
194- }*/
195-
196- return p->obj->MasterTransaction(lpParams);
197-}
198-
199-//////////////////////////////////////////////////////////////////////////
200-// Slave
201-
202-DWORD CPlugin::SlaveTransaction(LPVOID lpParams)
203-{
204- return ThreadFinish(), 0;
205-}
206-
207-BOOL CPlugin::SlaveInitialize(const SLAVE_PLUGIN &init)
208-{
209- m_SlavePlugin = init;
210- m_fMaster = FALSE;
211- m_SlavePlugin.dbRuntime = 0.0;
212- CloseHandleList();
213- return TRUE;
214-}
215-
216-DWORD WINAPI CPlugin::doSlaveTransaction(LPVOID lpParams)
217-{
218- LPPLUGIN_PARAMS p = (LPPLUGIN_PARAMS)lpParams;
219- HANDLE hCurrent = GetCurrentThread();
220-
221- // Set Affinity
222- if (SetThreadAffinityMask(hCurrent, p->dwAffinity) == 0)
223- {
224- TRACE2("***** ERROR: SetThreadAffinityMask(%d) Processor(%d)", GetLastError(), p->dwIndex);
225- return 0;
226- }
227- /*if (SetThreadIdealProcessor(hCurrent, p->dwAffinity) == -1)
228- {
229- TRACE2("***** ERROR: SetThreadIdealProcessor(%d) Processor(%d)", GetLastError(), p->dwIndex);
230- return 0;
231- }*/
232-
233- return p->obj->SlaveTransaction(lpParams);
234-}
235-
236-void CPlugin::CloseHandleList(BOOL fWait, DWORD dwMilliseconds)
237-{
238- CSingleLock sl(&m_ThdLock, TRUE);
239- UINT nSize = m_ThdList.GetSize();
240-
241- if (nSize > 0)
242- {
243- if (fWait)
244- {
245- for (UINT i = 0; i < nSize; i++)
246- {
247- m_PlgPrmList[i].fAlive = FALSE;
248- }
249-
250- WaitForMultipleObjects(nSize, m_ThdList.GetData(), TRUE, dwMilliseconds);
251- }
252-
253- for (UINT i = 0; i < nSize; i++)
254- {
255- CloseHandle(m_ThdList[i]);
256- }
257-
258- m_ThdList.RemoveAll();
259- m_ThdIDList.RemoveAll();
260- m_PlgPrmList.RemoveAll();
261- }
262-}
263-
264-void CPlugin::SetCalcReport(DWORD dwIndex, double dbRuntime)
265-{
266- UINT nSize = m_Reportlist.GetSize();
267-
268- if (m_fMaster && !m_fSystem && (nSize > dwIndex))
269- {
270- m_Reportlist[dwIndex].wNodeID = m_MasterPlugin.wNodeID;
271- m_Reportlist[dwIndex].wSubID = static_cast<WORD>(dwIndex);
272- m_Reportlist[dwIndex].dwAddress = m_MasterPlugin.dwAddress;
273- m_Reportlist[dwIndex].dbRuntime = dbRuntime;
274- }
275-}
276-
277-//////////////////////////////////////////////////////////////////////////
\ No newline at end of file
Show on old repository browser