示例#1
0
/*---------------------------------------------------------------------------
**  MBECONNECTTOSUPER --  Establish a connection between the application
**  running on 'mytid' with the Supervisor running at pid@host with
**  'supertid'.
*/
int
mbConnectToSuper (int mytid, int supertid, char *host, int pid)
{
    char   msg[SZ_LINE];
    char   *whoAmI = mbAppGetName ();		/* app name		*/
    int    mysuper = mbAppGet (APP_STID);	/* current app's super  */
    int    mypid   = getpid();
    int	   i, info, super = -1;


    if (mbAppGet(APP_STID) == mytid) {
	fprintf (stderr, "ERROR: Supervisor connecting to itelf.\n");
	return (ERR);
    }


    /*  Look for a Supervisor and send a connect message.
     */
    for (i=MB_CONNECT_RETRYS; i; i--) {
        info = pvm_lookup (SUPERVISOR, -1, &super);
        if (info == PvmNoEntry || (mysuper != supertid)) {
            /* Supervisor not found, so connect to specified supertid.
	     */
            memset (msg, 0, SZ_LINE);
            sprintf (msg, "{ tid=%d who=%s host=%s pid=%d }",
                abs(mytid), whoAmI, host, mypid);
            if (MB_DEBUG) printf ("Supervisor msg '%s'\n", msg);
            if (mbusSend (SUPERVISOR, ANY, MB_CONNECT, msg) != ERR)
		break;
            sleep (1);

        } else {
            if (MB_DEBUG)
                printf ("Supervisor already on msgbus at tid=%d\n", super);

	    /* FIXME -- Need to disconnect from old Supervisor.
            memset (msg, 0, SZ_LINE);
            sprintf (msg, "{ tid=%d who=%s host=%s pid=%d }",
                abs(mytid), whoAmI, host, mypid);
            if (mbusSend (SUPERVISOR, ANY, MB_DISCONNECT, msg) != ERR)
		break;
	     */
            break;
        }
    }

    if (super < 0) {
        if (MB_VERBOSE) fprintf(stderr,"Supervisor not on msgbus, returning\n");
        super = ERR;
    } else {
	mbAppSet (APP_TID, abs (mytid));
	mbAppSet (APP_STID, super);
    }

    return (super);
}
示例#2
0
/*  Local Message Handler
 */
void
myHandler (int from, int subject, char *msg)
{
    int   tid = 0, pid = 0, mytid = mbAppGet (APP_TID);
    char  *me, who[128], host[128];
    char  *w = who, *h = host;
    double expID;

    extern smCache_t *smc;


    me = (char *)mbAppGetName();

    switch (subject) {
    case MB_CONNECT:
	if (console)
	    fprintf (stderr, "CONNECT on %s: %s\n", me, msg);

	mbParseConnectMsg (msg, &tid, &w, &h, &pid);

	/*  If it's the supervisor connecting, and we don't already have an
	 *  established connection to the Super, set it up now.
	 */
	if (isSupervisor (who) && mbAppGet (APP_STID) < 0) {
	    mytid = mbAppGet(APP_TID);
	    if (mbConnectToSuper (mytid, tid, host, pid) == OK)
		mbAppSet (APP_TID, abs(mytid));
	}

	/*  When we get a CONNECT message, post a notifier so we're
	 *  alerted whent the task exits.
	mbAddTaskExitHandler (tid, myTaskExited);
	 */

	break;

    case MB_START:
	if (console) 
	    fprintf (stderr, "START on %s: %s\n", me, msg);

	if (strncmp (msg, "process", 7) == 0) {
	    /*  Begin processing an image given the ExpID.
	    */
	    expID = (double) atof (&msg[8]);
	    if (console)
	    	fprintf (stderr, "PXF processing ExpID %.6lf\n", expID);

	    /* Process the pages.
	    */
	    if (!noop)
	        pxfProcess (smc, expID);

	    dhsTransferComplete (dca_tid, seqno);

	    memset (buf, 0, SZ_BUF);
            sprintf (buf, "process pxf done %.6lf", expID);
            mbusSend (SUPERVISOR, ANY, MB_SET, buf);
            mbusSend (SUPERVISOR, ANY, MB_STATUS, "inactive");
            mbusSend (SUPERVISOR, ANY, MB_STATUS, "Ready...");

            mbusSend (SUPERVISOR, ANY, MB_ACK, "");
            mbusSend (SUPERVISOR, ANY, MB_ACK, "");
            mbusSend (SUPERVISOR, ANY, MB_ACK, "");

	    if (console) {
		fprintf (stderr, "\n");
		fprintf (stderr, "**************************************\n");
		fprintf (stderr, "PXF processing Done: ExpID %.6lf\n", expID);
		fprintf (stderr, "**************************************\n\n");
	    }
	}
	break;

    case MB_SET:
	if (console && strncmp (msg, "no-op", 5) != 0)
	    fprintf (stderr, "SET on %s: %s\n", me, msg);

	if (strncmp (msg, "dca_tid", 7) == 0) {
	    dca_tid = atoi (&msg[8]);

	} else if (strncmp (msg, "nbin", 4) == 0) {
	    /*
	    nbin = atoi (&msg[5]);
	    */

	} else if (strncmp (msg, "seqno", 5) == 0) {
	    seqno = atoi (&msg[6]);

	} else if (strncmp (msg, "no-op", 5) == 0) {
	    /*
	    mbusSend (SUPERVISOR, ANY, MB_ACK, "");
	    */
		;

        } else if (strncmp (msg, "keyword add", 11) == 0) {
            char *sp, *op, *ip = &msg[12];
	    char buf[SZ_LINE];

	    /* printf ("Adding keyword monitor: '%s'\n", ip); */
	    while (*ip) {
		/* skip leading whitespace */
		for (sp=ip; *ip && isspace(*sp); sp++) ip++;

		/* Copy the keyword to the list.
		*/
		bzero (buf, SZ_LINE);
		for (op=&buf[0]; *ip && !isspace (*ip); ) *op++ = *ip++;
		if (! keywList[NKeywords])
		    keywList[NKeywords] = malloc (SZ_LINE);
		strcpy (keywList[NKeywords++], buf);
	    }

        } else if (strncmp (msg, "keyword del", 11) == 0) {
            char *key = &msg[12];
            int  i, j;

            for (i=0; i < NKeywords; i++) {
                if (strcmp (keywList[i], key) == 0) {
                    for (j=i+1; j < NKeywords; )
                        strcpy (keywList[i++], keywList[j++]);
                    NKeywords--;
                    break;
                }
            }
        }
	break;

    case MB_EXITING:
	/*  If it's the supervisor disconnecting, .....
	 */
	if (console) 
	    fprintf (stderr, "DISCONNECT on %s: %s\n", me, msg);
	break;

    case MB_STATUS:
	/* Send a Status response.... */
        mbusSend (SUPERVISOR, ANY, MB_STATUS, "Ready...");
	break;

    case MB_PING:
	/* Return an ACK/STATUS to sender .... */
        mbusSend (SUPERVISOR, ANY, MB_ACK, "");
	break;

    case MB_DONE: 				/* Exit for now... */
	exit (0);
	break;

    case MB_ERR: 				/* No-op */
	break;

    default:
	if (console) {
	    fprintf (stderr, "DEFAULT recv:%d:  ", subject);
	    fprintf (stderr, "   from:%d  subj:%d\n   msg='%s'\n",
		from, subject, msg);
	}
	if (strncmp (msg, "quit", 4) == 0)
	    exit (0);
    }

    return;
}
示例#3
0
/* Handle a command given to us from the commandline.
 */
void
inputEventHandler (char *cmd)
{
    char   cmdin[128], *tok = NULL, *group = NULL;
    char  *arg1=NULL, *arg2=NULL, *arg3=NULL;
    static int init = 0;


    /* Command loop */
    if (init++ == 0)  printf("command (%d)>  ", getpid());


    bzero (cmdin, 128);				/* Save input command 	*/
    strcpy(cmdin, cmd);

    if (cmd[0] == '?') {				/* HELP    	*/
        consHelp ();

    } else if (strncmp(cmd, "init", 3) == 0) {		/* INIT    	*/
        printf("Initializing...");
        mbusInitialize(SUPERVISOR, NULL);
        printf("done.");

    } else if (strncmp(cmd, "ping", 3) == 0) {		/* PING   */
        if ((tok = consTok(cmd, 2))) {
            if (tok[0] == 's') {
                printf ("Supervisor Ping = %d\n",
                        mbusSend (SUPERVISOR, ANY, MB_PING, NULL) );
            } else if (tok[0] == 'c') {
                printf ("Client Ping = %d\n",
                        mbusSend (CLIENT, ANY, MB_PING, NULL) );
            }
        }

    } else if (strncmp(cmd, "stop", 3) == 0) {		/* STOP   */
        if ((tok = consTok(cmd, 2))) {
            if (tok[0] == 's') {
                printf("Stopping Supervisor...NYI\n");
            } else if (tok[0] == 'c') {
                printf("Stopping Client...NYI\n");
            }
        }

    } else if (strncmp(cmd, "bcast", 3) == 0) {		/* BCAST  */
        if ((group = consTok(cmd, 2)))
            mbusBcast (group, (arg1=consTok(cmdin,3)), MB_STATUS);

    } else if (strncmp(cmd, "send", 3) == 0) {		/* SEND   */
        if ((tok = consTok(cmd, 2))) {
            if (tok[0] == 's') {
                mbusSend(SUPERVISOR, ANY, MB_STATUS, (arg1=consTok(cmdin,3)));
            } else if (tok[0] == 'c') {
                mbusSend(CLIENT, ANY, MB_STATUS, (arg1=consTok(cmdin,3)));
            } else {
                printf ("Usage: send [s|c] <msg>\n");
            }
        }


    } else if (strncmp(cmd, "whoami", 3) == 0) {	/* WHOAMI   */
        printf ("%s\n",  mbAppGetName());

    } else if (strncmp(cmd, "halt", 3) == 0) {		/* HALT    */
        printf("Halting message bus....\n");
        if (mbusHalt() < 0)
            fprintf(stderr, "Error halting message bus....\n");

    } else if (strncmp(cmd, "getfds", 3) == 0) {	/* GETFDS  */
        int i, nfds, *fds;
        extern int pvm_getfds ();

        nfds = pvm_getfds (&fds);
        printf("nfds = %d\t", nfds);
        for (i = 0; i < nfds; i++)
            printf("fd[%d]=%d  ", i, fds[i]);
        printf("\n");

    } else
        printf ("unrecognized command: '%s'\n", cmd);


    if (tok)   free (tok); 			/* Clean up		*/
    if (group) free (group);
    if (arg1)  free (arg1);
    if (arg2)  free (arg2);
    if (arg3)  free (arg3);

    printf("\ncommand (%d)>  ", getpid());
}