ZFFramework
 
Loading...
Searching...
No Matches
ZFHttpServer.h
Go to the documentation of this file.
1
5
6#ifndef _ZFI_ZFHttpServer_h_
7#define _ZFI_ZFHttpServer_h_
8
9#include "ZFHttpRequest.h"
11
13zfabstract ZFLIB_ZFNet ZFHttpServerTask : zfextend ZFObject {
14 ZFOBJECT_DECLARE_ABSTRACT(ZFHttpServerTask, ZFObject)
15
16 // ============================================================
17 // recv
18public:
23
24public:
29
36
37public:
42
49
50public:
63
64 // ============================================================
65 // resp
66public:
68 virtual void respCode(ZF_IN zfuint code) zfpurevirtual;
69
71 virtual void respBody(ZF_IN const zfstring &value, ZF_IN const zfstring &contentType) zfpurevirtual;
73 virtual void respBody(ZF_IN const ZFInput &value, ZF_IN const zfstring &contentType) zfpurevirtual;
74
75public:
80
87
89 virtual void respHeader(ZF_IN const zfstring &key, ZF_IN const zfstring &value) zfpurevirtual;
91 virtual void respHeaderRemove(ZF_IN const zfstring &key) zfpurevirtual;
95 virtual void respHeaderIterValue(ZF_IN const zfiter &it, ZF_IN const zfstring &value) zfpurevirtual;
98
99 // ============================================================
100 // util
101public:
106
107protected:
110};
111
112// ============================================================
126zfclass ZFLIB_ZFNet ZFHttpServer : zfextend ZFObject, zfimplement ZFTaskId {
127 ZFOBJECT_DECLARE(ZFHttpServer, ZFObject)
128 ZFIMPLEMENT_DECLARE(ZFTaskId)
129
130
136 ZFEVENT(OnRequest)
137
138public:
149 ZFMP_IN(const zfstring &, addr)
152
155
158
161
168
173
178
183 , ZFMP_IN(const ZFListener &, impl)
185
186protected:
188 virtual void onRequest(ZF_IN ZFHttpServerTask *task) {
189 this->observerNotify(zfself::E_OnRequest(), task);
190 }
191public:
192 zffinal void _ZFP_ZFHttpServer_onRequest(ZF_IN ZFHttpServerTask *task) {
193 this->onRequest(task);
194 }
195
196protected:
198 virtual void objectOnInit(void);
200 virtual void objectOnDeallocPrepare(void);
201protected:
204
205private:
206 void *d;
207};
208
212zfclass ZFLIB_ZFNet ZFHttpServerThreadPool : zfextend ZFThreadPool {
213 ZFOBJECT_DECLARE(ZFHttpServerThreadPool, ZFThreadPool)
214 ZFOBJECT_SINGLETON_DECLARE(ZFHttpServerThreadPool, instance)
215};
216
218#endif // #ifndef _ZFI_ZFHttpServer_h_
219
#define zffinal
dummy macro shows that a method or class is designed must not to be overrided
Definition ZFCoreTypeDef_ClassType.h:63
#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_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
_ZFT_t_zfindex zfindex
similar to size_t, used for index and size only
Definition ZFCoreTypeDef_CoreType.h:154
_zft_zftimet zftimet
time unit, ensured at least 64 bit, ensured signed
Definition ZFCoreTypeDef_CoreType.h:203
_ZFT_t_zfuint zfuint
same as unsigned int, see zfindex
Definition ZFCoreTypeDef_CoreType.h:169
zft_zfstring< zfchar > zfstring
see zft_zfstring
Definition ZFCoreTypeDef_StringType.h:15
http operation
v_ZFHttpMethod::ZFEnumType ZFHttpMethod
see v_ZFHttpMethod
Definition ZFHttpRequest.h:35
#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_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 ZFLIB_ZFNet
used to export symbols
Definition ZFNetDef.h:15
#define zfabstract
typename for class showing that its abstract
Definition ZFObjectClassTypeFwd.h:42
#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_ABSTRACT(ChildClass, SuperClass,...)
necessary for every abstract class inherit from ZFObject
Definition ZFObjectDeclare.h:152
#define ZFOBJECT_ON_INIT_DECLARE_1(ZFMP_0)
see ZFOBJECT_ON_INIT_INLINE_1
Definition ZFObjectDeclare.h:263
#define ZFOBJECT_DECLARE(ChildClass, SuperClass,...)
necessary for every class inherit from ZFObject
Definition ZFObjectDeclare.h:126
#define ZFOBJECT_SINGLETON_DECLARE(AccessTypeName, accessMethodName)
util macro to declare a singleton instance access for ZFObject type
Definition ZFObjectGlobalInstance.h:256
#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_ASSIGN(Type, Name,...)
see ZFPROPERTY_RETAIN
Definition ZFPropertyDeclare.h:128
static zfidentity E_OnRequest(void)
called when receive from client
virtual zfstring & addr()
the addr of the server, typically "0.0.0.0"
Definition ZFHttpServer.h:154
virtual void objectOnInit(void)
override this to init your object
virtual zfuint & port()
the port of the server
Definition ZFHttpServer.h:157
virtual void start()
start the server
virtual zftimet & timeout()
timeout
Definition ZFHttpServer.h:160
virtual void stop()
stop the server
virtual zfbool started()
whether the server started
virtual void onRequest(const ZFListener &impl)
util for impl
virtual void objectInfoImpl(zfstring &ret)
see objectInfo
virtual void objectOnDeallocPrepare(void)
called before objectOnDealloc, safe to call virtual functions here
see ZFHttpServer
Definition ZFHttpServer.h:13
virtual void respHeader(const zfstring &key, const zfstring &value)=0
resp header modify
virtual zfstring recvParamIterValue(const zfiter &it)=0
recv header access
virtual zfiter recvHeaderIter(void)=0
recv header access
virtual ZFHttpMethod recvMethod(void)=0
recv http method
virtual zfstring recvServerAddr(void)=0
the addr of the server
virtual void respHeaderIterValue(const zfiter &it, const zfstring &value)=0
resp header modify
virtual zfstring recvClientAddr(void)=0
the addr of the client
virtual void respCode(zfuint code)=0
resp status code
virtual zfstring recvHeaderIterKey(const zfiter &it)=0
recv header access
virtual zfuint recvServerPort(void)=0
the addr of the server
virtual void respHeaderIterRemove(const zfiter &it)=0
resp header modify
virtual void respHeaderRemove(const zfstring &key)=0
resp header modify
virtual zfstring contentInfo()
print all content info, usually for debug use only
virtual zfindex respHeaderCount(void)=0
resp header count
virtual void respBody(const zfstring &value, const zfstring &contentType)=0
resp body
virtual zfindex recvHeaderCount(void)=0
recv header count
virtual zfstring recvParam(const zfstring &key)=0
recv header access
virtual zfstring respHeaderIterValue(const zfiter &it)=0
resp header access
virtual zfiter recvParamIter(void)=0
recv header access
virtual zfstring headerInfo()
print all header, usually for debug use only
virtual zfindex recvParamCount(void)=0
recv header count
virtual zfstring respHeader(const zfstring &key)=0
resp header access
virtual zfstring recvHeader(const zfstring &key)=0
recv header access
virtual zfstring recvBody(void)=0
recv body
virtual zfstring recvParamIterKey(const zfiter &it)=0
recv header access
virtual zfiter respHeaderIter(void)=0
resp header access
virtual zfiter respHeaderIterFind(const zfstring &key)=0
resp header modify
virtual void respBody(const ZFInput &value, const zfstring &contentType)=0
resp body
virtual void objectInfoImpl(zfstring &ret)
see objectInfo
virtual zfstring recvHeaderIterValue(const zfiter &it)=0
recv header access
virtual zfuint recvClientPort(void)=0
the addr of the client
virtual zfstring recvPath(void)=0
recv url path
virtual zfstring respHeaderIterKey(const zfiter &it)=0
resp header access
static ZFHttpServerThreadPool * instance()
general input callback
Definition ZFIOCallback_input.h:37
listener as ZFCallback, mostly used by ZFObject::observerNotify
Definition ZFObjectObserver.h:30
void observerNotify(zfidentity eventId, ZFObject *param0=zft_zfnull, ZFObject *param1=zft_zfnull)
notify the observer with eventId
iterator for ZFFramework
Definition zfiter.h:40
#define zftext(s)
util macro for zfstring::shared
Definition zfstring.h:694