From: Aleš Křenek Date: Wed, 27 Feb 2008 12:51:03 +0000 (+0000) Subject: implemented -f field1,field2,... X-Git-Tag: glite-yaim-myproxy_R_4_0_1_4~20 X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=65f005d12a27b57aee896ea0d85073a6df1224fd;p=jra1mw.git implemented -f field1,field2,... --- diff --git a/org.glite.lb.client/Makefile b/org.glite.lb.client/Makefile index 9d52c2c..646910a 100644 --- a/org.glite.lb.client/Makefile +++ b/org.glite.lb.client/Makefile @@ -220,8 +220,8 @@ ${THRPLUSLIB}: ${PLUSTHROBJS} ${THRLIB} 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} @@ -240,7 +240,7 @@ ${TOOLS}: ${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 diff --git a/org.glite.lb.client/src/notify.c b/org.glite.lb.client/src/notify.c index 6d56466..9445a47 100644 --- a/org.glite.lb.client/src/notify.c +++ b/org.glite.lb.client/src/notify.c @@ -10,6 +10,8 @@ #include "glite/lb/context.h" #include "glite/lb/notification.h" +#include "notify_supp.h" + static char *me; @@ -62,9 +64,10 @@ static void usage(char *cmd) 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" @@ -78,6 +81,7 @@ int main(int argc,char **argv) time_t valid; char *errt, *errd; struct timeval tout = {220, 0}; + void *fields = NULL; int sock = -1; char *fake_addr = NULL; @@ -182,8 +186,9 @@ int main(int argc,char **argv) 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; @@ -192,10 +197,16 @@ int main(int argc,char **argv) 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); @@ -223,7 +234,11 @@ int main(int argc,char **argv) 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; @@ -236,6 +251,7 @@ int main(int argc,char **argv) free(jobid_s); stat.state = EDG_WLL_JOB_UNDEF; } +#endif if (recv_nid) { edg_wll_NotifIdFree(recv_nid); diff --git a/org.glite.lb.client/src/notify_supp.cpp b/org.glite.lb.client/src/notify_supp.cpp new file mode 100644 index 0000000..1b7bd61 --- /dev/null +++ b/org.glite.lb.client/src/notify_supp.cpp @@ -0,0 +1,67 @@ +#include +#include +#include +#include + +#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 *fields = new std::vector; + + 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 > attrs_t; + +void print_fields(void **ff,const edg_wll_NotifId n,edg_wll_JobStat const *s) +{ + std::vector *fields = (std::vector *) 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::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; +}