xref: /haiku/src/servers/net/Services.h (revision 4bd0c1066b227cec4b79883bdef697c7a27f2e90)
1 /*
2  * Copyright 2006-2015, 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_connection;
22 typedef std::map<std::string, service*> ServiceNameMap;
23 typedef std::map<int, service_connection*> 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,
41 									struct service*& service);
42 			void				_Update(const BMessage& services);
43 			status_t			_LaunchService(struct service& service,
44 									int socket);
45 			status_t			_Listener();
46 	static	status_t			_Listener(void* self);
47 
48 private:
49 			thread_id			fListener;
50 			BLocker				fLock;
51 			ServiceNameMap		fNameMap;
52 			ServiceSocketMap	fSocketMap;
53 			uint32				fUpdate;
54 			int					fReadPipe;
55 			int					fWritePipe;
56 			int					fMinSocket;
57 			int					fMaxSocket;
58 			fd_set				fSet;
59 };
60 
61 
62 const static uint32 kMsgUpdateServices = 'srvU';
63 
64 
65 #endif	// SERVICES_H
66