example code moved from lb.client
authorMichal Voců <michal@ruk.cuni.cz>
Wed, 26 Mar 2008 15:13:18 +0000 (15:13 +0000)
committerMichal Voců <michal@ruk.cuni.cz>
Wed, 26 Mar 2008 15:13:18 +0000 (15:13 +0000)
org.glite.lb.doc/examples/Makefile [new file with mode: 0644]
org.glite.lb.doc/examples/client_headers.h [new file with mode: 0644]
org.glite.lb.doc/examples/example1.c [new file with mode: 0644]
org.glite.lb.doc/examples/example1_code.c [new file with mode: 0644]
org.glite.lb.doc/examples/util.c [new file with mode: 0644]

diff --git a/org.glite.lb.doc/examples/Makefile b/org.glite.lb.doc/examples/Makefile
new file mode 100644 (file)
index 0000000..62b09a8
--- /dev/null
@@ -0,0 +1,81 @@
+glite_location:=${GLITE_LOCATION}
+glite_prefix:=${glite_location}
+
+nothrflavour=gcc32dbg
+thrflavour=gcc32dbgpthr
+
+CC:=gcc
+CXX:=g++
+
+COMMON_LIB:=-lglite_lb_common_${nothrflavour}
+COMMON_LIB_THR:=-lglite_lb_common_${thrflavour}
+CLIENT_LIB:=-lglite_lb_client_${nothrflavour}
+CLIENT_LIB_THR:=-lglite_lb_client_${thrflavour}
+JOBID_LIB:=-lglite_jobid
+
+LIB:=${COMMON_LIB} ${CLIENT_LIB} ${JOBID_LIB}
+LIB_THR:=${COMMON_LIB_THR} ${CLIENT_LIB_THR} ${JOBID_LIB}
+PLUSLIB:=
+PLUSLIB_THR:=
+
+CFLAGS:=${DEBUG} \
+       -I${glite_prefix}/include \
+       -D_GNU_SOURCE 
+
+CXXFLAGS:=${CFLAGS}
+
+host_cpu:=${shell uname -m}
+ifeq (${host_cpu},x86_64)
+       LDFLAGS:=-L${glite_prefix}/lib64 
+else
+       LDFLAGS:=-L${glite_prefix}/lib
+endif
+
+COMPILE:=libtool --mode=compile ${CC} ${CFLAGS}
+CXXCOMPILE:=libtool --mode=compile ${CXX} ${CXXFLAGS}
+LINK:=libtool --mode=link ${CC} ${LDFLAGS} 
+LINKXX:=libtool --mode=link ${CXX} ${LDFLAGS}
+INSTALL:=libtool --mode=install install
+
+EXAMPLES_SRC:=example1.c
+EXAMPLES:=${EXAMPLES_SRC:.c=}
+
+EXTRA_SRC:=util.c
+EXTRA_OBJ:=${EXTRA_SRC:.c=.o}
+
+# TODO: migrate them here from branch_RC31_3
+# EXAMPLES_PLUS_SRC:=
+# EXAMPLES_PLUS:=${EXAMPLES_PLUS_SRC:.cpp=}
+# EXAMPLES_PLUS_THR_SRC:=
+# EXAMPLES_PLUS_THR:=${EXAMPLES_PLUS_THR_SRC:.cpp=}
+
+EXAMPLES_THR_SRC:=
+EXAMPLES_THR:=${EXAMPLES_CL_THR_SRC:.c=}
+
+default all: examples
+
+examples: ${EXAMPLES} ${EXAMPLES_THR} ${EXAMPLES_PLUS} ${EXAMPLES_PLUS_THR}
+
+${EXAMPLES}: %: %.o ${EXTRA_OBJ}
+       ${LINK} -o $@ $< ${EXTRA_OBJ} ${LIB}
+
+${EXAMPLES_THR}: %: %.o
+       ${LINK} -o $@ $< ${LIB_THR}
+
+${EXAMPLES_PLUS}: %: %.o
+       ${LINKXX} -o $@ $< ${PLUSLIB}
+
+${EXAMPLES_PLUS_THR}: %: %.o
+       ${LINKXX} -o $@ $< ${PLUSLIB_THR}
+
+# catches $TOOLS and logevent compilation
+%.o: %.c 
+       ${CC} ${CFLAGS} -c $<
+
+%.o: %.cpp
+       ${CXX} ${CXXFLAGS} -c $<
+
+clean:
+       rm -rvf ${EXAMPLES} ${EXAMPLES_CL} ${EXAMPLES_CL_THR} 
+       rm -rvf *.o .libs/
+
diff --git a/org.glite.lb.doc/examples/client_headers.h b/org.glite.lb.doc/examples/client_headers.h
new file mode 100644 (file)
index 0000000..c4cd498
--- /dev/null
@@ -0,0 +1,4 @@
+#include "glite/lb/context.h"
+#include "glite/lb/xml_conversions.h"
+#include "glite/lb/consumer.h"
+
diff --git a/org.glite.lb.doc/examples/example1.c b/org.glite.lb.doc/examples/example1.c
new file mode 100644 (file)
index 0000000..a26c451
--- /dev/null
@@ -0,0 +1,20 @@
+#ident "$Header$"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <expat.h>
+
+#include "client_headers.h"
+
+#include "glite/lb/xml_conversions.h"
+
+extern void print_jobs(edg_wll_JobStat *);
+
+int main(int argc,char **argv)
+{
+
+#include "example1_code.c"
+
+       return 0;
+}
diff --git a/org.glite.lb.doc/examples/example1_code.c b/org.glite.lb.doc/examples/example1_code.c
new file mode 100644 (file)
index 0000000..e12a1b7
--- /dev/null
@@ -0,0 +1,31 @@
+edg_wll_Context     ctx;    
+edg_wll_JobStat    *statesOut = NULL;
+edg_wll_QueryRec    jc[2];
+
+edg_wll_InitContext(&ctx);
+
+jc[0].attr = EDG_WLL_QUERY_ATTR_JOBID;
+jc[0].op = EDG_WLL_QUERY_OP_EQUAL;
+if ( edg_wlc_JobIdParse(
+            "https://lhun.ics.muni.cz:9000/OirOgeWh_F9sfMZjnIPYhQ",
+            &jc[0].value.j) )
+{
+       edg_wll_FreeContext(ctx);
+       exit(1);
+}
+jc[1].attr = EDG_WLL_QUERY_ATTR_UNDEF;
+if (edg_wll_QueryJobs(ctx, jc, 0, NULL, &statesOut)) {
+       char    *err_text,*err_desc;
+       
+       edg_wll_Error(ctx,&err_text,&err_desc);
+       fprintf(stderr,"QueryJobs: %s (%s)\n",err_text,err_desc);
+       free(err_text);
+       free(err_desc);
+}
+else {
+       print_jobs(statesOut);  /* process the returned data */
+       edg_wll_FreeStatus(statesOut);
+       free(statesOut);
+}
+edg_wlc_JobIdFree(jc[0].value.j);
+edg_wll_FreeContext(ctx);
diff --git a/org.glite.lb.doc/examples/util.c b/org.glite.lb.doc/examples/util.c
new file mode 100644 (file)
index 0000000..73be67a
--- /dev/null
@@ -0,0 +1,54 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <expat.h>
+
+#include "client_headers.h"
+
+
+int use_proxy = 0;
+
+void
+print_jobs(edg_wll_JobStat *states) 
+{
+       int             i,j;
+
+       for (i=0; states[i].state != EDG_WLL_JOB_UNDEF; i++) {  
+               char *id = edg_wlc_JobIdUnparse(states[i].jobId);
+               char *st = edg_wll_StatToString(states[i].state);
+               
+               if (!states[i].parent_job) {
+                       if (states[i].jobtype == EDG_WLL_STAT_SIMPLE) { 
+                               printf("      %s .... %s %s\n", id, st, (states[i].state==EDG_WLL_JOB_DONE) ? edg_wll_done_codeToString(states[i].done_code) : "" );
+                       }
+                       else if ((states[i].jobtype == EDG_WLL_STAT_DAG) || 
+                               (states[i].jobtype == EDG_WLL_STAT_COLLECTION)) {
+                               printf("%s  %s .... %s %s\n", (states[i].jobtype==EDG_WLL_STAT_DAG)?"DAG ":"COLL",id, st, (states[i].state==EDG_WLL_JOB_DONE) ? edg_wll_done_codeToString(states[i].done_code) : "");
+                               for (j=0; states[j].state != EDG_WLL_JOB_UNDEF; j++) {
+                                       if (states[j].parent_job) {
+                                               char *par_id = edg_wlc_JobIdUnparse(states[j].parent_job);
+                                               
+                                               if (!strcmp(id,par_id)) {
+                                                       char *sub_id = edg_wlc_JobIdUnparse(states[j].jobId),
+                                                            *sub_st = edg_wll_StatToString(states[j].state);
+                                                       
+                                                       printf(" `-       %s .... %s %s\n", sub_id, sub_st, (states[j].state==EDG_WLL_JOB_DONE) ? edg_wll_done_codeToString(states[j].done_code) : "");
+                                                       free(sub_id);
+                                                       free(sub_st);
+                                               }
+                                               free(par_id);
+                                       }       
+                               }
+                       }
+               }
+                       
+               free(id);
+               free(st);
+       }
+
+       printf("\nFound %d jobs\n",i);
+}
+
+
+