ZFFramework
 
Loading...
Searching...
No Matches
ZFTask.h
Go to the documentation of this file.
1
5
6#ifndef _ZFI_ZFTask_h_
7#define _ZFI_ZFTask_h_
8
9#include "ZFResultType.h"
11
15zfclass ZFLIB_ZFCore ZFTask : zfextend ZFObject, zfimplement ZFTaskId {
17 ZFIMPLEMENT_DECLARE(ZFTaskId)
18
19public:
23 ZFEVENT(TaskOnStart)
29 ZFEVENT(TaskOnStop)
30
31public:
43 , ZFMP_IN_OPT(const ZFListener &, onStop, zfnull)
44 )
46 virtual void stop(void) {
48 }
49
52 ZFMETHOD_DECLARE_1(void, stop
53 , ZFMP_IN(ZFResultType, resultType)
54 )
59
60public:
65 , ZFMP_IN_OPT(ZFObject *, result, zfnull)
66 )
71 , ZFMP_IN(const zfstring &, errorHint)
72 , ZFMP_IN_OPT(ZFObject *, result, zfnull)
73 )
74
75public:
89
90public:
92 virtual inline void taskOnStart(void) {
93 }
94
95 virtual inline void taskOnStop(ZF_IN ZFResultType resultType) {
96 }
97
98protected:
104 ZFMP_IN(const ZFListener &, implOnStart)
105 , ZFMP_IN_OPT(const ZFListener &, implOnStop, zfnull)
107protected:
109 virtual void objectOnInit(void) {
111 }
113 virtual void objectOnDeallocPrepare(void) {
114 this->stop();
116 }
119
120private:
121 zfbool _ZFP_started;
122 ZFListener _ZFP_onStop;
123protected:
125 ZFTask(void)
126 : _ZFP_started(zffalse)
127 , _ZFP_onStop()
128 {
129 }
131};
132
134#endif // #ifndef _ZFI_ZFTask_h_
135
#define ZFLIB_ZFCore
used to export symbols
Definition ZFCoreEnvDef.h:30
#define zfextend
dummy macro shows class inherit from another
Definition ZFCoreTypeDef_ClassType.h:53
#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_OUT
dummy macro that shows the param used as required input and output
Definition ZFCoreTypeDef_ClassType.h:196
_ZFT_t_zfbool zfbool
bool type
Definition ZFCoreTypeDef_CoreType.h:103
#define zffalse
bool false type
Definition ZFCoreTypeDef_CoreType.h:111
#define zfnull
same as NULL, defined for future use
Definition ZFCoreTypeDef_CoreType.h:88
zft_zfstring< zfchar > zfstring
see zft_zfstring
Definition ZFCoreTypeDef_StringType.h:15
#define ZFMP_IN_OPT(ParamType, paramName, DefaultValue)
see ZFMP_IN
Definition ZFMethod.h:108
#define ZFMP_IN(ParamType, paramName)
macro to wrap param types for ZFMETHOD_INLINE_0 series
Definition ZFMethod.h:105
#define ZFMETHOD_DECLARE_0(ReturnType, MethodName)
see ZFMethod
Definition ZFMethodDeclare.h:693
#define ZFMETHOD_DECLARE_2(ReturnType, MethodName, ZFMP_0, ZFMP_1)
see ZFMethod
Definition ZFMethodDeclare.h:1025
#define ZFMETHOD_DECLARE_1(ReturnType, MethodName, ZFMP_0)
see ZFMethod
Definition ZFMethodDeclare.h:854
#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_ON_INIT_DECLARE_2(ZFMP_0, ZFMP_1)
see ZFOBJECT_ON_INIT_INLINE_1
Definition ZFObjectDeclare.h:290
#define ZFOBJECT_DECLARE_WITH_CUSTOM_CTOR(ChildClass, SuperClass,...)
declare object which allow custom constructor
Definition ZFObjectDeclare.h:142
#define ZFIMPLEMENT_DECLARE(ImplementedInterfaces,...)
see ZFINTERFACE_DECLARE
Definition ZFObjectInterface.h:169
#define zfimplement
shows class implement from interface, see ZFInterface
Definition ZFObjectInterface.h:24
#define ZFEVENT(YourEvent)
see ZFObject::observerNotify
Definition ZFObjectObserver.h:328
#define ZFPROPERTY_RETAIN(Type, Name,...)
declare a retain property
Definition ZFPropertyDeclare.h:104
#define ZFPROPERTY_ASSIGN(Type, Name,...)
see ZFPROPERTY_RETAIN
Definition ZFPropertyDeclare.h:128
result type define
v_ZFResultType::ZFEnumType ZFResultType
see v_ZFResultType
Definition ZFResultType.h:23
listener as ZFCallback, mostly used by ZFObject::observerNotify
Definition ZFObjectObserver.h:30
virtual void objectOnInit(void)
override this to init your object
virtual void objectOnDeallocPrepare(void)
called before objectOnDealloc, safe to call virtual functions here
Definition ZFObjectCore.h:758
virtual void notifyFail(const zfstring &errorHint, ZFObject *result=(zft_zfnull))
util method to call stop with fail result
virtual void notifySuccess(ZFObject *result=(zft_zfnull))
util method to call stop with success result
virtual ZFResultType & resultType()
for task impl to store task result, reset to success when start
Definition ZFTask.h:84
virtual void objectInfoImpl(zfstring &ret)
see objectInfo
virtual void taskOnStart(void)
called to start task
Definition ZFTask.h:92
virtual void stop(void)
stop task
Definition ZFTask.h:46
virtual void objectOnDeallocPrepare(void)
called before objectOnDealloc, safe to call virtual functions here
Definition ZFTask.h:113
virtual zfstring & errorHint()
for task impl to store error hint, reset when start
Definition ZFTask.h:88
virtual zfbool started()
whether task running
virtual zfany const & result()
for task impl to store task result, actual result depends on task, reset to null when start
Definition ZFTask.h:80
virtual void start(const ZFListener &onStop=(zft_zfnull))
start the task
virtual void taskOnStop(ZFResultType resultType)
called to stop task
Definition ZFTask.h:95
virtual void objectOnInit(const ZFListener &implOnStart, const ZFListener &implOnStop=(zft_zfnull))
util constructor to attach custom impl to E_TaskOnStart and E_TaskOnStop
result type define
Definition ZFResultType.h:15
@ e_Cancel
Definition ZFResultType.h:18
util method to cast ZFObject types freely
Definition zfany.h:35