]> jspc29.x-matter.uni-frankfurt.de Git - daqdata.git/commitdiff
Allow asynchronous rpc for system command -- mm
authorhadaq <hadaq>
Sat, 9 Nov 2002 10:03:18 +0000 (10:03 +0000)
committerhadaq <hadaq>
Sat, 9 Nov 2002 10:03:18 +0000 (10:03 +0000)
hadaq/agent.c
hadaq/agent.x
hadaq/tcldaq.c

index 7c2aee0e92dc41c9fd9579b7f3ec73d604b89b5c..a14b03e411f65847a8e505c99d77bb0625f7d3f1 100644 (file)
@@ -1,4 +1,4 @@
-static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/agent.c,v 6.9 2002-10-28 07:41:18 hadaq Exp $";
+static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/agent.c,v 6.10 2002-11-09 10:03:18 hadaq Exp $";
 
 #define _GNU_SOURCE
 #include <unistd.h>
@@ -91,7 +91,7 @@ int * rpcworker_stop_1_svc(int *dummy, struct svc_req *x)
        return rpcworker_stop_1(dummy, NULL);
 }
 
-int *rpcsystem_1(char **command, CLIENT * cl)
+void *rpcsystem_1(char **command, CLIENT * cl)
 {
        static int retVal;
 
@@ -100,7 +100,21 @@ int *rpcsystem_1(char **command, CLIENT * cl)
        return &retVal;
 }
 
-int * rpcsystem_1_svc(char **dummy, struct svc_req *x)
+void * rpcsystem_1_svc(char **dummy, struct svc_req *x)
 {
        return rpcsystem_1(dummy, NULL);
 }
+
+int *rpcjoin_1(int *dummy, CLIENT * cl)
+{
+       static int retVal;
+
+       retVal = 0;
+
+       return &retVal;
+}
+
+int * rpcjoin_1_svc(int *dummy, struct svc_req *x)
+{
+       return rpcjoin_1(dummy, NULL);
+}
index e3f5a528097ac151962e2a2365d1ce1a04fc068d..4573815649b78bc81333212b0507635657400698 100644 (file)
@@ -10,6 +10,7 @@ program DAQAGENTPROG {
                int RpcWorker_start(RpcWorker_startArgs) = 1;
                string RpcWorker_status(int) = 2;
                int RpcWorker_stop(int) = 3;
-               int RpcSystem(string) = 4;
+               void RpcSystem(string) = 4;
+               int RpcJoin(int) = 5;
        } = 1;
 } = 0x20000002;
index 7633263abf7a80d31883b1acba77d97482d06606..9d179b4117f53122c7580f63ac548c51b105d7a9 100644 (file)
@@ -1,4 +1,4 @@
-static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/tcldaq.c,v 6.8 2002-11-08 15:16:03 hadaq Exp $";
+static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/tcldaq.c,v 6.9 2002-11-09 10:03:18 hadaq Exp $";
 
 #define _GNU_SOURCE
 #include <unistd.h>
@@ -15,6 +15,16 @@ static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hada
 #include "worker.h"
 #include "agent.h"
 
+#define MAX_NTHR 16
+static nThr = 0;
+static char agents[MAX_NTHR][512];
+
+typedef struct ThrArgsS {
+       int id;
+       char *agent;
+       char *command;
+} ThrArgs;
+
 int AgentCmd(ClientData clientData, Tcl_Interp * interp, int argc, char *argv[])
 {
        CLIENT *cl;
@@ -93,22 +103,60 @@ int WorkerCmd(ClientData clientData, Tcl_Interp * interp, int argc, char *argv[]
 
 int SystemCmd(ClientData clientData, Tcl_Interp * interp, int argc, char *argv[])
 {
+       int SystemCmdR = 0;
        CLIENT *cl;
-       int res, *resP;
 
        if (argc < 3) {
                Tcl_AppendResult(interp, "usage: c_system <agent> command", NULL);
                return TCL_ERROR;
        }
-       sscanf(argv[1], "%p", &cl);
-       if (NULL == (resP = rpcsystem_1(&argv[2], cl))) {
-               Tcl_AppendResult(interp, clnt_sperror(cl, "rpcsystem_1"), NULL);
-               return TCL_ERROR;
+       strcpy(agents[nThr++], argv[1]);
+       if (NULL == (cl = clnt_create(argv[1], DAQAGENTPROG, DAQAGENTVERS, "tcp"))) {
+               clnt_pcreateerror("clnt_create");
+               SystemCmdR = -1;
+       } else {
+               static struct timeval TIMEOUT = { 0, 0 };
+               clnt_control(cl, CLSET_TIMEOUT, (char *)&TIMEOUT);
+               if (NULL == rpcsystem_1(&argv[2], cl)) {
+                       clnt_perror(cl, "rpcsystem_1");
+                       SystemCmdR = 0;
+               } else {
+                       SystemCmdR = 0;
+               }
+               clnt_destroy(cl);
        }
-       res = *resP;
-       sprintf(interp->result, "%d", res);
+       sprintf(interp->result, "%d", SystemCmdR);
 
-       return TCL_OK;
+       return SystemCmdR == 0 ? TCL_OK : TCL_ERROR;
+}
+
+int JoinAllCmd(ClientData clientData, Tcl_Interp * interp, int argc, char *argv[])
+{
+       int JoinAllCmdR;
+       CLIENT *cl;
+       int res;
+
+       JoinAllCmdR = 0;
+       while (nThr > 0) {
+               --nThr;
+               if (NULL == (cl = clnt_create(agents[nThr], DAQAGENTPROG, DAQAGENTVERS, "tcp"))) {
+                       clnt_pcreateerror("clnt_create");
+                       JoinAllCmdR = -1;
+               } else {
+                       static struct timeval TIMEOUT = { 120, 0 };
+                       clnt_control(cl, CLSET_TIMEOUT, (char *)&TIMEOUT);
+                       if (NULL == rpcjoin_1(&res, cl)) {
+                               clnt_perror(cl, "rpcjoin_1");
+                               JoinAllCmdR = -1;
+                       } else {
+                               JoinAllCmdR = 0;
+                       }
+                       clnt_destroy(cl);
+               }
+       }
+       sprintf(interp->result, "%d", JoinAllCmdR);
+
+       return JoinAllCmdR == 0 ? TCL_OK : TCL_ERROR;
 }
 
 int Daq_Init(Tcl_Interp * interp)
@@ -120,6 +168,7 @@ int Daq_Init(Tcl_Interp * interp)
        Tcl_CreateCommand(interp, "c_worker", WorkerCmd, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
        Tcl_CreateCommand(interp, "c_agent", AgentCmd, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
        Tcl_CreateCommand(interp, "c_system", SystemCmd, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
+       Tcl_CreateCommand(interp, "c_joinall", JoinAllCmd, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
 
        /*
    * Specify a user-specific startup file to invoke if the application