xref: /haiku/src/add-ons/kernel/file_systems/netfs/client/SendReceiveRequest.h (revision fce4895d1884da5ae6fb299d23c735c598e690b1)
1 // SendReceiveRequest.h
2 
3 #ifndef NET_FS_SEND_RECEIVE_REQUEST_H
4 #define NET_FS_SEND_RECEIVE_REQUEST_H
5 
6 #include "RequestChannel.h"
7 #include "RequestConnection.h"
8 
9 
10 // error code when disconnected
11 enum {
12 	ERROR_NOT_CONNECTED = ENOTCONN
13 };
14 
15 // SendRequest
16 template<typename Reply>
17 static
18 status_t
19 SendRequest(RequestConnection* connection, Request* request,
20 	Reply** _reply)
21 {
22 	Request* reply;
23 	status_t error = connection->SendRequest(request, &reply);
24 	if (error != B_OK)
25 		return error;
26 	*_reply = dynamic_cast<Reply*>(reply);
27 	if (!*_reply) {
28 		delete reply;
29 		return B_BAD_DATA;
30 	}
31 	return B_OK;
32 }
33 
34 // ReceiveRequest
35 template<typename SpecificRequest>
36 static
37 status_t
38 ReceiveRequest(RequestChannel* channel, SpecificRequest** _request)
39 {
40 	Request* request;
41 	status_t error = channel->ReceiveRequest(&request);
42 	if (error != B_OK)
43 		return error;
44 	*_request = dynamic_cast<SpecificRequest*>(request);
45 	if (!*_request) {
46 		delete request;
47 		return B_BAD_DATA;
48 	}
49 	return B_OK;
50 }
51 
52 
53 #endif	// NET_FS_SEND_RECEIVE_REQUEST_H
54