home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 (1993) / nebula.bin / SourceCode / Broadcast / BroadcastDaemon / BroadcastDaemon.m < prev    next >
Encoding:
Text File  |  1993-01-14  |  2.5 KB  |  94 lines

  1. /* Copyright (c) 1992 by NightShade Software.  All rights reserved.
  2.  *    You may modify and (hopefully) improve this code if you keep the
  3.  *    original copyright messages, don't sell it, and share your improvements
  4.  *    with with the World.
  5.  *
  6.  * NAME
  7.  *     main() -- Broadcast.daemon
  8.  *
  9.  * DESCRIPTION
  10.  *     A Workspace daemon used to broadcast a message to the user logged
  11.  *     in to the console from a user logged in remotely.
  12.  *
  13.  * COMMENTS/PROBLEMS
  14.  *     You get what you pay for...
  15.  *
  16.  * AUTHOR/DATE CREATED
  17.  *     Gary Ritchie/December 22, 1992
  18.  *
  19.  * REVISIONS
  20.  *
  21.  */
  22.  
  23. #import <appkit/Application.h>
  24. #import <ListenerAdditions.h>
  25. #import <BroadcastListener.h>
  26. #import <shared.h>
  27. #import "Controller.h"
  28.  
  29. int main(int argc, char *argv[])
  30. {
  31.     id theController;
  32.     id theListener;
  33.     NXDefaultsVector workspaceDefs = {{"LaunchPaths", ""}};
  34.     char *orig;
  35.     char *new;
  36.     const char *p;
  37.     char *str, *anotherstr;
  38.     port_t thePort;
  39.    
  40.     /* See if we are already running */
  41.     if (thePort = NXPortNameLookup(BROADCASTPORT, NULL)) {
  42.         port_deallocate(task_self(), thePort);
  43.     NXLogError("Broadcast.daemon already running\n");
  44.     exit(1);
  45.     }
  46.     
  47.     /* The Controller handles the Broadcast messages */
  48.     theController = [[Controller alloc] init];
  49.     
  50.     /* We need an Application object for operation of Alert Panels */
  51.     [Application new];
  52.     [NXApp setDelegate:theController]; 
  53.     
  54.     /* Install ourself in the Workspace's defaults so that we are
  55.      * launched every time the user logs in.
  56.      */
  57.     NXRegisterDefaults("Workspace", workspaceDefs);
  58.     p = NXGetDefaultValue("Workspace", "LaunchPaths");
  59.     if (!p) p = "";
  60.     orig = NXCopyStringBuffer(p);
  61.     new = malloc(strlen(orig) + MAXPATHLEN + 1);
  62.     new[0] = '\0';
  63.     str = strtok(orig, ";");
  64.     while (str) {
  65.         anotherstr = strstr(str, "Broadcast.daemon");
  66.     if (!anotherstr) {
  67.         if (strlen(new)) strcat(new, ";");
  68.             strcat(new, str);
  69.     }
  70.     str = strtok(NULL, ";");
  71.     }
  72.     if (strlen(new)) strcat(new, ";");
  73.     strcat(new, argv[0]);
  74.     NXWriteDefault("Workspace", "LaunchPaths", new);
  75.     free(orig);
  76.     free(new);
  77.     
  78.     /* Allocate a listener and publicly advertise it */
  79.     theListener = [[BroadcastListener alloc] init];
  80.     [theListener setDelegate:theController];
  81.     if ([theListener publicCheckInAs:BROADCASTPORT]) {
  82.         [theListener free];
  83.     [theController free];
  84.     NXLogError("Broadcast.daemon failed to register public port.\n");
  85.         exit(1);
  86.     }
  87.     [theListener addPort];
  88.     
  89.     [NXApp run];
  90.     [NXApp free];
  91.     
  92.     return(0);
  93. }
  94.