RSS

(root)/iphone/tappity : 49 : tappity/source/TappityServer.m

To get this branch, use:
bzr branch /browse/iphone/tappity

« back to all changes in this revision

Viewing changes to tappity/source/TappityServer.m

Dömötör Gulyás
2009-10-28 22:34:56
Revision ID: dognotdog@gmail.com-20091028213456-9pjbddhboknsf5w8
tappity now no longer eating some events

Show diffs side-by-side

added added

removed removed

10
10
#import "Tappity.h"
11
11
#import <QuartzCore/QuartzCore.h>
12
12
#import <OpenGLES/ES1/gl.h>
 
13
#import <CoreLocation/CoreLocation.h>
13
14
 
14
15
 
15
16
static void _setStandardSocketOpts(int socket)
21
22
        setsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(timeout));
22
23
}
23
24
 
24
 
@interface UIApplication (TappityPrivate)
25
 
- (void)_playbackEvents:(id)arg1 atPlaybackRate:(float)arg2 messageWhenDone:(id)arg3 withSelector:(SEL)arg4;
26
 
@end
27
25
 
28
26
@implementation TappityServer
29
27
 
145
143
 
146
144
- (void) startScreenieTimer
147
145
{
 
146
        [captureTimer invalidate];
148
147
        captureTimer = [NSTimer scheduledTimerWithTimeInterval: desiredFrameInterval target: self selector: @selector(captureScreen) userInfo: nil repeats: YES];
149
148
        
150
149
        
176
175
        return YES;
177
176
}
178
177
 
179
 
- (void) startWithName: (NSString*) name
 
178
- (void) startListening
180
179
{
181
 
        NSLog(@"starting tappity server");
182
 
        
183
 
        [serviceName release];
184
 
        serviceName = [name retain];
185
 
 
186
180
        myAddress.sin_family = AF_INET;                                 // host byte order
187
181
        myAddress.sin_port = htons(1234);                               // short, network byte order, any port
188
182
        myAddress.sin_addr.s_addr = htonl(INADDR_ANY);  // auto-fill with my IP
205
199
 
206
200
}
207
201
 
 
202
- (void) startWithName: (NSString*) name
 
203
{
 
204
        NSLog(@"starting tappity server");
 
205
        
 
206
        [serviceName release];
 
207
        serviceName = [name retain];
 
208
        
 
209
        [self startListening];
 
210
 
 
211
}
 
212
 
 
213
/*
208
214
static size_t _read_i8(const void* buf, uint8_t* p)
209
215
{
210
216
        uint8_t v = 0;
292
298
 
293
299
        return gse;
294
300
}
 
301
*/
 
302
 
 
303
- (void) doEventPlayback
 
304
{
 
305
        [[UIApplication sharedApplication] _playbackEvents: queuedEvents atPlaybackRate: 1.0f messageWhenDone: self withSelector: @selector(eventPlaybackDone:)];
 
306
        
 
307
        [queuedEvents autorelease];
 
308
        queuedEvents = nil;
 
309
        eventPlaybackBusy = YES;
 
310
}
 
311
- (void) eventPlaybackDone:(NSDictionary*)detail
 
312
{
 
313
        if ([queuedEvents count])
 
314
        {
 
315
                [self doEventPlayback];
 
316
        }
 
317
        else
 
318
                eventPlaybackBusy = NO;
 
319
}
295
320
 
296
321
- (void) dataReceived: (NSData*) tapData
297
322
{
302
327
        assert(tapDict);
303
328
        switch([[tapDict objectForKey: TapIdKey] intValue])
304
329
        {
 
330
/*
305
331
                case kTapTouchEvent:
306
332
                {
307
333
                        NSLog(@"TOUCH EVENT");
336
362
                        
337
363
                        break;
338
364
                }
 
365
*/
339
366
                case kTapRecordedEvent:
340
 
                {
341
 
//                      NSLog(@"RECORDED EVENT");
342
 
                        
 
367
                {                       
343
368
                        NSDictionary* eventDict = [tapDict objectForKey: TapRecordedEventKey];
344
369
                        
345
 
                        [[UIApplication sharedApplication] _playbackEvents:[NSArray arrayWithObject: eventDict] atPlaybackRate: 1.0f messageWhenDone: nil withSelector: nil];
 
370
                        if (!queuedEvents)
 
371
                                queuedEvents = [[NSMutableArray alloc] init];
346
372
 
 
373
                        [queuedEvents addObject: eventDict];
 
374
                        
 
375
                        if (!eventPlaybackBusy)
 
376
                        {
 
377
                                [self doEventPlayback];
 
378
                        }
347
379
                        break;
348
380
                }
349
381
                case kTapAcceleration:
350
 
                {
351
 
//                      NSLog(@"RECORDED EVENT");
352
 
                        
 
382
                {                       
353
383
                        NSArray* accel = [tapDict objectForKey: TapAccelerationKey];
354
384
                        
355
385
                        UIAccelerometer* accm = [UIAccelerometer sharedAccelerometer];
360
390
                        
361
391
                        break;
362
392
                }
 
393
                case kTapLocation:
 
394
                {
 
395
                        static CLLocation* oldLoc = nil;
 
396
                        CLLocation* loc = [NSKeyedUnarchiver unarchiveObjectWithData: [tapDict objectForKey: TapLocationKey]];
 
397
                        if ([locationDelegate respondsToSelector: @selector(locationManager:didUpdateToLocation:fromLocation:)])
 
398
                        {
 
399
                                [locationDelegate locationManager: (id)self didUpdateToLocation: loc fromLocation: oldLoc];
 
400
                        }
 
401
                        oldLoc = loc;
 
402
                        break;
 
403
                }
 
404
                case kTapCompass:
 
405
                {
 
406
                        CLHeading* hdg = [NSKeyedUnarchiver unarchiveObjectWithData: [tapDict objectForKey: TapCompassKey]];
 
407
                        if ([headingDelegate respondsToSelector: @selector(locationManager:didUpdateHeading:)])
 
408
                        {
 
409
                                [headingDelegate locationManager: (id)self didUpdateHeading: hdg];
 
410
                        }
 
411
                        break;
 
412
                }
363
413
        }
364
414
        
365
415
        [tapData release];
615
665
        [super dealloc];
616
666
}
617
667
 
 
668
@synthesize locationDelegate, headingDelegate;
 
669
 
618
670
@end

Loggerhead 1.17 is a web-based interface for Bazaar branches