ZFFramework
 
Loading...
Searching...
No Matches
ZFProtocolZFThread.h
Go to the documentation of this file.
1
5
6#ifndef _ZFI_ZFProtocolZFThread_h_
7#define _ZFI_ZFProtocolZFThread_h_
8
9#include "ZFCore/ZFProtocol.h"
10#include "ZFCore/ZFThread.h"
12
17public:
23 virtual void *nativeThreadRegister(ZF_IN ZFThread *ownerZFThread) zfpurevirtual;
29 virtual void nativeThreadUnregister(ZF_IN void *token) zfpurevirtual;
34
39
44
48 virtual void *sleepTokenCreate(void);
52 virtual void sleepTokenDestroy(ZF_IN void *sleepToken);
56 virtual zfbool sleep(
57 ZF_IN void *sleepToken
58 , ZF_IN zftimet miliSecs
59 );
63 virtual void sleepCancel(ZF_IN void *sleepToken);
64
69 return zftrue;
70 }
71
76 virtual void *executeInMainThread(ZF_IN const ZFListener &runnable) zfpurevirtual;
80 virtual void executeInMainThreadCleanup(ZF_IN void *nativeToken) zfpurevirtual;
81
94 virtual void *executeInNewThread(
95 ZF_IN const ZFListener &runnable
96 , ZF_IN const ZFListener &runnableCleanup
101 virtual void executeInNewThreadCleanup(ZF_IN void *nativeToken) zfpurevirtual;
103
104// ============================================================
106zfclass ZFLIB_ZFCore ZFThreadMainThread : zfextend ZFThread {
107 ZFOBJECT_DECLARE(ZFThreadMainThread, ZFThread)
108
109public:
111 virtual void threadStart(
112 ZF_IN_OPT ZFObject *param0 = zfnull
113 , ZF_IN_OPT ZFObject *param1 = zfnull
114 ) {
115 ZFCoreLogTrim("you must not start main thread");
116 }
118 virtual zfbool threadStarted(void) {
119 return zftrue;
120 }
122 virtual zfbool threadRunning(void) {
123 return zftrue;
124 }
126 virtual void threadStop(void) {
127 ZFCoreLogTrim("you must not stop main thread");
128 }
130 virtual void threadWait(void) {
131 ZFCoreLogTrim("you must not wait main thread");
132 }
134 virtual zfbool threadWait(ZF_IN zftimet miliSecs) {
135 ZFCoreLogTrim("you must not wait main thread");
136 return zffalse;
137 }
139 virtual zfbool isMainThread(void) {
140 return zftrue;
141 }
142};
143
144// ============================================================
146typedef void *(*ZFMainThreadTaskImplCallbackExecute)(ZF_IN const ZFListener &runnable);
148typedef void (*ZFMainThreadTaskImplCallbackCleanup)(ZF_IN void *nativeToken);
149
168 );
173
175#endif // #ifndef _ZFI_ZFProtocolZFThread_h_
176
#define ZFLIB_ZFCore
used to export symbols
Definition ZFCoreEnvDef.h:30
#define ZFCoreLogTrim(format,...)
log without header info, see ZFCoreLog
Definition ZFCoreLog.h:80
#define zfextend
dummy macro shows class inherit from another
Definition ZFCoreTypeDef_ClassType.h:53
#define zfpurevirtual
dummy macro shows that a method is pure virtual method
Definition ZFCoreTypeDef_ClassType.h:68
#define zfoverride
dummy macro shows that method override parent's method
Definition ZFCoreTypeDef_ClassType.h:58
#define ZF_IN
dummy macro that shows the param used as required input
Definition ZFCoreTypeDef_ClassType.h:180
#define ZF_IN_OPT
dummy macro that shows the param used as optional input
Definition ZFCoreTypeDef_ClassType.h:184
_ZFT_t_zfbool zfbool
bool type
Definition ZFCoreTypeDef_CoreType.h:103
#define zftrue
bool true type
Definition ZFCoreTypeDef_CoreType.h:107
_zft_zftimet zftimet
time unit, ensured at least 64 bit, ensured signed
Definition ZFCoreTypeDef_CoreType.h:203
#define zffalse
bool false type
Definition ZFCoreTypeDef_CoreType.h:111
#define zfnull
same as NULL, defined for future use
Definition ZFCoreTypeDef_CoreType.h:88
#define ZF_NAMESPACE_GLOBAL_BEGIN
begin namespace ZFFramework
Definition ZFNamespace.h:97
#define ZF_NAMESPACE_GLOBAL_END
end namespace ZFFramework
Definition ZFNamespace.h:98
#define zfclass
same as class, shows that this class is a ZFObject type
Definition ZFObjectClassTypeFwd.h:38
#define ZFOBJECT_DECLARE(ChildClass, SuperClass,...)
necessary for every class inherit from ZFObject
Definition ZFObjectDeclare.h:126
protocol definitions for ZFFramework
#define ZFPROTOCOL_INTERFACE_END(ModuleName)
for more information, please refer to ZFPROTOCOL_INTERFACE_BEGIN
Definition ZFProtocol.h:414
#define ZFPROTOCOL_INTERFACE_BEGIN(ZFLIB_, ModuleName)
declare a protocol interface for ZFFramework
Definition ZFProtocol.h:408
void ZFMainThreadTaskImplSet(ZFMainThreadTaskImplCallbackExecute executeImpl, ZFMainThreadTaskImplCallbackCleanup cleanupImpl=zft_zfnull)
set custom impl for ZFThread::taskQueueAdd for main thread
ZFMainThreadTaskImplCallbackCleanup ZFMainThreadTaskImplGetCleanup(void)
see ZFMainThreadTaskImplSet
void(* ZFMainThreadTaskImplCallbackCleanup)(void *nativeToken)
see ZFMainThreadTaskImplSet
Definition ZFProtocolZFThread.h:148
void *(* ZFMainThreadTaskImplCallbackExecute)(const ZFListener &runnable)
see ZFMainThreadTaskImplSet
Definition ZFProtocolZFThread.h:146
ZFMainThreadTaskImplCallbackExecute ZFMainThreadTaskImplGetExecute(void)
see ZFMainThreadTaskImplSet
thread utility
listener as ZFCallback, mostly used by ZFObject::observerNotify
Definition ZFObjectObserver.h:30
virtual ZFThread * threadForToken(void *token)=0
get thread from token created by nativeThreadRegister
virtual void * executeInNewThread(const ZFListener &runnable, const ZFListener &runnableCleanup)=0
run the runnable in new thread
virtual zfbool sleep(void *sleepToken, zftimet miliSecs)
see ZFThread::sleep
virtual void sleepTokenDestroy(void *sleepToken)
see ZFThread::sleep
virtual void sleepCancel(void *sleepToken)
see ZFThread::sleep
virtual void * executeInMainThread(const ZFListener &runnable)=0
run the runnable in main thread
virtual ZFThread * mainThread(void)=0
see ZFThread::mainThread
virtual ZFThread * currentThread(void)=0
see ZFThread::currentThread
virtual void * sleepTokenCreate(void)
see ZFThread::sleep
virtual void executeInMainThreadCleanup(void *nativeToken)=0
used to cleanup nativeToken
virtual void executeInNewThreadCleanup(void *nativeToken)=0
used to cleanup nativeToken
virtual zfbool executeInMainThreadAvailable(void)
whether executeInMainThread available
Definition ZFProtocolZFThread.h:68
virtual void * nativeThreadRegister(ZFThread *ownerZFThread)=0
see ZFThread::nativeThreadUnregister
virtual void nativeThreadUnregister(void *token)=0
see ZFThread::nativeThreadUnregister, nativeThreadRegister
thread utility
Definition ZFThread.h:23
virtual zfbool threadRunning(void)
return true only if thread is running
Definition ZFProtocolZFThread.h:122
virtual zfbool isMainThread(void)
return true if current thread is main thread
Definition ZFProtocolZFThread.h:139
virtual void threadStop(void)
request stop the thread, may not be stopped immediately
Definition ZFProtocolZFThread.h:126
virtual void threadStart(ZFObject *param0=zft_zfnull, ZFObject *param1=zft_zfnull)
start thread, do nothing if already started
Definition ZFProtocolZFThread.h:111
virtual void threadWait(void)
wait until thread finished running
Definition ZFProtocolZFThread.h:130
virtual zfbool threadWait(zftimet miliSecs)
wait until thread finished running, or timeout
Definition ZFProtocolZFThread.h:134
virtual zfbool threadStarted(void)
return true if start is called and hasn't been stopped or end
Definition ZFProtocolZFThread.h:118