Esempio n. 1
0
/**
 *  SAMP_CMDEXEC -- Execute a command in a remote application.
 *
 *  @brief      Execute a command in a remote application.
 *  @fn         stat = samp_cmdExec (handle_t handle, String recip, String cmd)
 *
 *  @param  handle      samp struct handle
 *  @param  recip       name of recipient (or 'all')
 *  @param  cmd         Command string
 *  @return        	SAMP_OK or SAMP_ERR
 */
int
samp_cmdExec (handle_t handle, String recip, String cmd)
{
    Samp *sampP = samp_H2P (handle);
    Hub    *hub = sampP->hub;
    int  status = SAMP_OK;

    Msg   msg   = samp_newMsg ();
    Param param = samp_newParam ();


    if (!hub)
	return (SAMP_ERR);

    /*  Create message map.
     */
    samp_msgMType (msg, "client.cmd.exec");
    samp_msgParam (msg, param);
	samp_addStringParam (msg, "cmd", cmd);

    status = samp_sendMsg (handle, recip, msg);
    samp_freeMsg (msg);

    return (status);
}
Esempio n. 2
0
/**
 *  SAMP_PARAMSET -- Set an parameter variable in a remote application.
 *
 *  @brief      Set an parameter variable in a remote application.
 *  @fn         stat = samp_paramSet (handle_t handle, String recip,
 *				String name, String value)
 *
 *  @param  handle      samp struct handle
 *  @param  recip       name of recipient (or 'all')
 *  @param  name        Name of variable in receiver's environment
 *  @param  value       Value of variable or NULL            
 *  @return        	SAMP_OK or SAMP_ERR
 */
int
samp_paramSet (handle_t handle, String recip, String name, String value)
{
    Samp *sampP = samp_H2P (handle);
    Hub    *hub = sampP->hub;
    int  status = SAMP_OK;

    Msg   msg   = samp_newMsg ();
    Param param = samp_newParam ();


    if (!hub)
	return (SAMP_ERR);

    /*  Create message map.
     */
    samp_msgMType (msg, "client.param.set");
    samp_msgParam (msg, param);
	samp_addStringParam (msg, "name", name);
	samp_addStringParam (msg, "value", value);

    status = samp_sendMsg (handle, recip, msg);
    samp_freeMsg (msg);

    return (status);
}
Esempio n. 3
0
/**
 *  SAMP_SPECLOADSSAGENERIC -- Load a generic spectrum from an SSA service.
 *
 *  @brief      Load a generic spectrum from an SSA service.
 *  @fn         stat = samp_specLoadSSAGeneric (handle_t handle, String recip,
 *			String url, Map meta, String spectrumId, String name)
 *
 *  @param  handle      samp struct handle
 *  @param  recip       name of recipient (or 'all')
 *  @param  url         URL of spectrum to load
 *  @param  meta        Metadata map describing data found at the URL
 *  @param  spectrumId  Identifier for spectrum (optional)
 *  @param  name        Name used to label spectrum (optional);
 *  @return             SAMP_OK or SAMP_ERR
 */
int
samp_specLoadSSAGeneric (handle_t handle, String recip, String url, Map meta, 
		String spectrumId, String name)
{
    Samp  *sampP = samp_H2P (handle);
    Hub     *hub = sampP->hub;
    int	  status = SAMP_OK;

    Msg   msg    = samp_newMsg ();
    Param param  = samp_newParam ();


    if (!hub)
	return (SAMP_ERR);

    /*  Create message map.
     */
    samp_msgMType (msg, "spectrum.load.ssa-generic");
    samp_msgParam (msg, param);
	samp_addStringParam (msg, "url", url);
	samp_addMapParam (msg, "meta", meta);
	samp_addStringParam (msg, "spectrum-id", spectrumId);
	samp_addStringParam (msg, "name", name);

    status = samp_sendMsg (handle, recip, msg);
    samp_freeMsg (msg);					   /* clean up        */

    return (status);
}
Esempio n. 4
0
/**
 *  SAMP_COORDPOINTATSKY -- Tell an app to point at an RA/Dec coordinate.
 *
 *  @brief      Tell an app to point at an RA/Dec coordinate.
 *  @fn         stat = samp_coordPointAtSky (handle_t handle, String recip, 
 *				float ra, float dec)
 *
 *  @param  handle      samp struct handle
 *  @param  recip       name of recipient (or 'all')
 *  @param  ra          RA of coord in degrees
 *  @param  dec         Dec of coord in degrees
 *  @return             SAMP_OK or SAMP_ERR
 */
int
samp_coordPointAtSky (handle_t handle, String recip, float ra, float dec)
{
    Samp  *sampP = samp_H2P (handle);
    Hub     *hub = sampP->hub;
    Msg    msg   = samp_newMsg ();
    Param  param = samp_newParam ();
    int   status = SAMP_OK;


    if (!hub)
	return (SAMP_ERR);

    /*  Create message map.
     */
    samp_msgMType (msg, "coord.pointAt.sky");
    samp_msgParam (msg, param);
	samp_addFloatParam (msg, "ra", ra);
	samp_addFloatParam (msg, "dec", dec);

    status = samp_sendMsg (handle, recip, msg);
    samp_freeMsg (msg);

    return (status);
}
Esempio n. 5
0
/**
 *  SAMP_IMAGELOADFITS -- Tell an app to load a FITS image.
 *
 *  @brief      Tell an app to load a FITS image.
 *  @fn         stat = samp_imageLoadFITS (handle_t handle, String recip, 
 *			String url, String tableId, String name)
 *
 *  @param  handle      samp struct handle
 *  @param  recip       Message recipient (or "all" for broadcast)
 *  @param  url         URL to table to be loaded
 *  @param  imageId     ID assigned to image (optional)
 *  @param  name        Name assigned to image (optional)
 *  @return             SAMP_OK or SAMP_ERR
 */
int
samp_imageLoadFITS (handle_t handle, String recip, String url, 
		String imageId, String name)
{
    Samp  *sampP = samp_H2P (handle);
    Hub     *hub = sampP->hub;
    int	  status = SAMP_OK;

    Msg   msg    = samp_newMsg ();
    Param param  = samp_newParam ();


    if (!hub)
	return (SAMP_ERR);

    /*  Create message map.
     */
    samp_msgMType (msg, "image.load.fits");
    samp_msgParam (msg, param);
	samp_addStringParam (msg, "url", url);
	samp_addStringParam (msg, "image-id", imageId);
	samp_addStringParam (msg, "name", name);

    status = samp_sendMsg (handle, recip, msg);
    samp_freeMsg (msg);					   /* clean up        */

    return (status);
}
Esempio n. 6
0
/**
 *  SAMP_BIBLOAD -- Exchange a bibcode.
 *
 *  @brief      Exchange a bibcode.
 *  @fn         val = samp_bibLoad (handle_t handle, String recip, String bibcode)
 *
 *  @param  handle      samp struct handle
 *  @param  recip       name of recipient (or 'all')
 *  @param  bibcode     Bibcode string
 *  @return        	SAMP_OK or SAMP_ERR
 */
int
samp_bibLoad (handle_t handle, String recip, String bibcode)
{
    Samp *sampP = samp_H2P (handle);
    Hub    *hub = sampP->hub;
    int  status = SAMP_OK;

    Msg   msg   = samp_newMsg ();
    Param param = samp_newParam ();


    if (!hub)
	return (SAMP_ERR);

    /*  Create message map.
     */
    samp_msgMType (msg, "bibcode.load");
    samp_msgParam (msg, param);
	samp_addStringParam (msg, "bibcode", bibcode);

    status = samp_sendMsg (handle, recip, msg);
    samp_freeMsg (msg);

    return (status);
}
/**
 *  SAMP_GETREGISTEREDCLIENTS -- Get the list of public-ids of the registered
 *  clients.
 *
 *  @brief      ...
 *  @fn         handle = samp_hubOpen (Samp *samp)
 *
 *  @param  samp        ...
 *  @return             ...
 */
List
samp_GetRegisteredClients (handle_t samp)
{
    Samp *sampP = samp_H2P(samp);
    Hub *hub = sampP->hub;
    int res;
    List lres = (List) 0;


    if (!hub)
	return ((List) 0);

    xr_initParam (hub->id);
    xr_setStringInParam (hub->id, hub->privateKey);

    xr_callSync (hub->id, "samp.hub.getRegisteredClients");

    xr_getArrayFromResult (hub->id, &res);

    /*
    lres = samp_newList ();
    for (i=0; i < samp_listLen (res); i++) {
	samp_setStringInList (lres, xr_getStringFromList (list, i);
    }
    */
    lres = res;

    return (lres);
}
Esempio n. 8
0
/**
 *  SAMP_TABLEHIGHLIGHTROW -- Tell an app to highlight a table row.
 *
 *  @brief      Tell an app to highlight a table row.
 *  @fn         stat = samp_tableHighlightRow (handle_t handle, String recip, 
 *			String tableId, String url, int row)
 *
 *  @param  handle      samp struct handle
 *  @param  recip       Message recipient (or "all" for broadcast)
 *  @param  tableId     ID associated with a previously loaded table
 *  @param  url         URL to table to be loaded
 *  @param  rows        List of (zero-based) row indices
 *  @return             SAMP_OK or SAMP_ERR
 */
int
samp_tableHighlightRow (handle_t handle, String recip, String tableId, 
		String url, int row)
{
    Samp  *sampP = samp_H2P (handle);
    Hub     *hub = sampP->hub;
    int   status = SAMP_OK;

    Msg    msg   = samp_newMsg ();
    Param  param = samp_newParam ();


    if (!hub)
	return (SAMP_ERR);

    /*  Create message map.
     */
    samp_msgMType (msg, "table.highlight.row");
    samp_msgParam (msg, param);
	samp_addStringParam (msg, "url", url);
	samp_addStringParam (msg, "table-id", tableId);
	samp_addIntParam (msg, "row", row);

    status = samp_sendMsg (handle, recip, msg);
    samp_freeMsg (msg);

    return (status);
}
Esempio n. 9
0
/**
 *  SAMP_ADDCLIENT -- Add a newly registered client to the list of known
 *  apps so we can do the public-private name translation.
 */
int
samp_addClient (handle_t handle, String name, String id)
{
    Samp  *sampP = samp_H2P (handle);	/* get struct pointer	*/
    register int  i = 0;


    /*  Scan the list of registered clients in case this is a name change.
     */        
    for (i=0; i < sampP->nclients; i++) {
	if (strcasecmp (sampP->clients[i].pubId, id) == 0) 
	    break;
    }

    /*  Otherwise, add new client.
     */
    memset (sampP->clients[i].name, 0, SZ_NAME);
    memset (sampP->clients[i].pubId, 0, SZ_NAME);

    strcpy (sampP->clients[i].name, name);
    strcpy (sampP->clients[i].pubId, id);
    sampP->nclients++;

    return (SAMP_OK);
}
/**
 *  SAMP_DECLAREMETATA -- (Re)Declare all of our metadata.
 *
 *  @brief      ...
 *  @fn         handle = samp_hubOpen (Samp *samp)
 *
 *  @param  samp        ...
 *  @return             ...
 */
int
samp_DeclareMetadata (handle_t samp)
{
    Samp *sampP = samp_H2P(samp);
    Hub *hub = sampP->hub;
    int   map;


    if (!hub)
	return (SAMP_ERR);

    xr_initParam (hub->id);

    xr_setStringInParam (hub->id, hub->appId);
    map = xr_newStruct ();
        xr_setStringInStruct (map, "samp.name", hub->appName);
        xr_setStringInStruct (map, "samp.description.text", hub->description);
    xr_setStructInParam (hub->id, map);

    xr_callSync (hub->id, "samp.hub.declareMetadata");

    /* ignore result */

    return (SAMP_OK);
}
/**
 *  SAMP_PING --  Ping the hub/app to see if it is alive (returns >0).
 *
 *  @brief      Ping the hub/app to see if it is alive (returns >0).
 *  @fn         handle = samp_Ping (handle_t samp, String appName)
 *
 *  @param  samp        samp struct handle
 *  @param  appName     application name
 *  @return             OK or ERR if no response
 */
int
samp_Ping (handle_t samp, String appName)
{
    Samp *sampP = samp_H2P(samp);
    char  *tag = (char *) NULL;
    int   res = -1;
    Map   resp = (Map) 0;


    if (strncasecmp (appName, "hub", 3) == 0) {
        res = samp_hubPing (sampP->hub);
        return ( samp_hubPing (sampP->hub) );
    } else {
        Msg   msg   = samp_newMsg ();
        Param param = samp_newParam ();

	samp_msgMType (msg, "samp.app.ping");
	samp_msgParam (msg, param);

	tag = samp_msgTag();
        if (strncasecmp (appName, "all", 3) == 0) {
	    /* callAll */
	    resp = samp_callAll (samp, tag, msg);

        } else {
	    /* call    */
	    resp = samp_callAndWait (samp, appName, tag, msg);
	    samp_freeMap (resp);
	}

	samp_freeMsg (msg);
    }

    return (SAMP_ERR);
}
Esempio n. 12
0
/**
 *  SAMP_MAPCLIENTS -- Map the public-ids of registered clients to the 
 *  appName.
 */
int
samp_mapClients (handle_t handle)
{
    Samp  *sampP = samp_H2P (handle);	/* get struct pointer	*/
    register int  i = 0;
    char  *pub, rstr[SZ_RESSTR], *sres = rstr;
    List clients;
    Map  resp;


    /*  Get the list of registered clients and their metadata.
     */        
    sampP->nclients = 0;
    clients = samp_GetRegisteredClients (handle);
    for (i=0; i < samp_listLen (clients); i++) {
	pub = samp_getStringFromList (clients, i);
        resp = samp_GetMetadata (handle, pub);
        xr_getStringFromStruct (resp, "samp.name", &sres);

	memset (sampP->clients[i].name, 0, SZ_NAME);
	memset (sampP->clients[i].pubId, 0, SZ_NAME);

	sampP->nclients++;
	strcpy (sampP->clients[i].name, sres);
	strcpy (sampP->clients[i].pubId, pub);
	/*
	if (resp) 
	    xr_freeStruct (resp);
	*/
    }
    samp_freeList (clients);

    return (SAMP_OK);
}
Esempio n. 13
0
/**
 *  SAMP_UNSUBSCRIBE -- Unsubscribe to a given mtype.
 *
 *  @brief  	Unsubscribe to a given mtype.
 *  @fn		samp_Unsubscribe (handle_t handle, String mtype)
 * 
 *  @param handle	user handle to samp struct
 *  @param mtype	mtype name
 *  @return		nothing
 */
void 
samp_Unsubscribe (handle_t handle, String mtype)
{
    Samp *sampP = samp_H2P (handle);
    register int i, j, found = 0;


    /* Find the mtype in question.
     */
    for (i=0; i < sampP->nsubs; i++) {
	if (strcasecmp (sampP->subs[i].mtype, mtype) == 0) {
	    found = 1;
	    break;
	}
    }

    if (found) {
	/*  Shift the remainder of the list. 		
	 */
	for (j=i; j < (sampP->nsubs - 1); j++) {
	    memset (sampP->subs[j].mtype, 0, SZ_LINE);
            strcpy (sampP->subs[j].mtype, sampP->subs[j+1].mtype);
            sampP->subs[j].userFunc = sampP->subs[j+1].userFunc;
            sampP->subs[j].sampFunc = sampP->subs[j+1].sampFunc;
	}
	memset (sampP->subs[j].mtype, 0, SZ_LINE);
        sampP->nsubs--;

	/*  Send unsubscribe msg to Hub.
	 */
        samp_DeclareSubscriptions (handle);
    }
}
Esempio n. 14
0
/**
 *  SAMP_SHUTDOWN -- Shut down the active SAMP interface.
 *
 *  @brief  	Shut down the active SAMP interface.
 *  @fn		sampShutdown (handle_t handle)
 * 
 *  @param handle	user handle to samp struct
 *  @return		nothing
 */
int 
sampShutdown (handle_t handle)
{
    Samp *sampP = samp_H2P (handle);


    /* Close existing Hub handle.
     */
    if (sampP->hubHandle > 0 && samp_hubClose (sampP->hubHandle) != SAMP_OK)
	if (sampP->verbose)
            fprintf (stderr, "Error closing Hub connection.\n");

    /*  Stop XML-RPC server thread
     */
#ifdef KILL_SAMP_SERVER
    if (pthread_kill (sampP->svrThread, SIGUSR1) != 0)
	fprintf (stderr, "Error killing server thread %ld\n", 
	    (long) sampP->svrThread);
#endif

    sampP->hubHandle = -1;
    sampP->svrThread =  0;
    sampP->active    =  0;

    return (SAMP_OK);
}
Esempio n. 15
0
/**
 *  SAMP_CLOSE -- Close the SAMP interface.
 *
 *  @brief  	Close the SAMP interface and free resources.
 *  @fn		sampClose (handle_t handle)
 * 
 *  @param handle	user handle to samp struct
 *  @return		nothing
 */
void 
sampClose (handle_t handle)
{
    Samp *sampP = samp_H2P (handle);	/* get struct pointer	*/


    sampTrace (handle, "sampClose (%d)\n", handle);
    if (sampP == (Samp *) NULL)
	return;

    /* Close existing Hub handle.
     */
    if (sampP && sampP->hub) {
      if (sampP->hubHandle > 0 && samp_hubClose (sampP->hubHandle) != SAMP_OK)
	  if (sampP->verbose)
	      fprintf (stderr, "Error closing Hub connection.\n");
    }
    sampP->hubHandle = 0;

    if (sampP->hub)				/* free Hub structure	*/
	 free ((void *) sampP->hub);
    sampP->hub = (Hub *) NULL;

    if (sampP->hubHandle > 0)			/* release handles	*/
        samp_freeHandle (sampP->hubHandle);
    sampP->hubHandle = -1;
    samp_freeHandle (handle);

    if (sampP) free ((void *) sampP);		/* free SAMP structure	*/
    sampP = (Samp *) NULL;
}
Esempio n. 16
0
/**
 *  SAMP_SETSAMPHANDLER -- Set the SAMP interface handler for the mtype.
 *
 *  @brief      Set the SAMP interface handler for the mtype.
 *  @fn         samp_setSampHandler (handle_t handle, String mtype, void *func)
 *
 *  @param handle       user handle to samp struct
 *  @param mtype        mtype name
 *  @param func         callback function
 *  @return             nothing
 */
void
samp_setSampHandler (handle_t handle, String mtype, void *func)
{
    Samp *sampP = samp_H2P (handle);
    register int i;


    /*  Search first through the list of mtypes supported by the interface
     *  that may have handlers.  These handlers will parse the message map
     *  and call the user function with a simpler interface (e.g. call with
     *  the URL argument instead of the rawmessage map.
     */
    for (i=0; i < sampP->nsubs; i++) {
        if (strcasecmp (mtype, sampP->subs[i].mtype) == 0) {
            sampP->subs[i].sampFunc = func;
            return;
        }
    }

    /*  This is a new mtype handler.
     */
    strcpy (sampP->subs[sampP->nsubs].mtype, mtype);
    sampP->subs[sampP->nsubs].sampFunc = func;
    sampP->nsubs++;
}
Esempio n. 17
0
/**
 *  SAMP_REMOVECLIENT -- Remove a registered client from the list of known
 *  apps that do the public-private name translation.
 */
int
samp_removeClient (handle_t handle, String id)
{
    Samp  *sampP = samp_H2P (handle);	/* get struct pointer	*/
    register int  i = 0;


    /*  Find the client.
     */        
    for (i=0; i < sampP->nclients; i++) {
	if (strcasecmp (sampP->clients[i].pubId, id) == 0) {
	    if (i == (sampP->nclients - 1)) {	/* last entry, ignore */
	        ;
	    } else {
		/* Shift the list. */
    		for (i=0; i < (sampP->nclients-1); i++) {
	            strcpy (sampP->clients[i].name,sampP->clients[i+1].name);
	            strcpy (sampP->clients[i].pubId,sampP->clients[i+1].pubId);
    		}
	    }
	    memset (sampP->clients[i].name, 0, SZ_NAME);
	    memset (sampP->clients[i].pubId, 0, SZ_NAME);
	    sampP->nclients--;
	    break;
	}
    }

    return (SAMP_OK);
}
Esempio n. 18
0
/**
 *  SAMP_SETAPPNAME -- Set the application name string.
 *
 *  @brief	Set the application name string.
 *  @fn		samp_setAppVersion (handle_t handle, String name)
 * 
 *  @param  handle	samp handle
 *  @param  name	application name
 *  @return		nothing
 */
void
samp_setAppName (handle_t handle, String name)
{
    Samp *sampP = samp_H2P (handle);

    strcpy (sampP->appName, name);
    strcpy (sampP->hub->appName, name);
}
Esempio n. 19
0
/**
 *  SAMP_SETAPPVERSION -- Set the application version string.
 *
 *  @brief	Set the application version string.
 *  @fn		samp_setAppVersion (handle_t handle, String version)
 * 
 *  @param  handle	samp handle
 *  @param  name	application version
 *  @return		nothing
 */
void
samp_setAppVersion (handle_t handle, String version)
{
    Samp *sampP = samp_H2P (handle);

    strcpy (sampP->appVer, version);
    strcpy (sampP->hub->appVer, version);
}
Esempio n. 20
0
/**
 *  SAMPVERBOSE -- Set interface verbose level.
 *
 *  @brief  	Set interface debug level.
 *  @fn		sampVerbose (handle_t handle, int value)
 * 
 *  @param handle	user handle to samp struct
 *  @param value	verbose value
 *  @return		nothing
 */
int 
sampVerbose (handle_t handle, int value)
{
    Samp *sampP = samp_H2P (handle);	/* get struct pointer	*/
    if (value >= 0)
        sampP->verbose = value;

    return (sampP->verbose);
}
Esempio n. 21
0
/**
 *  SAMP_SENDMSG -- Send the specified message.
 *
 *  @brief      Send the specified message.
 *  @fn         stat = samp_sendMsg (handle_t handle, String recip, Map msg)
 *
 *  @param  handle      samp struct handle
 *  @param  recip       Name of recipient (or 'all')
 *  @param  msg         Message map
 *  @return        	SAMP_OK or SAMP_ERR
 */
int
samp_sendMsg (handle_t handle, String recip, Map msg)
{
    Samp   *sampP = samp_H2P (handle);
    String  tag = samp_msgTag();
    Map     resp = (Map) 0;
    int     i, status = SAMP_OK;
    char   *pubId = samp_app2id (handle, recip);
    char   *msg_id = NULL;


    /*  Execute the message call to the Hub.  This is where we implement the
     *  messaging pattern, i.e. broadcast vs directed message, synch vs
     *  asynch vs notify, etc.
     */
    if (strncasecmp (recip, "all", 3) == 0) {
	switch (sampP->msgMode) {
	case SAMP_SYNCH:			       	       /* call        */
	    for (i=0; i < sampP->nclients; i++) {
		pubId = sampP->clients[i].pubId;
                resp = samp_callAndWait (handle, pubId, tag, msg);
    		status = samp_setErr (handle, resp);
		if (status != SAMP_OK) {
		    ;  /* FIXME -- Do something about this. */
		}
	    }
	    break;
	case SAMP_ASYNCH:
            resp = samp_callAll (handle, tag, msg); 	       /* callAll     */
	    break;
	case SAMP_NOTIFY:
            resp = samp_notifyAll (handle, msg); 	       /* notifyAll   */
	    break;
	default:
	    ;
	}
    } else {
	switch (sampP->msgMode) {
	case SAMP_SYNCH:
            resp = samp_callAndWait (handle, pubId, tag, msg); /* callAndWait */
    	    status = samp_setErr (handle, resp);
	    break;
	case SAMP_ASYNCH:
            msg_id = samp_call (handle, pubId, tag, msg);      /* call        */
	    status = (msg_id ? SAMP_OK : SAMP_ERR);
	    break;
	case SAMP_NOTIFY:
            (void) samp_notify (handle, pubId, msg);           /* notify      */
	    break;
	default:
	    ;
	}
    }

    return (status);
}
Esempio n. 22
0
/**
 *  SAMP_SETTIMEOUT -- Set the message timeout value (in seconds).
 *
 *  @brief	Set the message timeout value (in seconds).
 *  @fn		samp_setTimeout (handle_t handle, int timeout)
 * 
 *  @param  handle	samp handle
 *  @param  name	application name
 *  @return		nothing
 */
void
samp_setTimeout (handle_t handle, int timeout)
{
    Samp *sampP = samp_H2P (handle);
    char  buf[32];

    memset (buf, 0, 32);
    sprintf (buf, "%d", timeout);

    strcpy (sampP->hub->timeout, buf);
}
Esempio n. 23
0
/**
 *  SAMP_HUBACTIVE -- Determine if the Hub is active (i.e. connected).
 *
 *  @brief  	Determine if the Hub is active (i.e. connected).
 *  @fn		samp_hubActive (handle_t handle)
 * 
 *  @param handle	user handle to samp struct
 *  @return		nothing
 */
int 
samp_setOpt (handle_t handle, char *opt, int value)
{
    Samp *sampP = samp_H2P (handle);

    if (strcasecmp ("mapClients", opt) == 0) {
	sampP->mapClients = value;
    }

    return (0);
}
Esempio n. 24
0
/**
 *  SAMP_METADATA -- Set a metadata field for the application.  This will
 *  	be sent to the Hub later in a declareMetadata() call.
 *
 *  @brief 	Set a metadata field value for the application.
 *  @fn		samp_Metadata (handle_t handle, String field, String value)
 * 
 *  @param  handle	samp handle
 *  @param  field	metadata field to set (name, author, etc)
 *  @param  samp	value of field
 *  @return		nothing
 */
void
samp_Metadata (handle_t handle, String field, String value)
{
    Samp *sampP = samp_H2P (handle);
    Hub  *hub = sampP->hub;


    sampTrace (handle, "sampSetMetadata (%d) %s = %s\n", handle, field, value);

    if (strcmp (field, "samp.name") == 0) { 	/* Known metadata values      */
        strcpy (sampP->meta.name, value);
	strcpy (sampP->appName, value);
	if (hub)
	    strcpy (hub->appName, value);
    } else if (strcmp (field, "samp.description.text") == 0) {
        strcpy (sampP->meta.desc, value);
	strcpy (sampP->description, value);
	if (hub)
	    strcpy (hub->description, value);
    } else if (strcmp (field, "samp.icon.url") == 0) {
        strcpy (sampP->meta.iconURL, value);
	if (hub)
            strcpy (hub->meta.iconURL, value);
    } else if (strcmp (field, "samp.documentation.url") == 0) {
        strcpy (sampP->meta.docURL, value);
	if (hub)
            strcpy (hub->meta.docURL, value);
    } else {
	sampP->meta.aKey[sampP->meta.nkeys] = calloc (1, strlen (field) + 1);
	sampP->meta.aVal[sampP->meta.nkeys] = calloc (1, strlen (value) + 1);

        strcpy (sampP->meta.aKey[sampP->meta.nkeys], field);
        strcpy (sampP->meta.aVal[sampP->meta.nkeys], value);
        sampP->meta.nkeys++;

	if (hub) {
	    int n = hub->meta.nkeys;
	    hub->meta.aKey[n] = calloc (1, strlen (field) + 1);
	    hub->meta.aVal[n] = calloc (1, strlen (value) + 1);

            strcpy (hub->meta.aKey[n], field); 
            strcpy (hub->meta.aVal[n], value);
            hub->meta.nkeys++;
	}
    }

    if (hub) {
    	strcpy (hub->meta.name, sampP->appName);
    	strcpy (hub->appName, sampP->appName);
    	strcpy (hub->appVer, sampP->appVer);
    	strcpy (hub->meta.desc, sampP->description);
    	strcpy (hub->description, sampP->description);
    }
}
Esempio n. 25
0
/**
 *  SAMP_LISTCLIENTS -- List the available clients to stdout.
 */
int
samp_listClients (handle_t handle)
{
    Samp  *sampP = samp_H2P (handle);	/* get struct pointer	*/
    register int  i = 0;

    for (i=0; i < sampP->nclients; i++)
	printf ("%2d:  PubID = '%s'\tName = '%s'\n",
	    i, sampP->clients[i].pubId, sampP->clients[i].name);

    return (SAMP_OK);
}
Esempio n. 26
0
/**
 *  SAMP_SENDGENERIC -- Send a generic message.
 *
 *  @brief      Send a geenric message.
 *  @fn         stat = samp_sendGeneric (handle_t handle, String recip, 
 *			    String mtype, String args[])
 *
 *  @param  handle      samp struct handle
 *  @param  recip       Name of recipient (or 'all')
 *  @param  mtype       Message type
 *  @param  args        Argument list
 *  @return        	SAMP_OK or SAMP_ERR
 *
 *  This method can be used to send any user-defined message.  The 'mtype'
 *  string is arbitrary, we just assume the receiving client can understand
 *  what it means.  The 'args' String array can be an array of values in
 *  which case the parameter name will be a series of generic 'arg0' thru
 *  'argN-1' names.
 *
 *
 */
int
samp_sendGeneric (handle_t handle, String recip, String mtype, String args[])
{
    Samp *sampP = samp_H2P (handle);
    Hub    *hub = sampP->hub;
    int  status = SAMP_OK, i = 0;
    char   *arg = NULL, *par, *val, *eq, buf[SZ_NAME];

    Msg   msg   = samp_newMsg ();
    Param param = samp_newParam ();


    if (!hub)
	return (SAMP_ERR);

    /*  Create message map.
     */
    samp_msgMType (msg, mtype);
    samp_msgParam (msg, param);

    for (i=0; args[i]; i++) {
        arg = args[i];
	if (!arg || !arg[0])
	    break;

	if ((eq =strchr (arg, (int) '='))) {		/* param=value 	*/
	    *eq = '\0';
	    par = arg;
	    val = (isspace(*(eq+1)) ? NULL : (eq + 1));
	} else {
	    memset (buf, 0, SZ_NAME);			/* generic name	*/
	    sprintf (buf, "arg%d", i);
	    par = buf;
	    val = arg;
	}

	if (strncmp (par, "i:", 2) == 0) {		/* int param	*/
	    par += 2;
	    samp_addIntParam (msg, par, (val ? atoi(val) : 0));
	} else if (strncmp (par, "f:", 2) == 0) {	/* float param	*/
	    par += 2;
	    samp_addFloatParam (msg, par, (val ? atof(val) : 0.0));
	} else {					/* string param	*/
	    samp_addStringParam (msg, par, val);
	}
    }

    status = samp_sendMsg (handle, recip, msg);
    samp_freeMsg (msg);

    return (status);
}
/**
 *  SAMP_DECLARESUBSCRIPIONS -- Declare the messages we're interested in.
 *
 *  @brief      ...
 *  @fn         handle = samp_hubOpen (Samp *samp)
 *
 *  @param  samp        ...
 *  @return             ...
 */
void
samp_DeclareSubscriptions (handle_t samp, Map subscriptions)
{
    Samp *sampP = samp_H2P(samp);
    Hub *hub = sampP->hub;

    if (!hub)
	return;

    xr_initParam (hub->id);

    /*  NYI  */
}
Esempio n. 28
0
/**
 *  SAMP_TABLESELECTROWLIST -- Tell an app to select a list of table rows.
 *
 *  @brief      Tell an app to select a list of table rows.
 *  @fn         stat = samp_tableSelectRowList (handle_t handle, String recip, 
 *			String tableId, String url, int rows[], int nrows)
 *
 *  @param  handle      samp struct handle
 *  @param  recip       Message recipient (or "all" for broadcast)
 *  @param  tableId     ID associated with a previously loaded table
 *  @param  url         URL to table to be loaded
 *  @param  rows        Array of (zero-based) row indices
 *  @param  nrows       Number of rows
 *  @return             SAMP_OK or SAMP_ERR
 */
int
samp_tableSelectRowList (handle_t handle, String recip, String tableId, 
		String url, int rows[], int nrows)
{
    Samp *sampP = samp_H2P (handle);
    Hub *hub = sampP->hub;


    if (!hub)
	return (SAMP_ERR);

    return (SAMP_OK);
}
/**
 *  SAMP_GETMETADATA -- Get the metadata for a specified app.
 *
 *  @brief      Get the metadata for a specified app.
 *  @fn         map = samp_GetMetadata (Samp *samp, String pubId)
 *
 *  @param  samp        samp struct handle
 *  @param  pubId       App public-id
 *  @return             Map to message response
 */
Map
samp_GetMetadata (handle_t samp, String pubId)
{
    Samp *sampP = samp_H2P(samp);
    Hub *hub = sampP->hub;
    Map   resp  = (Map) 0;
/*
    Map   err = (Map) 0, snum = (Map) 0, res = (Map) 0;
*/


    if (!hub)
	return ((Map) 0);

    xr_initParam (hub->id);             /* set calling parameters       */
    xr_setStringInParam (hub->id, hub->privateKey);
    xr_setStringInParam (hub->id, pubId);

    if (xr_callSync (hub->id, "samp.hub.getMetadata") == OK) {
        xr_getStructFromResult (hub->id, &resp);
/*
        char  rstr[SZ_RESSTR], *sres = rstr;
        resp = samp_newMap ();
            xr_getStringFromStruct (snum, "samp.status", &sres);
	    if (strcasecmp (sres, "samp.ok") != 0) {
        	xr_freeStruct (snum);
    		return ( (Map) 0 );
	    } else {
                xr_getStructFromStruct (snum, "samp.error", &err);
                xr_getStringFromStruct (snum, "samp.errortxt", &sres);
		memset (sampP->errortxt, 0, SZ_LINE);
		strcpy (sampP->errortxt, sres);

                xr_getStructFromStruct (snum, "samp.result", &res);
	    }
        xr_freeStruct (snum);
*/
        return (resp);
    } else {
	memset (sampP->errortxt, 0, SZ_LINE);
	strcpy (sampP->errortxt, xr_getErrMsg (hub->id));
 
	fprintf (stderr, "Error: '%s'\n", sampP->errortxt);
    }

    return ( (Map) 0 );
}
Esempio n. 30
0
char *
samp_getClients (handle_t handle)
{
    Samp  *sampP = samp_H2P (handle);	/* get struct pointer	*/
    static char clients[SZ_CLIENT_LIST];
    register int  i = 0;

    memset (clients, 0, SZ_CLIENT_LIST);
    for (i=0; i < sampP->nclients; i++) {
	strcat (clients, sampP->clients[i].pubId);
	strcat (clients, " ");
	strcat (clients, sampP->clients[i].name);
	strcat (clients, "\n");
    }
	
    return (clients);
}