Skip to content

Commit d664fac

Browse files
huangjianxiongsetoutsoft
huangjianxiong
authored andcommitted
add taskhandler
1 parent 1fde8c2 commit d664fac

File tree

15 files changed

+1541
-617
lines changed

15 files changed

+1541
-617
lines changed

SOUI/SOUI.pro

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
######################################################################
2-
# Automatically generated by qmake (2.01a) ?? ?? 23 19:29:25 2014
2+
# Automatically generated by qmake (3.0) ?? ?? 13 13:54:06 2019
33
######################################################################
44

55
TEMPLATE = lib
@@ -110,6 +110,9 @@ HEADERS += include/SApp.h \
110110
include/helper/SplitString.h \
111111
include/helper/copylist.hpp \
112112
include/helper/SResID.h \
113+
include/helper/SScriptTimer.h \
114+
include/helper/STaskHandler.h \
115+
include/helper/STileViewItemLocator.h \
113116
include/helper/STime.h \
114117
include/helper/STimerEx.h \
115118
include/helper/SScriptTimer.h \
@@ -203,8 +206,8 @@ SOURCES += src/SApp.cpp \
203206
src/control/STreeView.cpp \
204207
src/control/SMenuBar.cpp \
205208
src/control/SDateTimePicker.cpp \
206-
src/core/Accelerator.cpp \
207-
src/core/FocusManager.cpp \
209+
src/core/Accelerator.cpp \
210+
src/core/FocusManager.cpp \
208211
src/core/SDropTargetDispatcher.cpp \
209212
src/core/SHostDialog.cpp \
210213
src/core/shostwnd.cpp \
@@ -232,6 +235,7 @@ SOURCES += src/SApp.cpp \
232235
src/helper/SMenu.cpp \
233236
src/helper/STimerEx.cpp \
234237
src/helper/SScriptTimer.cpp \
238+
src/helper/STaskHandler.cpp \
235239
src/helper/stooltip.cpp \
236240
src/helper/AppDir.cpp \
237241
src/helper/SListViewItemLocator.cpp \

SOUI/include/helper/STaskHandler.h

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#pragma once
2+
3+
#include <interface/STaskLoop-i.h>
4+
#include <helper/SSharedPtr.hpp>
5+
#include <unknown/obj-ref-impl.hpp>
6+
#include <helper/SFunctor.hpp>
7+
#include <core/SimpleWnd.h>
8+
#include <helper/SSemaphore.h>
9+
#include <souicoll.h>
10+
namespace SOUI
11+
{
12+
class SOUI_EXP STaskHandler : public TObjRefImpl<ITaskLoop>, protected CSimpleWnd
13+
{
14+
public:
15+
/**
16+
* Constructor.
17+
*/
18+
STaskHandler();
19+
20+
/**
21+
* Destructor.
22+
*/
23+
virtual ~STaskHandler();
24+
25+
/**
26+
* Start task mgr thread.
27+
*/
28+
void start(const char * pszName, Priority priority);
29+
30+
/**
31+
* Stop task mgr synchronized.
32+
*/
33+
void stop();
34+
35+
36+
/**
37+
* Remove tasks for a sepcific object from task mgr pening task list
38+
* @param object the specific object wants pending functors to be removed
39+
*/
40+
void cancelTasksForObject(void *object);
41+
42+
/**
43+
* Cancel tasks for a specific task ID list
44+
* @param taskList the task ID list to be canceled
45+
* @return the removed task list.
46+
*/
47+
bool cancelTask(long taskId);
48+
49+
50+
/**
51+
* get the total task number in the task mgr queue.
52+
* @return total task number in task mgr queue
53+
*/
54+
int getTaskCount() const;
55+
56+
/**
57+
* get the run loop status.
58+
* @return the running status
59+
*/
60+
bool isRunning();
61+
62+
long postTask(const IRunnable *runnable, bool waitUntilDone, int priority);
63+
64+
bool getName(char * pszBuf, int nBufLen);
65+
66+
bool getRunningTaskInfo(char *buf, int bufLen);
67+
68+
private:
69+
class TaskItem
70+
{
71+
public:
72+
TaskItem(IRunnable *runnable_, int nPriority_)
73+
: taskID(0)
74+
, runnable(runnable_)
75+
, nPriority(nPriority_)
76+
, semaphore(NULL)
77+
{}
78+
79+
const char *getRunnableInfo()
80+
{
81+
return runnable->getClassInfo();
82+
}
83+
84+
long taskID;
85+
SSharedPtr<IRunnable> runnable;
86+
SSemaphore *semaphore;
87+
int nPriority;
88+
};
89+
90+
void OnTimer(UINT_PTR id);
91+
92+
BEGIN_MSG_MAP_EX(STaskHandler)
93+
MSG_WM_TIMER(OnTimer)
94+
CHAIN_MSG_MAP(CSimpleWnd)
95+
END_MSG_MAP()
96+
97+
mutable SCriticalSection m_taskListLock;
98+
SCriticalSection m_runningLock;
99+
SSemaphore m_itemsSem;
100+
SList<TaskItem> m_items;
101+
102+
SCriticalSection m_runningInfoLock;
103+
bool m_hasRunningItem;
104+
TaskItem m_runningItem;
105+
long m_nextTaskID;
106+
bool m_isRunning;
107+
DWORD m_dwThreadID;
108+
};
109+
}

0 commit comments

Comments
 (0)