RSS

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

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

« back to all changes in this revision

Viewing changes to tappity/source/Tappity.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

17
17
 
18
18
#import "Tappity.h"
19
19
 
20
 
#import "GraphicsServices.h"
 
20
//#import "GraphicsServices.h"
21
21
 
22
22
NSString* TapIdKey              = @"tapId";
23
23
NSString* TapTouchesKey = @"tapTouches";
45
45
        @synchronized (self)
46
46
        {
47
47
                [activeThreads removeObjectForKey: key];
 
48
                
 
49
                if (![activeThreads count])
 
50
                {
 
51
                        close(commsSocket);
 
52
                        commsSocket = -1;
 
53
                        
 
54
                        
 
55
                }
48
56
        }
49
57
}
50
58
 
63
71
                fd_set readfds;
64
72
                fd_set writefds;
65
73
                fd_set errorfds;
 
74
                int socket = -1;
66
75
                int maxSocket = -1;
 
76
                
 
77
                @synchronized(self)
 
78
                {
 
79
                        socket = commsSocket;
 
80
                }
67
81
 
68
82
                tv.tv_sec = 1;
69
83
                tv.tv_usec = 0;
72
86
                FD_ZERO(&writefds);
73
87
                FD_ZERO(&errorfds);
74
88
 
75
 
                FD_SET(commsSocket, &readfds);
76
 
                FD_SET(commsSocket, &errorfds);
77
 
                maxSocket = MAX(maxSocket, commsSocket);
 
89
                FD_SET(socket, &readfds);
 
90
                FD_SET(socket, &errorfds);
 
91
                maxSocket = MAX(maxSocket, socket);
78
92
                
79
93
                if (maxSocket < 0)
80
94
                {
89
103
                        break;
90
104
                }
91
105
 
92
 
                if (FD_ISSET(commsSocket, &readfds))
 
106
                if (FD_ISSET(socket, &readfds))
93
107
                {
94
108
                        //NSLog(@"receiving...");
95
109
                        if (!expectedMessageSize)
97
111
                                uint32_t buf = 0;
98
112
                                int actuallyRead = 0;
99
113
                        
100
 
                                actuallyRead = recv(commsSocket, &buf, sizeof(uint32_t), MSG_PEEK);
 
114
                                actuallyRead = recv(socket, &buf, sizeof(uint32_t), MSG_PEEK);
101
115
                                
102
116
                                if (actuallyRead == sizeof(uint32_t))
103
117
                                {
104
 
                                        actuallyRead = recv(commsSocket, &buf, sizeof(uint32_t), 0);
 
118
                                        actuallyRead = recv(socket, &buf, sizeof(uint32_t), 0);
105
119
                                        expectedMessageSize = ntohl(buf);
106
120
                                        currentData = [[NSMutableData alloc] initWithLength: expectedMessageSize];
107
121
                                }
115
129
                                                break;
116
130
                                        }
117
131
                                }
 
132
                                else if (actuallyRead == 0)
 
133
                                {
 
134
                                        printf("remote socket closed.\n");
 
135
                                        break;
 
136
                                }
118
137
                        }
119
138
                        else
120
139
                        {
121
140
                                size_t readAmount = expectedMessageSize - currentlyRead;
122
141
                                int actuallyRead = 0;
123
142
                        
124
 
                                actuallyRead = recv(commsSocket, [currentData mutableBytes] + currentlyRead, readAmount, 0);
 
143
                                actuallyRead = recv(socket, [currentData mutableBytes] + currentlyRead, readAmount, 0);
125
144
                                if (actuallyRead == -1)
126
145
                                {
127
 
                                        close(commsSocket);
128
 
                                        self->commsSocket = 0;
129
146
                                        printf("Connection dropped with error.\n");
130
147
                                        break;
131
148
                                }
 
149
                                else if (actuallyRead == 0)
 
150
                                {
 
151
                                        printf("remote socket closed.\n");
 
152
                                        break;
 
153
                                }
 
154
 
132
155
                                currentlyRead += actuallyRead;
133
156
                                
134
157
                                if (currentlyRead == expectedMessageSize)
224
247
                size_t dataSent = 0;
225
248
                uint32_t header = htonl([data length]);
226
249
                int err = 0;
 
250
                int socket = -1;
 
251
                
 
252
                @synchronized(self)
 
253
                {
 
254
                        socket = commsSocket;
 
255
                }
227
256
 
228
257
                while (dataSent < sizeToSend)
229
258
                {
230
 
                        if ((err = send(commsSocket, &header + dataSent, sizeToSend - dataSent, 0)) == -1)
 
259
                        if ((err = send(socket, &header + dataSent, sizeToSend - dataSent, 0)) == -1)
231
260
                        {
232
261
                                perror("send");
233
262
                                break;
242
271
                        dataSent = 0;
243
272
                        while (dataSent < sizeToSend)
244
273
                        {
245
 
                                if ((err = send(commsSocket, [data bytes] + dataSent, sizeToSend - dataSent, 0)) == -1)
 
274
                                if ((err = send(socket, [data bytes] + dataSent, sizeToSend - dataSent, 0)) == -1)
246
275
                                {
247
276
                                        perror("send");
248
277
                                        break;
317
346
 
318
347
@end
319
348
 
320
 
@interface GSEventProxy : NSObject
321
 
{
322
 
@public
323
 
    unsigned int flags;
324
 
    unsigned int type;
325
 
    unsigned int ignored1;
326
 
    float x1;
327
 
    float y1;
328
 
    float x2;
329
 
    float y2;
330
 
    unsigned int ignored2[10];
331
 
    unsigned int ignored3[7];
332
 
    float sizeX;
333
 
    float sizeY;
334
 
    float x3;
335
 
    float y3;
336
 
    unsigned int ignored4[3];
337
 
}
338
 
@end
339
 
@implementation GSEventProxy
340
 
@end
341
 
 
342
 
@implementation UIEvent (Synthesize)
343
 
 
344
 
- (id)initWithTouches:(NSSet *) touches
345
 
{
346
 
        UITouch* touch = [touches anyObject];
347
 
    CGPoint location = [touch locationInView: touch.window];
348
 
    GSEventProxy *gsEventProxy = [[GSEventProxy alloc] init];
349
 
    gsEventProxy->x1 = location.x;
350
 
    gsEventProxy->y1 = location.y;
351
 
    gsEventProxy->x2 = location.x;
352
 
    gsEventProxy->y2 = location.y;
353
 
    gsEventProxy->x3 = location.x;
354
 
    gsEventProxy->y3 = location.y;
355
 
    gsEventProxy->sizeX = 1.0;
356
 
    gsEventProxy->sizeY = 1.0;
357
 
    gsEventProxy->flags = ([touch phase] == UITouchPhaseEnded) ? 0x1010180 : 0x3010180;
358
 
    gsEventProxy->type = 3001;    
359
 
    
360
 
    //
361
 
    // On SDK versions 3.0 and greater, we need to reallocate as a
362
 
    // UITouchesEvent.
363
 
    //
364
 
    Class touchesEventClass = objc_getClass("UITouchesEvent");
365
 
    if (touchesEventClass && ![[self class] isEqual: touchesEventClass])
366
 
    {
367
 
        [self release];
368
 
        self = [touchesEventClass alloc];
369
 
    }
370
 
    
371
 
    self = [self _initWithEvent:gsEventProxy touches:touches];
372
 
    if (self != nil)
373
 
    {
374
 
    }
375
 
    return self;
376
 
}
377
 
 
 
349
 
 
350
/*
378
351
void _printGSPathPoint(GSTouchPointRef p)
379
352
{
380
353
//      printf("P: 0x%08X 0x%08X 0x%08X 0x%08X (%G, %G)\n", p->unk0, p->unk1, p->unk2, p->unk5, p->x, p->y);
406
379
        printf("\n");
407
380
}
408
381
 
409
 
@end
410
 
 
411
382
@implementation GSEvent
412
383
@end
 
384
*/
413
385
 

Loggerhead 1.17 is a web-based interface for Bazaar branches