xref: /haiku/src/servers/net/Services.h (revision 2b76973fa2401f7a5edf68e6470f3d3210cbcff3)
1 /*
2  * Copyright 2006-2007, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Axel Dörfler, axeld@pinc-software.de
7  */
8 #ifndef SERVICES_H
9 #define SERVICES_H
10 
11 
12 #include <Handler.h>
13 #include <Locker.h>
14 
15 #include <map>
16 #include <string>
17 #include <sys/select.h>
18 
19 
20 struct service;
21 struct service_address;
22 typedef std::map<std::string, service*> ServiceNameMap;
23 typedef std::map<int, service_address*> ServiceSocketMap;
24 
25 
26 class Services : public BHandler {
27 	public:
28 		Services(const BMessage& services);
29 		virtual ~Services();
30 
31 		status_t InitCheck() const;
32 
33 		virtual void MessageReceived(BMessage* message);
34 
35 	private:
36 		void _NotifyListener(bool quit = false);
37 		void _UpdateMinMaxSocket(int socket);
38 		status_t _StartService(struct service& service);
39 		status_t _StopService(struct service& service);
40 		status_t _ToService(const BMessage& message, struct service*& service);
41 		void _Update(const BMessage& services);
42 		int32 _CompareServices(struct service& a, struct service& b);
43 		status_t _LaunchService(struct service& service, int socket);
44 		status_t _Listener();
45 		static status_t _Listener(void* self);
46 
47 		thread_id	fListener;
48 		BLocker		fLock;
49 		ServiceNameMap fNameMap;
50 		ServiceSocketMap fSocketMap;
51 		uint32		fUpdate;
52 		int			fReadPipe;
53 		int			fWritePipe;
54 		int			fMinSocket;
55 		int			fMaxSocket;
56 		fd_set		fSet;
57 };
58 
59 const static uint32 kMsgUpdateServices = 'srvU';
60 
61 #endif	// SERVICES_H
62