Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Problem with a Foundation Tool

Problem with a Foundation Tool
Thread Tools
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
May 31, 2003, 05:14 PM
 
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
Reply With Quote
May 31, 2003, 05:54 PM
 
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
Reply With Quote
Jun 1, 2003, 04:47 PM
 
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.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 03:37 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2