(file) Return to daVarRpcProc.c CVS log (file) (dir) Up to [HallC] / Analyzer / CTP

  1 saw   1.1 /*-----------------------------------------------------------------------------
  2            * Copyright (c) 1993 Southeastern Universities Research Association,
  3            *                    Continuous Electron Beam Accelerator Facility
  4            *
  5            * This software was developed under a United States Government license
  6            * described in the NOTICE file included as part of this distribution.
  7            *
  8            * Stephen A. Wood, 12000 Jefferson Ave., Newport News, VA 23606
  9            * Email: saw@cebaf.gov  Tel: (804) 249-7367  Fax: (804) 249-5800
 10            *-----------------------------------------------------------------------------
 11            * 
 12            * Description:
 13            *  RPC server interface routines.
 14            *  Actual rpc routines on the server side.  These routines repackage
 15            *  the rpc argument and call the real server routines.
 16            *
 17            * Author:  Stephen Wood, CEBAF Hall C
 18            *
 19            * Revision History:
 20            *   $Log: daVarRpcProc.c,v $
 21 saw   1.2.16.1  *   Revision 1.2  1999/11/04 20:34:04  saw
 22                 *   Alpha compatibility.
 23                 *   New RPC call needed for root event display.
 24                 *   Start of code to write ROOT trees (ntuples) from new "tree" block
 25                 *
 26 saw   1.2       *   Revision 1.5  1999/08/25 13:16:05  saw
 27                 *   *** empty log message ***
 28                 *
 29                 *   Revision 1.4  1999/03/01 19:52:30  saw
 30                 *   Need svc_soc.h on sun
 31                 *
 32                 *   Revision 1.3  1994/11/07 14:15:46  saw
 33                 *   Add davar_readmultiple_test_1
 34                 *   Add Callback routine
 35                 *   On HP, replace broken xdr_free's with my own freeing
 36 saw   1.1       *
 37                 *	  Revision 1.2  1993/12/03  19:30:58  saw
 38                 *	  Remove some miscelaneous print statements
 39                 *
 40                 *	  Revision 1.1  1993/05/10  21:14:59  saw
 41                 *	  Initial revision
 42                 *
 43                 */
 44                
 45                #include <stdio.h>
 46                #include <rpc/rpc.h>		/* always need this here */
 47                #ifdef __sun
 48                #include <rpc/svc_soc.h>
 49                #endif
 50                #include <limits.h>
 51                #include "daVarRpc.h"		/* need this too: generated by rpcgen */
 52                #include <sys/socket.h>
 53                #include <netdb.h>
 54                #include <netinet/in.h>
 55                #include <time.h>
 56                
 57 saw   1.1      #include "cfortran.h"
 58                #include "daVar.h"
 59                #include "daVarHandlers.h"
 60                
 61                #ifdef hpux
 62                #define xdr_on_hp_is_broken
 63                #endif
 64                
 65 saw   1.2      int daVarCallBack();
 66                FCALLSCFUN0(INT,daVarCallBack,THCALLBACK,thcallback);
 67 saw   1.1      
 68                
 69                static struct timeval TIMEOUT = { 5, 0}; /* Allow 5 seconds for timeout */
 70                /*
 71                 * Remote verson of "ackmessage"
 72                 */
 73                int *nullproc_1(int *argp, CLIENT *clnt)
 74                {
 75                  static int result;
 76                
 77                  result = 0;
 78                
 79                	return(&result);
 80                }
 81                /*
 82                 * Remote verson of "ackmessage"
 83                 */
 84                int * 
 85                davar_ackmessage_1(char **argp, CLIENT *clnt)
 86                {
 87                
 88 saw   1.1      	static int  result;
 89                
 90                /*	printf("Ack: %s\n",*argp);*/
 91                	result = strlen(*argp);
 92                
 93                	return(&result);
 94                }
 95                NAMELIST * 
 96                davar_getlist_1(char **argp, CLIENT *clnt)
 97                {
 98                
 99                	static NAMELIST result={0,0};
100                	char **list;
101                	int i, count;
102                
103                	if(result.NAMELIST_val){
104                /*	  printf("Freeing previous list\n");*/
105                	  daVarFreeList(result.NAMELIST_val);
106                	}
107                	daVarList(*argp,&list,&count); /* Check error code */
108                	result.NAMELIST_len = count;
109 saw   1.1      	result.NAMELIST_val = list;
110                
111                	return(&result);
112                }
113                
114                
115                
116                RVALLIST *davar_readmultiple_1(NAMELIST *argp, CLIENT *clnt)
117                {
118                  static RVALLIST result;
119                  int i;
120                  static int need_to_free=0;
121                
122                /*  minfo = mallinfo();
123                  printf("AA:%d %d\n",minfo.arena,minfo.ordblks);*/
124                  if(need_to_free) {
125                #ifdef xdr_on_hp_is_broken
126                    for(i=0; i<result.RVALLIST_len; i++){
127                      free(result.RVALLIST_val[i].any_u.i.i_val);
128                    }
129                    free(result.RVALLIST_val);
130 saw   1.1      #else
131                    xdr_free(xdr_RVALLIST, (void *) &result);
132                #endif
133                  } else need_to_free = 1;
134                /*  minfo = mallinfo();
135                  printf("BB:%d %d\n",minfo.arena,minfo.ordblks);*/
136                
137                  result.RVALLIST_len = argp->NAMELIST_len;
138                  result.RVALLIST_val = (any *) malloc(result.RVALLIST_len*sizeof(any));
139                
140                  for(i=0; i<argp->NAMELIST_len; i++){
141                    daVarReadVar(argp->NAMELIST_val[i],&(result.RVALLIST_val[i]));
142                  }
143                  return(&result);
144                }    
145                
146                ERRLIST *davar_writemultiple_1(WVALLIST *argp, CLIENT *clnt)
147                {
148                  static ERRLIST result;
149                  int i;
150                
151 saw   1.1        xdr_free(xdr_ERRLIST, (void *) &result);
152                
153                  result.ERRLIST_len = argp->WVALLIST_len;
154                  result.ERRLIST_val = (int *) malloc(result.ERRLIST_len*sizeof(any));
155                
156                  for(i=0; i<argp->WVALLIST_len; i++){
157                    result.ERRLIST_val[i] =
158                      daVarWriteVar(argp->WVALLIST_val[i].name,argp->WVALLIST_val[i].val);
159                  }
160                  return(&result);
161                }    
162                
163                daVarCallBackList *thCallBackListP=0;
164                
165                int *davar_readmultiple_test_1(TESTNAMELIST *argp, CLIENT *clnt)
166                {				/* Code fragment to get client info */
167                  static int result;
168                  int i;
169                  daVarCallBackList *next,*this;
170                
171                  TESTNAMELIST *argcopy;
172 saw   1.1      
173                  SVCXPRT *transp;
174                  struct sockaddr_in *sock,*sockcopy;
175                 
176                /*  printf("IN davar_readmultiple_test_1\n");*/
177                  sock = (struct sockaddr_in *)
178                    svc_getcaller(((struct svc_req *) clnt)->rq_xprt);
179                
180                  /* Copy the arguments */
181                  argcopy = (TESTNAMELIST *) malloc(sizeof(TESTNAMELIST));
182                  argcopy->test_condition = (char *) malloc(strlen(argp->test_condition)+1);
183                  strcpy(argcopy->test_condition, argp->test_condition);
184                  argcopy->max_time_wait = argp->max_time_wait;
185                  argcopy->max_event_wait = argp->max_event_wait;
186                  argcopy->prog = argp->prog;
187                  argcopy->vers = argp->vers;
188                  argcopy->NAMELISTP = (NAMELIST *) malloc(sizeof(NAMELIST));
189                  argcopy->NAMELISTP->NAMELIST_len = argp->NAMELISTP->NAMELIST_len;
190                  argcopy->NAMELISTP->NAMELIST_val =
191                    (char **) malloc(argp->NAMELISTP->NAMELIST_len*sizeof(char *));
192                  for(i=0; i<argp->NAMELISTP->NAMELIST_len; i++){
193 saw   1.1          argcopy->NAMELISTP->NAMELIST_val[i] = (char *)
194                      malloc(strlen(argp->NAMELISTP->NAMELIST_val[i])+1);
195                    strcpy(argcopy->NAMELISTP->NAMELIST_val[i]
196                            ,argp->NAMELISTP->NAMELIST_val[i]);
197                  }
198                  /* Copy the socket */
199                  sockcopy = (struct sockaddr_in *) malloc(sizeof(struct sockaddr_in));
200                  bzero(sockcopy,sizeof(struct sockaddr_in));
201                  bcopy(sock,sockcopy,sizeof(struct sockaddr_in));
202                  
203                /*  printf("Socket copied\n");*/
204                  next = thCallBackListP;
205                  this = thCallBackListP = (daVarCallBackList *)
206                    malloc(sizeof(daVarCallBackList));
207                  this->sock_in = sockcopy;         /* Actually need to copy structure */
208                  this->list = argcopy;
209                  this->start_time = time(0);	/* Record when request came in */
210                  this->next = next;
211                
212                  
213                #if 0
214 saw   1.1        hp = (struct hostent *)
215                    gethostbyaddr((char *)&sockcopy->sin_addr, sizeof(sockcopy->sin_addr),AF_INET);
216                  printf("%s %s\n", inet_ntoa(sockcopy->sin_addr), hp->h_name);
217                #endif
218                
219                  result = S_SUCCESS;
220                  return(&result);
221                }
222                int *
223                davar_readmultiple_test_cb_1(argp, clnt)
224                	RVALLIST *argp;
225                	CLIENT *clnt;
226                {
227                	static int clnt_res;
228                	enum clnt_stat clnt_stat;
229                
230 saw   1.2.16.1 	/*#if 0*/
231 saw   1.1      	{
232                	  struct sockaddr_in sock;
233                	  struct hostent *hp;
234                 
235                	  clnt_control(clnt, CLGET_SERVER_ADDR, (char *) &sock);
236                	  hp = (struct hostent *)
237                	    gethostbyaddr((char *)&sock.sin_addr, sizeof(sock.sin_addr),AF_INET);
238                	  printf("cb_1:  %s %s\n", inet_ntoa(sock.sin_addr), hp->h_name);
239                	}
240 saw   1.2.16.1 	/*#endif*/
241 saw   1.1      
242                	memset((char *)&clnt_res, 0, sizeof(clnt_res));
243                	if ((clnt_stat = clnt_call(clnt, DAVAR_READMULTIPLE_TEST_CB, xdr_RVALLIST, argp, xdr_int, &clnt_res, TIMEOUT)) != RPC_SUCCESS) {
244                	  printf("clnt call failed, clnt_stat = %d\n",clnt_stat);
245                	  clnt_perrno(clnt_stat);
246                		return (NULL);
247                	}
248                	return (&clnt_res);
249                }
250 saw   1.2      WVALLIST *davar_readpatternmatch_1(char **argp, CLIENT *clnt)
251                {
252                  static WVALLIST result;
253                  int i;
254                  static int need_to_free=0;
255                  char *pattern;
256                  char **vlist;
257                  int count;
258                
259                /*  minfo = mallinfo();
260                  printf("AA:%d %d\n",minfo.arena,minfo.ordblks);*/
261                  /*  printf("In davar_readpatternmatch_1 doing pattern '%s'\n",*argp);*/
262                  if(need_to_free) {
263                #ifdef xdr_on_hp_is_broken
264                    for(i=0; i<result.WVALLIST_len; i++){
265                      free(result.WVALLIST_val[i].val->any_u.i.i_val);
266                      free(result.WVALLIST_val[i].name);
267                    }
268                    free(result.WVALLIST_val);
269                #else
270                    xdr_free(xdr_WVALLIST, (void *) &result);
271 saw   1.2      #endif
272                  } else need_to_free = 1;
273                /*  minfo = mallinfo();
274                  printf("BB:%d %d\n",minfo.arena,minfo.ordblks);*/
275                
276                  daVarList(*argp,&vlist,&count);
277                
278                  result.WVALLIST_len = count;
279                  result.WVALLIST_val = (wany *) malloc(count*sizeof(wany));
280                
281                  for(i=0; i<count; i++){
282                    /*    printf("%d: %s\n",i,vlist[i]);*/
283                    result.WVALLIST_val[i].name = (char *) malloc(strlen(vlist[i])+1);
284                    strcpy(result.WVALLIST_val[i].name,vlist[i]);
285                    /*    daVarReadVar(vlist[i],&(result.WVALLIST_val[i].val));*/
286                    result.WVALLIST_val[i].val = malloc(sizeof(any));
287                    daVarReadVar(vlist[i],result.WVALLIST_val[i].val);
288                  }
289                  /*  daVarFreeList(vlist);*/
290                  return(&result);
291                }    
292 saw   1.2      
293                int daVarCallBack()
294 saw   1.1      /* Scan the list of pending readmultiple requests.  Make a call back for
295                   each request for which the test is true or blank.  Ignore the time
296                   out stuff for now. */
297                {
298                  daVarCallBackList *this,*next,**last;
299                  TESTNAMELIST *argp;
300                  struct sockaddr_in *sock_in;
301                  struct hostent *hp;
302                  DAINT itest;
303                  static RVALLIST rpc;
304                  CLIENT *clnt;
305                  int i;
306                  int *status;
307                  int pending,processed;
308                  int testresult,timeout;
309                
310                  this = thCallBackListP;
311                  last = &thCallBackListP;
312                  pending = 0;
313                  processed = 0;
314                
315 saw   1.1        while(this) {
316                    argp = this->list;
317                    argp->max_event_wait--;
318                    testresult = (argp->test_condition == 0 ||
319                       argp->test_condition[0] == '\0' ||
320                       (thEvalImed(argp->test_condition,0,&itest),itest));
321                    timeout = (argp->max_event_wait < 0 
322                      || (time(0)-this->start_time) > argp->max_time_wait);
323                    if(testresult || timeout) {
324                      sock_in = this->sock_in;
325                /*      printf("PORT=%d,%x\n",sock_in->sin_port,htonl(sock_in->sin_addr.s_addr));*/
326                      hp = (struct hostent *)
327                        gethostbyaddr((char *)&sock_in->sin_addr, sizeof(sock_in->sin_addr)
328                                      ,AF_INET);
329                /*      printf("Creating client for %s(%x %x)\n",hp->h_name
330                             ,argp->prog,argp->vers);*/
331                      if(testresult) {
332                        /* Build the structure with the return data */
333                        rpc.RVALLIST_len = argp->NAMELISTP->NAMELIST_len;
334                        rpc.RVALLIST_val = (any *) malloc(rpc.RVALLIST_len*sizeof(any));
335                
336 saw   1.1              for(i=0; i<argp->NAMELISTP->NAMELIST_len; i++){
337                          daVarReadVar(argp->NAMELISTP->NAMELIST_val[i],
338                                       &(rpc.RVALLIST_val[i]));
339                        }
340                      } else {
341                        rpc.RVALLIST_len = 0;
342                        rpc.RVALLIST_val = 0;
343                      }
344 saw   1.2.16.1 #if 0
345 saw   1.2            {
346                	/* This is really weird.  clnt_create only works if we copy the hostname*/
347                	char *host;
348                	host = malloc(strlen(hp->h_name)+1);
349                	strcpy(host,hp->h_name);
350                	clnt = clnt_create(host, argp->prog, argp->vers, "tcp");
351                	free(host);
352                      }
353 saw   1.2.16.1 #endif
354 saw   1.2            {
355                	/* This is really weird.  On the alpha it seems we need to copy the
356                	   host name to a separate variable.  Maybe clnt_create calls some
357                	   function that mucks with the hp structure. */
358                	char *host;
359                	host = malloc(strlen(hp->h_name)+1);
360                	strcpy(host,hp->h_name);
361                	clnt = clnt_create(host, argp->prog, argp->vers, "tcp");
362                	if(clnt) {
363                	  status = davar_readmultiple_test_cb_1(&rpc, clnt);
364                	  clnt_destroy(clnt);
365                	  /* We don't care what the status was. */
366                	} else {
367                	  fprintf(stderr,"Callback to %s failed\n",host);
368                	}
369                	free(host);
370 saw   1.1            }
371                #ifdef xdr_on_hp_is_broken
372                      if(testresult) {
373                        for(i=0; i<argp->NAMELISTP->NAMELIST_len; i++){
374                          free(rpc.RVALLIST_val[i].any_u.i.i_val);
375                        }
376                        free(rpc.RVALLIST_val);
377                      }
378                      for(i=0; i<argp->NAMELISTP->NAMELIST_len;i++){
379                        free(argp->NAMELISTP->NAMELIST_val[i]);
380                      }
381                      free(argp->NAMELISTP->NAMELIST_val);
382                      free(argp->NAMELISTP);
383                      free(argp->test_condition);
384                #else
385                      if(testresult) {
386                	xdr_free(xdr_RVALLIST, (void *) &rpc);
387                      }
388                      xdr_free(xdr_TESTNAMELIST, (void *) argp);
389                #endif
390                      free(argp);
391 saw   1.1            free(this->sock_in);
392                      next = this->next;
393                      *last = next;
394                      free(this);
395                      this = next;
396                      processed++;
397                    } else {
398                      last = &(this->next);
399                      this = this->next;
400                      pending++;
401                    }
402                  }
403                  if(processed&&pending==0) return(-1);
404                  else return(pending);
405                }

Analyzer/Replay: Mark Jones, Documents: Stephen Wood
Powered by
ViewCVS 0.9.2-cvsgraph-1.4.0