diff options
Diffstat (limited to 'vendor/voclient/libsamp/examples')
-rw-r--r-- | vendor/voclient/libsamp/examples/Makefile | 165 | ||||
-rw-r--r-- | vendor/voclient/libsamp/examples/README | 68 | ||||
-rw-r--r-- | vendor/voclient/libsamp/examples/send.c | 269 | ||||
-rw-r--r-- | vendor/voclient/libsamp/examples/snoop.c | 149 |
4 files changed, 651 insertions, 0 deletions
diff --git a/vendor/voclient/libsamp/examples/Makefile b/vendor/voclient/libsamp/examples/Makefile new file mode 100644 index 00000000..9096b935 --- /dev/null +++ b/vendor/voclient/libsamp/examples/Makefile @@ -0,0 +1,165 @@ +#/////////////////////////////////////////////////////////////////////////////// +#// +#// Makefile for the libsamp example tasks. +#// +#/////////////////////////////////////////////////////////////////////////////// + +# primary dependencies + +NAME = samp +VERSION = 1.0 +PLATFORM := $(shell uname -s) +PLMACH := $(shell ../../getarch) +HERE := $(shell /bin/pwd) + + +# secondary dependencies + +LIBBASE = lib$(NAME) +STATICLIB = $(HERE)/$(LIBBASE).a +SHAREDLIB = $(HERE)/$(LIBBASE).so.$(VERSION) + + +# stuff that's precious to keep + +.PRECIOUS: $(STATICLIB) $(SHAREDLIB) +.KEEP_STATE: + + +# includes, flags and libraries +CC = gcc +CINCS = -I$(HERE) -I../ -I../../include -L../ -L../../lib/ -L../ +CFLAGS = -g -Wall -D$(PLATFORM) $(CINCS) + +ifeq ("$(PLATFORM)", "Darwin") + ifeq ("$(PLMACH)", "macintel") + CARCH = -m64 -mmacosx-version-min=10.5 + else + CARCH = -arch i386 -arch ppc -m32 -mmacosx-version-min=10.4 + endif +else + CLIBS = -lm -lc -lpthread -lcurl + CARCH = -D$(PLATFORM) +endif + +#CARCH = -arch i386 -arch ppc -m32 -mmacosx-version-min=10.4 +CLIBS = -lm -lc -lcurl -lpthread +CFLAGS = -g -Wall $(CARCH) -D$(PLATFORM) $(CINCS) -L./ + + + + +#F77 = g77 +F77 = gfortran +FFLAGS = -g -Wall + + + +# list of source and include files + +C_SRCS = snoop.c send.c +C_OBJS = +C_INCS = + +F77_SRCS = +F77_OBJS = +F77_INCS = + +SPP_SRCS = +SPP_OBJS = +SPP_INCS = + + +LIBS = -lsamp -lcurl + +SPP_TASKS = +F77_TASKS = +C_TASKS = snoop send + +TARGETS = $(F77_TASKS) $(SPP_TASKS) $(C_TASKS) + + +# Targets + +all: $(TARGETS) + +c_progs: $(C_TASKS) +spp_progs: $(SPP_TASKS) +f77_progs: $(F77_TASKS) + +clean: + /bin/rm -rf .make.state .nse_depinfo *.[aeo] *.dSYM + /bin/rm -rf $(TARGETS) + +everything: + make clean + make all + make install + +help: HELP + +install: all + + + +############################################################################### +# Unit test programs to be built. +############################################################################### + +demo: $(TARGETS) + + +########################### +# C Test programs +########################### + +zztest: zztest.c + $(CC) $(CFLAGS) -o zztest zztest.c $(LIBS) + +snoop: snoop.c ../libsamp.a + $(CC) $(CFLAGS) -o snoop snoop.c $(LIBS) + +send: send.c ../libsamp.a + $(CC) $(CFLAGS) -o send send.c $(LIBS) + + + +########################### +# SPP Test programs +########################### + +#foo_spp: foo_spp.x +# xc -/I../ -/L../ foo_spp.x -lsamp + + + +########################### +# Fortran Test programs. +########################### + +#foo_f77: foo_f77.f +# $(F77) $(FFLAGS) -o foo_f77 foo_f77.f ../libsamp.a -lc + + + + +############################################################################### +# Leave this stuff alone. +############################################################################### + +$(STATICLIB): $(C_SRCS:%.c=Static/%.o) + /usr/bin/ar rv $@ $? +Static/%.o: %.c $(C_INCS) + /usr/bin/gcc $(CINCS) $(CFLAGS) -c $< -o $@ +Static: + /bin/mkdir $@ + chmod 777 $@ + +$(SHAREDLIB): $(C_SRCS:%.c=Shared/%.o) + /usr/bin/ld -shared -o $@ $? -lc -ldl +Shared/%.o: %.c $(C_INCS) + /usr/bin/gcc $(CINCS) $(CFLAGS) -fpic -shared -c $< -o $@ +Shared: + /bin/mkdir $@ + chmod 777 $@ + diff --git a/vendor/voclient/libsamp/examples/README b/vendor/voclient/libsamp/examples/README new file mode 100644 index 00000000..461b3501 --- /dev/null +++ b/vendor/voclient/libsamp/examples/README @@ -0,0 +1,68 @@ + + This directory contains the example tasks for the LIBSAMP interface. +Current examples include: + + + samp General SAMP commandline interface + snoop Print all messages available to a client application + send Send a message of a specific mtype to one or more apps + + +Example Programs +---------------- + + The interface distribution comes with a 'zztest.c' test application +meant to exercise various methods of the interface. This is a largely +undocumented unit test program intended only for development, users +should instead look at the programs in the 'examples' directory. +Current examples include: + + + snoop Print all messages available to a client application + send Send a message of a specific mtype to one or more apps + + +Examples: + + 1) Print out messages received by a client application: + + % snoop print all available messages + % snoop -m image.load.fits print only the one mtype + % snoop -s topcat only message from 'TOPCAT' + + 2) Print the usage of the 'send' (or 'snoop') application: + + % send -h + + 3) Broadcast a message to all clients subscribed to a mtype: + + % send image.load.fits http://foo.edu/bar.fits testId testName + + 4) Send a message to a specific app (c4) using synchronous message pattern: + + % send -r c4 -p sync client.env.get HOME + + 5) Send a client multiple messages from a single connection: + + % cat msgs.txt + client.cmd.exec show noao + client.cmd.exec imstat dev$pix + client.cmd.exec imstat dev$pix[*,1:10] + client.cmd.exec imstat dev$pix[*,10:20] + client.cmd.exec imstat dev$pix[*,20:30] + % send -r iraf -f msgs.txt + + The message text file must containt the mtype as the first value, the + remainder of the line are the arguments specific to that mtype. + + +Note that each of these examples assumes an already-running Hub. A +standalone hub is provided in the 'jsamp' directory included in the +distribution. To start a hub from the toplevel directory: + + % java -jar jsamp/jsamp-1.3.jar hub + +This should be done before trying the above example. Note that applications +such as Topcat or Aladin have a builtin Hub that can also be used. + + diff --git a/vendor/voclient/libsamp/examples/send.c b/vendor/voclient/libsamp/examples/send.c new file mode 100644 index 00000000..72ed63d7 --- /dev/null +++ b/vendor/voclient/libsamp/examples/send.c @@ -0,0 +1,269 @@ +/** + * SEND - Example task to send a single SAMP message for the cmdline. + * + * Usage: + * + * % send [-hvd] [-r recipient] [-p pattern] [-f file] <mtype> [args ...] + * + * where <mtype> mtype of message to send + * -r <recipient> send to specified application (or all) + * -p <pattern> message pattern: sync|async|notify + * -f <file> send all commands in the file + * -h print help summary + * -v verbose output + * -d debug output + */ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <ctype.h> + +#include "samp.h" /* LIBSAMP interface */ + +#define SZ_MTYPE 64 +#define MAX_ARGS 8 +#define MATCH(s) (strcasecmp(mtype,s)==0) + +int samp = 0; /* samp struct handle */ + +int verbose = 0; /* task options */ +int debug = 0; +char *recip = "all"; +char *pattern = NULL; +char *cmdfile = NULL; +char mtype[SZ_MTYPE]; + +FILE *fd = (FILE *) NULL; + + +static char *name = "send"; /* metadata */ +static char *descr = "Example App"; + +static void help_summary (void); +static void procCmd (int samp, char *recip, char *mtype, char *args[], + int numargs); + + +/**************************************************************************** + * Program entry point. + */ +int +main (int argc, char **argv) +{ + char cmd[SZ_CMD], *args[MAX_ARGS], mtype[SZ_CMD]; + int i, j, len, numargs = 0; + + + memset (mtype, 0, SZ_MTYPE); /* initialize */ + for (i=0; i < MAX_ARGS; i++) + args[i] = calloc (1, SZ_LINE); + + /* Process commandline arguments. + */ + for (i=1; i < argc; i++) { + if (argv[i][0] == '-' && !(isdigit(argv[i][1]))) { + len = strlen (argv[i]); + for (j=1; j < len; j++) { + switch (argv[i][j]) { + case 'h': help_summary (); return (0); + case 'd': debug++; break; + case 'v': verbose++; break; + + case 'f': cmdfile = argv[++i]; j = len; break; + case 'p': pattern = argv[++i]; j = len; break; + case 'r': recip = argv[++i]; j = len; break; + + default: + fprintf (stderr, "Unknown option '%c'\n\n", argv[i][j]); + help_summary (); + break; + } + } + } else { + /* Remainder of argv is the mtype and its arguments. + */ + if (!mtype[0]) + strcpy (mtype, argv[i]); + else { + if (strcasecmp (mtype, "client.cmd.exec") == 0) { + strcat (args[0], argv[i]); + strcat (args[0], " "); + } else + strcpy (args[numargs++], argv[i]); + } + } + } + + + /* Initialize the SAMP interface. + */ + samp = sampInit (name, descr); + + /* Use Synchronous mode by default so we don't exit before receiving + * the reply. Otherwise, we could cause an error in the recipient. + */ + samp_setSyncMode (samp); + + /* Set alternative messaging pattern if requested. Valid values are + * 'synch', 'asynch' or 'notify'. This could just as well be done + * after the startup and would take effect for subsequent messages. + */ + if (pattern) { + switch (tolower(pattern[0])) { + case 's': break; /* default mode */ + case 'a': samp_setASyncMode (samp); break; + case 'n': samp_setNotifyMode (samp); break; + default: + if (verbose) + fprintf (stderr, "Warning: Invalid pattern '%s'\n", pattern); + } + } + + /* Register with the Hub and begin messaging. Since we're a single-shot + * command we won't bother to register metadata or subscribe to + * messages. The startup will run the server thread to handle the + * responses + */ + sampStartup (samp); + + + /* Process the messages in the named file, or from the cmdline. Since + * there is some overhead in connecting to the hub, this is an efficient + * way to send multiple messages from a single connection. + */ + if (cmdfile) { + fd = (cmdfile[0] == '-' ? stdin : fopen (cmdfile, "r")); + if (fd) { + memset (cmd, 0, SZ_CMD); + while (fgets (cmd, SZ_CMD, fd)) { + cmd[strlen(cmd)-1] = '\0'; /* kill newline */ + memset (mtype, 0, SZ_CMD); + memset (&args[0][0], 0, (SZ_MTYPE * MAX_ARGS)); + + if (strncasecmp (cmd, "client.cmd.exec", 15) == 0) { + /* special-case for exec command to create a single arg */ + strcpy (mtype, "client.cmd.exec"); + sprintf (args[0], "%s", &cmd[16]); + numargs = 1; + + } else { + numargs = sscanf (cmd, "%s %s %s %s %s %s %s %s %s", + mtype, args[0], args[1], args[2], args[3], + args[4], args[5], args[6], args[7]); + } + + procCmd (samp, recip, mtype, args, numargs); + } + if (fd != stdin) + fclose (fd); + } else + fprintf (stderr, "Cannot open input file '%s'\n", cmdfile); + + } else + procCmd (samp, recip, mtype, args, numargs); + + + if (sampShutdown (samp) < 0) /* clean up */ + fprintf (stderr, "SAMP shutdown fails\n"); + sampClose (samp); + + return (0); +} + + +/** + * + */ +static void +procCmd (int samp, char *recip, char *mtype, char *args[], int numargs) +{ + int stat = 0; + + + /* Format the message and send it. + */ + if (MATCH ("samp.app.ping")) { + stat = samp_Ping (samp, recip); + + } else if (MATCH ("table.load.fits")) { + stat = samp_tableLoadFITS (samp, recip, args[0], args[1], args[2]); + + } else if (MATCH ("table.load.votable")) { + stat = samp_tableLoadVOTable (samp, recip, args[0], args[1], + args[2]); + + } else if (MATCH ("table.highlight.row")) { + stat = samp_tableHighlightRow (samp, recip, args[0], args[1], + atoi(args[2])); + + } else if (MATCH ("image.load.fits")) { + stat = samp_imageLoadFITS (samp, recip, args[0], args[1], args[2]); + + } else if (MATCH ("coord.pointAt.sky")) { + stat = samp_coordPointAtSky (samp, recip, + atof(args[0]), atof(args[1])); + + } else if (MATCH ("client.cmd.exec")) { + if (verbose) + printf ("Sending: '%s'\n", args[0]); + samp_cmdExec (samp, recip, args[0]); + + } else if (MATCH ("client.env.get")) { + char *v = samp_envGet (samp, recip, args[0]); + printf ("%s\n", v); + free ((void *) v); + + } else if (MATCH ("client.env.set")) { + stat = samp_envSet (samp, recip, args[0], args[1]); + + } else if (MATCH ("client.param.get")) { + char *v = samp_paramGet (samp, recip, args[0]); + printf ("%s\n", v); + free ((void *) v); + + } else if (MATCH ("client.param.set")) { + stat = samp_paramSet (samp, recip, args[0], args[1]); + + } else if (MATCH ("bibcode.load")) { + stat = samp_bibLoad (samp, recip, args[1]); + + } else { + stat = samp_sendGeneric (samp, recip, mtype, args); + } + + if (verbose) + fprintf (stderr, "%s\n", (stat < 0 ? "Error" : "OK")); +} + + +static void +help_summary (void) +{ + fprintf (stderr, + " Usage:\n" + " %% send [-hvd] [-f file] [-r recip] [-p pattern] <mtype> [args....]\n" + "\n" + " where <mtype> mtype of message to send\n" + " -r <recipient> send to specified app (or 'all')\n" + " -p <pattern> message pattern: sync|async|notify\n" + " -f <file> send messages in the named file\n" + " -h print help summary\n" + " -v verbose output\n" + " -d debug output\n" + "\n" + " Valid mtypes and required params are:\n" + "\n" + " samp.app.ping\n" + " table.load.votable url [table-id] [name]\n" + " table.load.fits url [table-id] [name]\n" + " image.load.fits url [image-id] [name]\n" + " client.cmd.exec cmd_str\n" + " client.env.set keyw value\n" + " client.env.get keyw\n" + " client.param.set keyw value\n" + " client.param.get keyw\n" + "\n" + ); +} diff --git a/vendor/voclient/libsamp/examples/snoop.c b/vendor/voclient/libsamp/examples/snoop.c new file mode 100644 index 00000000..7fb511cc --- /dev/null +++ b/vendor/voclient/libsamp/examples/snoop.c @@ -0,0 +1,149 @@ +/** + * SNOOP - Example task to subscribe to all message and print them out. + * + * Usage: + * % snoop [-m mtype] [-s sender] [-v] [-d] + * + * where -m <mtype> print only the given mtype + * -s <sender> print messages from named sender + * -v verbose output + * -d debug output + */ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <ctype.h> + +#include "samp.h" /* LIBSAMP interface */ + + + +int samp = 0; /* samp struct handle */ + +int verbose = 0; /* task options */ +int debug = 0; +char *mtype = NULL; +char *filt_mtype = NULL; +char *filt_sender = NULL; + +static char *name = "snoop"; /* metadata */ +static char *descr = "Example App"; + + +static void help_summary (void); + + + +/**************************************************************************** + * Simple user-methods to install as message handlers. In this case + * we have a simple method to filter message by type or sender so we + * only print the desired messages. + */ + +void msg_handler (char *sender, char *msg_id, int params) +{ + if (filt_sender && strcasecmp (filt_sender, sender)) + return; + if (filt_mtype && strcasecmp (filt_mtype, mtype)) + return; + + /* Either no filters were set, or the message is of the requested type, + * print the contents. + */ + samp_printMessage (mtype, sender, msg_id, params); +} + + + +/**************************************************************************** + * Program entry point. + */ +int +main (int argc, char **argv) +{ + int i, j, len; + char cmd[SZ_CMD]; + + + /* Process commandline arguments. + */ + memset (cmd, 0, SZ_CMD); + for (i=1; i < argc; i++) { + if (argv[i][0] == '-' && !(isdigit(argv[i][1]))) { + len = strlen (argv[i]); + for (j=1; j < len; j++) { + switch (argv[i][j]) { + case 'm': filt_mtype = argv[++i]; j = len; break; + case 's': filt_sender = argv[++i]; j = len; break; + case 'd': debug++; break; + case 'v': verbose++; break; + default: + fprintf (stderr, "Unknown option '%c'\n\n", argv[i][j]); + help_summary (); + break; + } + } + } else + break; + } + + + /* Initialize the SAMP interface. + */ + samp = sampInit (name, descr); + + /* Set up some local application metadata values. These tell the + * Hub and other applications who we are. + */ + samp_Metadata (samp, "author.email", "Will E Coyote"); + samp_Metadata (samp, "author.name", "rascal@acme.com"); + + /* Subscribe to all message types and install the message handler. + */ + samp_Subscribe (samp, "*", msg_handler); + + /* Register with the Hub and begin messaging ..... + */ + sampStartup (samp); + + /* Loop until we're told to quit. + */ + memset (cmd, 0, SZ_CMD); + do { + if (cmd[0] == 'q') + break; + printf ("Type 'q' to quit ......\n"); + } while (fgets (cmd, SZ_CMD, stdin)); + + + /* Clean up. The Shutdownunregisters us from the Hub, we then need + * to close the interface separately to free any allocated memory. + */ + if (sampShutdown (samp) < 0) + fprintf (stderr, "Shutdown fails\n"); + sampClose (samp); + + return (0); +} + + + +/******************************** + ** Private methods. + *******************************/ +static void +help_summary (void) +{ + fprintf (stderr, + " Usage:\n" + " %% snoop [-m mtype] [-s sender] [-v] [-d]\n" + "\n" + " where -m <mtype> print only the given mtype\n" + " -s <sender> print messages from named sender\n" + " -v verbose output\n" + " -d debug output\n" + "\n" + ); +} |