PageRenderTime 45ms CodeModel.GetById 1ms app.highlight 40ms RepoModel.GetById 1ms app.codeStats 0ms

/core/externals/google-toolbox-for-mac/Foundation/GTMTransientRootPortProxy.m

http://macfuse.googlecode.com/
Objective C | 80 lines | 45 code | 14 blank | 21 comment | 3 complexity | cd77ce4f3ae220271c47d8c24a052ce7 MD5 | raw file
 1//
 2//  GTMTransientRootPortProxy.m
 3//
 4//  Copyright 2006-2009 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 "GTMTransientRootPortProxy.h"
20#import "GTMObjC2Runtime.h"
21
22@interface GTMTransientRootPortProxy (ProtectedMethods)
23// Returns an NSConnection for NSPorts.  This method overrides the one in
24// the GTMTransientRootProxy which allows us to create a connection with a
25// NSPort.
26//
27- (NSConnection *)makeConnection;
28@end
29
30
31@implementation GTMTransientRootPortProxy
32
33+ (id)rootProxyWithReceivePort:(NSPort *)receivePort
34                      sendPort:(NSPort *)sendPort
35                      protocol:(Protocol *)protocol
36                requestTimeout:(NSTimeInterval)requestTimeout
37                  replyTimeout:(NSTimeInterval)replyTimeout {
38  return [[[self alloc] initWithReceivePort:receivePort
39                                   sendPort:sendPort
40                                   protocol:protocol
41                             requestTimeout:requestTimeout
42                               replyTimeout:replyTimeout] autorelease];
43}
44
45- (id)initWithReceivePort:(NSPort *)receivePort
46                 sendPort:(NSPort *)sendPort
47                 protocol:(Protocol *)protocol
48           requestTimeout:(NSTimeInterval)requestTimeout
49             replyTimeout:(NSTimeInterval)replyTimeout {
50  if ((!sendPort && !receivePort) || !protocol) {
51    [self release];
52    return nil;
53  }
54
55  requestTimeout_ = requestTimeout;
56  replyTimeout_ = replyTimeout;
57
58  receivePort_ = [receivePort retain];
59  sendPort_ = [sendPort retain];
60  
61  protocol_ = protocol;  // Protocols can't be retained
62  return self;
63}
64
65- (void)dealloc {
66  [receivePort_ release];
67  [sendPort_ release];
68  [super dealloc];
69}
70
71@end
72
73@implementation GTMTransientRootPortProxy (ProtectedMethods)
74
75- (NSConnection *)makeConnection {
76  return [NSConnection connectionWithReceivePort:receivePort_
77                                        sendPort:sendPort_];
78}
79
80@end