RSS

(root)/iphone/tappity : 50 : 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-30 10:05:15
Revision ID: dognotdog@gmail.com-20091030090515-tzzgj0hpoq1qi7ik
tappity server is changed to automagically hook into the relevant classes when linked with -ObjC; network header is changed to contain msg id in addition to size

Show diffs side-by-side

added added

removed removed

20
20
//#import "GraphicsServices.h"
21
21
 
22
22
NSString* TapIdKey              = @"tapId";
 
23
NSString* TapDataKey    = @"tapData";
23
24
NSString* TapTouchesKey = @"tapTouches";
24
25
NSString* TapGSEventKey = @"tapGSEvent";
25
26
NSString* TapTouchPhaseKey = @"tapTouchPhase";
108
109
                        //NSLog(@"receiving...");
109
110
                        if (!expectedMessageSize)
110
111
                        {
111
 
                                uint32_t buf = 0;
 
112
                                uint32_t header[2] = {0,0};
112
113
                                int actuallyRead = 0;
113
114
                        
114
 
                                actuallyRead = recv(socket, &buf, sizeof(uint32_t), MSG_PEEK);
 
115
                                actuallyRead = recv(socket, header, 8, MSG_PEEK);
115
116
                                
116
 
                                if (actuallyRead == sizeof(uint32_t))
 
117
                                if (actuallyRead == 8)
117
118
                                {
118
 
                                        actuallyRead = recv(socket, &buf, sizeof(uint32_t), 0);
119
 
                                        expectedMessageSize = ntohl(buf);
 
119
                                        actuallyRead = recv(socket, header, 8, 0);
 
120
                                        expectedMessageSize = ntohl(header[1]);
 
121
                                        currentMessageId = ntohl(header[0]);
120
122
                                        currentData = [[NSMutableData alloc] initWithLength: expectedMessageSize];
121
123
                                }
122
124
                                else if (actuallyRead == -1)
169
171
                                        }
170
172
 
171
173
                                        if (receiveDataOnMainThread)
172
 
                                                [self performSelectorOnMainThread: @selector(dataReceived:) withObject: currentData waitUntilDone: NO];
 
174
                                                [self performSelectorOnMainThread: @selector(dataReceived:) withObject: [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt: currentMessageId], TapIdKey, currentData, TapDataKey, nil] waitUntilDone: NO];
173
175
                                        else
174
 
                                                [self dataReceived: currentData];
 
176
                                                [self dataReceived: [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt: currentMessageId], TapIdKey, currentData, TapDataKey, nil]];
175
177
 
176
178
                                        currentData = nil;
177
179
                                        currentlyRead = 0;
206
208
        }
207
209
}
208
210
 
209
 
- (void) sendData: (NSData*) tapData
 
211
- (void) sendData: (NSData*) tapData withIdentifier: (NSInteger) messageId
210
212
{               
211
213
        [sendLock lock];
212
214
 
213
215
        if (!sendQueue)
214
216
                sendQueue = [[NSMutableArray alloc] init];
215
217
 
216
 
        [sendQueue addObject: tapData];
 
218
        [sendQueue addObject: [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInteger: messageId], TapIdKey, tapData, TapDataKey, nil]];
217
219
        
218
220
        [sendLock signal];
219
221
        [sendLock unlock];
238
240
                                
239
241
                //NSLog(@"sending");
240
242
                
241
 
                NSData* data = [[sendQueue objectAtIndex: 0] retain];
 
243
                NSDictionary* dict = [[sendQueue objectAtIndex: 0] retain];
 
244
                NSData* data = [dict objectForKey: TapDataKey];
 
245
                uint32_t messageId = [[dict objectForKey: TapIdKey] intValue];
242
246
                [sendQueue removeObjectAtIndex: 0];
243
247
                
244
248
                [sendLock unlock];
245
249
 
246
 
                size_t sizeToSend = 4;
 
250
                size_t sizeToSend = 8;
247
251
                size_t dataSent = 0;
248
 
                uint32_t header = htonl([data length]);
 
252
                uint32_t header[2] = {htonl(messageId), htonl([data length])};
249
253
                int err = 0;
250
254
                int socket = -1;
251
 
                
 
255
 
252
256
                @synchronized(self)
253
257
                {
254
258
                        socket = commsSocket;
256
260
 
257
261
                while (dataSent < sizeToSend)
258
262
                {
259
 
                        if ((err = send(socket, &header + dataSent, sizeToSend - dataSent, 0)) == -1)
 
263
                        if ((err = send(socket, header + dataSent, sizeToSend - dataSent, 0)) == -1)
260
264
                        {
261
265
                                perror("send");
262
266
                                break;
281
285
                                        
282
286
                        }
283
287
                }
284
 
                [data release];
 
288
                [dict release];
285
289
                
286
290
                if (err == -1)
287
291
                        break;

Loggerhead 1.17 is a web-based interface for Bazaar branches