Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

f_his_hist.c

Go to the documentation of this file.
00001 //-------------------------------------------------------------
00002 //        Go4 Release Package v3.04-01 (build 30401)
00003 //                      28-November-2008
00004 //---------------------------------------------------------------
00005 //   The GSI Online Offline Object Oriented (Go4) Project
00006 //   Experiment Data Processing at EE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
00015 //----------------------------------------------------------------
00016 #include "typedefs.h"
00017 #include "f_his_hist.h"
00018 #include "f_his_toupper.h"
00019 #include "f_his_swpbas.h"
00020 #include "f_stccomm.h"
00021 #include "f_swaplw.h"
00022 #include "f_ut_compress.h"
00023 #include "portnum_def.h"
00024 #include <stdio.h>
00025 #include <errno.h>
00026 #include <ctype.h>
00027 #include <string.h>
00028 #include <stdlib.h>
00029 static CHARS c_gl_serv_access[64];
00030 static CHARS c_gl_serv_base[32];
00031 static INTS4 l_gl_serv_port;
00032 static INTS4 l_gl_serv_chan;
00033 static INTS4 l_gl_serv_verb;
00034 struct s_tcpcomm *ps_tcpserv;
00035 s_his_comm s_his_comm_serv;
00036 /*****************+***********+****************************************/
00037 /*                                                                    */
00038 /*   GSI, Gesellschaft fuer Schwerionenforschung mbH                  */
00039 /*   Postfach 11 05 41                                                */
00040 /*   D-6100 Darmstadt 11                                              */
00041 /*                                                                    */
00042 /*1+ C Procedure ***********+******************************************/
00043 /*                                                                    */
00044 /*+ Module      : f_his_getbas                                        */
00045 /*                                                                    */
00046 /*--------------------------------------------------------------------*/
00047 /*+ CALLING     : l=f_his_getbas(char server, int port, char base, char password, int **p_buf)*/
00048 /*--------------------------------------------------------------------*/
00049 /*                                                                    */
00050 /*+ PURPOSE     : Returns list of histogram available from server     */
00051 /*                                                                    */
00052 /*+ ARGUMENTS   :                                                     */
00053 /*                                                                    */
00054 /*+   c_server  : Node of server.                                     */
00055 /*+  l_port     : Port number (must be known from server)             */
00056 /*+  c_base     : Histogram base name                                 */
00057 /*+  c_password : Password if required from server                    */
00058 /*+    p_buf    : Address of buffer pointer.                          */
00059 /*                Data base is allocated and address returned.        */
00060 /*                                                                    */
00061 /*+ Return type : int.                                                */
00062 /*-               COMM__SUCCESS : OK                                  */
00063 /*-               COMM__ERROR   : Error                               */
00064 /*-               COMM__NOACCESS: Password wrong                      */
00065 /*-               COMM__NOBASE  : Base wrong                          */
00066 /*-               COMM__NOSERVER: Cannot connect (Port?)              */
00067 /*-               COMM__NOHIST  : Histogram not there                 */
00068 /*                                                                    */
00069 /*2+DESCRIPTION***+***********+****************************************/
00070 /*                                                                    */
00071 /*+ FUNCTION    : Connects to histogram server.                       */
00072 /*                Allocates and returns LEA data base                 */
00073 /*                Bse must be compressed by server.                   */
00074 /*                                                                    */
00075 /*2+IMPLEMENTATION************+****************************************/
00076 /*                                                                    */
00077 /*+ File name   : f_his_hist.c                                        */
00078 /*+ Version     : 1.01                                                */
00079 /*+ Author      : Hans Essel                                          */
00080 /*+ Created     : 21-May-2000                                         */
00081 /*+ Updates     : Date        Purpose                                 */
00082 /*                                                                    */
00083 /*1- C Main ****************+******************************************/
00084 INTS4 f_his_getbas(CHARS *pc_server, INTS4 l_port, CHARS *pc_base, CHARS *pc_access,INTS4 **p_buffer)
00085 {
00086 s_his_comm s_his_comm_cli;
00087 s_his_head *ps_his_head;
00088 INTS4 i_j,i_l,l_status,l_chan,l_swap,l_buffer,l_histos,l_size;
00089 INTS4 *pl_all,*pl_l;
00090 s_compress               *ps_compress;
00091 struct s_tcpcomm *ps_tcpcli;
00092 
00093 ps_tcpcli = (struct s_tcpcomm *) malloc (sizeof( struct s_tcpcomm));
00094 
00095 /* get base ***************************************************/
00096 s_his_comm_cli.lu_endian=1;
00097 s_his_comm_cli.lu_size=0;
00098 s_his_comm_cli.lu_histos=0;
00099 s_his_comm_cli.lu_action=COMM__GETBASE;
00100 s_his_comm_cli.l_status=COMM__SUCCESS;
00101 strcpy(s_his_comm_cli.c_histo,"*");
00102 strcpy(s_his_comm_cli.c_access,pc_access);
00103 strcpy(s_his_comm_cli.c_base,pc_base);
00104 l_status = f_stc_connectserver (pc_server,l_port, &l_chan, ps_tcpcli);
00105 if(l_status != STC__SUCCESS) {l_status=COMM__NOSERVER;goto g_return;}
00106 l_status = f_stc_write(&s_his_comm_cli,sizeof(s_his_comm),l_chan);
00107 if(l_status != STC__SUCCESS) {l_status=COMM__ERROR;goto g_return;}
00108 l_status = f_stc_read (&s_his_comm_cli,sizeof(s_his_comm),l_chan,-1);
00109 if(l_status != STC__SUCCESS) {l_status=COMM__ERROR;goto g_return;}
00110 l_swap = (s_his_comm_cli.lu_endian > 1);
00111 if(l_swap) l_status = f_swaplw((INTS4 *)&s_his_comm_cli,5,NULL);
00112 if(s_his_comm_cli.l_status != COMM__SUCCESS) {l_status=s_his_comm_cli.l_status;goto g_return;}
00113 
00114 /* allocate buffer for comporessed base */
00115 pl_all  = (INTS4 *)malloc(s_his_comm_cli.lu_size);
00116 l_buffer = s_his_comm_cli.lu_size;
00117 /* break total buffer in TCP buffers */
00118 pl_l=pl_all;
00119 i_l=l_buffer/16384;
00120 l_buffer=l_buffer%16384;
00121 for(i_j=0;i_j<i_l;i_j++){l_status = f_stc_read (pl_l,16384,l_chan,-1);pl_l+=4096;}
00122 if(l_buffer > 0)         l_status = f_stc_read (pl_l,l_buffer,l_chan,-1);
00123 if(l_status != STC__SUCCESS) {l_status=COMM__ERROR;goto g_return;}
00124 /* uncompress base */
00125 ps_compress = (s_compress *) pl_all;
00126 if(l_swap == 1)
00127 {
00128   f_swaplw((INTS4 *)pl_all,sizeof(s_compress)/4,NULL);
00129   pl_l=pl_all+(sizeof(s_compress)/4);
00130   f_swaplw((INTS4 *)pl_l,ps_compress->l_masks,NULL);
00131 }
00132 *p_buffer  = (INTS4 *)malloc(ps_compress->l_full_bytes);
00133 f_ut_compr_unpack((INTU1 *)pl_all,(INTU1 *) *p_buffer,ps_compress->l_full_bytes);
00134 if(l_swap == 1) l_status = f_his_swpbas((s_head*) *p_buffer);
00135 
00136 l_status=COMM__SUCCESS;
00137 g_return:
00138 f_stc_discclient (l_chan);
00139 f_stc_close (ps_tcpcli);
00140 free(pl_all);
00141 free(ps_tcpcli);
00142 return(l_status);
00143 }
00144 /*1+ C Procedure ***********+******************************************/
00145 /*                                                                    */
00146 /*+ Module      : f_his_getdir                                        */
00147 /*                                                                    */
00148 /*--------------------------------------------------------------------*/
00149 /*+ CALLING     : l=f_his_getdir(char server, int port, char base, char password,*/
00150 /*                              char histo, int **p_buf, int **l_histos)*/
00151 /*                                                                    */
00152 /*--------------------------------------------------------------------*/
00153 /*                                                                    */
00154 /*+ PURPOSE     : Returns list of histogram available from server     */
00155 /*                                                                    */
00156 /*+ ARGUMENTS   :                                                     */
00157 /*                                                                    */
00158 /*+   c_server  : Node of server.                                     */
00159 /*+  l_port     : Port number (must be known from server)             */
00160 /*+  c_base     : Histogram base name                                 */
00161 /*+  c_password : Password if required from server                    */
00162 /*+  c_histo    : Histogram wildcard                                  */
00163 /*+    p_buf    : Address of buffer pointer.                          */
00164 /*                If NULL, buffer is allocated, if not l_histos gives */
00165 /*                size of buffer in sizeof(s_his_head).               */
00166 /*+   l_histos  : Size in sizeof(s_his_head) of buffer,               */
00167 /*                returns number of histograms                        */
00168 /*                                                                    */
00169 /*+ Return type : int.                                                */
00170 /*-               COMM__SUCCESS : OK                                  */
00171 /*-               COMM__ERROR   : Error                               */
00172 /*-               COMM__NOACCESS: Password wrong                      */
00173 /*-               COMM__NOBASE  : Base wrong                          */
00174 /*-               COMM__NOSERVER: Cannot connect (Port?)              */
00175 /*-               COMM__NOHIST  : Histogram not there                 */
00176 /*                                                                    */
00177 /*2+DESCRIPTION***+***********+****************************************/
00178 /*                                                                    */
00179 /*+ FUNCTION    : Connects to histogram server.                       */
00180 /*                Returns buffer with s_his_head slots                */
00181 /*                                                                    */
00182 /*2+IMPLEMENTATION************+****************************************/
00183 /*                                                                    */
00184 /*+ File name   : f_his_hist.c                                        */
00185 /*+ Version     : 1.01                                                */
00186 /*+ Author      : Hans Essel                                          */
00187 /*+ Created     : 21-May-2000                                         */
00188 /*+ Updates     : Date        Purpose                                 */
00189 /*                                                                    */
00190 /*1- C Main ****************+******************************************/
00191 INTS4 f_his_getdir(CHARS *pc_server, INTS4 l_port, CHARS *pc_base, CHARS *pc_access, CHARS *pc_histo
00192                   ,INTS4 **p_buffer, INTS4 *pl_histos)
00193 {
00194 s_his_comm s_his_comm_cli;
00195 s_his_head *ps_his_head;
00196 INTS4 i_j,i_l,l_status,l_chan,l_swap,l_buffer,l_histos,l_size;
00197 INTS4 *pl_all,*pl_l;
00198 struct s_tcpcomm *ps_tcpcli;
00199 
00200 ps_tcpcli = (struct s_tcpcomm *) malloc (sizeof( struct s_tcpcomm));
00201 
00202 /* get directory ***************************************************/
00203 s_his_comm_cli.lu_endian=1;
00204 s_his_comm_cli.lu_size=0;
00205 s_his_comm_cli.lu_histos=0;
00206 s_his_comm_cli.lu_action=COMM__GETDIR;
00207 s_his_comm_cli.l_status=COMM__SUCCESS;
00208 strcpy(s_his_comm_cli.c_histo,pc_histo);
00209 strcpy(s_his_comm_cli.c_access,pc_access);
00210 strcpy(s_his_comm_cli.c_base,pc_base);
00211 l_status = f_stc_connectserver (pc_server,l_port, &l_chan, ps_tcpcli);
00212 if(l_status != STC__SUCCESS) {l_status=COMM__NOSERVER;goto g_return;}
00213 l_status = f_stc_write(&s_his_comm_cli,sizeof(s_his_comm),l_chan);
00214 if(l_status != STC__SUCCESS) {l_status=COMM__ERROR;goto g_return;}
00215 l_status = f_stc_read (&s_his_comm_cli,sizeof(s_his_comm),l_chan,-1);
00216 if(l_status != STC__SUCCESS) {l_status=COMM__ERROR;goto g_return;}
00217 l_swap = (s_his_comm_cli.lu_endian > 1);
00218 if(l_swap) l_status = f_swaplw((INTS4 *)&s_his_comm_cli,5,NULL);
00219 if(s_his_comm_cli.l_status != COMM__SUCCESS) {l_status=s_his_comm_cli.l_status;goto g_return;}
00220 
00221 l_histos=s_his_comm_cli.lu_histos;
00222 l_size=sizeof(s_his_head)*l_histos;
00223 /* allocate buffer */
00224 if(*p_buffer == 0)
00225 {
00226      pl_all  = (INTS4 *)malloc(l_size);
00227     *p_buffer = pl_all;
00228 }
00229 else
00230 {
00231     if(*pl_histos < l_histos) {l_status=COMM__ERROR;goto g_return;}
00232     pl_all = *p_buffer;
00233 }
00234 *pl_histos = l_histos;
00235 l_buffer = s_his_comm_cli.lu_size;
00236 /* break total buffer in TCP buffers */
00237 pl_l=pl_all;
00238 i_l=l_buffer/16384;
00239 l_buffer=l_buffer%16384;
00240 for(i_j=0;i_j<i_l;i_j++){l_status = f_stc_read (pl_l,16384,l_chan,-1);pl_l+=4096;}
00241 if(l_buffer > 0)         l_status = f_stc_read (pl_l,l_buffer,l_chan,-1);
00242 if(l_status != STC__SUCCESS) {l_status=COMM__ERROR;goto g_return;}
00243 
00244 ps_his_head = (s_his_head *)pl_all;
00245 for(i_j=0;i_j<s_his_comm_cli.lu_histos;i_j++)
00246 {
00247     if(l_swap) l_status = f_swaplw((INTS4 *)ps_his_head,16,NULL);
00248     ps_his_head++;
00249 
00250 }
00251 l_status=COMM__SUCCESS;
00252 g_return:
00253 f_stc_discclient (l_chan);
00254 f_stc_close (ps_tcpcli);
00255 free(ps_tcpcli);
00256 return(l_status);
00257 }
00258 /*****************+***********+****************************************/
00259 /*                                                                    */
00260 /*   GSI, Gesellschaft fuer Schwerionenforschung mbH                  */
00261 /*   Postfach 11 05 41                                                */
00262 /*   D-6100 Darmstadt 11                                              */
00263 /*                                                                    */
00264 /*1+ C Procedure ***********+******************************************/
00265 /*                                                                    */
00266 /*+ Module      : f_his_gethis                                        */
00267 /*                                                                    */
00268 /*--------------------------------------------------------------------*/
00269 /*+ CALLING     : l=f_his_gethis(char server, int port, char base, char password,*/
00270 /*                        char histo, s_his_head **p_head, int **p_buf, int **l_size)*/
00271 /*                                                                    */
00272 /*--------------------------------------------------------------------*/
00273 /*                                                                    */
00274 /*+ PURPOSE     : Returns histogram from server                       */
00275 /*                                                                    */
00276 /*+ ARGUMENTS   :                                                     */
00277 /*                                                                    */
00278 /*+   c_server  : Node of server.                                     */
00279 /*+  l_port     : Port number (must be known from server)             */
00280 /*+  c_base     : Histogram base name                                 */
00281 /*+  c_password : Password if required from server                    */
00282 /*+  c_histo    : Histogram                                           */
00283 /*+    p_head   : Address of header pointer (s_his_head)              */
00284 /*                If NULL, s_his_head will be allocated               */
00285 /*+    p_buf    : Address of buffer pointer                           */
00286 /*                If NULL, buffer for data will be allocated          */
00287 /*+   l_size    : Size in bytes of buffer, returns size               */
00288 /*                                                                    */
00289 /*+ Return type : int.                                                */
00290 /*-               COMM__SUCCESS : OK                                  */
00291 /*-               COMM__ERROR   : Error                               */
00292 /*-               COMM__NOACCESS: Password wrong                      */
00293 /*-               COMM__NOBASE  : Base wrong                          */
00294 /*-               COMM__NOSERVER: Cannot connect (Port?)              */
00295 /*-               COMM__NOHIST  : Histogram not there                 */
00296 /*                                                                    */
00297 /*2+DESCRIPTION***+***********+****************************************/
00298 /*                                                                    */
00299 /*+ FUNCTION    : Connects to histogram server.                       */
00300 /*                Returns buffer with s_his_head and data buffer      */
00301 /*                Required buffer size can be obtained from           */
00302 /*                s_his_head after calling f_his_getdir.              */
00303 /*                                                                    */
00304 /*2+IMPLEMENTATION************+****************************************/
00305 /*                                                                    */
00306 /*+ File name   : f_his_hist.c                                        */
00307 /*+ Version     : 1.01                                                */
00308 /*+ Author      : Hans Essel                                          */
00309 /*+ Created     : 21-May-2000                                         */
00310 /*+ Updates     : Date        Purpose                                 */
00311 /*                                                                    */
00312 /*1- C Main ****************+******************************************/
00313 INTS4 f_his_gethis(CHARS *pc_server, INTS4 l_port, CHARS *pc_base, CHARS *pc_access, CHARS *pc_histo
00314                   , s_his_head **p_head, INTS4 **p_buffer, INTS4 *pl_size)
00315 {
00316 s_his_comm s_his_comm_cli;
00317 s_his_head *ps_his_head;
00318 INTS4 i_j,i_l,l_status,l_chan,l_swap,l_buffer,l_histos,l_size;
00319 INTS4 *pl_all,*pl_head,*pl_l;
00320 struct s_tcpcomm *ps_tcpcli;
00321 
00322 ps_tcpcli = (struct s_tcpcomm *) malloc (sizeof( struct s_tcpcomm));
00323 
00324 /* get histogram ******************************************************/
00325 s_his_comm_cli.lu_endian=1;
00326 s_his_comm_cli.lu_size=0;
00327 s_his_comm_cli.lu_histos=0;
00328 s_his_comm_cli.lu_action=COMM__GETHIST;
00329 s_his_comm_cli.l_status=COMM__SUCCESS;
00330 strcpy(s_his_comm_cli.c_histo,pc_histo);
00331 strcpy(s_his_comm_cli.c_access,pc_access);
00332 strcpy(s_his_comm_cli.c_base,pc_base);
00333 l_status = f_stc_connectserver (pc_server,l_port, &l_chan, ps_tcpcli);
00334 if(l_status != STC__SUCCESS) {l_status=COMM__NOSERVER;goto g_return;}
00335 l_status = f_stc_write(&s_his_comm_cli,sizeof(s_his_comm),l_chan);
00336 if(l_status != STC__SUCCESS) {l_status=COMM__ERROR;goto g_return;}
00337 l_status = f_stc_read (&s_his_comm_cli,sizeof(s_his_comm),l_chan,-1);
00338 if(l_status != STC__SUCCESS) {l_status=COMM__ERROR;goto g_return;}
00339 l_swap = (s_his_comm_cli.lu_endian > 1);
00340 if(l_swap) l_status = f_swaplw((INTS4 *)&s_his_comm_cli,5,NULL);
00341 if(s_his_comm_cli.l_status != COMM__SUCCESS) {l_status=s_his_comm_cli.l_status;goto g_return;}
00342 
00343 l_size=s_his_comm_cli.lu_size-sizeof(s_his_head);
00344 /* allocate buffer */
00345 if(*p_buffer == 0)
00346 {
00347      pl_all  = (INTS4 *)malloc(l_size);
00348     *p_buffer = pl_all;
00349 }
00350 else
00351 {
00352     if(*pl_size < l_size) {l_status=COMM__ERROR;goto g_return;}
00353     pl_all = *p_buffer;
00354 }
00355 /* allocate header buffer */
00356 if(*p_head == 0)
00357 {
00358      ps_his_head = (s_his_head *)malloc(sizeof(s_his_head));
00359     *p_head = ps_his_head;
00360 }
00361 else ps_his_head = *p_head;
00362 
00363 l_status = f_stc_read (ps_his_head,sizeof(s_his_head),l_chan,-1);
00364 if(l_swap) l_status = f_swaplw((INTS4 *)ps_his_head,16,NULL);
00365 
00366 *pl_size = l_size;
00367 l_buffer = l_size;
00368 
00369 /* break total buffer in TCP buffers */
00370 pl_l=pl_all;
00371 i_l=l_buffer/16384;
00372 l_buffer=l_buffer%16384;
00373 for(i_j=0;i_j<i_l;i_j++){l_status = f_stc_read (pl_l,16384,l_chan,-1);pl_l+=4096;}
00374 if(l_buffer > 0)         l_status = f_stc_read (pl_l,l_buffer,l_chan,-1);
00375 if(l_status != STC__SUCCESS) {l_status=COMM__ERROR;goto g_return;}
00376 
00377 if(l_swap) l_status = f_swaplw((INTS4 *)pl_all,l_size/4,NULL);
00378 
00379 l_status=COMM__SUCCESS;
00380 g_return:
00381 f_stc_discclient (l_chan);
00382 f_stc_close (ps_tcpcli);
00383 free(ps_tcpcli);
00384 return(l_status);
00385 }
00386 /*1+ C Procedure ***********+******************************************/
00387 /*                                                                    */
00388 /*+ Module      : f_his_server                                        */
00389 /*                                                                    */
00390 /*--------------------------------------------------------------------*/
00391 /*+ CALLING     : l=f_his_server(int *pl_port, char base, char accesss)*/
00392 /*--------------------------------------------------------------------*/
00393 /*                                                                    */
00394 /*+ PURPOSE     : Start histogram server                              */
00395 /*                                                                    */
00396 /*+ ARGUMENTS   :                                                     */
00397 /*                                                                    */
00398 /*+  pl_port    : Address to receive port number used.                */
00399 /*+  base       : Base name                                           */
00400 /*+  access     : Password                                            */
00401 /*                                                                    */
00402 /*+ Return type : int.                                                */
00403 /*-               COMM__SUCCESS : OK                                  */
00404 /*-               COMM__ERROR   : Error                               */
00405 /*                                                                    */
00406 /*2+DESCRIPTION***+***********+****************************************/
00407 /*                                                                    */
00408 /*+ FUNCTION    : Creates histogram server.                           */
00409 /*                Returns port number                                 */
00410 /*                                                                    */
00411 /*2+IMPLEMENTATION************+****************************************/
00412 /*                                                                    */
00413 /*+ File name   : f_his_hist.c                                        */
00414 /*+ Version     : 1.01                                                */
00415 /*+ Author      : Hans Essel                                          */
00416 /*+ Created     : 21-May-2000                                         */
00417 /*+ Updates     : Date        Purpose                                 */
00418 /*                                                                    */
00419 /*1- C Main ****************+******************************************/
00420 INTS4 f_his_server(CHARS *pc_base, CHARS *pc_access, INTS4 *pl_port)
00421 {
00422 INTS4 *pl_l,i_j,i_l,ll,l_buffer,l_status;
00423 
00424 ps_tcpserv  = (struct s_tcpcomm *) malloc (sizeof( struct s_tcpcomm));
00425 l_gl_serv_port=PORT__HIST_SERV;
00426 strcpy(c_gl_serv_access,pc_access);
00427 strcpy(c_gl_serv_base,pc_base);
00428 f_his_toupper(c_gl_serv_access,sizeof(c_gl_serv_access));
00429 f_his_toupper(c_gl_serv_base,sizeof(c_gl_serv_base));
00430 
00431 while((l_status = f_stc_createserver (&l_gl_serv_port, ps_tcpserv)) != STC__SUCCESS)
00432 {
00433     l_gl_serv_port++;
00434     if(l_gl_serv_port > PORT__HIST_SERV + 20)
00435     {
00436        printf("Error creating histogram server\n");
00437        return(COMM__ERROR);
00438     }
00439 }
00440 *pl_port=l_gl_serv_port;
00441 return(0);
00442 }
00443 
00444 /*1+ C Procedure ***********+******************************************/
00445 /*                                                                    */
00446 /*+ Module      : f_his_wait                                          */
00447 /*                                                                    */
00448 /*--------------------------------------------------------------------*/
00449 /*+ CALLING     : l=f_his_wait(int *pl_action, char histogram)        */
00450 /*--------------------------------------------------------------------*/
00451 /*                                                                    */
00452 /*+ PURPOSE     : Wait for client                                     */
00453 /*                                                                    */
00454 /*+ ARGUMENTS   :                                                     */
00455 /*                                                                    */
00456 /*+  pl_action  : Address to receive required action.                 */
00457 /*+  histogram  : Histogram sepc.                                     */
00458 /*                                                                    */
00459 /*+ Return type : int.                                                */
00460 /*-               COMM__SUCCESS : OK                                  */
00461 /*-               COMM__ERROR   : Error                               */
00462 /*-               COMM__NOACCESS: Password wrong                      */
00463 /*-               COMM__NOBASE  : Base wrong                          */
00464 /*                                                                    */
00465 /*2+DESCRIPTION***+***********+****************************************/
00466 /*                                                                    */
00467 /*+ FUNCTION    : Waits for client to connect.                        */
00468 /*                Returns action required.                            */
00469 /*                Checks for correct base and password                */
00470 /*                                                                    */
00471 /*2+IMPLEMENTATION************+****************************************/
00472 /*                                                                    */
00473 /*+ File name   : f_his_hist.c                                        */
00474 /*+ Version     : 1.01                                                */
00475 /*+ Author      : Hans Essel                                          */
00476 /*+ Created     : 21-May-2000                                         */
00477 /*+ Updates     : Date        Purpose                                 */
00478 /*                                                                    */
00479 /*1- C Main ****************+******************************************/
00480 INTS4 f_his_wait(INTS4 *pl_action, CHARS *pc_histo)
00481 {
00482 INTS4 *pl_l,i_j,i_l,ll,l_buffer,l_status;
00483 /* Wait for client to connect */
00484     if(l_gl_serv_verb == 1) {printf("Waiting for client on port %d [%s] \n",l_gl_serv_port,c_gl_serv_access);}
00485     l_status = f_stc_acceptclient (ps_tcpserv, &l_gl_serv_chan);
00486     if(l_status != STC__SUCCESS) { printf("error accepting client\n"); return(COMM__ERROR);}
00487     if(l_gl_serv_verb == 1) {printf("Client connected. \n");}
00488     l_status = f_stc_read (&s_his_comm_serv,sizeof(s_his_comm),l_gl_serv_chan,-1);
00489     if(l_status != STC__SUCCESS) { printf("error reading client\n"); f_stc_discclient(l_gl_serv_chan);return(COMM__ERROR); }
00490     /* check access */
00491     f_his_toupper(s_his_comm_serv.c_access,sizeof(s_his_comm_serv.c_access));
00492     f_his_toupper(s_his_comm_serv.c_base,sizeof(s_his_comm_serv.c_base));
00493     if((strlen(c_gl_serv_access) != 0) &
00494        (strcmp(s_his_comm_serv.c_access,c_gl_serv_access) != 0))
00495     {
00496         printf("Client connected with wrong password [%s]. \n",s_his_comm_serv.c_access);
00497    s_his_comm_serv.lu_endian=1;
00498    s_his_comm_serv.lu_size=0;
00499    s_his_comm_serv.lu_histos=0;
00500    s_his_comm_serv.l_status=COMM__NOACCESS;
00501    l_status = f_stc_write (&s_his_comm_serv,sizeof(s_his_comm), l_gl_serv_chan);
00502         f_stc_discclient (l_gl_serv_chan);
00503    return(COMM__NOACCESS);
00504     }
00505     /* check base name */
00506     if(strcmp(s_his_comm_serv.c_base,c_gl_serv_base) != 0)
00507     {
00508         printf("Client connected for wrong base [%s]. \n",s_his_comm_serv.c_base);
00509    s_his_comm_serv.lu_endian=1;
00510    s_his_comm_serv.lu_size=0;
00511    s_his_comm_serv.lu_histos=0;
00512    s_his_comm_serv.l_status=COMM__NOBASE;
00513    l_status = f_stc_write (&s_his_comm_serv,sizeof(s_his_comm), l_gl_serv_chan);
00514         f_stc_discclient (l_gl_serv_chan);
00515    return(COMM__NOBASE);
00516     }
00517     if(s_his_comm_serv.lu_endian > 100) l_status = f_swaplw((INTS4 *)&s_his_comm_serv,5,NULL);
00518     if(l_gl_serv_verb == 1) {printf("%d: %d %d %d %d %d \"%s\" \"%s\" \"%s\"\n",l_status
00519            ,s_his_comm_serv.lu_endian
00520            ,s_his_comm_serv.lu_action
00521            ,s_his_comm_serv.lu_histos
00522            ,s_his_comm_serv.lu_size
00523            ,s_his_comm_serv.l_status
00524            ,s_his_comm_serv.c_access
00525            ,s_his_comm_serv.c_base
00526            ,s_his_comm_serv.c_histo);}
00527 *pl_action=s_his_comm_serv.lu_action;
00528 strcpy(pc_histo,s_his_comm_serv.c_histo);
00529 return(COMM__SUCCESS);
00530 }
00531 
00532 /*1+ C Procedure ***********+******************************************/
00533 /*                                                                    */
00534 /*+ Module      : f_his_senddir                                       */
00535 /*                                                                    */
00536 /*--------------------------------------------------------------------*/
00537 /*+ CALLING     : l=f_his_senddir(s_his_head *ps_head, int l_histos)  */
00538 /*--------------------------------------------------------------------*/
00539 /*                                                                    */
00540 /*+ PURPOSE     : Send list of available histogram                    */
00541 /*                                                                    */
00542 /*+ ARGUMENTS   :                                                     */
00543 /*                                                                    */
00544 /*+  ps_head    : Address of header list.                             */
00545 /*+  l_histos   : Number of histograms                                */
00546 /*                                                                    */
00547 /*+ Return type : int.                                                */
00548 /*-               COMM__SUCCESS : OK                                  */
00549 /*-               COMM__ERROR   : Error                               */
00550 /*-               COMM__NOHIST  : Histogram not there                 */
00551 /*                                                                    */
00552 /*2+DESCRIPTION***+***********+****************************************/
00553 /*                                                                    */
00554 /*+ FUNCTION    : Send list of s_his_head to client.                  */
00555 /*                                                                    */
00556 /*2+IMPLEMENTATION************+****************************************/
00557 /*                                                                    */
00558 /*+ File name   : f_his_hist.c                                        */
00559 /*+ Version     : 1.01                                                */
00560 /*+ Author      : Hans Essel                                          */
00561 /*+ Created     : 21-May-2000                                         */
00562 /*+ Updates     : Date        Purpose                                 */
00563 /*                                                                    */
00564 /*1- C Main ****************+******************************************/
00565 INTS4 f_his_senddir(s_his_head *ps_head, INTS4 l_histos)
00566 {
00567 INTS4 *pl_l,i_j,i_l,ll,l_buffer,l_status;
00568 
00569 if(l_gl_serv_verb == 1) {printf("Send directory %s. \n",s_his_comm_serv.c_histo);}
00570 s_his_comm_serv.lu_histos=l_histos;
00571 s_his_comm_serv.lu_endian=1;
00572 s_his_comm_serv.lu_action=COMM__PUTDIR;
00573 s_his_comm_serv.lu_size=sizeof(s_his_head)*s_his_comm_serv.lu_histos;
00574 s_his_comm_serv.l_status=COMM__SUCCESS;
00575 l_status = f_stc_write (&s_his_comm_serv,sizeof(s_his_comm), l_gl_serv_chan);
00576 if(l_status != STC__SUCCESS)
00577 { printf("error writing comm to client\n"); f_stc_discclient(l_gl_serv_chan);return(COMM__ERROR);}
00578 
00579 /* break total buffer in TCP buffers */
00580 pl_l=(INTS4 *)ps_head;
00581 l_buffer = s_his_comm_serv.lu_size;
00582 i_l=l_buffer/16384;
00583 l_buffer=l_buffer%16384;
00584 for(i_j=0;i_j<i_l;i_j++){l_status = f_stc_write (pl_l,16384,l_gl_serv_chan);pl_l+=4096;}
00585 if(l_buffer > 0)         l_status = f_stc_write (pl_l,l_buffer,l_gl_serv_chan);
00586 
00587 if(l_status != STC__SUCCESS)
00588 { printf("error writing directory to client\n"); f_stc_discclient(l_gl_serv_chan);return(COMM__ERROR);}
00589 f_stc_discclient (l_gl_serv_chan);
00590 return(COMM__SUCCESS);
00591 }
00592 /*1+ C Procedure ***********+******************************************/
00593 /*                                                                    */
00594 /*+ Module      : f_his_sendhis                                       */
00595 /*                                                                    */
00596 /*--------------------------------------------------------------------*/
00597 /*+ CALLING     : l=f_his_sendhis(s_his_head *ps_head, int histos, char *histo, int *data)*/
00598 /*--------------------------------------------------------------------*/
00599 /*                                                                    */
00600 /*+ PURPOSE     : Send histogram                                      */
00601 /*                                                                    */
00602 /*+ ARGUMENTS   :                                                     */
00603 /*                                                                    */
00604 /*+  ps_head    : Address of header list.                             */
00605 /*+  histos     : Number of histograms                                */
00606 /*+  histo      : Name of requested histograms                        */
00607 /*+  data       : Pointer array to histogram data                     */
00608 /*                                                                    */
00609 /*+ Return type : int.                                                */
00610 /*-               COMM__SUCCESS : OK                                  */
00611 /*-               COMM__ERROR   : Error                               */
00612 /*-               COMM__NOHIST  : Histogram not there                 */
00613 /*                                                                    */
00614 /*2+DESCRIPTION***+***********+****************************************/
00615 /*                                                                    */
00616 /*+ FUNCTION    : Send one s_his_head and data to client.             */
00617 /*                Histogram is searched by name.                      */
00618 /*                                                                    */
00619 /*2+IMPLEMENTATION************+****************************************/
00620 /*                                                                    */
00621 /*+ File name   : f_his_hist.c                                        */
00622 /*+ Version     : 1.01                                                */
00623 /*+ Author      : Hans Essel                                          */
00624 /*+ Created     : 21-May-2000                                         */
00625 /*+ Updates     : Date        Purpose                                 */
00626 /*                                                                    */
00627 /*1- C Main ****************+******************************************/
00628 INTS4 f_his_sendhis(s_his_head *ps_head, INTS4 l_histos, CHARS *pc_histo, INTS4 *pl_data)
00629 {
00630 s_his_head *ps_his_head;
00631 INTS4 *pl_l,i_j,i_l,ll,l_buffer,l_status;
00632 
00633 s_his_comm_serv.lu_endian=1;
00634 s_his_comm_serv.lu_histos=0;
00635 s_his_comm_serv.lu_action=COMM__PUTHIST;
00636 ps_his_head = ps_head;
00637 for(ll=0;ll<l_histos;ll++)
00638 {
00639     pl_l = pl_data;
00640     if(strcmp(ps_his_head->c_name,pc_histo) == 0)
00641     {
00642    s_his_comm_serv.lu_histos=1;
00643    s_his_comm_serv.l_status=COMM__SUCCESS;
00644    s_his_comm_serv.lu_size=sizeof(s_his_head)+ps_his_head->l_bins_1 * ps_his_head->l_bins_2 * 4;
00645    l_status = f_stc_write (&s_his_comm_serv,sizeof(s_his_comm), l_gl_serv_chan);
00646    if(l_status != STC__SUCCESS)
00647         { printf("error writing comm to client\n"); f_stc_discclient(l_gl_serv_chan); return(COMM__ERROR);}
00648    if(l_gl_serv_verb == 1) {printf("%-32s %8d\n",ps_his_head->c_name,s_his_comm_serv.lu_size-sizeof(s_his_head));}
00649    l_status = f_stc_write (ps_his_head,sizeof(s_his_head), l_gl_serv_chan);
00650    if(l_status != STC__SUCCESS)
00651    { printf("error writing header to client\n"); f_stc_discclient(l_gl_serv_chan); return(COMM__ERROR); }
00652 
00653    /* break total buffer in TCP buffers */
00654    l_buffer = s_his_comm_serv.lu_size-sizeof(s_his_head);
00655    i_l=l_buffer/16384;
00656    l_buffer=l_buffer%16384;
00657    for(i_j=0;i_j<i_l;i_j++){l_status = f_stc_write (pl_l,16384,l_gl_serv_chan);pl_l+=4096;}
00658    if(l_buffer > 0)         l_status = f_stc_write (pl_l,l_buffer,l_gl_serv_chan);
00659    if(l_status != STC__SUCCESS)
00660    { printf("error writing data to client\n"); f_stc_discclient(l_gl_serv_chan); return(COMM__ERROR); }
00661    break;
00662     } /* found */
00663     ps_his_head++;
00664 } /* loop */
00665 if(s_his_comm_serv.lu_histos == 0)
00666 {
00667     if(l_gl_serv_verb == 1) {printf("Histogram %s not found\n",pc_histo);}
00668     s_his_comm_serv.l_status=COMM__NOHIST;
00669     s_his_comm_serv.lu_size=0;
00670     l_status = f_stc_write (&s_his_comm_serv,sizeof(s_his_comm), l_gl_serv_chan);
00671     if(l_status != STC__SUCCESS)
00672     { printf("error writing comm to client\n"); f_stc_discclient(l_gl_serv_chan); return(COMM__ERROR); }
00673     f_stc_discclient (l_gl_serv_chan);
00674     return(COMM__NOHIST);
00675 }
00676 f_stc_discclient (l_gl_serv_chan);
00677 return(COMM__SUCCESS);
00678 }
00679 /*1+ C Procedure ***********+******************************************/
00680 /*                                                                    */
00681 /*+ Module      : f_his_close                                         */
00682 /*                                                                    */
00683 /*--------------------------------------------------------------------*/
00684 /*+ CALLING     : l=f_his_close()                                     */
00685 /*--------------------------------------------------------------------*/
00686 /*                                                                    */
00687 /*+ PURPOSE     : Stop server, close sockets                          */
00688 /*                                                                    */
00689 /*+ ARGUMENTS   :                                                     */
00690 /*                                                                    */
00691 /*+ Return type : int.                                                */
00692 /*-               COMM__SUCCESS : OK                                  */
00693 /*-               COMM__ERROR   : Error                               */
00694 /*                                                                    */
00695 /*2+DESCRIPTION***+***********+****************************************/
00696 /*                                                                    */
00697 /*+ FUNCTION    : Stop server, close sockets .                        */
00698 /*                                                                    */
00699 /*2+IMPLEMENTATION************+****************************************/
00700 /*                                                                    */
00701 /*+ File name   : f_his_hist.c                                        */
00702 /*+ Version     : 1.01                                                */
00703 /*+ Author      : Hans Essel                                          */
00704 /*+ Created     : 21-May-2000                                         */
00705 /*+ Updates     : Date        Purpose                                 */
00706 /*                                                                    */
00707 /*1- C Main ****************+******************************************/
00708 INTS4 f_his_close()
00709 {
00710 printf("Exit histogram server\n");
00711 f_stc_close (ps_tcpserv);
00712 free(ps_tcpserv);
00713 return(COMM__SUCCESS);
00714 }
00715 
00716 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Fri Nov 28 12:59:32 2008 for Go4-v3.04-1 by  doxygen 1.4.2