/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. #import "GTMTransientRootPortProxy.h"
  19. #import "GTMObjC2Runtime.h"
  20. @interface GTMTransientRootPortProxy (ProtectedMethods)
  21. // Returns an NSConnection for NSPorts. This method overrides the one in
  22. // the GTMTransientRootProxy which allows us to create a connection with a
  23. // NSPort.
  24. //
  25. - (NSConnection *)makeConnection;
  26. @end
  27. @implementation GTMTransientRootPortProxy
  28. + (id)rootProxyWithReceivePort:(NSPort *)receivePort
  29. sendPort:(NSPort *)sendPort
  30. protocol:(Protocol *)protocol
  31. requestTimeout:(NSTimeInterval)requestTimeout
  32. replyTimeout:(NSTimeInterval)replyTimeout {
  33. return [[[self alloc] initWithReceivePort:receivePort
  34. sendPort:sendPort
  35. protocol:protocol
  36. requestTimeout:requestTimeout
  37. replyTimeout:replyTimeout] autorelease];
  38. }
  39. - (id)initWithReceivePort:(NSPort *)receivePort
  40. sendPort:(NSPort *)sendPort
  41. protocol:(Protocol *)protocol
  42. requestTimeout:(NSTimeInterval)requestTimeout
  43. replyTimeout:(NSTimeInterval)replyTimeout {
  44. if ((!sendPort && !receivePort) || !protocol) {
  45. [self release];
  46. return nil;
  47. }
  48. requestTimeout_ = requestTimeout;
  49. replyTimeout_ = replyTimeout;
  50. receivePort_ = [receivePort retain];
  51. sendPort_ = [sendPort retain];
  52. protocol_ = protocol; // Protocols can't be retained
  53. return self;
  54. }
  55. - (void)dealloc {
  56. [receivePort_ release];
  57. [sendPort_ release];
  58. [super dealloc];
  59. }
  60. @end
  61. @implementation GTMTransientRootPortProxy (ProtectedMethods)
  62. - (NSConnection *)makeConnection {
  63. return [NSConnection connectionWithReceivePort:receivePort_
  64. sendPort:sendPort_];
  65. }
  66. @end