Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/MbsAPI/f_his_hist.c

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

Generated on Tue Nov 8 10:56:08 2005 for Go4-v2.10-5 by doxygen1.2.15