PageRenderTime 73ms CodeModel.GetById 68ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/core/externals/google-toolbox-for-mac/Foundation/GTMSignalHandler.h

http://macfuse.googlecode.com/
C++ Header | 76 lines | 12 code | 5 blank | 59 comment | 0 complexity | b050f2af796f07339bd90cb593fcfd9c MD5 | raw file
 1//
 2//  GTMSignalHandler.h
 3//
 4//  Copyright 2008 Google Inc.
 5//
 6//  Licensed under the Apache License, Version 2.0 (the "License"); you may not
 7//  use this file except in compliance with the License.  You may obtain a copy
 8//  of the License at
 9// 
10//  http://www.apache.org/licenses/LICENSE-2.0
11// 
12//  Unless required by applicable law or agreed to in writing, software
13//  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14//  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
15//  License for the specific language governing permissions and limitations under
16//  the License.
17//
18
19#import <Foundation/Foundation.h>
20
21// GTMSignalHandler.
22//
23// This is a very simple, easy-to-use class for registering handlers that get
24// called when a specific signal is delivered.  Also handy for ignoring
25// inconvenient signals.  Ignoring SIGKILL is not support for what should be
26// obvious reasons.  You can pass nil for target & action to ignore the signal.
27//
28// Example of how to catch SIGABRT and SIGTERM while ignring SIGWINCH:
29//   GTMSignalHandler *abrt, *term, *winch;
30//   abrt = [[GTMSignalHandler alloc]
31//               initWithSignal:SIGABRT
32//                       target:self
33//                       action:@selector(handleAbort:)];
34//
35//   term = [[GTMSignalHandler alloc]
36//               initWithSignal:SIGTERM
37//                       target:self
38//                       action:@selector(handleTerm:)];
39//
40//   winch = [[GTMSignalHandler alloc] initWithSignal:SIGWINCH
41//                initWithSignal:SIGWINCH
42//                        target:nil
43//                        action:NULL
44//
45//  -(void)handleTerm:(int)signo {
46//    .. do stuff ..
47//  }
48//
49// Release the handler when you're no longer interested in handling that signal.
50// Note that signal(SIG_IGN, signo) is performed on each signal handled by
51// objects of this class, and those do not get un-done.
52//
53// Multiple handlers for the same signal is NOT supported.
54//
55// kqueue() is used to handle the signals, and the default runloop for the first
56// signal handler is used for signal delivery, so keep that in mind when you're
57// using this class.  This class explicitly does not handle arbitrary runloops
58// and threading.
59//
60@interface GTMSignalHandler : NSObject {
61 @private
62  int signo_;
63  __weak id target_;
64  SEL action_;
65}
66
67// Returns a retained signal handler object that will invoke |handler| on the
68// |target| whenever a signal of number |signo| is delivered to the process.
69-(id)initWithSignal:(int)signo
70             target:(id)target
71             action:(SEL)action;
72
73// Invalidates the handler so that it isn't listening anymore.
74- (void)invalidate;
75
76@end