bug-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ 100069 ] NSTask or NSNotification problem


From: nobody
Subject: [ 100069 ] NSTask or NSNotification problem
Date: Wed, 20 Jun 2001 09:26:18 -0700

Support Request #100069, was updated on 2001-Jun-20 09:26
You can respond by visiting: 
http://savannah.gnu.org/support/?func=detailsupport&support_id=100069&group_id=99

Category: None
Status: Open
Priority: 5
Summary: NSTask or NSNotification problem

By: mjgundry
Date: 2001-Jun-20 09:26

Message:
Logged In: NO 
Browser: Mozilla/4.75 [en] (WinNT; U)

I am having a problem with recieving notifications from tasks. I'm not 
sure if this is an NSTask issue, a 
problem with NSNotification or just confusion on my part.

I need to do a number of tasks in order, so I've created a task list and 
launch the first task. I then listen 
for NSTaskDidTerminateNotification. When that notification arrives, I remove 
the completed task from the 
task list and launch the next one. The problem is that I am not receiving the 
notifications unless my 
runloop does some busy work (eg. NSLog).

I am currently using GNUStep Base 1.0.2 on Redhat 7.0 with the newer Gcc 
2.96-81.

I have created a small test program that demonstrates the problem. Remove the 
comment in front of 
NSLog and the program will operate the way I expect.

#import <Foundation/Foundation.h>

@interface TaskMan : NSObject
{
        NSMutableArray *taskList;
}

-nextTask:(NSNotification *) aNotification;
@end

@implementation TaskMan
-init
{
        NSTask *aTask;

        self = [super init];

        [[NSNotificationCenter defaultCenter] addObserver:self
                selector:@selector(nextTask:)
                name:NSTaskDidTerminateNotification
                object:nil];

        taskList = [[NSMutableArray alloc] init];

        aTask = [[NSTask alloc] init];
        [aTask setLaunchPath:@"/bin/ls"];
        [aTask setArguments:nil];
        [taskList addObject:aTask];

        aTask = [[NSTask alloc] init];
        [aTask setLaunchPath:@"/bin/ps"];
        [aTask setArguments:nil];
        [taskList addObject:aTask];

        aTask = [[NSTask alloc] init];
        [aTask setLaunchPath:@"/bin/pwd"];
        [aTask setArguments:nil];
        [taskList addObject:aTask];

        aTask = [[NSTask alloc] init];
        [aTask setLaunchPath:@"/bin/date"];
        [aTask setArguments:nil];
        [taskList addObject:aTask];

        [[taskList objectAtIndex:0] launch];

        return self;
}

-nextTask:(NSNotification *) aNotification
{
        if ([[aNotification object] terminationStatus] == 0) {
                [NSNotification 
notificationWithName:@"CommandCompletedSuccessfully"
                        object:self];
        } else {
                [NSNotification notificationWithName:@"CommandFailed"
                        object:self];
        }
        [taskList removeObjectAtIndex:0];

        if ([taskList count] > 0)
                [[taskList objectAtIndex:0] launch];
        else
                exit(0);

        return self;
}
@end

int main(int argc, char **argv, char** env)
{
        NSAutoreleasePool *pool;
        TaskMan *aTaskMan;

        pool = [NSAutoreleasePool new];
        aTaskMan = [[TaskMan alloc] init];

        while(1) {
                [[NSRunLoop currentRunLoop] runOnceBeforeDate:
                        [NSDate dateWithTimeIntervalSinceNow: 1]];

/* Uncomment the following line, and the app will complete all tasks */
/* otherwise it will hang */
//      NSLog(@"");
        }

        exit(0);        
}

----------------------------------------------------------------------
You can respond by visiting: 
http://savannah.gnu.org/support/?func=detailsupport&support_id=100069&group_id=99



reply via email to

[Prev in Thread] Current Thread [Next in Thread]