15a1d355fSStephan Aßmus// SendReceiveRequest.h
25a1d355fSStephan Aßmus
35a1d355fSStephan Aßmus#ifndef NET_FS_SEND_RECEIVE_REQUEST_H
45a1d355fSStephan Aßmus#define NET_FS_SEND_RECEIVE_REQUEST_H
55a1d355fSStephan Aßmus
65a1d355fSStephan Aßmus#include "RequestChannel.h"
75a1d355fSStephan Aßmus#include "RequestConnection.h"
85a1d355fSStephan Aßmus
95a1d355fSStephan Aßmus
105a1d355fSStephan Aßmus// error code when disconnected
115a1d355fSStephan Aßmusenum {
125a1d355fSStephan Aßmus	ERROR_NOT_CONNECTED = ENOTCONN
135a1d355fSStephan Aßmus};
145a1d355fSStephan Aßmus
155a1d355fSStephan Aßmus// SendRequest
165a1d355fSStephan Aßmustemplate<typename Reply>
175a1d355fSStephan Aßmusstatic
185a1d355fSStephan Aßmusstatus_t
195a1d355fSStephan AßmusSendRequest(RequestConnection* connection, Request* request,
205a1d355fSStephan Aßmus	Reply** _reply)
215a1d355fSStephan Aßmus{
225a1d355fSStephan Aßmus	Request* reply;
235a1d355fSStephan Aßmus	status_t error = connection->SendRequest(request, &reply);
245a1d355fSStephan Aßmus	if (error != B_OK)
255a1d355fSStephan Aßmus		return error;
265a1d355fSStephan Aßmus	*_reply = dynamic_cast<Reply*>(reply);
275a1d355fSStephan Aßmus	if (!*_reply) {
285a1d355fSStephan Aßmus		delete reply;
295a1d355fSStephan Aßmus		return B_BAD_DATA;
305a1d355fSStephan Aßmus	}
315a1d355fSStephan Aßmus	return B_OK;
325a1d355fSStephan Aßmus}
335a1d355fSStephan Aßmus
345a1d355fSStephan Aßmus// ReceiveRequest
355a1d355fSStephan Aßmustemplate<typename SpecificRequest>
365a1d355fSStephan Aßmusstatic
375a1d355fSStephan Aßmusstatus_t
385a1d355fSStephan AßmusReceiveRequest(RequestChannel* channel, SpecificRequest** _request)
395a1d355fSStephan Aßmus{
405a1d355fSStephan Aßmus	Request* request;
415a1d355fSStephan Aßmus	status_t error = channel->ReceiveRequest(&request);
425a1d355fSStephan Aßmus	if (error != B_OK)
435a1d355fSStephan Aßmus		return error;
445a1d355fSStephan Aßmus	*_request = dynamic_cast<SpecificRequest*>(request);
455a1d355fSStephan Aßmus	if (!*_request) {
465a1d355fSStephan Aßmus		delete request;
475a1d355fSStephan Aßmus		return B_BAD_DATA;
485a1d355fSStephan Aßmus	}
495a1d355fSStephan Aßmus	return B_OK;
505a1d355fSStephan Aßmus}
515a1d355fSStephan Aßmus
525a1d355fSStephan Aßmus
535a1d355fSStephan Aßmus#endif	// NET_FS_SEND_RECEIVE_REQUEST_H
54