22
24
setsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(timeout));
27
@interface CLLocationManager (TappityServer)
29
- (void) setDelegate_tappity: (id) delegate;
30
- (void) startUpdatingLocation_tappity;
31
- (void) stopUpdatingLocation_tappity;
32
- (void) startUpdatingHeading_tappity;
33
- (void) stopUpdatingHeading_tappity;
37
@interface UIAccelerometer (TappityServer)
39
- (void) setUpdateInterval_tappity: (NSTimeInterval) dt;
43
@interface EAGLContext (TappityServer)
45
- (BOOL)presentRenderbuffer_tappity:(NSUInteger)target;
51
@implementation CLLocationManager (TappityServer)
53
- (void) setDelegate_tappity: (id) obj
55
if ([obj respondsToSelector: @selector(locationManager:didUpdateToLocation:fromLocation:)])
57
[[TappityServer sharedServer] setLocationDelegate: obj];
59
if ([obj respondsToSelector: @selector(locationManager:didUpdateHeading:)])
61
[[TappityServer sharedServer] setHeadingDelegate: obj];
65
- (void) startUpdatingLocation_tappity
67
[[TappityServer sharedServer] sendData: [NSData data] withIdentifier: kTapStartUpdatingLocation];
70
- (void) stopUpdatingLocation_tappity
72
[[TappityServer sharedServer] sendData: [NSData data] withIdentifier: kTapStopUpdatingLocation];
75
- (void) startUpdatingHeading_tappity
77
[[TappityServer sharedServer] sendData: [NSData data] withIdentifier: kTapStartUpdatingHeading];
80
- (void) stopUpdatingHeading_tappity
82
[[TappityServer sharedServer] sendData: [NSData data] withIdentifier: kTapStopUpdatingHeading];
88
@implementation UIAccelerometer (TappityServer)
90
- (void) setUpdateInterval_tappity: (NSTimeInterval) dt
92
[[TappityServer sharedServer] setAccelerometerUpdateInterval: dt];
94
[self setUpdateInterval_tappity: dt];
99
@implementation EAGLContext (TappityServer)
101
- (BOOL)presentRenderbuffer_tappity:(NSUInteger)target
103
[TappityServer glGrabPoint];
104
return [self presentRenderbuffer_tappity: target];
110
static void swapMethods(Class c, SEL sela, SEL selb)
112
Method ma = class_getInstanceMethod(c, sela);
113
Method mb = class_getInstanceMethod(c, selb);
114
method_exchangeImplementations(ma, mb);
118
static void catch_pipe(int sig_num)
120
signal(SIGPIPE, catch_pipe);
123
__attribute__((constructor)) void initTappityServer(void)
125
// __builtin_printf("MOOOOOOOOOOOOOOO\n");
127
1. intercept UIAccelerometer
128
2. intercept CLLocationManager
129
class_getInstanceMethod(), method_setImplementation()
132
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
134
NSString* name = [[NSBundle mainBundle] bundleIdentifier];
136
[[TappityServer sharedServer] startWithName: name];
138
Class lmc = NSClassFromString(@"CLLocationManager");
141
swapMethods(lmc, @selector(setDelegate:), @selector(setDelegate_tappity:));
142
swapMethods(lmc, @selector(startUpdatingHeading:), @selector(startUpdatingHeading_tappity:));
143
swapMethods(lmc, @selector(startUpdatingLocation:), @selector(startUpdatingLocation_tappity:));
146
Class accc = [UIAccelerometer class];
147
swapMethods(accc, @selector(setUpdateInterval:), @selector(setUpdateInterval_tappity:));
149
Class glc = NSClassFromString(@"EAGLContext");
151
swapMethods(glc, @selector(presentRenderbuffer:), @selector(presentRenderbuffer_tappity:));
156
signal(SIGPIPE, catch_pipe);
26
163
@implementation TappityServer
30
172
if (!(self = [super init]))