diff dstep/foundation/NSOperation.d @ 14:89f3c3ef1fd2

Added the Foundation framework
author Jacob Carlborg <doob@me.com>
date Mon, 03 Aug 2009 15:23:15 +0200
parents
children 19885b43130e
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dstep/foundation/NSOperation.d	Mon Aug 03 15:23:15 2009 +0200
@@ -0,0 +1,219 @@
+/**
+ * Copyright: Copyright (c) 2009 Jacob Carlborg.
+ * Authors: Jacob Carlborg
+ * Version: Initial created: Aug 3, 2009 
+ * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
+ */
+module dstep.foundation.NSOperation;
+
+import dstep.foundation.NSArray;
+import dstep.foundation.NSObject;
+import dstep.foundation.NSSet;
+import dstep.objc.bridge.Bridge;
+import dstep.objc.objc : id;
+
+import bindings = dstep.foundation.NSOperation_bindings;
+
+alias NSInteger NSOperationQueuePriority;
+
+const NSString NSInvocationOperationVoidResultException;
+const NSString NSInvocationOperationCancelledException;
+
+enum
+{
+	NSOperationQueuePriorityVeryLow = -8,
+	NSOperationQueuePriorityLow = -4,
+	NSOperationQueuePriorityNormal = 0,
+	NSOperationQueuePriorityHigh = 4,
+	NSOperationQueuePriorityVeryHigh = 8
+}
+
+enum
+{
+	NSOperationQueueDefaultMaxConcurrentOperationCount = -1
+}
+
+static this ()
+{
+	NSInvocationOperationVoidResultException = new NSString(bindings.NSInvocationOperationVoidResultException);
+	NSInvocationOperationCancelledException = new NSString(bindings.NSInvocationOperationCancelledException);
+}
+
+class NSOperation : NSObject
+{
+	mixin ObjcWrap;
+
+	Object init ()
+	{
+		return invokeObjcSelf!(Object, "init");
+	}
+
+	this ()
+	{
+		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
+		id result = Bridge.invokeObjcMethod!(id, "init")(objcObject);
+
+		if (result)
+			objcObject = ret;
+
+		dObject = this;
+	}
+
+	void start ()
+	{
+		return invokeObjcSelf!(void, "start");
+	}
+
+	void main ()
+	{
+		return invokeObjcSelf!(void, "main");
+	}
+
+	bool isCancelled ()
+	{
+		return invokeObjcSelf!(bool, "isCancelled");
+	}
+
+	void cancel ()
+	{
+		return invokeObjcSelf!(void, "cancel");
+	}
+
+	bool isExecuting ()
+	{
+		return invokeObjcSelf!(bool, "isExecuting");
+	}
+
+	bool isFinished ()
+	{
+		return invokeObjcSelf!(bool, "isFinished");
+	}
+
+	bool isConcurrent ()
+	{
+		return invokeObjcSelf!(bool, "isConcurrent");
+	}
+
+	bool isReady ()
+	{
+		return invokeObjcSelf!(bool, "isReady");
+	}
+
+	void addDependency (NSOperation op)
+	{
+		return invokeObjcSelf!(void, "addDependency:", NSOperation)(op);
+	}
+
+	void removeDependency (NSOperation op)
+	{
+		return invokeObjcSelf!(void, "removeDependency:", NSOperation)(op);
+	}
+
+	NSArray dependencies ()
+	{
+		return invokeObjcSelf!(NSArray, "dependencies");
+	}
+
+	int queuePriority ()
+	{
+		return invokeObjcSelf!(int, "queuePriority");
+	}
+
+	void setQueuePriority (int p)
+	{
+		return invokeObjcSelf!(void, "setQueuePriority:", int)(p);
+	}
+}
+
+class NSOperationQueue : NSObject
+{
+	mixin ObjcWrap;
+
+	void addOperation (NSOperation op)
+	{
+		return invokeObjcSelf!(void, "addOperation:", NSOperation)(op);
+	}
+
+	NSArray operations ()
+	{
+		return invokeObjcSelf!(NSArray, "operations");
+	}
+
+	NSInteger maxConcurrentOperationCount ()
+	{
+		return invokeObjcSelf!(NSInteger, "maxConcurrentOperationCount");
+	}
+
+	void setMaxConcurrentOperationCount (NSInteger cnt)
+	{
+		return invokeObjcSelf!(void, "setMaxConcurrentOperationCount:", NSInteger)(cnt);
+	}
+
+	void setSuspended (bool b)
+	{
+		return invokeObjcSelf!(void, "setSuspended:", bool)(b);
+	}
+
+	bool isSuspended ()
+	{
+		return invokeObjcSelf!(bool, "isSuspended");
+	}
+
+	void cancelAllOperations ()
+	{
+		return invokeObjcSelf!(void, "cancelAllOperations");
+	}
+
+	void waitUntilAllOperationsAreFinished ()
+	{
+		return invokeObjcSelf!(void, "waitUntilAllOperationsAreFinished");
+	}
+}
+
+class NSInvocationOperation : NSOperation
+{
+	mixin ObjcWrap;
+
+	Object initWithTarget (Object target, SEL sel, Object arg)
+	{
+		return invokeObjcSelf!(Object, "initWithTarget:selector:object:", Object, SEL, Object)(target, sel, arg);
+	}
+
+	this (Object target, SEL sel, Object arg)
+	{
+		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
+		id result = Bridge.invokeObjcMethod!(id, "initWithTarget:selector:object:", Object, SEL, Object)(objcObject, target, sel, arg);
+
+		if (result)
+			objcObject = ret;
+
+		dObject = this;
+	}
+
+	Object initWithInvocation (NSInvocation inv)
+	{
+		return invokeObjcSelf!(Object, "initWithInvocation:", NSInvocation)(inv);
+	}
+
+	this (NSInvocation inv)
+	{
+		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
+		id result = Bridge.invokeObjcMethod!(id, "initWithInvocation:", NSInvocation)(objcObject, inv);
+
+		if (result)
+			objcObject = ret;
+
+		dObject = this;
+	}
+
+	NSInvocation invocation ()
+	{
+		return invokeObjcSelf!(NSInvocation, "invocation");
+	}
+
+	Object result ()
+	{
+		return invokeObjcSelf!(Object, "result");
+	}
+}
+