1 module kissrpc.RpcRequest;
2 
3 import kissrpc.Logs;
4 import kissrpc.Unit;
5 import kissrpc.Endian;
6 import kissrpc.RpcSocketBaseInterface;
7 import kissrpc.RpcResponse;
8 
9 
10 import std.stdio;
11 import std.traits;
12 import core.sync.semaphore;
13 
14 
15 alias  REQUEST_STATUS = RESPONSE_STATUS; 
16 
17 class RpcRequest
18 {
19 	this(const RPC_PACKAGE_COMPRESS_TYPE type = RPC_PACKAGE_COMPRESS_TYPE.RPCT_NO, const int secondsTimeOut = RPC_REQUEST_TIMEOUT_SECONDS)
20 	{
21 		timeOut = secondsTimeOut;
22 		timestamp = RPC_SYSTEM_TIMESTAMP;
23 		semaphore = new Semaphore;
24 		nonblock = true;
25 		compressType = type;
26 	}
27 
28 	this(RpcRequest req)
29 	{
30 		this.baseSocket = req.baseSocket;
31 		this.funcId = req.funcId;
32 		this.sequeNum = req.sequeNum;
33 		this.nonblock = req.nonblock;
34 		this.compressType = req.compressType;
35 	}
36 
37 	this(RpcSocketBaseInterface socket)
38 	{
39 		baseSocket = socket;
40 	}
41 
42 
43 	void push(ubyte[] arg)
44 	{
45 		funcArg = arg;
46 	}
47 
48 
49 
50 	bool pop(ref ubyte[] arg)
51 	{
52 		arg = funcArg;
53 
54 		return true;
55 	}
56 
57 	void bindFunc(const size_t id)
58 	{
59 		funcId = id;
60 	}
61 
62 	ulong getArgsNum()const
63 	{
64 		return 1;
65 	}
66 
67 	string getCallFuncName()const
68 	{
69 		return RpcBindFunctionMap[funcId];
70 	}
71 
72 	size_t getCallFuncId()const
73 	{
74 		return funcId;
75 	}
76 
77 	ubyte[] getFunArgList()
78 	{
79 		return funcArg;
80 	}
81 
82 	void setSocket(RpcSocketBaseInterface socket)
83 	{
84 		baseSocket = socket;
85 	}
86 
87 	auto getSocket()
88 	{
89 		return baseSocket;
90 	}
91 
92 	auto getTimestamp()const
93 	{
94 		return timestamp;
95 	}
96 
97 	void setSequence(ulong seque)
98 	{
99 		sequeNum = seque;
100 	}
101 
102 	auto getSequence()const
103 	{
104 		return sequeNum;
105 	}
106 
107 	auto getTimeout()const
108 	{
109 		return timeOut;
110 	}
111 
112 	void setStatus(RESPONSE_STATUS status)
113 	{
114 		response_status = status;
115 	}
116 
117 	auto getStatus()const
118 	{
119 		return response_status;
120 	}
121 
122 	auto getNonblock()const
123 	{
124 		return nonblock;
125 	}
126 
127 	void setNonblock(bool isNonblock)
128 	{
129 		nonblock = isNonblock;
130 	}
131 
132 	void semaphoreWait()
133 	{
134 		nonblock = false;
135 		semaphore.wait();
136 	}
137 
138 	void semaphoreRelease()
139 	{
140 		semaphore.notify();
141 	}
142 
143 	RPC_PACKAGE_COMPRESS_TYPE getCompressType()
144 	{
145 		return compressType;
146 	}
147 
148 	void setCompressType(RPC_PACKAGE_COMPRESS_TYPE type)
149 	{
150 		compressType = type;
151 	}
152 
153 private:
154 
155 	RPC_PACKAGE_COMPRESS_TYPE compressType;
156 
157 	RESPONSE_STATUS response_status;
158 
159 	ubyte[] funcArg;
160 	size_t funcId;
161 	RpcSocketBaseInterface baseSocket;
162 	Semaphore semaphore;
163 
164 	bool nonblock;
165 
166 	ulong timestamp;
167 	ulong timeOut;
168 	ulong sequeNum;
169 }