/** * SAMP_GETOKMAP -- Generate an 'OK' map we can return to the Hub. */ Map samp_getOKMap () { Map map; map = samp_newMap (); samp_setStringInMap (map, "samp.status", "samp.ok"); samp_setMapInMap (map, "samp.result", nullMap); return (map); }
/** * SAMP_ENVGETHANDLER -- Handle a client.env.set message * * @brief Handle a client.env.set message * @fn int samp_envGetHandler (String sender, * String mtype, String msg_id, Map msg_map) * * @param sender sender name * @param mtype mtype string * @param msg_id message id * @param msg_map message map struct * @return SAMP_OK or SAMP_ERR */ int samp_envGetHandler (String sender, String mtype, String msg_id, Map msg_map) { char name[SZ_NAME], value[SZ_NAME]; Map resp, vmap; int maxch = SZ_NAME; void (*func) (); strcpy (name, samp_getStringFromMap (msg_map, "name")); /* Call the user handler. */ memset (value, 0, SZ_NAME); if ( (func = samp_getUserHandler ("client.env.get")) ) { if (sampP->handlerMode == SAMP_CBR) (*func) (name, value, &maxch, strlen(name), strlen(value)); else (*func) (name, value, maxch); } /* Create the response to return the value. */ resp = samp_newMap (); samp_setStringInMap (resp, "samp.status", "samp.ok"); vmap = samp_newMap (); samp_setStringInMap (vmap, "value", value); samp_setMapInMap (resp, "samp.result", vmap); samp_setHandlerReply (resp); #ifdef FREE_IT samp_freeMap (vmap); /* clean up -- FIXME ?? */ samp_freeMap (resp); #endif return (SAMP_OK); }
/** * SAMP_GETNULLMAP -- Generate a 'Null' map we can return to the Hub. */ Map samp_getNullMap () { return ( samp_newMap() ); }
/** * SAMP_INIT -- Initialize the SAMP interface. * * @brief Initialize the SAMP interface. * @fn handle = sampInit (String name, String descr) * * @param appName application name * @param description description of application * @return samp handle */ handle_t sampInit (String appName, String description) { handle_t handle = -1; /* Allocate the SAMP structure. */ sampP = calloc (1, sizeof(Samp)); if ((sampH = handle = samp_newHandle ((void *) sampP)) < 0) { fprintf (stderr, "Error allocating Samp struct.\n"); return (-1); } /* Initialize our connection to the Hub and register as a client. */ strcpy (sampP->appName, appName); strcpy (sampP->appVer, "1.0"); strcpy (sampP->description, description); /* Open a connection to the Hub. */ if ((sampP->hubHandle = samp_hubOpen (sampP)) < 0) sampP->hub = (Hub *) NULL; else sampP->hub = (Hub *) samp_H2P (sampP->hubHandle); sampP->msgMode = DEF_CALLMODE; /* set some defaults */ sampP->handlerMode = SAMP_CBV; sampP->trace = SAMP_TRACE; sampP->verbose = TRUE; sampP->serverPort = samp_serverPort (); sampP->svrThread = (pthread_t) 0; sampP->defaultUserFunc = NULL; sampP->mapClients = TRUE; sampTrace (handle, "%d = sampInit(%s,'%s')\n", handle,appName,description); /* Create a NULL map for messages. */ nullMap = samp_newMap (); nullList = samp_newList (); /* Create a OK map for messages when there is no real value to be * returned. */ OK_Map = samp_newMap (); samp_setStringInMap (OK_Map, "samp.status", "samp.ok"); samp_setMapInMap (OK_Map, "samp.result", nullMap); /* Install signal handlers to do a proper cleanup. */ #ifndef IRAF signal (SIGCHLD, (SIGFUNC)samp_Exit); signal (SIGINT, (SIGFUNC)samp_Exit); #endif /* Return the handle to the structure. */ return ( handle ); }