Add auto-stop option

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@24789 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2007-03-06 21:44:40 +00:00
parent f11c2117f3
commit a069984c71
5 changed files with 5094 additions and 4449 deletions

View file

@ -25,6 +25,7 @@
#include <Foundation/Foundation.h>
#include <AppKit/NSPasteboard.h>
#include <GNUstepGUI/GSPasteboardServer.h>
#include "config.h"
#include <fcntl.h>
#ifdef HAVE_SYSLOG_H
@ -44,11 +45,14 @@
#endif
static BOOL is_daemon = NO; /* Currently running as daemon. */
static BOOL auto_stop = NO; /* Stop when all connections closed. */
static char ebuf[2048];
static NSMutableArray *connections = nil;
#ifdef HAVE_SYSLOG
static int log_priority;
static int log_priority = LOG_DEBUG;
static void
gpbs_log (int prio)
@ -779,9 +783,19 @@ NSMutableDictionary *pasteboards = nil;
if ([owner isProxy] == YES)
{
Protocol *p = @protocol(GSPasteboardCallback);
Protocol *p = @protocol(GSPasteboardCallback);
NSConnection *c = [owner connectionForProxy];
[owner setProtocolForProxy: p];
/* If this is on a connection we don't know about, add it to our
* list of pasteboard connections so that we can track its removal
* in order to auto_stop if necessary.
*/
if ([connections indexOfObjectIdenticalTo: c] == NSNotFound)
{
[connections addObject: c];
}
}
/*
* If neither the new nor the old owner of the pasteboard is the X
@ -1002,14 +1016,19 @@ NSMutableDictionary *pasteboards = nil;
}
if ([connection isKindOfClass: [NSConnection class]])
{
NSEnumerator *e = [pasteboards objectEnumerator];
PasteboardObject *o;
NSEnumerator *e = [pasteboards objectEnumerator];
PasteboardObject *o;
while ((o = [e nextObject]) != nil)
{
[o checkConnection: connection];
}
}
[connections removeObjectIdenticalTo: connection];
if (auto_stop == YES && [connections count] == 0)
{
exit(EXIT_SUCCESS);
}
return self;
}
@ -1079,11 +1098,11 @@ ihandler(int sig)
const char *e;
/*
* Prevent recursion.
*/
if (beenHere == YES)
{
abort();
* Prevent recursion.
*/
if (beenHere == YES)
{
abort();
}
beenHere = YES;
@ -1148,6 +1167,10 @@ init(int argc, char** argv, char **env)
printf("--verbose\tMore verbose debug output\n");
exit(EXIT_SUCCESS);
}
else if ([a isEqualToString: @"--auto"] == YES)
{
auto_stop = YES;
}
else if ([a isEqualToString: @"--daemon"] == YES)
{
is_daemon = YES;
@ -1265,6 +1288,8 @@ main(int argc, char** argv, char **env)
name: NSConnectionDidDieNotification
object: (id)conn];
connections = [NSMutableArray new];
hostname = [[NSUserDefaults standardUserDefaults] stringForKey: @"NSHost"];
if ([hostname length] == 0
|| [[NSHost hostWithName: hostname] isEqual: [NSHost currentHost]] == YES)