logevent: logevent.o args.o
${LINK} -o $@ logevent.o args.o ${LIB} ${EXT_LIB}
-notify: notify.o
- ${LINK} -o $@ notify.o ${LIB} ${EXT_LIB}
+notify: notify.o notify_supp.o
+ ${LINKXX} -o $@ notify.o notify_supp.o ${PLUSLIB} ${EXT_LIB}
${TOOLS} ${EXAMPLES}: %: %.o
${LINK} -o $@ $< ${LIB} ${EXT_LIB}
${FAKE_EXAMPLES:=.o}: %.o: %.cpp
${COMPILE} ${TEST_INC} -c $< -o $@
-${PLUSOBJS}: %.o: %.cpp
+notify_supp.o ${PLUSOBJS}: %.o: %.cpp
${CXXCOMPILE} -c $<
${PLUSTHROBJS}: %.thr.o: %.cpp
#include "glite/lb/context.h"
#include "glite/lb/notification.h"
+#include "notify_supp.h"
+
static char *me;
fprintf(stderr,"\n'refresh' command usage: %s refresh notifid\n"
" notifid Notification ID.\n", me);
if ( !cmd || !strcmp(cmd, "receive") )
- fprintf(stderr,"\n'receive' command usage: %s receive [ { -s socket_fd | -a fake_addr } ] [-t timeout] [notifid]\n"
+ fprintf(stderr,"\n'receive' command usage: %s receive [ { -s socket_fd | -a fake_addr } ] [-t timeout] [-f field1,field2,...] [notifid]\n"
" notifid Notification ID (not used if -s specified).\n"
" fake_addr Fake the client address.\n"
+ " field1,field2,... list of status fields to print (only owner by default)\n"
" timeout Timeout to receive operation in seconds.\n", me);
if ( !cmd || !strcmp(cmd, "drop") )
fprintf(stderr,"\n'drop' command usage: %s drop notifid\n"
time_t valid;
char *errt, *errd;
struct timeval tout = {220, 0};
+ void *fields = NULL;
int sock = -1;
char *fake_addr = NULL;
edg_wll_JobStat stat;
edg_wll_NotifId nid = NULL;
int c;
+ char *field_arg = "owner",*err;
- while ((c = getopt(argc-1,argv+1,"s:a:t:")) > 0) switch (c) {
+ while ((c = getopt(argc-1,argv+1,"s:a:t:f:")) > 0) switch (c) {
case 's':
if (fake_addr) { usage("receive"); return EX_USAGE; }
sock = atoi(optarg); break;
fake_addr = optarg; break;
case 't':
tout.tv_sec = atoi(optarg); break;
+ case 'f':
+ field_arg = optarg; break;
default:
usage("receive"); return EX_USAGE;
}
+ if ((err = parse_fields(field_arg,&fields))) {
+ fprintf(stderr,"%s: invalid argument\n",err);
+ return EX_USAGE;
+ }
memset(&stat,0,sizeof stat);
else goto receive_err;
}
- printf("\nnotification ID: %s\n", edg_wll_NotifIdUnparse(recv_nid));
+ print_fields(fields,recv_nid,&stat);
+
+/* original example */
+#if 0
+ printf("\nnotification ID: %s\n", edg_wll_NotifIdUnparse(recv_nid));
if (stat.state != EDG_WLL_JOB_UNDEF) {
char *jobid_s;
free(jobid_s);
stat.state = EDG_WLL_JOB_UNDEF;
}
+#endif
if (recv_nid) {
edg_wll_NotifIdFree(recv_nid);
--- /dev/null
+#include <stdlib.h>
+#include <string.h>
+#include <iostream>
+#include <vector>
+
+#include "glite/lb/LoggingExceptions.h"
+#include "glite/lb/JobStatus.h"
+#include "glite/lb/notification.h"
+
+#include "notify_supp.h"
+
+using namespace glite::lb;
+
+char * parse_fields(const char *arg,void **out)
+{
+ char *aux = strdup(arg),*p;
+ std::vector<JobStatus::Attr> *fields = new std::vector<JobStatus::Attr>;
+
+ for (p = strtok(aux,","); p; p = strtok(NULL,",")) {
+ try { fields->push_back(JobStatus::attrByName(p)); }
+ catch (std::runtime_error &e) { delete fields; return p; };
+ }
+
+ *out = (void *) fields;
+ return NULL;
+}
+
+std::string & escape(std::string &s)
+{
+ for (std::string::iterator p = s.begin(); p < s.end(); p++) switch (*p) {
+ case '\n':
+ case '\t':
+ s.insert(p-s.begin(),"\\"); p++;
+ break;
+ default: break;
+ }
+ return s;
+}
+
+typedef std::vector<std::pair<JobStatus::Attr,JobStatus::AttrType> > attrs_t;
+
+void print_fields(void **ff,const edg_wll_NotifId n,edg_wll_JobStat const *s)
+{
+ std::vector<JobStatus::Attr> *fields = (std::vector<JobStatus::Attr> *) ff;
+ JobStatus stat(*s,0);
+ attrs_t attrs = stat.getAttrs();
+ attrs_t::iterator a;
+
+ std::cout << glite_jobid_unparse(s->jobId) << '\t' << stat.name() << '\t';
+
+ for (std::vector<JobStatus::Attr>::iterator f = fields->begin(); f != fields->end(); f++) {
+ for (a = attrs.begin(); a != attrs.end() && a->first != *f; a++);
+ if (a != attrs.end() ) switch (a->second) {
+ case JobStatus::INT_T:
+ std::cout << stat.getValInt(a->first) << '\t';
+ break;
+ case JobStatus::STRING_T: {
+ std::string val = stat.getValString(a->first);
+ std::cout << (val.empty() ? "(null)" : escape(val)) << '\t';
+ } break;
+ default:
+ std::cout << "(unsupported)";
+ break;
+ }
+ }
+ std::cout << std::endl;
+}