/core/externals/update-engine/externals/google-toolbox-for-mac/Foundation/GTMTransientRootProxy.h

http://macfuse.googlecode.com/ · C++ Header · 113 lines · 25 code · 11 blank · 77 comment · 0 complexity · 8afbbcc2764a4bcb93762715a2c07f5b MD5 · raw file

  1. //
  2. // GTMTransientRootProxy.h
  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 <Foundation/Foundation.h>
  19. // Handle (re-)connecting to a transient root proxy object via DO.
  20. //
  21. // This class is designed to handle connecting and reconnecting to a Distributed
  22. // Objects root proxy (NSDistantObject* instance). It is a replacement for using
  23. // the NSDistantObject returned from NSConnection, directly. When the DO
  24. // connection is up, messages sent to this class are forwarded to the real
  25. // object (the NSDistantObject); when the DO connection is down, messages sent
  26. // to this class are silently swallowed. You can use the -isConnected method on
  27. // this class to see if the DO connection is up or down.
  28. //
  29. // This class may be useful when you need a DO connection, but the
  30. // server you're connected to may be going up and down. For example, the
  31. // web browser plugins in Google Desktop may need to connect to the Google
  32. // Desktop local webserver, but we'd want the browser plugins to be able to
  33. // gracefully handle the local Google Desktop webserver starting and stopping.
  34. //
  35. // === Example Usage ===
  36. //
  37. // Old code:
  38. //
  39. // NSDistantObject<MyProto> *o =
  40. // [NSConnection rootProxyForConnectionWithRegisteredName:@"server"
  41. // host:nil];
  42. // [o setProtocolForProxy:@protocol(MyProto)];
  43. // [o someMethodInMyProto];
  44. // // ... write a bunch of code to handle error conditions
  45. //
  46. // New code:
  47. //
  48. // GTMTransientRootProxy<MyProto> *o =
  49. // [GTMTransientRootProxy rootProxyWithRegisteredName:@"server"
  50. // host:nil
  51. // protocol:@protocol(MyProto)
  52. // requestTimeout:5.0
  53. // replyTimeout:5.0];
  54. // [o someMethodInMyProto];
  55. //
  56. // The 'Old code' requires you to handle all the error conditions that may
  57. // arise when using DO (such as the server crashing, or network going down),
  58. // handle properly tearing down the broken connection, and trying to reconnect
  59. // when the server finally comes back online. The 'New code' handles all of
  60. // those details for you.
  61. //
  62. // Also, when creating a GMTransientRootProxy object, you must tell it the
  63. // @protocol that will be used for communication - this is not optional. And
  64. // in order to quiet compiler warnings, you'll also want to staticly type
  65. // the pointer with the protocol as well.
  66. //
  67. @interface GTMTransientRootProxy : NSProxy {
  68. @protected
  69. __weak Protocol *protocol_;
  70. NSDistantObject *realProxy_;
  71. NSString *registeredName_;
  72. NSString *host_;
  73. NSTimeInterval requestTimeout_;
  74. NSTimeInterval replyTimeout_;
  75. }
  76. // Returns an autoreleased instance
  77. + (id)rootProxyWithRegisteredName:(NSString *)name
  78. host:(NSString *)host
  79. protocol:(Protocol *)protocol
  80. requestTimeout:(NSTimeInterval)requestTimeout
  81. replyTimeout:(NSTimeInterval)replyTimeout;
  82. // This function will return a GTMTransientRootProxy that is using Mach ports
  83. // for the connection. The |name| and |host| arguments will be used to lookup
  84. // the correct information to create the Mach port connection.
  85. //
  86. - (id)initWithRegisteredName:(NSString *)name
  87. host:(NSString *)host
  88. protocol:(Protocol *)protocol
  89. requestTimeout:(NSTimeInterval)requestTimeout
  90. replyTimeout:(NSTimeInterval)replyTimeout;
  91. // Returns YES if the DO connection is up and working, NO otherwise.
  92. //
  93. - (BOOL)isConnected;
  94. @end
  95. // Subclass of GTMTransientRootProxy that catches and ignores ALL exceptions.
  96. // This class overrides GTMTransientRootProxy's -forwardInvocation:
  97. // method, and wraps it in a try/catch block, and ignores all exceptions.
  98. //
  99. @interface GTMRootProxyCatchAll : GTMTransientRootProxy
  100. // Overridden, and ignores all thrown exceptions.
  101. - (void)forwardInvocation:(NSInvocation *)invocation;
  102. @end