view dwt/internal/cocoa/NSThread.d @ 13:f565d3a95c0a

Ported dwt.internal
author Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
date Fri, 22 Aug 2008 16:46:34 +0200
parents 8b48be5454ce
children d8635bb48c7c
line wrap: on
line source

/*******************************************************************************
 * Copyright (c) 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     
 * Port to the D programming language:
 *     Jacob Carlborg <jacob.carlborg@gmail.com>
 *******************************************************************************/
module dwt.internal.cocoa.NSThread;

import dwt.internal.cocoa.id;
import dwt.internal.cocoa.NSArray;
import dwt.internal.cocoa.NSDate;
import dwt.internal.cocoa.NSInteger;
import dwt.internal.cocoa.NSMutableDictionary;
import dwt.internal.cocoa.NSObject;
import dwt.internal.cocoa.NSString;
import dwt.internal.cocoa.OS;
import objc = dwt.internal.objc.runtime;

public class NSThread : NSObject
{

    public this ()
    {
        super();
    }

    public this (objc.id id)
    {
        super(id);
    }

    public static NSArray callStackReturnAddresses ()
    {
        objc.id result = OS.objc_msgSend(OS.class_NSThread, OS.sel_callStackReturnAddresses);
        return result !is null ? new NSArray(result) : null;
    }

    public void cancel ()
    {
        OS.objc_msgSend(this.id_, OS.sel_cancel);
    }

    public static NSThread currentThread ()
    {
        objc.id result = OS.objc_msgSend(OS.class_NSThread, OS.sel_currentThread);
        return result !is null ? new NSThread(result) : null;
    }

    public static void detachNewThreadSelector (objc.SEL selector, id target, id argument)
    {
        OS.objc_msgSend(OS.class_NSThread, OS.sel_detachNewThreadSelector_1toTarget_1withObject_1, selector, target !is null ? target.id_ : null,
                argument !is null ? argument.id_ : null);
    }

    public static void exit ()
    {
        OS.objc_msgSend(OS.class_NSThread, OS.sel_exit);
    }

    public id initWithTarget (id target, objc.SEL selector, id argument)
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_initWithTarget_1selector_1object_1, target !is null ? target.id_ : null, selector,
                argument !is null ? argument.id_ : null);
        return result !is null ? new id(result) : null;
    }

    public bool isCancelled ()
    {
        return OS.objc_msgSend(this.id_, OS.sel_isCancelled) !is null;
    }

    public bool isExecuting ()
    {
        return OS.objc_msgSend(this.id_, OS.sel_isExecuting) !is null;
    }

    public bool isFinished ()
    {
        return OS.objc_msgSend(this.id_, OS.sel_isFinished) !is null;
    }

    public static bool static_isMainThread ()
    {
        return OS.objc_msgSend(OS.class_NSThread, OS.sel_isMainThread) !is null;
    }

    public bool isMainThread ()
    {
        return OS.objc_msgSend(this.id_, OS.sel_isMainThread) !is null;
    }

    public static bool isMultiThreaded ()
    {
        return OS.objc_msgSend(OS.class_NSThread, OS.sel_isMultiThreaded) !is null;
    }

    public void main ()
    {
        OS.objc_msgSend(this.id_, OS.sel_main);
    }

    public static NSThread mainThread ()
    {
        objc.id result = OS.objc_msgSend(OS.class_NSThread, OS.sel_mainThread);
        return result !is null ? new NSThread(result) : null;
    }

    public NSString name ()
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_name);
        return result !is null ? new NSString(result) : null;
    }

    public void setName (NSString n)
    {
        OS.objc_msgSend(this.id_, OS.sel_setName_1, n !is null ? n.id_ : null);
    }

    public void setStackSize (NSUInteger s)
    {
        OS.objc_msgSend(this.id_, OS.sel_setStackSize_1, s);
    }

    public static bool setThreadPriority (double p)
    {
        return OS.objc_msgSend(OS.class_NSThread, OS.sel_setThreadPriority_1, p) !is null;
    }

    public static void sleepForTimeInterval (NSTimeInterval ti)
    {
        OS.objc_msgSend(OS.class_NSThread, OS.sel_sleepForTimeInterval_1, ti);
    }

    public static void sleepUntilDate (NSDate date)
    {
        OS.objc_msgSend(OS.class_NSThread, OS.sel_sleepUntilDate_1, date !is null ? date.id_ : null);
    }

    public NSUInteger stackSize ()
    {
        return cast(NSUInteger) OS.objc_msgSend(this.id_, OS.sel_stackSize);
    }

    public void start ()
    {
        OS.objc_msgSend(this.id_, OS.sel_start);
    }

    public NSMutableDictionary threadDictionary ()
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_threadDictionary);
        return result !is null ? new NSMutableDictionary(result) : null;
    }

    public static double threadPriority ()
    {
        return OS.objc_msgSend_fpret(OS.class_NSThread, OS.sel_threadPriority);
    }

}