/[projects]/smsdaemon/serialport/PosixSignalDispatcher.h
ViewVC logotype

Diff of /smsdaemon/serialport/PosixSignalDispatcher.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 195 by torben, Sun Nov 2 20:14:20 2008 UTC revision 196 by torben, Thu Dec 18 06:53:29 2008 UTC
# Line 33  PosixSignalHandlers. Line 33  PosixSignalHandlers.
33  class PosixSignalDispatcher  class PosixSignalDispatcher
34  {  {
35  public:  public:
36      /**          /**
37       * This is a singleton class and there is only one instance of this           * This is a singleton class and there is only one instance of this
38       * class per process. This instance can be obtained using the           * class per process. This instance can be obtained using the
39       * GetInstance() method.           * GetInstance() method.
40       */           */
41      static PosixSignalDispatcher& Instance() ;          static PosixSignalDispatcher& Instance() ;
42    
43      /**          /**
44       * Exception thrown when AttachHandler() fails due to a runtime           * Exception thrown when AttachHandler() fails due to a runtime
45       * error.           * error.
46       */           */
47      class CannotAttachHandler : public std::runtime_error          class CannotAttachHandler : public std::runtime_error
48      {          {
49      public:          public:
50          CannotAttachHandler( const std::string& whatArg ) :                  CannotAttachHandler( const std::string& whatArg ) :
51              runtime_error(whatArg) { }                                  runtime_error(whatArg) { }
52      } ;          } ;
53    
54      /**          /**
55       * Exception thrown when DetachHandler() fails due to a runtime           * Exception thrown when DetachHandler() fails due to a runtime
56       * error.           * error.
57       */           */
58      class CannotDetachHandler : public std::runtime_error          class CannotDetachHandler : public std::runtime_error
59      {          {
60      public:          public:
61          CannotDetachHandler( const std::string& whatArg ) :                  CannotDetachHandler( const std::string& whatArg ) :
62              runtime_error(whatArg) { }                                  runtime_error(whatArg) { }
63      } ;          } ;
64    
65      /**          /**
66       * Attach a signal handler to the signal dispatcher. The signal           * Attach a signal handler to the signal dispatcher. The signal
67       * handler's HandlePosixSignal() method will be called every time           * handler's HandlePosixSignal() method will be called every time
68       * the specified signal is received. The signal handler should           * the specified signal is received. The signal handler should
69       * not be destroyed while it attached to the signal dispatcher.           * not be destroyed while it attached to the signal dispatcher.
70       * Otherwise, weird things are bound to happen (i.e. "undefined           * Otherwise, weird things are bound to happen (i.e. "undefined
71       * behavior" shall ensue). Make sure you call DetachHandler() from           * behavior" shall ensue). Make sure you call DetachHandler() from
72       * the destructor of the signal handler.           * the destructor of the signal handler.
73       *           *
74       * If a PosixSignalHandler is attached to the same signal number           * If a PosixSignalHandler is attached to the same signal number
75       * multiple times, it will be called multiple times. Furthermore,           * multiple times, it will be called multiple times. Furthermore,
76       * it should also be detached as many times as it was attached           * it should also be detached as many times as it was attached
77       * before it is destroyed. Otherwise, undefined behavior may result.           * before it is destroyed. Otherwise, undefined behavior may result.
78       *           *
79       * @param posixSignalNumber The signal number that will result in           * @param posixSignalNumber The signal number that will result in
80       * call to the HandlePosixSignal() method of the signal handler.           * call to the HandlePosixSignal() method of the signal handler.
81       *           *
82       * @param signalHandler The signal handler to be invoked on receiving           * @param signalHandler The signal handler to be invoked on receiving
83       * a posixSignalNumber signal.           * a posixSignalNumber signal.
84       */           */
85      void AttachHandler( const int           posixSignalNumber,          void AttachHandler( const int           posixSignalNumber,
86                          PosixSignalHandler& signalHandler )                              PosixSignalHandler& signalHandler )
87          throw( CannotAttachHandler ) ;          throw( CannotAttachHandler ) ;
88    
89      /**          /**
90       * Detach the specified signal handler from the signal dispatcher.           * Detach the specified signal handler from the signal dispatcher.
91       * The signal handler will stop being called on receiving the           * The signal handler will stop being called on receiving the
92       * corresponding POSIX signal. If the signal handler is not           * corresponding POSIX signal. If the signal handler is not
93       * attached to the signal dispatcher when this method is called           * attached to the signal dispatcher when this method is called
94       * then this method has no effect.           * then this method has no effect.
95       *           *
96       * @param posixSignalNumber The signal number corresponding to           * @param posixSignalNumber The signal number corresponding to
97       * the signal handler.           * the signal handler.
98       *           *
99       * @param signalHandler The signal handler to be detached.           * @param signalHandler The signal handler to be detached.
100       */           */
101      void DetachHandler( const int                 posixSignalNumber,          void DetachHandler( const int                 posixSignalNumber,
102                          const PosixSignalHandler& signalHandler )                              const PosixSignalHandler& signalHandler )
103          throw( CannotDetachHandler,          throw( CannotDetachHandler,
104                 std::logic_error ) ;                 std::logic_error ) ;
105  private:  private:
106      /**          /**
107       * This is a singleton class and the only instances of this class           * This is a singleton class and the only instances of this class
108       * can only be accessed using the Instance() method. This is           * can only be accessed using the Instance() method. This is
109       * enforced by making the default constructor a private member           * enforced by making the default constructor a private member
110       * disalloweing construction of new instances of this class           * disalloweing construction of new instances of this class
111       */           */
112      PosixSignalDispatcher() ;          PosixSignalDispatcher() ;
113    
114      /**          /**
115       * This class cannot be subclassed. We enforce this by making           * This class cannot be subclassed. We enforce this by making
116       * the destructor a private member.           * the destructor a private member.
117       */           */
118      ~PosixSignalDispatcher() ;          ~PosixSignalDispatcher() ;
119    
120      /**          /**
121       * Copying of an instance of this class is not allowed. We           * Copying of an instance of this class is not allowed. We
122       * enforce this by making the copy constructor and the           * enforce this by making the copy constructor and the
123       * assignment operator private members.           * assignment operator private members.
124       */           */
125      PosixSignalDispatcher( const PosixSignalDispatcher& otherInstance ) ;          PosixSignalDispatcher( const PosixSignalDispatcher& otherInstance ) ;
126    
127      /**          /**
128       * Copying of an instance of this class is not allowed. We           * Copying of an instance of this class is not allowed. We
129       * enforce this by making the copy constructor and the           * enforce this by making the copy constructor and the
130       * assignment operator private members.           * assignment operator private members.
131       */           */
132      const PosixSignalDispatcher&          const PosixSignalDispatcher&
133      operator=( const PosixSignalDispatcher& otherInstance ) ;          operator=( const PosixSignalDispatcher& otherInstance ) ;
134  } ;  } ;
135    
136  #endif  #endif

Legend:
Removed from v.195  
changed lines
  Added in v.196

  ViewVC Help
Powered by ViewVC 1.1.20