2 * Copyright 2012 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Paweł Dziepak, pdziepak@quarnos.org
12 #include <condition_variable.h>
15 #include "Connection.h"
17 #include "RPCCallback.h"
25 ConditionVariable fEvent
;
34 class RequestManager
{
39 void AddRequest(Request
* request
);
40 Request
* FindRequest(uint32 xid
);
45 // Neither SinglyLinkedList nor DoublyLinkedList is what we want
46 // here. And DoublyLinkedQueue is not even a queue.
54 virtual status_t
ProcessCallback(CallbackRequest
* request
,
55 Connection
* connection
) = 0;
57 virtual ~ProgramData() { }
62 Server(Connection
* connection
,
63 PeerAddress
* address
);
66 status_t
SendCallAsync(Call
* call
, Reply
** reply
,
68 status_t
ResendCallAsync(Call
* call
,
71 inline status_t
WaitCall(Request
* request
,
73 inline status_t
CancelCall(Request
* request
);
74 status_t
WakeCall(Request
* request
);
78 inline const PeerAddress
& ID() const;
79 inline PeerAddress
LocalID() const;
81 inline ProgramData
* PrivateData();
82 inline void SetPrivateData(ProgramData
* privateData
);
84 Callback
* GetCallback();
87 inline uint32
_GetXID();
89 status_t
_StartListening();
92 static status_t
_ListenerThreadStart(void* object
);
96 status_t fThreadError
;
98 RequestManager fRequests
;
99 Connection
* fConnection
;
100 const PeerAddress
* fAddress
;
102 ProgramData
* fPrivateData
;
115 Server::WaitCall(Request
* request
, bigtime_t time
)
119 return request
->fEvent
.Wait(B_RELATIVE_TIMEOUT
, time
);
124 Server::CancelCall(Request
* request
)
126 fRequests
.FindRequest(request
->fXID
);
131 inline const PeerAddress
&
139 Server::LocalID() const
142 memset(&addr
, 0, sizeof(addr
));
143 fConnection
->GetLocalAddress(&addr
);
149 Server::PrivateData()
156 Server::SetPrivateData(ProgramData
* privateData
)
159 fPrivateData
= privateData
;
172 class ServerManager
{
177 status_t
Acquire(Server
** _server
, AddressResolver
* resolver
,
178 ProgramData
* (*createPrivateData
)(Server
*));
179 void Release(Server
* server
);
182 status_t
_Acquire(Server
** _server
, const PeerAddress
& address
,
183 ProgramData
* (*createPrivateData
)(Server
*));
185 ServerNode
* _Find(const PeerAddress
& address
);
186 void _Delete(ServerNode
* node
);
187 ServerNode
* _Insert(ServerNode
* node
);
196 #endif // RPCSERVER_H