Protocols: Move __THROW__ macro to MMSException header file
[remote/remote-mci.git] / mcs / FileDescriptor.h
blobdd5bcef3597389b6cd6880785edeb84ae57ce9c4
1 #ifndef _FILEDESCRIPTOR_H_
2 #define _FILEDESCRIPTOR_H_
4 #ifdef HAVE_CONFIG_H
5 #include "config.h"
6 #endif
8 #include "types.h"
9 #include "database.h"
10 #include <stdlib.h>
11 #include <sys/poll.h>
12 #include <signal.h>
13 #include <sys/time.h>
14 #include <errno.h>
16 namespace remote { namespace mcs {
18 class FileDescriptor;
20 typedef std::map<int,FileDescriptor*> filedescriptorsbyfd_t;
22 /** Base class for handling socket connections through file descriptors.
24 **/
25 class FileDescriptor
27 public:
28 /** Main service loop using poll() system call to receive fd events**/
29 static bool serviceLoop();
30 /** Handles an event on a specific file descriptor **/
31 virtual void handleEvent(short events) = 0;
32 /** Clean up and destroy a FileDescriptor object **/
33 virtual void destroy(bool silent=false);
34 protected:
35 void setTimeout(int secs);
36 static void clearTimeout();
37 FileDescriptor(int p_fd);
38 virtual ~FileDescriptor();
39 static void buildPollMap(pollfd* map);
40 static void installSignalHandlers();
41 static void exitSignalHandler(int signo);
42 static RETSIGTYPE timeoutHandler(int sig);
43 static filedescriptorsbyfd_t instances;
44 static int exitSignal;
45 static int currentFd;
46 int fd;
52 #endif