Commit c65374d0 authored by Leigh B. Stoller's avatar Leigh B. Stoller
Browse files

Minor rework of the example code. Get rid of example.c, and add

tbsend.c and tbrecv.c, which are trivial examples of how to send
and receive a sample event.
parent c9fc7b71
......@@ -3,7 +3,7 @@ TESTBED_SRCDIR = @top_srcdir@
OBJDIR = ../..
SUBDIR = event/example
PROGRAMS = example
PROGRAMS = tbrecv tbsend
include $(OBJDIR)/Makeconf
......@@ -16,7 +16,7 @@ CFLAGS += -O -g -static -Wall -pthread
CFLAGS += -I. -I${OBJDIR} -I$(SRCDIR)/../lib -I$(TESTBED_SRCDIR)/lib/libtb
CFLAGS += `elvin-config --cflags vin4mt`
LDFLAGS += -pthread -L../lib -L${OBJDIR}/lib/libtb
LDFLAGS += -pthread -static -L../lib -L${OBJDIR}/lib/libtb
LIBS += -levent -ltb
LIBS += -lcipher -lc_r
......@@ -28,8 +28,11 @@ LIBS += -lcipher -lc_r
#LIBS += `elvin-config --libs vin4mt`
LIBS += -L/usr/local/lib -lvin4mt -lvin4c -lvin4 -lssl -lcrypto -lm
example: example.o
$(CC) $(LDFLAGS) -static -o $@ example.o $(LIBS)
tbrecv: tbrecv.o
$(CC) $(LDFLAGS) -o $@ tbrecv.o $(LIBS)
tbsend: tbsend.o
$(CC) $(LDFLAGS) -o $@ tbsend.o $(LIBS)
$(PROGRAMS): ../lib/libevent.a ../lib/event.h
......
/*
* This is a sample client to run on a testbed node to capture all
* testbed events for the node. Modify as needed of course.
* This is a sample client to run on a testbed node to capture TBEXAMPLE
* events for the node. Modify as needed of course.
*/
#include <stdio.h>
......@@ -72,7 +72,7 @@ main(int argc, char **argv)
}
if (! (he = gethostbyname(buf))) {
fatal("could not get IP address from hostname");
fatal("could not get IP address from hostname: %s", buf);
}
memcpy((char *)&myip, he->h_addr, he->h_length);
strcpy(ipbuf, inet_ntoa(myip));
......@@ -103,11 +103,11 @@ main(int argc, char **argv)
/*
* Change this stuff as needed.
*/
tuple->host = ipaddr;
tuple->host = ADDRESSTUPLE_ALL;
tuple->site = ADDRESSTUPLE_ANY;
tuple->group = ADDRESSTUPLE_ANY;
tuple->expt = ADDRESSTUPLE_ANY; /* pid/eid */
tuple->objtype = ADDRESSTUPLE_ANY;
tuple->objtype = "TBEXAMPLE";
tuple->objname = ADDRESSTUPLE_ANY;
tuple->eventtype = ADDRESSTUPLE_ANY;
......@@ -161,7 +161,9 @@ callback(event_handle_t handle, event_notification_t notification, void *data)
event_notification_get_objname(handle, notification, buf[5], len);
event_notification_get_eventtype(handle, notification, buf[6], len);
info("Event: %lu %s %s %s %s %s %s %s\n", now.tv_sec,
info("Event: %lu:%d %s %s %s %s %s %s %s\n", now.tv_sec, now.tv_usec,
buf[0], buf[1], buf[2],
buf[3], buf[4], buf[5], buf[6]);
exit(0);
}
/*
* This is a sample event generator to send TBEXAMPLE events to all nodes
* in an experiment. Modify as needed of course.
*/
#include <stdio.h>
#include <ctype.h>
#include <netdb.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <time.h>
#include "log.h"
#include "event.h"
static char *progname;
void
usage()
{
fprintf(stderr,
"Usage: %s [-s server] [-p port] <event>\n",
progname);
exit(-1);
}
int
main(int argc, char **argv)
{
event_handle_t handle;
event_notification_t notification;
address_tuple_t tuple;
char *server = NULL;
char *port = NULL;
char buf[BUFSIZ], *bp;
struct timeval now;
int c;
progname = argv[0];
while ((c = getopt(argc, argv, "s:p:")) != -1) {
switch (c) {
case 's':
server = optarg;
break;
case 'p':
port = optarg;
break;
default:
usage();
}
}
argc -= optind;
argv += optind;
if (argc != 1)
usage();
loginit(0, 0);
/*
* Uppercase event tags for now. Should be wired in list instead.
*/
bp = argv[0];
while (*bp) {
*bp = toupper(*bp);
bp++;
}
/*
* Convert server/port to elvin thing.
*
* XXX This elvin string stuff should be moved down a layer.
*/
if (server) {
snprintf(buf, sizeof(buf), "elvin://%s%s%s",
server,
(port ? ":" : ""),
(port ? port : ""));
server = buf;
}
/*
* Construct an address tuple for generating the event.
*/
tuple = address_tuple_alloc();
if (tuple == NULL) {
fatal("could not allocate an address tuple");
}
tuple->objtype = "TBEXAMPLE";
tuple->eventtype= argv[0];
tuple->host = ADDRESSTUPLE_ALL;
/* Register with the event system: */
handle = event_register(server, 0);
if (handle == NULL) {
fatal("could not register with event system");
}
/* Generate the event */
notification = event_notification_alloc(handle, tuple);
if (notification == NULL) {
fatal("could not allocate notification");
}
gettimeofday(&now, NULL);
if (event_notify(handle, notification) == 0) {
fatal("could not send test event notification");
}
info("Sent at time: %lu:%d\n", now.tv_sec, now.tv_usec);
event_notification_free(handle, notification);
/* Unregister with the event system: */
if (event_unregister(handle) == 0) {
fatal("could not unregister with event system");
}
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment