2 * Copyright 2012-2013 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Paweł Dziepak, pdziepak@quarnos.org
8 #ifndef RPCCALLBACKSERVER_H
9 #define RPCCALLBACKSERVER_H
12 #include <util/AutoLock.h>
14 #include "Connection.h"
22 struct ConnectionEntry
{
23 Connection
* fConnection
;
26 ConnectionEntry
* fNext
;
27 ConnectionEntry
* fPrev
;
35 class CallbackServer
{
37 CallbackServer(int networkFamily
);
40 static CallbackServer
* Get(Server
* server
);
41 static void ShutdownAll();
43 status_t
RegisterCallback(Callback
* callback
);
44 status_t
UnregisterCallback(Callback
* callback
);
46 inline PeerAddress
LocalID();
49 status_t
StartServer();
50 status_t
StopServer();
52 status_t
NewConnection(Connection
* connection
);
53 status_t
ReleaseConnection(ConnectionEntry
* entry
);
55 static status_t
ListenerThreadLauncher(void* object
);
56 status_t
ListenerThread();
58 static status_t
ConnectionThreadLauncher(void* object
);
59 status_t
ConnectionThread(ConnectionEntry
* entry
);
61 inline Callback
* GetCallback(int32 id
);
64 static mutex fServerCreationLock
;
65 static CallbackServer
* fServers
[2];
67 mutex fConnectionLock
;
68 ConnectionEntry
* fConnectionList
;
69 ConnectionListener
* fListener
;
76 CallbackSlot
* fCallbackArray
;
85 CallbackServer::LocalID()
89 ASSERT(fListener
!= NULL
);
91 memset(&address
, 0, sizeof(address
));
92 fListener
->GetLocalAddress(&address
);
98 CallbackServer::GetCallback(int32 id
)
100 ReadLocker
_(fArrayLock
);
101 if (id
>= 0 && static_cast<uint32
>(id
) < fArraySize
)
102 return fCallbackArray
[id
].fCallback
;
109 #endif // RPCCALLBACKSERVER_H