xref: /haiku/headers/private/userlandfs/private/RequestPort.h (revision 93a78ecaa45114d68952d08c4778f073515102f2)
1 // RequestPort.h
2 
3 #ifndef USERLAND_FS_REQUEST_PORT_H
4 #define USERLAND_FS_REQUEST_PORT_H
5 
6 #include "Port.h"
7 #include "RequestAllocator.h"
8 
9 namespace UserlandFSUtil {
10 
11 class RequestHandler;
12 
13 // RequestPort
14 class RequestPort {
15 public:
16 								RequestPort(int32 size);
17 								RequestPort(const Port::Info* info);
18 								~RequestPort();
19 
20 			void				Close();
21 
22 			status_t			InitCheck() const;
23 
24 			Port*				GetPort();
25 			const Port::Info*	GetPortInfo() const;
26 
27 			status_t			SendRequest(RequestAllocator* allocator);
28 			status_t			SendRequest(RequestAllocator* allocator,
29 									RequestHandler* handler,
30 									Request** reply = NULL,
31 									bigtime_t timeout = -1);
32 			status_t			ReceiveRequest(Request** request,
33 									bigtime_t timeout = -1);
34 			status_t			HandleRequests(RequestHandler* handler,
35 									Request** reply = NULL,
36 									bigtime_t timeout = -1);
37 
38 			void				ReleaseRequest(Request* request);
39 
40 private:
41 			void				_PopAllocator();
42 
43 private:
44 			friend class ::KernelDebug;
45 			struct AllocatorNode;
46 
47 			Port				fPort;
48 			AllocatorNode*		fCurrentAllocatorNode;
49 };
50 
51 // RequestReleaser
52 class RequestReleaser {
53 public:
54 	inline RequestReleaser(RequestPort* port, Request* request)
55 		: fPort(port), fRequest(request) {}
56 
57 	inline ~RequestReleaser()
58 	{
59 		if (fPort && fRequest)
60 			fPort->ReleaseRequest(fRequest);
61 	}
62 
63 private:
64 	RequestPort*	fPort;
65 	Request*		fRequest;
66 };
67 
68 }	// namespace UserlandFSUtil
69 
70 using UserlandFSUtil::RequestPort;
71 using UserlandFSUtil::RequestReleaser;
72 
73 #endif	// USERLAND_FS_REQUEST_PORT_H
74