Exemple #1
0
static void adv_help (void)
{
  help_summary (cmds_advanced, sizeof(cmds_advanced)/sizeof(CMD),
                "Advanced commands available at current access level:\n");
}
/* PROC_CMD -- Process a single command.
 */
static int
proc_cmd (int samp, char *method, 
	char *arg1, char *arg2, char *arg3, char *arg4)
{
    register int   i = 0, stat = 0;
    char  *appName = NULL;
    char   rstr[SZ_RESSTR], *sres = rstr;
    Map    resp;


    if (debug)
	fprintf (stderr, "Proc_Cmd Method '%s'  Args: '%s' '%s' '%s'\n", 
				method,arg1,arg2,arg3);

    if (strcasecmp (method, "quit") == 0) {			/* QUIT */
	printf ("Quitting....\n\n");
        if (sampShutdown (samp) != 0)
            fprintf (stderr, "Shutdown fails\n");
        sampClose (samp);

	return (0);

    } else if (strcasecmp (method, "start") == 0) {		/* START */
	printf ("Starting SAMP interface .....\n");
        sampStartup (samp);

    } else if (strcasecmp (method, "stop") == 0) {		/* STOP */
	printf ("Stopping SAMP interface .....\n");
        sampShutdown (samp);

    } else if (strcasecmp (method, "help") == 0) {		/* HELP */
	help_summary ();

    } else if (strcasecmp (method, "listClient") == 0) {	/* LISTCLIENT */
	samp_listClients (samp);

    } else if (strcasecmp (method, "trace") == 0) {		/* TRACE */
	trace++;
	if (trace % 2)
            setenv ("XMLRPC_TRACE_XML", "1", 1);
	else
	    unsetenv ("XMLRPC_TRACE_XML");

    } else if (strcasecmp (method, "target") == 0) {		/* TARGET */
	appName = arg1;



    } else if (strcasecmp (method, "envSet") == 0) {		/* ENVSET */
	if (nscan < 4) {
	    cmdUsage ("envSet appName keyw value");
	} else {
	    stat = samp_envSet (samp, arg1, arg2, arg3);
	    print_result (samp, stat);
	}

    } else if (strcasecmp (method, "envGet") == 0) {		/* ENVGET */
	if (nscan < 3) {
	    cmdUsage ("envGet appName keyw");
	} else {
	    char *v = samp_envGet (samp, arg1, arg2);
	    if (v) 
	 	printf ("OK  '%s' = '%s'\n", arg2, v);
	    else
	 	printf ("ERR  '%s' not found\n", arg2);
	}
        ;

    } else if (strcasecmp (method, "paramSet") == 0) {		/* PARAMSET */
	if (nscan < 4) {
	    cmdUsage ("envSet appName keyw value");
	} else {
	    stat = samp_paramSet (samp, arg1, arg2, arg3);
	    print_result (samp, stat);
	}

    } else if (strcasecmp (method, "paramGet") == 0) {		/* PARAMGET */
        ;



    } else if (strcasecmp (method, "notify") == 0) {		/* NOTIFY */
	if (nscan < 3) {
	    cmdUsage ("notify appName mtype");
	} else {
	    int msg = make_msg (arg2);
	    samp_notify (samp, arg1, msg);
	    print_result (samp, SAMP_OK);
	}

    } else if (strcasecmp (method, "notifyAll") == 0) {		/* NOTIFYALL */
	if (nscan < 2) {
	    cmdUsage ("notifyAll mtype");
	} else {
	    int msg = make_msg (arg1);
	    stat = samp_notifyAll (samp, msg);
	    print_result (samp, stat);
	}

    } else if (strcasecmp (method, "call") == 0) {		/* CALL */
	if (nscan < 3) {
	    cmdUsage ("call appName mtype");
	} else {
	    int msg = make_msg (arg2);
	    char *id = samp_call (samp, arg1, "testTag", msg);
	    fprintf (stderr, "msgId = '%s'\n", id);
	    print_result (samp, stat);
	}

    } else if (strcasecmp (method, "callAll") == 0) {		/* CALLALL */
	if (nscan < 2) {
	    cmdUsage ("callAll mtype");
	} else {
	    int msg = make_msg (arg1);
	    stat = samp_callAll (samp, "allTag", msg);
	    print_result (samp, stat);
	}

    } else if (strcasecmp (method, "callAndWait") == 0) {	/* CALLANDWAIT*/
	if (nscan < 3) {
	    cmdUsage ("callAndWait appName mtype");
	} else {
	    int msg = make_msg (arg2);
	    stat = samp_callAndWait (samp, arg1, "waitTag", msg);
	    print_result (samp, stat);
	}



    } else if (strcasecmp (method, "Register") == 0) {		/* REGISTER */
	if (nscan < 3) {
	    cmdUsage ("Register appName appDesc");
	} else {
    	    if (samp_Register (samp) != OK)
		fprintf (stderr, "Registration fails\n");
    	    else {
		registered = 1;
		fprintf (stderr, "Registration OK\n");
	    }
	}

    } else if (strcasecmp (method, "Unregister") == 0) {  	/* UNREGISTER */
	if (samp == 0) {
	    fprintf (stderr, "Samp Hub not connected\n");
	} else {
    	    if (samp_UnRegister (samp) != OK)
		fprintf (stderr, "UnRegistration fails\n");
    	    else {
		registered = 0;
		fprintf (stderr, "UnRegistration OK\n");
	    }
	}

    } else if (strcasecmp (method, "DeclareMetadata") == 0) {	/* METADATA */
	if (samp == 0) {
	    fprintf (stderr, "Samp Hub not connected\n");
	} else {
    	    if (samp_DeclareMetadata (samp) != OK)
		fprintf (stderr, "Metadata declaration fails\n");
    	    else
		fprintf (stderr, "Metadata declaration OK\n");
	}

    } else if (strcasecmp (method, "Ping") == 0) {		/* PING */
	if (nscan < 2) {
	    cmdUsage ("Ping appName");

	} else {
	    if ((samp_Ping (samp, arg1)) < 0)
		fprintf (stderr, "%s responds w/ ERR\n", arg1);
	    else
		fprintf (stderr, "%s responds OK [%d]\n", arg1, cmdNum++);
	}

    } else if (strcasecmp (method, "GetMetadata") == 0) {      /* GETMETADATA */
	if (nscan < 2) {
	    cmdUsage ("GetMetadata appName");
	} else {
    	    if ((resp = samp_GetMetadata (samp, arg1)) > 0) {
	        xr_getStringFromStruct (resp, "samp.name", &sres);
	            printf ("  Name  = '%s'\n", sres);
	        xr_getStringFromStruct (resp, "author.name", &sres);
	            printf (" Author = '%s'\n", sres);
	        xr_getStringFromStruct (resp, "samp.description.text", &sres);
	            printf ("  Descr = '%s'\n", sres);
	        xr_getStringFromStruct (resp, "samp.icon.url", &sres);
	            printf ("IconURL = '%s'\n", sres);
	        xr_getStringFromStruct (resp, "samp.documentation.url", &sres);
	            printf (" DocURL = '%s'\n", sres);
	    }
	}
	    
							     /* SUBSCRIPTIONS */
    } else if (strcasecmp (method, "DeclareSubscriptions") == 0) {
	if ((samp_DeclareSubscriptions (samp)) < 0)
	    fprintf (stderr, "DeclareSubscriptions responds w/ ERR\n");
	else
	    fprintf (stderr, "DeclareSubscriptions OK\n");

    } else if (strcasecmp (method, "GetSubscriptions") == 0) {
	Map subs = (Map) 0;

	if ((subs = samp_GetSubscriptions (samp, arg1)) > 0) {
	    /*  Need xmlrpc_struct_read_member() to scan map names ....
	     */
	}

							     /* CLIENTS       */
    } else if (strcasecmp (method, "GetRegisteredClients") == 0) {
	/*  Print the list of registered clients.
	*/
	List clients = samp_GetRegisteredClients (samp);

	for (i=0; i < samp_listLen (clients); i++)
	    printf ("%s\n", samp_getStringFromList (clients, i));
	samp_freeList (clients);

    } else if (strcasecmp (method, "GetSubscribedClients") == 0) {
	if (nscan < 2) {
	    cmdUsage ("GetSubscribedClients mtype");

	} else {
	    /*  Print the list of clients subscribed to a specific mtype.
	     */
	    List clients = samp_GetSubscribedClients (samp, arg1);

	    for (i=0; i < samp_listLen (clients); i++)
	        printf ("%s\n", samp_getStringFromList (clients, i));
	    samp_freeList (clients);
	}


			      /* table.load.votable (url, [table-id], [name]) */
    } else if (strcasecmp (method, "tableLoadVOTable") == 0) {
	if (nscan < 2) {
	    cmdUsage ("tableLoadVOTable appName url [table-id] [name]");
	} else {
	    if (samp_tableLoadVOTable (samp, arg1, arg2, arg3, arg4) == SAMP_OK)
	        printf ("OK\n");
	    else
	        printf ("Error: '%s'\n", samp_getErr (samp));
	}

			         /* table.load.fits (url, [table-id], [name]) */
    } else if (strcasecmp (method, "tableLoadFITS") == 0) {
	if (nscan < 2) {
	    cmdUsage ("tableLoadFITS appName url [table-id] [name]");
	} else {
	    if (samp_tableLoadFITS (samp, arg1, arg2, arg3, arg4) == SAMP_OK)
	        printf ("OK\n");
	    else
	        printf ("Error: '%s'\n", samp_getErr (samp));
	}

			    /* table.highlight.row (table-id, url, (int) row) */
    } else if (strcasecmp (method, "tableHighlightRow") == 0) {
	;

			/* table.highlight.rowList (table-id, url, (List)row) */
    } else if (strcasecmp (method, "tableSelectRowList") == 0) {
	;

				 /* image.load.fits (url, [table-id], [name]) */
    } else if (strcasecmp (method, "imageLoadFits") == 0) {
	if (nscan < 2) {
	    cmdUsage ("imageLoadFITS appName url [image-id] [name]");
	} else {
	    if (samp_imageLoadFITS (samp, arg1, arg2, arg3, arg4) == SAMP_OK)
	        printf ("OK\n");
	    else
	        printf ("Error: '%s'\n", samp_getErr (samp));
	}

				 /* coord.pointAt.sky ((float)ra, (float)dec) */
    } else if (strcasecmp (method, "coordPointAtSky") == 0) {
	;

	/* spectrum.load.ssa-generic (url, (Map)meta, [spectrum-id], [name])  */
    } else if (strcasecmp (method, "specLoadSSAGeneric") == 0) {
	;

						     /* send (appName, mtype) */
    } else if (strcasecmp (method, "send") == 0) {
	;

    } else if (method[0])
	fprintf (stderr, "Unknown command '%s'\n", method);


    return (0);
}
Exemple #3
0
static void cmd_help (void)
{
  help_summary (cmds_basic, sizeof(cmds_basic)/sizeof(CMD),
                "Basic commands available at current access level:\n");
}