Write a ThreadSafeDelegate implementation, which will be used by MessageQueue.
authorRobert Sesek <rsesek@bluestatic.org>
Thu, 20 Jun 2013 02:05:32 +0000 (22:05 -0400)
committerRobert Sesek <rsesek@bluestatic.org>
Thu, 20 Jun 2013 02:05:32 +0000 (22:05 -0400)
MacGDBp.xcodeproj/project.pbxproj
Source/ThreadSafeDeleage.h [new file with mode: 0644]
Source/ThreadSafeDeleage.m [new file with mode: 0644]

index c930fda994c7af2d7ad0854394d581752a8f2f4a..2b8dcb0e26314e96ff5af6f4a25b746f94905faa 100644 (file)
@@ -24,6 +24,7 @@
                1E416FF90D36F821009A53A2 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1E416FF60D36F821009A53A2 /* MainMenu.xib */; };
                1E42F1D70F53317B008412DB /* dsa_pub.pem in Resources */ = {isa = PBXBuildFile; fileRef = 1E42F1D60F53317B008412DB /* dsa_pub.pem */; };
                1E4C7AF90DA401C7000A9DC7 /* BreakpointManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E4C7AF80DA401C7000A9DC7 /* BreakpointManager.m */; };
+               1E5C32AA177296DF00F4377B /* ThreadSafeDeleage.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E5C32A9177296DF00F4377B /* ThreadSafeDeleage.m */; };
                1E67E6FD0F3C052000E68F1B /* PreferencesPathsArrayController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E67E6FC0F3C052000E68F1B /* PreferencesPathsArrayController.m */; };
                1E6B5947116106FE001189D2 /* LoggingController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E6B5946116106FE001189D2 /* LoggingController.m */; };
                1E6B594C11610993001189D2 /* Log.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1E6B594A11610993001189D2 /* Log.xib */; };
@@ -97,6 +98,8 @@
                1E42F1D60F53317B008412DB /* dsa_pub.pem */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = dsa_pub.pem; sourceTree = "<group>"; };
                1E4C7AF70DA401C7000A9DC7 /* BreakpointManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BreakpointManager.h; path = Source/BreakpointManager.h; sourceTree = "<group>"; };
                1E4C7AF80DA401C7000A9DC7 /* BreakpointManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BreakpointManager.m; path = Source/BreakpointManager.m; sourceTree = "<group>"; };
+               1E5C32A8177296DF00F4377B /* ThreadSafeDeleage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ThreadSafeDeleage.h; path = Source/ThreadSafeDeleage.h; sourceTree = "<group>"; };
+               1E5C32A9177296DF00F4377B /* ThreadSafeDeleage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ThreadSafeDeleage.m; path = Source/ThreadSafeDeleage.m; sourceTree = "<group>"; };
                1E67E6FB0F3C052000E68F1B /* PreferencesPathsArrayController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PreferencesPathsArrayController.h; path = Source/PreferencesPathsArrayController.h; sourceTree = "<group>"; };
                1E67E6FC0F3C052000E68F1B /* PreferencesPathsArrayController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PreferencesPathsArrayController.m; path = Source/PreferencesPathsArrayController.m; sourceTree = "<group>"; };
                1E6B5945116106FE001189D2 /* LoggingController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LoggingController.h; path = Source/LoggingController.h; sourceTree = "<group>"; };
                                1EEBE841176FEA80003622C3 /* MessageQueue.m */,
                                1EEBE843176FFE04003622C3 /* ProtocolClient.h */,
                                1EEBE844176FFE04003622C3 /* ProtocolClient.m */,
+                               1E5C32A8177296DF00F4377B /* ThreadSafeDeleage.h */,
+                               1E5C32A9177296DF00F4377B /* ThreadSafeDeleage.m */,
                        );
                        name = Protocol;
                        sourceTree = "<group>";
                                1E109019136DD92D002E34E0 /* StripLineBreaksValueTransformer.m in Sources */,
                                1EEBE842176FEA80003622C3 /* MessageQueue.m in Sources */,
                                1EEBE845176FFE04003622C3 /* ProtocolClient.m in Sources */,
+                               1E5C32AA177296DF00F4377B /* ThreadSafeDeleage.m in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
diff --git a/Source/ThreadSafeDeleage.h b/Source/ThreadSafeDeleage.h
new file mode 100644 (file)
index 0000000..f80dfa0
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * MacGDBp
+ * Copyright (c) 2013, Blue Static <http://www.bluestatic.org>
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if not,
+ * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#import <Foundation/Foundation.h>
+
+@interface ThreadSafeDeleage : NSObject
+
+@property(readonly, atomic) NSObject* object;
+
+- (id)initWithObject:(NSObject*)object
+            protocol:(Protocol*)protocol
+              thread:(NSThread*)thread;
+
+- (id)initWithObject:(NSObject*)object
+            protocol:(Protocol*)protocol
+              thread:(NSThread*)thread
+               modes:(NSArray*)runLoopModes;
+
+@end
diff --git a/Source/ThreadSafeDeleage.m b/Source/ThreadSafeDeleage.m
new file mode 100644 (file)
index 0000000..dc340df
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * MacGDBp
+ * Copyright (c) 2013, Blue Static <http://www.bluestatic.org>
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if not,
+ * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#import "ThreadSafeDeleage.h"
+
+@implementation ThreadSafeDeleage {
+  NSObject* _object;
+  Protocol* _protocol;
+  NSThread* _thread;
+  NSArray* _modes;
+}
+
+@synthesize object = _object;
+
+- (id)initWithObject:(NSObject*)object
+            protocol:(Protocol*)protocol
+              thread:(NSThread*)thread {
+  return [self initWithObject:object
+                     protocol:protocol
+                       thread:thread
+                        modes:@[ NSRunLoopCommonModes ]];
+}
+
+- (id)initWithObject:(NSObject*)object
+            protocol:(Protocol*)protocol
+              thread:(NSThread*)thread
+               modes:(NSArray*)runLoopModes {
+  if ((self = [super init])) {
+    _object = object;
+    _protocol = protocol;
+    _thread = thread;
+    _modes = [runLoopModes retain];
+  }
+  return self;
+}
+
+- (void)dealloc {
+  [_modes release];
+  [super dealloc];
+}
+
+- (BOOL)conformsToProtocol:(Protocol*)protocol {
+  return [_protocol isEqual:protocol];
+}
+
+- (NSMethodSignature*)methodSignatureForSelector:(SEL)aSelector {
+  if (!_object)
+    return [_protocol methodSignatureForSelector:aSelector];
+  return [_object methodSignatureForSelector:aSelector];
+}
+
+- (BOOL)respondsToSelector:(SEL)aSelector {
+  if (!_object)
+    return [_protocol respondsToSelector:aSelector];
+  return [_object respondsToSelector:aSelector];
+}
+
+- (void)forwardInvocation:(NSInvocation*)invocation {
+  if ([_object respondsToSelector:[invocation selector]]) {
+    [self performSelector:@selector(dispatchInvocation:)
+                 onThread:_thread
+               withObject:invocation
+            waitUntilDone:NO
+                    modes:_modes];
+  }
+}
+
+- (void)dispatchInvocation:(NSInvocation*)invocation {
+  [invocation invokeWithTarget:_object];
+}
+
+@end