 |
 |
Problem with a Foundation Tool
|
 |
|
 |
|
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status:
Offline
|
|
I'm trying to write a background daemon that just sits there and reads in a file every five minutes and waits for a rendezvous connection to come along and read the data.
All of the action takes place in controller. It creates a timer upon its initialization that reads in the file every five minutes. My problem is that I can't get the Main program to work write. How do I make Main just sit there and let controller do all the work?
Code:
#import <Foundation/Foundation.h>
#import <Machine.h>
#import <FHMclientcontroller.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
FHMclientcontroller *controller=[[FHMclientcontroller alloc] init];
while (1) {
}
[pool release];
return 0;
}
If I build and run this, it creates the controller and initializes the timer and all of the contoller routines, but then it just sits there. I just sort of assumed that the while loop would keep the app going and conroller would be sent the appropriate method from the timer, but the timer never seems to fire.I realize this is probably a pretty basic question, but I've never written a command-line tool before. I'm trying to make a thin cli client from a graphical cocoa app that is already running fine.
thanks,
kman
|
|
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
You need to create an NSRunLoop. It will keep your program going, and timers depend on the presence of a run loop anyway. The only trick is that, in order to keep the run loop from exiting, you need to give it some input source--a dummy port works fine.
|
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
Originally posted by Chuckit:
You need to create an NSRunLoop. It will keep your program going, and timers depend on the presence of a run loop anyway. The only trick is that, in order to keep the run loop from exiting, you need to give it some input source--a dummy port works fine.
He already said he had a timer... [[NSRunLoop currentRunLoop] run] is all you need, IIRC.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |