xref: /haiku/src/servers/app/drawing/interface/remote/NetReceiver.h (revision cbe0a0c436162d78cc3f92a305b64918c839d079)
1 /*
2  * Copyright 2009, Haiku, Inc.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Michael Lotz <mmlr@mlotz.ch>
7  */
8 #ifndef NET_RECEIVER_H
9 #define NET_RECEIVER_H
10 
11 #include <AutoDeleter.h>
12 #include <OS.h>
13 #include <SupportDefs.h>
14 
15 class BNetEndpoint;
16 class StreamingRingBuffer;
17 
18 typedef status_t (*NewConnectionCallback)(void *cookie, BNetEndpoint &endpoint);
19 
20 
21 class NetReceiver {
22 public:
23 								NetReceiver(BNetEndpoint *endpoint,
24 									StreamingRingBuffer *target,
25 									NewConnectionCallback callback = NULL,
26 									void *newConnectionCookie = NULL);
27 								~NetReceiver();
28 
29 		BNetEndpoint *			Endpoint() { return fEndpoint.Get(); }
30 
31 private:
32 static	int32					_NetworkReceiverEntry(void *data);
33 		status_t				_Listen();
34 		status_t				_Transfer();
35 
36 		BNetEndpoint *			fListener;
37 		StreamingRingBuffer *	fTarget;
38 
39 		thread_id				fReceiverThread;
40 		bool					fStopThread;
41 
42 		NewConnectionCallback	fNewConnectionCallback;
43 		void *					fNewConnectionCookie;
44 
45 		ObjectDeleter<BNetEndpoint>
46 								fEndpoint;
47 };
48 
49 #endif // NET_RECEIVER_H
50