home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / tests / gtprtfrm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-15  |  2.5 KB  |  69 lines

  1. #include <stdio.h>
  2. #include <Sender.h>
  3. #include <Receiver.h>
  4.  
  5. /*
  6.  *    This program takes two arguments: the name of the application
  7.  *    to be found, and a flag specifying whether a new copy of the
  8.  *    application is to be launched, whether it is open or not.
  9.  *    To set the flag to force a new copy of the app to be launched,
  10.  *    type anything for the second argument; the existence of
  11.  *    argv[2] is enough to set the flag.
  12.  *
  13.  *    This program will send the GetPortFromName
  14.  *    message to the local Port Manager, asking for the port
  15.  *    number of the application passed in as argument.  If the
  16.  *    application is currently registered, the Port Manager will
  17.  *    reply with the Port information for that application.  If the
  18.  *    application is not currently running, the SenderGetPortFromName()
  19.  *    method will attempt to launch the application, wait a few seconds,
  20.  *    then ask the Port Manager again if the application is running.
  21.  *
  22.  *    Usage:
  23.  *        getPortFromName <applicationName> [new]
  24.  */
  25.  
  26. main(int argc, char** argv)
  27. {
  28.   Sender*    sender;
  29.   Receiver*    receiver;
  30.   Port        senderPort;
  31.   Port        appPort;
  32.   PortArray*    appList = (PortArray*)NULL;
  33.   int        counter;
  34.   int        result = 0;
  35.   char*        strdup(char*);
  36.  
  37.   printf("Starting the test.\n");
  38.   senderPort.hostName = strdup("localhost");
  39.   senderPort.portNumber = PortMgrPortNumber;
  40.   sender = NewSender(&senderPort);                    /* Make a connection with the Port Manager */
  41.   appPort.appName = argv[1];                        /* Fill in Port information for the app being requested */
  42.   if (argc > 2)                                /* Check if this application should launch a new copy... */
  43.     appPort.hostName = LaunchNewApp;                    /* ...of the app specified in argv[1] */
  44.   else
  45.     appPort.hostName = "localhost";
  46.   result = SenderGetPortFromName(sender, &appPort, &appList);        /* Try to get the requested application's Port information */
  47.   if (result !=0)
  48.   {
  49.     printf("The GetPortFromName message failed for some reason.\n");
  50.     printf("Either the application was not open, or it could not\n");
  51.     printf("be launched, or the Port Manager did not respond.\n");
  52.     exit(result);
  53.   }
  54.   if (appList)                                /* GetPortFromName message was successful */
  55.     {
  56.       printf("Information about apps named %s that are currently registered\n");
  57.       printf("with the Port Manager:\n\n");
  58.       for (counter = 0; counter < appList->numberOfPorts; counter++)
  59.     {
  60.       printf("%d. Name: %s \t Host: %s \t Port: %d\n",
  61.          counter+1,
  62.          appList->portArray[counter].appName,
  63.          appList->portArray[counter].hostName,
  64.          appList->portArray[counter].portNumber);
  65.     }
  66.       exit(0);
  67.     }
  68. }
  69.