00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "typedefs.h"
00015 #include "f_stccomm.h"
00016
00017
00018
00019 #ifdef GSI__LYNX
00020 #undef unix
00021 #endif
00022
00023 #ifdef GSI__LINUX
00024 #undef unix
00025 #endif
00026
00027 #ifdef GSI__SOLARIS
00028 #undef unix
00029 #endif
00030
00031 #ifdef GSI__WINNT
00032 #endif
00033
00034 #ifdef GSI__AIX
00035 #define AIX_DEC
00036 #endif
00037
00038 #ifdef unix
00039 #define AIX_DEC
00040 #endif
00041
00042 #ifdef GSI__WINNT
00043 #include <time.h>
00044 #include <memory.h>
00045 #include <sys/timeb.h>
00046 #include <sys/types.h>
00047 #include <stdio.h>
00048 #include <stdlib.h>
00049 #include <fcntl.h>
00050 #include <string.h>
00051 #include <sys/stat.h>
00052 #include <fcntl.h>
00053 #define DEF_FILE_ACCE S_IREAD|S_IWRITE
00054 #define GET__OPEN_FLAG O_RDONLY|O_BINARY
00055 #define PUT__OPEN_APD_FLAG O_RDWR|O_APPEND
00056 #define PUT__CRT_FLAG O_CREAT|O_RDWR
00057 #define PUT__CRT_OPT ""
00058
00059 #include <winsock.h>
00060 #define WS_VERSION_REQD 0x0101
00061 #define WS_VERSION_MAJOR HIBYTE(WS_VERSION_REQD)
00062 #define WS_VERSION_MINOR LOBYTE(WS_VERSION_REQD)
00063 #define MIN_SOCKETS_REQD 6
00064
00065 #endif
00066
00067 #ifdef Linux
00068 #include <stdio.h>
00069 #include <stdlib.h>
00070 #include <fcntl.h>
00071 #include <string.h>
00072 #include <unistd.h>
00073 #include <memory.h>
00074 #include <pwd.h>
00075 #include <sys/time.h>
00076 #include <sys/timeb.h>
00077 #include <sys/types.h>
00078 #include <sys/stat.h>
00079 #define DEF_FILE_ACCE S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH
00080 #define GET__OPEN_FLAG O_RDONLY
00081 #define PUT__OPEN_APD_FLAG O_RDWR|O_APPEND
00082 #define PUT__CRT_FLAG O_CREAT|O_RDWR
00083 #define PUT__CRT_OPT ""
00084 #endif
00085
00086 #ifdef Solaris
00087 #include <stdio.h>
00088 #include <stdlib.h>
00089 #include <fcntl.h>
00090 #include <string.h>
00091 #include <unistd.h>
00092 #include <memory.h>
00093 #include <pwd.h>
00094 #include <sys/time.h>
00095 #include <sys/timeb.h>
00096 #include <sys/types.h>
00097 #include <sys/stat.h>
00098 #define DEF_FILE_ACCE S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH
00099 #define GET__OPEN_FLAG O_RDONLY
00100 #define PUT__OPEN_APD_FLAG O_RDWR|O_APPEND
00101 #define PUT__CRT_FLAG O_CREAT|O_RDWR
00102 #define PUT__CRT_OPT ""
00103 #endif
00104
00105 #ifdef Darwin
00106 #include <stdio.h>
00107 #include <stdlib.h>
00108 #include <fcntl.h>
00109 #include <string.h>
00110 #include <unistd.h>
00111 #include <memory.h>
00112 #include <pwd.h>
00113 #include <sys/time.h>
00114 #include <sys/timeb.h>
00115 #include <sys/types.h>
00116 #include <sys/stat.h>
00117 #define DEF_FILE_ACCE S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH
00118 #define GET__OPEN_FLAG O_RDONLY
00119 #define PUT__OPEN_APD_FLAG O_RDWR|O_APPEND
00120 #define PUT__CRT_FLAG O_CREAT|O_RDWR
00121 #define PUT__CRT_OPT ""
00122 #endif
00123
00124
00125
00126 #ifdef _AIX
00127 #include <stdio.h>
00128 #include <stdlib.h>
00129 #include <fcntl.h>
00130 #include <string.h>
00131 #include <unistd.h>
00132 #include <memory.h>
00133 #include <pwd.h>
00134 #include <sys/time.h>
00135 #include <sys/timeb.h>
00136 #include <sys/types.h>
00137 #include <sys/mode.h>
00138 #define DEF_FILE_ACCE S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH
00139 #define GET__OPEN_FLAG O_RDONLY
00140 #define PUT__OPEN_APD_FLAG O_RDWR|O_APPEND
00141 #define PUT__CRT_FLAG O_CREAT|O_RDWR
00142 #define PUT__CRT_OPT ""
00143 #endif
00144
00145 #if MBS_ENDIAN == 1
00146 #include "s_filhe_swap.h"
00147 #else
00148 #include "s_filhe.h"
00149 #endif
00150
00151
00152 #ifdef RFIO
00153 #define RFIO_open rfio_open
00154 #define RFIO_close rfio_close
00155 #define RFIO_read rfio_read
00156 #define RFIO_lseek rfio_lseek
00157 #include "rawapin.h"
00158 #else
00159 #define RFIO_open open
00160 #define RFIO_close close
00161 #define RFIO_read read
00162 #define RFIO_lseek lseek
00163 #endif
00164
00165
00166
00167
00168 #include "fLmd.h"
00169
00170
00171 #include "gps_sc_def.h"
00172 #include "f_evt.h"
00173 #include "f_evcli.h"
00174 #include "portnum_def.h"
00175
00176 INTS4 f_evt_get_newbuf(s_evt_channel *);
00177 INTS4 f_evt_check_buf(CHARS *,INTS4 *, INTS4 *, INTS4 *, INTS4 *);
00178 INTS4 f_evt_ini_bufhe(s_evt_channel *ps_chan);
00179 INTS4 f_evt_swap_filhe(s_bufhe *);
00180 INTS4 f_ut_utime(INTS4, INTS4, CHARS *);
00181
00182 static struct s_tcpcomm s_tcpcomm_st_evt;
00183 static CHARS c_temp[MAX_BUF_LGTH];
00184 static int l_gl_source_port = 0;
00185 static int l_gl_evt_check = 0;
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243 INTS4 f_evt_get_subevent(s_ve10_1 *ps_ve10_1, INTS4 l_subevent, INTS4 **pl_se, INTS4 **pl_d,INTS4 *pl_lwords)
00244 {
00245 s_ves10_1 *ps_ves10_1;
00246 INTS4 l_total,l_sub,l_sum;
00247 INTS4 l,ll,l_status,*pl_next;
00248
00249 if(ps_ve10_1 == NULL) return(GETEVT__FAILURE);
00250 pl_next = (INTS4 *) (ps_ve10_1 + 1);
00251 l_total = ps_ve10_1->l_dlen-4;
00252 l_sum = 0;
00253 ll=0;
00254 while(l_sum < l_total)
00255 {
00256 ps_ves10_1 = (s_ves10_1 *) pl_next;
00257 ll++;
00258 if(ll == l_subevent)
00259 {
00260 if(pl_lwords != NULL) *pl_lwords = ps_ves10_1->l_dlen/2-1;
00261 if(pl_se != NULL) *pl_se = (INTS4 *) ps_ves10_1;
00262 if(pl_d != NULL) *pl_d = (INTS4 *) (ps_ves10_1+1);
00263 return(GETEVT__SUCCESS);
00264 }
00265 l_sub = ps_ves10_1->l_dlen+4;
00266 l_sum += l_sub;
00267 pl_next = (INTS4 *)(ps_ves10_1);
00268 pl_next += l_sub/2;
00269 }
00270 if(pl_lwords != NULL) *pl_lwords = ll;
00271 if(pl_se != NULL) *pl_se = NULL;
00272 if(pl_d != NULL) *pl_d = NULL;
00273 if(l_subevent == 0) return(ll);
00274 else return(GETEVT__NOMORE);
00275 }
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306 INTS4 f_evt_type(s_bufhe *ps_bufhe,s_evhe *ps_evhe, INTS4 l_subid,INTS4 l_long,INTS4 l_hex,INTS4 l_data)
00307 {
00308 s_ves10_1 *ps_ves10_1;
00309 s_ve10_1 *ps_ve10_1;
00310 s_filhe *ps_filhe;
00311 INTS2 *pi_data;
00312 INTS4 *pl_data;
00313 INTS4 l_mode,l_s;
00314 INTS4 l,ll,l_status,l_ldata,l_used;
00315 CHARS c_line[132];
00316 CHARS c_full[132];
00317 CHARS c_time[32];
00318
00319 strcpy(c_full," ");
00320 l_ldata=l_data;
00321 if((l_hex+l_long) > 0) l_ldata=1;
00322
00323
00324 if(ps_bufhe != NULL)
00325 {
00326 sprintf(c_line,"--------------------------------------------------------");
00327 printf("%s\n",c_line);
00328
00329 ll=ps_bufhe->l_dlen*2;
00330 if(ll%512 > 0)ll += 512-ll%512;
00331
00332 l_status = f_ut_utime(ps_bufhe->l_time[0],ps_bufhe->l_time[1],c_time);
00333 if(ps_bufhe->i_type == 2000)
00334 {
00335 ps_filhe=(s_filhe *)ps_bufhe;
00336 sprintf(c_line,"File header info:");
00337 printf("%s\n",c_line);
00338 sprintf(c_line,"Size: %d [%d b], used %d [b]",ps_filhe->filhe_dlen,ll,ps_filhe->filhe_used*2);
00339 printf("%s\n",c_line);
00340 sprintf(c_line,"Label: %s",ps_filhe->filhe_label);
00341 printf("%s\n",c_line);
00342 sprintf(c_line,"File: %s",ps_filhe->filhe_file);
00343 printf("%s\n",c_line);
00344 sprintf(c_line,"User: %s",ps_filhe->filhe_user);
00345 printf("%s\n",c_line);
00346 sprintf(c_line,"Time: %s",ps_filhe->filhe_time);
00347 printf("%s\n",c_line);
00348 sprintf(c_line,"Run: %s",ps_filhe->filhe_run);
00349 printf("%s\n",c_line);
00350 sprintf(c_line,"Exp: %s",ps_filhe->filhe_exp);
00351 printf("%s\n",c_line);
00352 for(ll=0;ll<ps_filhe->filhe_lines;ll++)
00353 {
00354 sprintf(c_line,"comment: %s",ps_filhe->s_strings[ll].string);
00355 printf("%s\n",c_line);
00356 }
00357 }
00358 else
00359 {
00360 l_used=ps_bufhe->i_used;
00361 if(ps_bufhe->l_dlen > MAX__DLEN)l_used=ps_bufhe->l_free[2];
00362 sprintf(c_line,"Buffer %9d, Length %5d[w] Size %5d[b] used %5d[w] %s",
00363 ps_bufhe->l_buf,
00364 ps_bufhe->l_dlen,
00365 ll,l_used,
00366 c_time);
00367 printf("%s\n",c_line);
00368 sprintf(c_line," Events %3d Type/Subtype %5d %5d FragEnd=%d FragBegin=%d Total %5d[w]",
00369 ps_bufhe->l_evt,
00370 ps_bufhe->i_type,
00371 ps_bufhe->i_subtype,
00372 ps_bufhe->h_end,
00373 ps_bufhe->h_begin,
00374 ps_bufhe->l_free[1]);
00375 printf("%s\n",c_line);
00376 }
00377 sprintf(c_line,"--------------------------------------------------------");
00378 printf("%s\n",c_line);
00379 }
00380
00381 if(ps_evhe == NULL) return(0);
00382
00383
00384 if(ps_evhe->i_type != 10)
00385 {
00386 sprintf(c_line,"Event type %d, subtype %d, data longwords %d",
00387 ps_evhe->i_type,ps_evhe->i_subtype,ps_evhe->l_dlen/2);
00388 printf("%s\n",c_line);
00389 if((l_ldata != 0) & ((ps_evhe->i_type == 4)|(ps_evhe->i_type == 6)))
00390 {
00391 pl_data = (INTS4 *)ps_evhe;
00392 pl_data += 2;
00393 for(l=0;l<ps_evhe->l_dlen/2;l++)
00394 {
00395 sprintf(c_line,"%08x ",*pl_data);
00396 strcat(c_full,c_line);
00397 pl_data++;
00398 if(l%8 == 7) {
00399 printf("%s\n",c_full);
00400 strcpy(c_full," ");
00401 }
00402 }
00403 if(strlen(c_full) > 2) printf("%s\n",c_full);
00404 }
00405 return(0);
00406 }
00407
00408
00409 ps_ve10_1 = (s_ve10_1 *)ps_evhe;
00410
00411 sprintf(c_line,"Event %9d Type/Subtype %5d %5d Length %5d[w] Trigger %2d",
00412 ps_ve10_1->l_count,
00413 ps_ve10_1->i_type,
00414 ps_ve10_1->i_subtype,
00415 ps_ve10_1->l_dlen,
00416 ps_ve10_1->i_trigger);
00417 printf("%s\n",c_line);
00418
00419
00420 l_s=0;
00421 l_status=0;
00422 while(l_status == 0)
00423 {
00424 l_s++;
00425 l_status=f_evt_get_subevent(ps_ve10_1,l_s,(INTS4 **)&ps_ves10_1,(INTS4 **)&pl_data,(INTS4 *)&ll);
00426 if(l_status == 0)
00427 {
00428 if((l_subid < 0)|(l_subid == ps_ves10_1->i_procid))
00429 {
00430 sprintf(c_line," SubEv ID %6d Type/Subtype %5d %5d Length %5d[w] Control %2d Subcrate %2d",
00431 ps_ves10_1->i_procid,
00432 ps_ves10_1->i_type,
00433 ps_ves10_1->i_subtype,
00434 ps_ves10_1->l_dlen,
00435 ps_ves10_1->h_control,
00436 ps_ves10_1->h_subcrate);
00437 printf("%s\n",c_line);
00438 if(l_ldata != 0)
00439 {
00440 if((l_long != 0) | (l_hex != 0))
00441 {
00442 for(l=0;l<ll;l++)
00443 {
00444 if(l_hex != 0) sprintf(c_line,"%04x.%04x ",(*pl_data>>16)&0xffff,*pl_data&0xffff);
00445 else sprintf(c_line,"%8d ",*pl_data);
00446 strcat(c_full,c_line);
00447 pl_data++;
00448 if(l%8 == 7)
00449 {
00450 printf("%s\n",c_full);
00451 strcpy(c_full," ");
00452 }
00453 }
00454 if(strlen(c_full) > 2)printf("%s\n",c_full);
00455 strcpy(c_full," ");
00456 }
00457 else
00458 {
00459 for(l=0;l<ll;l++)
00460 {
00461 sprintf(c_line,"%8d%8d",*pl_data&0xffff,(*pl_data>>16)&0xffff);
00462 strcat(c_full,c_line);
00463 pl_data++;
00464 if(l%4 == 3)
00465 {
00466 printf("%s\n",c_full);
00467 strcpy(c_full," ");
00468 }
00469 }
00470 if(strlen(c_full) > 2)printf("%s\n",c_full);
00471 strcpy(c_full," ");
00472 }
00473 }
00474 }
00475 }
00476 }
00477 return(0);
00478 }
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495 INTS4 f_evt_source_port(INTS4 l_port)
00496 {
00497 l_gl_source_port=l_port;
00498 if (l_port>0) printf("Use MBS source port %d\n",l_port);
00499 return 0;
00500 }
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518 INTS4 f_evt_rev_port(INTS4 l_port)
00519 {
00520 l_gl_source_port=l_port;
00521 if (l_port>0) printf("Use MBS source port %d\n",l_port);
00522 return 0;
00523 }
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561 INTS4 f_evt_get_open(INTS4 l_mode, CHARS *pc_server, s_evt_channel *ps_chan,
00562 CHARS **ps_info, INTS4 l_sample, INTS4 l_param)
00563 {
00564
00565 INTS4 l_swap, l_swap_head, l_is_goosybuf, l_filehead=0, l_size, l_size_head, l_dummy, l_header_size, l_port;
00566 INTS2 *pi;
00567 CHARS c_file[256], *pc_temp;
00568 s_filhe *ps_filhe;
00569 struct s_varstr
00570 {
00571 INTS2 i_varstr;
00572 CHARS c_varstr[128];
00573 } s_varstr_file;
00574 INTS4 l_status,ll;
00575
00576 l_port = l_gl_source_port;
00577
00578
00579 #ifndef GSI__WINNT
00580
00581 if((pc_temp=strchr(pc_server,':')) != NULL) {
00582 l_mode=GETEVT__RFIO;
00583
00584 }
00585 #endif
00586
00587 #ifndef RFIO
00588 if(l_mode == GETEVT__RFIO)
00589 {
00590 printf("rfio not supported!\n");
00591 return(GETEVT__NOFILE);
00592 }
00593 #endif
00594
00595 if(ps_info != NULL) *ps_info=NULL;
00596
00597 if(ps_chan->l_timeout==0)ps_chan->l_timeout=-1;
00598 strcpy(ps_chan->c_channel,pc_server);
00599 switch(l_mode) {
00600 case GETEVT__FILE :
00601 strcpy(c_file,pc_server);
00602 if(strlen(c_file) < 5) strcat(c_file,".lmd");
00603 else {
00604 pc_temp = (CHARS *) &c_file[strlen(c_file)-4];
00605 if((strcmp(pc_temp,".LMD") != 0) &&
00606 (strcmp(pc_temp,".lmd") != 0)) strcat(c_file,".lmd");
00607 }
00608
00609 if((ps_chan->l_channel_no=open(c_file,GET__OPEN_FLAG))== -1)
00610 {
00611 return(GETEVT__NOFILE);
00612 }
00613
00614 if(read(ps_chan->l_channel_no,c_temp,MIN_BUF_LGTH)!=MIN_BUF_LGTH) {
00615 printf("LMD format error: no LMD file: %s\n",c_file);
00616 close(ps_chan->l_channel_no);
00617 ps_chan->l_channel_no=-1;
00618 return(GETEVT__NOLMDFILE);
00619 }
00620
00621 ps_chan->pLmd=NULL;
00622 if((*((INTS4 *)(c_temp+4)) == LMD__TYPE_FILE_HEADER_101_1)||
00623 (*((INTS4 *)(c_temp+4)) == 0x65000100)){
00624 close(ps_chan->l_channel_no);
00625 ps_chan->pLmd=fLmdAllocateControl();
00626 fLmdGetOpen(ps_chan->pLmd,c_file,NULL,LMD__BUFFER,LMD__NO_INDEX);
00627 ps_chan->l_server_type=l_mode;
00628 return GETEVT__SUCCESS;
00629 }
00630
00631
00632 f_evt_check_buf(c_temp, &l_size_head, &l_is_goosybuf, &l_swap_head, &l_filehead);
00633 if(((l_is_goosybuf==0)&(l_filehead==0))|(l_size_head==0)) {
00634 printf("LMD format error: swap=%d, header=%d, isLMD=%d, size=%d\n",l_swap_head,l_filehead,l_is_goosybuf,l_size_head);
00635 close(ps_chan->l_channel_no);
00636 ps_chan->l_channel_no=-1;
00637 return(GETEVT__NOLMDFILE);
00638 }
00639
00640
00641 if(l_filehead == 1) {
00642 lseek(ps_chan->l_channel_no, 0, SEEK_SET);
00643 l_header_size=l_size_head;
00644 if(((s_filhe *)c_temp)->filhe_dlen > MAX__DLEN){
00645 l_header_size=((s_filhe *)c_temp)->filhe_used*2+48;
00646
00647 }
00648 if(read(ps_chan->l_channel_no,c_temp,l_header_size)!=l_header_size){
00649 printf("LMD format error: no LMD file: %s\n",c_file);
00650 close(ps_chan->l_channel_no);
00651 ps_chan->l_channel_no=-1;
00652 return(GETEVT__NOLMDFILE);
00653 }
00654 if(read(ps_chan->l_channel_no,c_temp,MIN_BUF_LGTH)!=MIN_BUF_LGTH) {
00655 close(ps_chan->l_channel_no);
00656 ps_chan->l_channel_no=-1;
00657 return(GETEVT__RDERR);
00658 }
00659 f_evt_check_buf(c_temp, &l_size, &l_is_goosybuf, &l_swap, &l_dummy);
00660 if((l_is_goosybuf==0)|(l_size!=l_size_head)|(l_swap!=l_swap_head)) {
00661 printf("LMD format error: swap=%d, isLMD=%d, size=%d\n",l_swap,l_is_goosybuf,l_size);
00662 close(ps_chan->l_channel_no);
00663 ps_chan->l_channel_no=-1;
00664 return(GETEVT__NOLMDFILE);
00665 }
00666 }
00667 ps_chan->l_buf_size=l_size_head;
00668 lseek(ps_chan->l_channel_no, 0, SEEK_SET);
00669 if(ps_info != NULL) *ps_info=NULL;
00670
00671 if(l_filehead == 1) {
00672 if(read(ps_chan->l_channel_no,c_temp,l_header_size)!=l_header_size) {
00673 printf("LMD format error: no LMD file: %s\n",c_file);
00674 close(ps_chan->l_channel_no);
00675 ps_chan->l_channel_no=-1;
00676 return(GETEVT__NOLMDFILE);
00677 }
00678 ps_filhe = (s_filhe *) c_temp;
00679 if(ps_info != NULL) {
00680 if( l_swap_head ==1) f_evt_swap_filhe((s_bufhe *)ps_filhe);
00681 *ps_info=c_temp;
00682 }
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699 }
00700
00701
00702
00703 ps_chan->l_io_buf_size=ps_chan->l_buf_size;
00704
00705 break;
00706 case GETEVT__STREAM :
00707
00708 if (l_port<=0) l_port = PORT__STREAM_SERV;
00709
00710
00711 if(f_stc_connectserver(pc_server,l_port,&ps_chan->l_channel_no,
00712 &s_tcpcomm_st_evt)!=STC__SUCCESS)
00713 {
00714 return(GETEVT__NOSERVER);
00715 }
00716
00717 l_status=f_stc_read(c_temp,16,ps_chan->l_channel_no,ps_chan->l_timeout);
00718 if(l_status == STC__TIMEOUT) return(GETEVT__TIMEOUT);
00719 if(l_status != STC__SUCCESS) return(GETEVT__RDERR);
00720
00721 if( *((INTS4 *)(c_temp))!=1)f_evt_swap(c_temp, 16);
00722 ps_chan->l_buf_size=*((INTS4 *)(c_temp+4));
00723 ps_chan->l_bufs_in_stream=*((INTS4 *)(c_temp+8));
00724
00725 ps_chan->l_stream_bufs = 0;
00726
00727 ps_chan->l_io_buf_size=(ps_chan->l_buf_size)*(ps_chan->l_bufs_in_stream);
00728
00729 ps_chan->pLmd=NULL;
00730 if(*((INTS4 *)(c_temp+12)) == 0) {
00731 ps_chan->pLmd=fLmdAllocateControl();
00732 ps_chan->pLmd->pTCP=&s_tcpcomm_st_evt;
00733
00734 fLmdInitMbs(ps_chan->pLmd,pc_server,ps_chan->l_buf_size,ps_chan->l_bufs_in_stream,0,PORT__STREAM_SERV,ps_chan->l_timeout);
00735 printf("f_evt_get_open for STREAM: port=%d timeout=%d \n",l_port, ps_chan->l_timeout);
00736
00737 ps_chan->l_server_type=l_mode;
00738 return GETEVT__SUCCESS;
00739 }
00740
00741 break;
00742 case GETEVT__TRANS :
00743
00744 if (l_port<=0) l_port = PORT__TRANSPORT;
00745
00746
00747 if(f_stc_connectserver(pc_server,l_port,&ps_chan->l_channel_no,
00748 &s_tcpcomm_st_evt)!=STC__SUCCESS)
00749 {
00750 return(GETEVT__NOSERVER);
00751 }
00752
00753 l_status=f_stc_read(c_temp,16,ps_chan->l_channel_no,ps_chan->l_timeout);
00754 if(l_status == STC__TIMEOUT) return(GETEVT__TIMEOUT);
00755 if(l_status != STC__SUCCESS) return(GETEVT__RDERR);
00756
00757 if( *((INTS4 *)(c_temp))!=1)f_evt_swap(c_temp, 16);
00758 ps_chan->l_buf_size=*((INTS4 *)(c_temp+4));
00759 ps_chan->l_bufs_in_stream=*((INTS4 *)(c_temp+8));
00760
00761 ps_chan->l_io_buf_size=ps_chan->l_buf_size;
00762
00763 ps_chan->pLmd=NULL;
00764 if(*((INTS4 *)(c_temp+12)) == 0) {
00765 ps_chan->pLmd=fLmdAllocateControl();
00766 ps_chan->pLmd->pTCP=&s_tcpcomm_st_evt;
00767 fLmdInitMbs(ps_chan->pLmd,pc_server,ps_chan->l_buf_size,ps_chan->l_bufs_in_stream,0,PORT__TRANSPORT,ps_chan->l_timeout);
00768 printf("f_evt_get_open for TRANSPORT: port=%d timeout=%d \n",l_port, ps_chan->l_timeout);
00769 ps_chan->l_server_type=l_mode;
00770 return GETEVT__SUCCESS;
00771 }
00772
00773 break;
00774 case GETEVT__REVSERV :
00775 if (l_port<=0) l_port = PORT__EVENT_SERV;
00776 if(f_evcli_con(ps_chan, pc_server, l_port, -1, l_sample)!=STC__SUCCESS)
00777 {
00778 return(GETEVT__NOSERVER);
00779 }
00780 break;
00781 case GETEVT__EVENT :
00782 if (l_port<=0) l_port = PORT__EVENT_SERV;
00783 if(f_evcli_con(ps_chan, pc_server, l_port, -1, l_sample)!=STC__SUCCESS)
00784 {
00785 return(GETEVT__NOSERVER);
00786 }
00787 break;
00788 case GETEVT__RFIO :
00789 ps_chan->l_channel_no=-1;
00790 ps_chan->l_channel_no=RFIO_open(pc_server,GET__OPEN_FLAG,0);
00791 if(ps_chan->l_channel_no < 0) return(GETEVT__NOSERVER);
00792
00793 if(RFIO_read(ps_chan->l_channel_no,c_temp,MIN_BUF_LGTH)!=MIN_BUF_LGTH)
00794 {
00795 printf("LMD format error: no LMD file: %s\n",pc_server);
00796 RFIO_close(ps_chan->l_channel_no);
00797 ps_chan->l_channel_no=-1;
00798 return(GETEVT__NOLMDFILE);
00799 }
00800
00801 f_evt_check_buf(c_temp, &l_size_head, &l_is_goosybuf, &l_swap_head, &l_filehead);
00802 if(((l_is_goosybuf==0)&(l_filehead==0))|(l_size_head==0))
00803 {
00804 printf("LMD format error: swap=%d, header=%d, isLMD=%d, size=%d\n",l_swap_head,l_filehead,l_is_goosybuf,l_size_head);
00805 RFIO_close(ps_chan->l_channel_no);
00806 ps_chan->l_channel_no=-1;
00807 return(GETEVT__NOLMDFILE);
00808 }
00809
00810 if(l_filehead == 1)
00811 {
00812 RFIO_lseek(ps_chan->l_channel_no, 0, SEEK_SET);
00813 if(RFIO_read(ps_chan->l_channel_no,c_temp,l_size_head)!=l_size_head)
00814 {
00815 printf("LMD format error: no LMD file: %s\n",pc_server);
00816 RFIO_close(ps_chan->l_channel_no);
00817 ps_chan->l_channel_no=-1;
00818 return(GETEVT__NOLMDFILE);
00819 }
00820 if(RFIO_read(ps_chan->l_channel_no,c_temp,MIN_BUF_LGTH)!=MIN_BUF_LGTH)
00821 {
00822 RFIO_close(ps_chan->l_channel_no);
00823 ps_chan->l_channel_no=-1;
00824 return(GETEVT__RDERR);
00825 }
00826 f_evt_check_buf(c_temp, &l_size, &l_is_goosybuf, &l_swap, &l_dummy);
00827 if((l_is_goosybuf==0)|(l_size!=l_size_head)|(l_swap!=l_swap_head))
00828 {
00829 printf("LMD format error: swap=%d, isLMD=%d, size=%d\n",l_swap,l_is_goosybuf,l_size);
00830 RFIO_close(ps_chan->l_channel_no);
00831 ps_chan->l_channel_no=-1;
00832 return(GETEVT__NOLMDFILE);
00833 }
00834 }
00835 ps_chan->l_buf_size=l_size_head;
00836 RFIO_lseek(ps_chan->l_channel_no, 0, SEEK_SET);
00837 if(ps_info != NULL)*ps_info=NULL;
00838
00839 if(l_filehead == 1)
00840 {
00841 if(RFIO_read(ps_chan->l_channel_no,c_temp,l_size_head)!=l_size_head)
00842 {
00843 printf("LMD format error: no LMD file: %s\n",pc_server);
00844 RFIO_close(ps_chan->l_channel_no);
00845 ps_chan->l_channel_no=-1;
00846 return(GETEVT__NOLMDFILE);
00847 }
00848 ps_filhe=(s_filhe *)c_temp;
00849 if(ps_info != NULL)
00850 {
00851 if( l_swap_head ==1)f_evt_swap_filhe((s_bufhe *)ps_filhe);
00852 *ps_info=c_temp;
00853 }
00854
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870 }
00871 ps_chan->l_io_buf_size=ps_chan->l_buf_size;
00872 break;
00873 default :
00874 if(ps_info != NULL) *ps_info=NULL;
00875 return(GETEVT__NOSERVER);
00876 }
00877
00878 if((l_mode != GETEVT__EVENT)&(l_mode != GETEVT__REVSERV))
00879 {
00880 if( (ps_chan->pc_io_buf=malloc(ps_chan->l_io_buf_size))==NULL)
00881 {
00882 printf("Memory allocation error\n");
00883 exit(2);
00884 }
00885 ps_chan->l_evt_buf_size=ps_chan->l_io_buf_size;
00886 if( (ps_chan->pc_evt_buf=malloc(ps_chan->l_evt_buf_size))==NULL)
00887 {
00888 printf("Memory allocation error\n");
00889 exit(2);
00890 }
00891 }
00892 ps_chan->l_server_type=l_mode;
00893 ps_chan->l_first_get=1;
00894 return GETEVT__SUCCESS;
00895 }
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923 INTS4 f_evt_get_event(s_evt_channel *ps_chan, INTS4 **ppl_buffer, INTS4 **ppl_goobuf)
00924 {
00925 INTS4 l_temp,l_prev_ok=1, l_stat, l_used;
00926 s_bufhe *ps_bufhe_cur;
00927 s_ve10_1 *ps_ve10_1;
00928 sMbsHeader *pevt;
00929
00930
00931 if(ps_chan->pLmd != NULL){
00932 if(ps_chan->l_server_type == GETEVT__TRANS)
00933 l_stat=fLmdGetMbsEvent(ps_chan->pLmd, &pevt);
00934 else if(ps_chan->l_server_type == GETEVT__STREAM)
00935 l_stat=fLmdGetMbsEvent(ps_chan->pLmd, &pevt);
00936 else if(ps_chan->l_server_type == GETEVT__FILE)
00937 l_stat=fLmdGetElement(ps_chan->pLmd,LMD__NO_INDEX, &pevt);
00938
00939
00940 if(pevt==NULL){
00941 if (ps_chan->l_server_type == GETEVT__FILE){
00942 if(l_stat == GETLMD__NOMORE) return(GETEVT__NOMORE);
00943 if(l_stat == GETLMD__EOFILE) return(GETEVT__NOMORE);
00944 if(l_stat == GETLMD__NOBUFFER) return(GETEVT__FAILURE);
00945 return(GETEVT__RDERR);
00946 } else {
00947 if(l_stat == LMD__TIMEOUT) return(GETEVT__TIMEOUT);
00948 else return (GETEVT__RDERR);
00949 }
00950 }
00951
00952 if(ppl_goobuf)*ppl_goobuf = NULL;
00953 *ppl_buffer = (INTS4 *)pevt;
00954 return(GETEVT__SUCCESS);
00955 }
00956
00957 if((ps_chan->l_server_type == GETEVT__EVENT)|(ps_chan->l_server_type == GETEVT__REVSERV))
00958 {
00959 *ppl_goobuf = NULL;
00960 if(f_evcli_evt(ps_chan) != STC__SUCCESS)
00961 {
00962 l_stat=f_evcli_buf(ps_chan);
00963 if(l_stat == STC__TIMEOUT) return(GETEVT__TIMEOUT);
00964 if(l_stat != STC__SUCCESS) return(GETEVT__FAILURE);
00965 }
00966 *ppl_buffer = (INTS4 *) ps_chan->pc_evt_buf;
00967 return(GETEVT__SUCCESS);
00968 }
00969
00970
00971
00972
00973 if(ps_chan->l_first_get==1)
00974 {
00975 ps_chan->l_buf_posi=0;
00976 ps_chan->l_buf_lmt=0;
00977 ps_chan->l_io_buf_posi=MAX_LONG;
00978 ps_chan->l_first_buf=1;
00979 ps_chan->l_first_get=0;
00980 }
00981
00982
00983
00984
00985
00986 ps_chan->l_evt_buf_posi=0;
00987
00988
00989 while(1)
00990 {
00991
00992
00993 while (ps_chan->l_buf_posi >= ps_chan->l_buf_lmt)
00994 {
00995
00996
00997 if(ps_chan->l_io_buf_posi>=ps_chan->l_io_buf_size)
00998 {
00999 if((l_temp=f_evt_get_newbuf(ps_chan))!=GETEVT__SUCCESS) return(l_temp);
01000 ps_chan->l_io_buf_posi=0;
01001 }
01002 ps_chan->ps_bufhe = (s_bufhe*) (ps_chan->pc_io_buf+ps_chan->l_io_buf_posi);
01003 l_prev_ok = (ps_chan->l_buf_no == (ps_chan->ps_bufhe->l_buf-1));
01004 ps_chan->l_buf_no = ps_chan->ps_bufhe->l_buf;
01005 if(ps_chan->ps_bufhe->i_type == 2000) {
01006 printf("Unsolicited file header found!\n");
01007 ps_chan->l_io_buf_posi += ps_chan->l_buf_size;
01008 ps_chan->l_buf_posi = ps_chan->l_io_buf_posi;
01009 ps_chan->l_buf_lmt = ps_chan->l_io_buf_posi;
01010 } else {
01011 l_used=ps_chan->ps_bufhe->l_free[2];
01012 if(ps_chan->ps_bufhe->l_dlen <= MAX__DLEN)l_used=ps_chan->ps_bufhe->i_used;
01013 ps_chan->l_buf_posi = ps_chan->l_io_buf_posi + sizeof(s_bufhe);
01014 ps_chan->l_buf_lmt = ps_chan->l_buf_posi + l_used*2;
01015 ps_chan->l_io_buf_posi += ps_chan->l_buf_size;
01016 }
01017 }
01018
01019
01020 ps_chan->ps_ve10_1 = (s_ve10_1 *) (ps_chan->pc_io_buf + ps_chan->l_buf_posi);
01021 if( (ps_chan->l_evt_buf_posi != 0) || ((ps_chan->ps_bufhe->h_end==1) && (ps_chan->l_first_buf==1)) ) {
01022 ps_chan->l_buf_posi += sizeof(s_evhe);
01023 ps_chan->l_frag_len = ps_chan->ps_ve10_1->l_dlen*2;
01024 } else
01025 ps_chan->l_frag_len = (ps_chan->ps_ve10_1->l_dlen-4)*2 + sizeof(s_ve10_1);
01026
01027 if(ps_chan->l_frag_len + ps_chan->l_buf_posi > ps_chan->l_buf_lmt)
01028 {
01029 return(GETEVT__FRAGMENT);
01030 }
01031
01032
01033
01034 if((ps_chan->ps_bufhe->h_end==1)&&((ps_chan->l_first_buf==1) || (l_prev_ok == 0))) {
01035
01036 ps_chan->l_first_buf=0;
01037 l_prev_ok=1;
01038 ps_chan->l_evt_buf_posi=0;
01039 ps_chan->l_buf_posi += ps_chan->l_frag_len;
01040
01041 continue;
01042 }
01043
01044 ps_chan->l_first_buf=0;
01045
01046
01047
01048 if( (ps_chan->l_evt_buf_posi==0) &&
01049 ( (ps_chan->ps_bufhe->h_begin==0) || ((ps_chan->l_buf_posi+ps_chan->l_frag_len) < ps_chan->l_buf_lmt) ) )
01050 {
01051 *ppl_buffer = (INTS4 *)(ps_chan->pc_io_buf+ps_chan->l_buf_posi);
01052 ps_chan->l_buf_posi += ps_chan->l_frag_len;
01053 ps_chan->l_evt_buf_posi = 0;
01054 if(ppl_goobuf) *ppl_goobuf = (INTS4 *) (ps_chan->ps_bufhe);
01055 return(GETEVT__SUCCESS);
01056 }
01057
01058
01059 if(ps_chan->l_evt_buf_posi==0)
01060 {
01061 memcpy((CHARS *)&ps_chan->s_bufhe_1,(CHARS *)ps_chan->ps_bufhe,sizeof(s_bufhe));
01062 ps_bufhe_cur=(s_bufhe *)&ps_chan->s_bufhe_1;
01063 }
01064
01065
01066 if(ps_chan->l_evt_buf_size<ps_chan->l_evt_buf_posi+ps_chan->l_frag_len)
01067 {
01068 ps_chan->l_evt_buf_size=ps_chan->l_evt_buf_posi+ps_chan->l_frag_len;
01069 if( (ps_chan->pc_evt_buf=realloc
01070 (ps_chan->pc_evt_buf, ps_chan->l_evt_buf_size))==NULL)
01071 {
01072 printf("Memory allocation error\n");
01073 exit(2);
01074 }
01075 }
01076 memcpy(ps_chan->pc_evt_buf+ps_chan->l_evt_buf_posi,ps_chan->pc_io_buf+ps_chan->l_buf_posi,
01077 ps_chan->l_frag_len);
01078 ps_chan->l_buf_posi += ps_chan->l_frag_len;
01079 if(ps_chan->l_evt_buf_posi == 0)
01080 {
01081 }
01082 ps_chan->l_evt_buf_posi += ps_chan->l_frag_len;
01083
01084 if((ps_chan->ps_bufhe->h_begin!=1)||(ps_chan->l_buf_posi<ps_chan->l_buf_lmt))
01085 {
01086
01087 ((s_ve10_1 *)(ps_chan->pc_evt_buf))->l_dlen=ps_chan->l_evt_buf_posi/2-4;
01088 *ppl_buffer=(INTS4 *)(ps_chan->pc_evt_buf);
01089 if(ppl_goobuf)*ppl_goobuf=(INTS4 *)(ps_bufhe_cur);
01090 return(GETEVT__SUCCESS);
01091 }
01092 }
01093 }
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106
01107
01108
01109
01110
01111
01112
01113 INTS4 f_evt_get_close(s_evt_channel * ps_chan)
01114 {
01115 INTS4 l_close_failure;
01116 INTS4 l_status;
01117
01118
01119 if(ps_chan->pLmd != NULL){
01120 if(ps_chan->l_server_type == GETEVT__TRANS)fLmdCloseMbs(ps_chan->pLmd);
01121 else if(ps_chan->l_server_type == GETEVT__STREAM)fLmdCloseMbs(ps_chan->pLmd);
01122 else if(ps_chan->l_server_type == GETEVT__FILE) fLmdGetClose(ps_chan->pLmd);
01123 free(ps_chan->pLmd);
01124 ps_chan->pLmd=NULL;
01125 return GETEVT__SUCCESS;
01126 }
01127
01128 l_close_failure=0;
01129 if(ps_chan->l_channel_no >= 0)
01130 {
01131 switch(ps_chan->l_server_type)
01132 {
01133 case GETEVT__FILE :
01134 if(close(ps_chan->l_channel_no)==-1) l_close_failure=1;
01135 if(ps_chan->pc_io_buf != NULL)free(ps_chan->pc_io_buf);
01136 if(ps_chan->pc_evt_buf != NULL)free(ps_chan->pc_evt_buf);
01137 break;
01138 case GETEVT__STREAM :
01139
01140 f_stc_write("CLOSE", 12, ps_chan->l_channel_no);
01141 if(f_stc_discclient(ps_chan->l_channel_no)!=STC__SUCCESS)l_close_failure=1;
01142 if(f_stc_close(&s_tcpcomm_st_evt)!=STC__SUCCESS) l_close_failure=1;
01143 if(ps_chan->pc_io_buf != NULL)free(ps_chan->pc_io_buf);
01144 if(ps_chan->pc_evt_buf != NULL)free(ps_chan->pc_evt_buf);
01145 break;
01146 case GETEVT__TRANS :
01147
01148 if(f_stc_discclient(ps_chan->l_channel_no)!=STC__SUCCESS)l_close_failure=1;
01149 if(f_stc_close(&s_tcpcomm_st_evt)!=STC__SUCCESS) l_close_failure=1;
01150 if(ps_chan->pc_io_buf != NULL)free(ps_chan->pc_io_buf);
01151 if(ps_chan->pc_evt_buf != NULL)free(ps_chan->pc_evt_buf);
01152 break;
01153 case GETEVT__REVSERV :
01154 case GETEVT__EVENT :
01155 if(f_evcli_close(ps_chan)!=STC__SUCCESS) l_close_failure=1;
01156 break;
01157 case GETEVT__RFIO :
01158 RFIO_close(ps_chan->l_channel_no);
01159 ps_chan->l_channel_no=-1;
01160 if(ps_chan->pc_io_buf != NULL)free(ps_chan->pc_io_buf);
01161 if(ps_chan->pc_evt_buf != NULL)free(ps_chan->pc_evt_buf);
01162 break;
01163 default :
01164 l_close_failure=1;
01165 }
01166 ps_chan->pc_io_buf=NULL;
01167 ps_chan->l_channel_no=-1;
01168 if(l_close_failure==1) return(GETEVT__CLOSE_ERR);
01169 return GETEVT__SUCCESS;
01170 }
01171 return GETEVT__SUCCESS;
01172
01173 }
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193
01194
01195
01196
01197
01198
01199
01200
01201
01202
01203
01204
01205 INTS4 f_evt_put_open(CHARS *pc_file, INTS4 l_size, INTS4 l_stream,
01206 INTS4 l_type, INTS4 l_subtype, s_evt_channel *ps_chan, CHARS *ps_filhe)
01207 {
01208 s_filhe *ps_file_head;
01209 INTS4 l_write_size;
01210 INTS4 l_status,ll;
01211 time_t s_timet;
01212 struct timeb s_timeb;
01213
01214 CHARS c_mode[80];
01215 CHARS c_file[256], *pc_temp;
01216 struct s_varstr
01217 {
01218 INTS2 i_varstr;
01219 CHARS c_varstr[128];
01220 } s_varstr_file;
01221
01222
01223 ps_chan->pLmd=NULL;
01224 if(l_stream==0) {
01225 ps_chan->pLmd=fLmdAllocateControl();
01226 l_status=fLmdPutOpen(ps_chan->pLmd,pc_file,NULL,l_size,
01227 LMD__NO_OVERWRITE,LMD__INDEX,LMD__LARGE_FILE);
01228 return(l_status);
01229 }
01230
01231
01232 ps_chan->l_first_put=1;
01233
01234 ps_chan->l_buf_size=l_size;
01235 ps_chan->l_bufs_in_stream=l_stream;
01236 ps_chan->l_buf_type=l_type;
01237 ps_chan->l_buf_subtype=l_subtype;
01238 ps_chan->l_io_buf_size=ps_chan->l_buf_size * ps_chan->l_bufs_in_stream;
01239 if( (ps_chan->pc_io_buf=malloc(ps_chan->l_io_buf_size))==NULL)
01240 {
01241 printf("Memory allocation error\n");
01242 exit(2);
01243 }
01244
01245 strcpy(c_file,pc_file);
01246 if(strlen(c_file) < 5) strcat(c_file,".lmd");
01247 else
01248 {
01249 pc_temp = (CHARS *) &c_file[strlen(c_file)-4];
01250 if((strcmp(pc_temp,".LMD") != 0) &&
01251 (strcmp(pc_temp,".lmd") != 0)) strcat(c_file,".lmd");
01252 }
01253 if((ps_chan->l_channel_no=open(c_file,PUT__OPEN_APD_FLAG) )!= -1)
01254 return(PUTEVT__FILE_EXIST);
01255 else
01256 {
01257 if((ps_chan->l_channel_no=open(c_file,PUT__CRT_FLAG,
01258 DEF_FILE_ACCE) )== -1)
01259 return(PUTEVT__FAILURE);
01260
01261 else
01262 {
01263
01264 ps_file_head=(s_filhe *)ps_chan->pc_io_buf;
01265
01266 if(ps_filhe != NULL)
01267 {
01268 memcpy(ps_file_head, ps_filhe,ps_chan->l_buf_size );
01269 }
01270 else
01271 {
01272 memset( ps_file_head, '\0', ps_chan->l_buf_size);
01273 sprintf(ps_file_head->filhe_run, "Pid %d\0", getpid());
01274 ps_file_head->filhe_run_l=strlen(ps_file_head->filhe_run);
01275 }
01276 ps_file_head->filhe_dlen=ps_chan->l_buf_size/2;
01277 ps_file_head->filhe_subtype=1;
01278 ps_file_head->filhe_type=2000;
01279 ftime(&s_timeb);
01280 ps_file_head->filhe_stime[0]=(INTS4)s_timeb.time;
01281 ps_file_head->filhe_stime[1]=(INTS4)s_timeb.millitm;
01282 ps_file_head->filhe_free[0]=1;
01283 ps_file_head->filhe_file_l=strlen(c_file);
01284 strcpy(ps_file_head->filhe_file, c_file);
01285 strcpy(ps_file_head->filhe_user, getenv("USER"));
01286 ps_file_head->filhe_user_l=strlen(ps_file_head->filhe_user);
01287 time(&s_timet);
01288 strcpy(c_mode, ctime(&s_timet));
01289 strcpy(ps_file_head->filhe_time, &c_mode[4]);
01290 ps_file_head->filhe_time[20]=' ';
01291 l_write_size=write(ps_chan->l_channel_no,(CHARS *)ps_file_head,
01292 ps_chan->l_buf_size);
01293 if(l_write_size==-1)
01294 {
01295 return(PUTEVT__WRERR);
01296 }
01297 if(l_write_size!=ps_chan->l_buf_size)
01298 {
01299 return(PUTEVT__TOOBIG);
01300 }
01301 return(PUTEVT__SUCCESS);
01302 }
01303 }
01304 }
01305
01306
01307
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317
01318
01319
01320
01321
01322
01323
01324
01325
01326
01327 INTS4 f_evt_put_event(s_evt_channel *ps_chan, INTS4 *pl_evt_buf)
01328 {
01329 INTS4 l_evt_buf_posi;
01330 INTS4 l_buf_remain_size;
01331 INTS4 l_write_size, l_temp, l_free;
01332 INTS4 l_status;
01333 CHARS *pc_addr;
01334 s_bufhe *ps_bufhe;
01335
01336
01337 if(ps_chan->pLmd != NULL){
01338 l_status=fLmdPutElement(ps_chan->pLmd,(sMbsHeader *)pl_evt_buf);
01339 return(l_status);
01340 }
01341
01342 if(ps_chan->l_first_put==1)
01343 {
01344 ps_chan->l_first_put=0;
01345 ps_chan->l_io_buf_posi=0;
01346 ps_chan->l_buf_no=1;
01347 }
01348 l_evt_buf_posi=0;
01349 ps_chan->l_evt_size=( ((s_ve10_1 *)(pl_evt_buf))->l_dlen)*2 + sizeof(s_evhe);
01350
01351
01352 l_buf_remain_size = ps_chan->l_io_buf_size - ps_chan->l_io_buf_posi;
01353 l_temp = (l_buf_remain_size / ps_chan->l_buf_size)*(sizeof(s_bufhe)+sizeof(s_evhe) );
01354 l_buf_remain_size -= l_temp;
01355
01356 if(ps_chan->l_evt_size>l_buf_remain_size)
01357 {
01358 memset(ps_chan->pc_io_buf+ps_chan->l_io_buf_posi, '\0', ps_chan->l_io_buf_size-ps_chan->l_io_buf_posi);
01359
01360 l_temp=(ps_chan->l_io_buf_posi/ps_chan->l_buf_size)*ps_chan->l_buf_size;
01361 if(ps_chan->l_io_buf_posi%ps_chan->l_buf_size == 0) l_temp -= ps_chan->l_buf_size;
01362
01363 ps_chan->ps_bufhe=(s_bufhe *)(ps_chan->pc_io_buf + l_temp);
01364 if(l_temp==0)ps_chan->ps_bufhe->h_end = 0;
01365 else ps_chan->ps_bufhe->h_end = ((s_bufhe *)((CHARS *)ps_chan->ps_bufhe - ps_chan->l_buf_size))->h_begin;
01366 ps_chan->ps_bufhe->h_begin = 0;
01367 for(l_temp=0;l_temp<ps_chan->l_io_buf_size;l_temp+=ps_chan->l_buf_size)
01368 {
01369 pc_addr = ps_chan->pc_io_buf+l_temp;
01370 ps_bufhe=(s_bufhe *)pc_addr;
01371 if(ps_bufhe->l_evt>0)
01372 {
01373 l_write_size=write(ps_chan->l_channel_no, pc_addr,ps_chan->l_buf_size);
01374 if(l_write_size==-1) return(PUTEVT__WRERR);
01375 if(l_write_size!=ps_chan->l_buf_size) return(PUTEVT__TOOBIG);
01376 }
01377 else ps_chan->l_buf_no--;
01378 }
01379 ps_chan->l_io_buf_posi=0;
01380 ps_chan->ps_bufhe=(s_bufhe *)ps_chan->pc_io_buf;
01381
01382 l_buf_remain_size = ps_chan->l_io_buf_size;
01383 l_temp = (l_buf_remain_size / ps_chan->l_buf_size) * (sizeof(s_bufhe)+sizeof(s_evhe) );
01384 l_buf_remain_size -= l_temp;
01385 l_buf_remain_size += sizeof(s_evhe);
01386
01387 if(ps_chan->l_evt_size>l_buf_remain_size) return(PUTEVT__TOO_SMALLS);
01388 }
01389
01390 if(ps_chan->l_io_buf_posi==0)f_evt_ini_bufhe(ps_chan);
01391
01392
01393 while(l_evt_buf_posi<ps_chan->l_evt_size)
01394 {
01395 ps_chan->ps_ve10_1 = (s_ve10_1 *)(ps_chan->pc_io_buf + ps_chan->l_io_buf_posi);
01396 if((ps_chan->l_io_buf_posi%ps_chan->l_buf_size)==0)
01397 {
01398 ps_chan->l_io_buf_posi += sizeof(s_bufhe);
01399 ps_chan->ps_ve10_1 = (s_ve10_1 *)(ps_chan->pc_io_buf + ps_chan->l_io_buf_posi);
01400 if(l_evt_buf_posi != 0)
01401 {
01402 ps_chan->l_io_buf_posi += sizeof(s_evhe);
01403 l_write_size=(ps_chan->l_io_buf_posi/ps_chan->l_buf_size)*ps_chan->l_buf_size;
01404
01405 ps_chan->ps_bufhe=(s_bufhe *)(ps_chan->pc_io_buf + l_write_size);
01406 ps_chan->ps_bufhe->i_used += sizeof(s_evhe)/2;
01407 }
01408 }
01409 l_write_size=(ps_chan->l_io_buf_posi/ps_chan->l_buf_size)*ps_chan->l_buf_size;
01410
01411 ps_chan->ps_bufhe=(s_bufhe *)(ps_chan->pc_io_buf + l_write_size);
01412 l_write_size = l_write_size + ps_chan->l_buf_size - ps_chan->l_io_buf_posi;
01413
01414 if(l_write_size>(ps_chan->l_evt_size-l_evt_buf_posi))
01415 l_write_size=(ps_chan->l_evt_size-l_evt_buf_posi);
01416 memcpy(ps_chan->pc_io_buf + ps_chan->l_io_buf_posi, (CHARS *)pl_evt_buf + l_evt_buf_posi, l_write_size);
01417 ps_chan->ps_bufhe->l_evt ++;
01418 ps_chan->l_io_buf_posi += l_write_size;
01419 l_evt_buf_posi += l_write_size;
01420 ps_chan->ps_bufhe->i_used += l_write_size/2;
01421
01422
01423
01424 l_free=(ps_chan->l_io_buf_posi/ps_chan->l_buf_size)*ps_chan->l_buf_size;
01425
01426 l_free = l_free + ps_chan->l_buf_size - ps_chan->l_io_buf_posi;
01427 if(l_free==ps_chan->l_buf_size)l_free=0;
01428
01429 if(l_free<sizeof(s_ve10_1))ps_chan->l_io_buf_posi += l_free;
01430
01431 if(l_evt_buf_posi!=l_write_size)
01432 {
01433 ps_chan->ps_ve10_1->l_dlen= l_write_size/2;
01434 ps_chan->ps_ve10_1->i_subtype = ps_chan->l_buf_subtype;
01435 ps_chan->ps_ve10_1->i_type = ps_chan->l_buf_type;
01436 }
01437 else ps_chan->ps_ve10_1->l_dlen= (l_write_size-sizeof(s_evhe))/2;
01438 if((ps_chan->l_io_buf_posi%ps_chan->l_buf_size)==0)
01439 {
01440 if(l_evt_buf_posi<ps_chan->l_evt_size) ps_chan->ps_bufhe->h_begin = 1;
01441 if(ps_chan->l_io_buf_posi > ps_chan->l_buf_size)
01442 ps_chan->ps_bufhe->h_end = ((s_bufhe *)((CHARS *)ps_chan->ps_bufhe - ps_chan->l_buf_size))->h_begin;
01443 ps_chan->ps_bufhe->l_free[1] = ((s_ve10_1 *)(pl_evt_buf))->l_dlen;
01444 }
01445
01446 }
01447 return(PUTEVT__SUCCESS);
01448 }
01449
01450
01451
01452
01453
01454
01455
01456
01457
01458
01459
01460
01461
01462
01463
01464
01465
01466
01467
01468
01469
01470 INTS4 f_evt_put_buffer(s_evt_channel *ps_chan, s_bufhe *ps_bufhe)
01471 {
01472 INTS4 l_write_size, l_temp, l_free;
01473 INTS4 l_status;
01474 CHARS *pc_addr;
01475
01476
01477 if(ps_chan->pLmd != NULL){
01478 l_status=fLmdPutBuffer(ps_chan->pLmd,(sMbsHeader *)(ps_bufhe+1),ps_bufhe->l_evt);
01479 return(l_status);
01480 }
01481
01482 ps_chan->l_io_buf_posi = ps_chan->l_buf_size;
01483 ps_chan->l_io_buf_size = ps_chan->l_buf_size;
01484 l_write_size=write(ps_chan->l_channel_no, (CHARS *) ps_bufhe, ps_chan->l_buf_size);
01485 if(l_write_size==-1)
01486 {
01487 return(PUTEVT__WRERR);
01488 }
01489 if(l_write_size!=ps_chan->l_buf_size)
01490 {
01491 return(PUTEVT__TOOBIG);
01492 }
01493 return PUTEVT__SUCCESS;
01494 }
01495
01496
01497
01498
01499
01500
01501
01502
01503
01504
01505
01506
01507
01508
01509
01510
01511
01512
01513
01514
01515
01516 INTS4 f_evt_put_close(s_evt_channel *ps_chan)
01517 {
01518 INTS4 l_write_size, l_temp, l_temp2;
01519 INTS4 l_status;
01520 CHARS *pc_addr;
01521
01522
01523 if(ps_chan->pLmd != NULL){
01524 l_status=fLmdPutClose(ps_chan->pLmd);
01525 return(l_status);
01526 }
01527
01528 if(ps_chan->l_first_put==1) goto g_close;
01529
01530
01531 if((ps_chan->l_io_buf_posi%ps_chan->l_buf_size)!=0)
01532 {
01533 l_temp=(ps_chan->l_io_buf_posi/ps_chan->l_buf_size)*ps_chan->l_buf_size;
01534
01535 memset(ps_chan->pc_io_buf+ps_chan->l_io_buf_posi, '\0',
01536 l_temp+ps_chan->l_buf_size-ps_chan->l_io_buf_posi);
01537
01538 ps_chan->ps_bufhe=(s_bufhe *)(ps_chan->pc_io_buf + l_temp);
01539
01540 ps_chan->ps_bufhe->l_dlen = (ps_chan->l_buf_size - sizeof(s_bufhe))/2;
01541 ps_chan->ps_bufhe->h_begin = 0;
01542 if(l_temp==0)
01543 ps_chan->ps_bufhe->h_end = 0;
01544 else
01545 ps_chan->ps_bufhe->h_end = ((s_bufhe *)((CHARS *)ps_chan->ps_bufhe - ps_chan->l_buf_size))
01546 ->h_begin;
01547 ps_chan->ps_bufhe->i_used = (ps_chan->l_io_buf_posi%ps_chan->l_buf_size -
01548 sizeof(s_bufhe))/2;
01549 }
01550
01551
01552 if(ps_chan->l_io_buf_posi!=ps_chan->l_io_buf_size)
01553 {
01554 if((ps_chan->l_io_buf_posi%ps_chan->l_buf_size)!=0)
01555 l_write_size=(ps_chan->l_io_buf_posi/ps_chan->l_buf_size+1) *
01556 ps_chan->l_buf_size;
01557 else
01558 l_write_size=ps_chan->l_io_buf_posi;
01559
01560 for(l_temp=0;l_temp<l_write_size;l_temp+=ps_chan->l_buf_size){
01561
01562
01563 l_temp2=write(ps_chan->l_channel_no, ps_chan->pc_io_buf+l_temp,
01564 ps_chan->l_buf_size);
01565 if(l_temp2==-1)
01566 {
01567 return(PUTEVT__WRERR);
01568 }
01569 if(l_temp2!=ps_chan->l_buf_size)
01570 {
01571 return(PUTEVT__TOOBIG);
01572 }
01573 }
01574 }
01575
01576 g_close:
01577 free(ps_chan->pc_io_buf);
01578
01579
01580 l_status=close(ps_chan->l_channel_no);
01581 ps_chan->l_channel_no=-1;
01582 if(l_status == -1) return(PUTEVT__CLOSE_ERR);
01583 else return PUTEVT__SUCCESS;
01584 }
01585
01586
01587
01588
01589
01590
01591
01592
01593
01594
01595
01596
01597
01598
01599
01600
01601
01602
01603
01604
01605
01606
01607
01608
01609
01610 INTS4 f_evt_error( INTS4 l_error , CHARS *pc_dest , INTS4 l_out )
01611 {
01612 CHARS c_line[80];
01613
01614 switch( l_error )
01615 {
01616 case GETEVT__NOFILE :
01617 sprintf(c_line,"-I-f_evt: no such input file");
01618 break;
01619 case GETEVT__NOTAGFILE :
01620 sprintf(c_line,"-I-f_evt: no such tag file");
01621 break;
01622 case GETEVT__NOTAG :
01623 sprintf(c_line,"-I-f_evt: no such event tag");
01624 break;
01625 case GETEVT__TIMEOUT :
01626 sprintf(c_line,"-I-f_evt: time out");
01627 break;
01628 case GETEVT__NOSERVER :
01629 sprintf(c_line,"-I-f_evt: no such server");
01630 break;
01631 case GETEVT__RDERR :
01632 sprintf(c_line,"-I-f_evt: read server error");
01633 break;
01634 case GETEVT__TAGRDERR :
01635 sprintf(c_line,"-I-f_evt: read tag file error");
01636 break;
01637 case GETEVT__TAGWRERR :
01638 sprintf(c_line,"-I-f_evt: write tag file error");
01639 break;
01640 case GETEVT__FRAGMENT :
01641 sprintf(c_line,"-I-f_evt: data format error");
01642 break;
01643 case GETEVT__NOMORE :
01644 sprintf(c_line,"-I-f_evt: no more event");
01645 break;
01646 case GETEVT__CLOSE_ERR:
01647 sprintf(c_line,"-I-f_evt: close server error");
01648 break;
01649 case GETEVT__FAILURE :
01650 sprintf(c_line,"-I-f_evt: failure");
01651 break;
01652 case GETEVT__NOCHANNEL :
01653 sprintf(c_line,"-I-f_evt: too many channels");
01654 break;
01655 case GETEVT__NOLMDFILE :
01656 sprintf(c_line,"-I-f_evt: input file is no LMD file");
01657 break;
01658 case GETEVT__SUCCESS :
01659 sprintf(c_line,"-I-f_evt: success");
01660 break;
01661 case PUTEVT__FILE_EXIST :
01662 sprintf(c_line,"-I-f_evt: output file already exist");
01663 break;
01664 case PUTEVT__WRERR :
01665 sprintf(c_line,"-I-f_evt: write file error");
01666 break;
01667 case PUTEVT__TOOBIG :
01668 sprintf(c_line,"-I-f_evt: output file too large");
01669 break;
01670 case PUTEVT__TOO_SMALLS:
01671 sprintf(c_line,"-I-f_evt: event can not fit in a stream");
01672 break;
01673 case PUTEVT__CLOSE_ERR :
01674 sprintf(c_line,"-I-f_evt: close output error");
01675 break;
01676 case PUTEVT__FAILURE :
01677 sprintf(c_line,"-I-f_evt: output failure");
01678 break;
01679 case PUTEVT__NOCHANNEL :
01680 sprintf(c_line,"-I-f_evt: too many channels");
01681 break;
01682 default :
01683 sprintf(c_line,"-I-f_evt: unknown message id %d",l_error);
01684 if(l_out==0)printf("%s\n",c_line);
01685 if(l_out==1)strcpy(pc_dest,c_line);
01686 return GETEVT__FAILURE;
01687 }
01688
01689 if(l_out==0)printf("%s\n",c_line);
01690 if(l_out==1)strcpy(pc_dest,c_line);
01691
01692 return GETEVT__SUCCESS;
01693 }
01694
01695
01696
01697
01698
01699
01700
01701
01702
01703
01704
01705
01706
01707
01708
01709
01710
01711
01712
01713
01714
01715
01716
01717 INTS4 f_evt_get_buffer(s_evt_channel *ps_chan, INTS4 *ps_buffer)
01718 {
01719 INTS4 l_temp;
01720 CHARS * pc_temp;
01721 INTS4 l_status;
01722
01723 pc_temp=(CHARS *)ps_chan->pc_io_buf;
01724 switch(ps_chan->l_server_type)
01725 {
01726 case GETEVT__FILE :
01727 l_temp=read(ps_chan->l_channel_no,ps_buffer, ps_chan->l_buf_size);
01728 if(l_temp == 0)
01729
01730 {
01731 ps_chan->l_io_buf_size = 0;
01732 return(GETEVT__NOMORE);
01733 }
01734 else if(l_temp == -1)
01735 {
01736 ps_chan->l_io_buf_size = 0;
01737 return(GETEVT__RDERR);
01738 }
01739 break;
01740 case GETEVT__RFIO :
01741 l_temp=RFIO_read(ps_chan->l_channel_no,(CHARS *)ps_buffer, ps_chan->l_buf_size);
01742 if(l_temp == 0)
01743 {
01744 ps_chan->l_io_buf_size = 0;
01745 return(GETEVT__NOMORE);
01746 }
01747 else if(l_temp == -1)
01748 {
01749 ps_chan->l_io_buf_size = 0;
01750 return(GETEVT__RDERR);
01751 }
01752 break;
01753 case GETEVT__STREAM :
01754 if(ps_chan->l_stream_bufs == 0)
01755 if(f_stc_write("GETEVT", 12, ps_chan->l_channel_no)!=STC__SUCCESS)
01756 {
01757 return(GETEVT__FAILURE);
01758 }
01759
01760 l_status=f_stc_read(ps_buffer, ps_chan->l_buf_size, ps_chan->l_channel_no,ps_chan->l_timeout);
01761 if(l_status == STC__TIMEOUT) return(GETEVT__TIMEOUT);
01762 if(l_status != STC__SUCCESS) return(GETEVT__RDERR);
01763 ps_chan->l_stream_bufs++;
01764 if(ps_chan->l_stream_bufs == ps_chan->l_bufs_in_stream)ps_chan->l_stream_bufs = 0;
01765 break;
01766 case GETEVT__TRANS :
01767 l_status=f_stc_read(ps_buffer, ps_chan->l_buf_size, ps_chan->l_channel_no,ps_chan->l_timeout);
01768 if(l_status == STC__TIMEOUT) return(GETEVT__TIMEOUT);
01769 if(l_status != STC__SUCCESS) return(GETEVT__RDERR);
01770 break;
01771 case GETEVT__REVSERV :
01772 case GETEVT__EVENT :
01773 default :
01774 return(GETEVT__FAILURE);
01775 }
01776
01777
01778 if( ((s_bufhe *)(ps_buffer))->l_free[0] !=1)
01779 f_evt_swap((CHARS *)ps_buffer, ps_chan->l_buf_size);
01780
01781 return(GETEVT__SUCCESS);
01782 }
01783
01784
01785
01786
01787
01788
01789
01790
01791
01792
01793
01794
01795
01796
01797
01798
01799
01800
01801
01802
01803 INTS4 f_evt_skip_buffer(s_evt_channel *ps_chan, INTS4 l_buffer)
01804 {
01805 INTS4 l_temp;
01806 CHARS * pc_temp;
01807 INTS4 l_status,ii;
01808
01809 pc_temp=(CHARS *)ps_chan->pc_io_buf;
01810 switch(ps_chan->l_server_type)
01811 {
01812 case GETEVT__FILE :
01813 l_temp=lseek(ps_chan->l_channel_no,l_buffer*ps_chan->l_buf_size,SEEK_CUR);
01814 if(l_temp == -1)
01815
01816 {
01817 return(GETEVT__NOMORE);
01818 }
01819 break;
01820 case GETEVT__RFIO :
01821 l_temp=RFIO_lseek(ps_chan->l_channel_no,l_buffer*ps_chan->l_buf_size,SEEK_CUR);
01822 if(l_temp == -1)
01823 {
01824 return(GETEVT__NOMORE);
01825 }
01826 break;
01827 case GETEVT__STREAM :
01828 case GETEVT__TRANS :
01829 case GETEVT__REVSERV :
01830 case GETEVT__EVENT :
01831 default : return(GETEVT__FAILURE);
01832 }
01833
01834 ps_chan->l_first_get=1;
01835 return(GETEVT__SUCCESS);
01836 }
01837
01838
01839
01840
01841
01842
01843
01844
01845
01846
01847
01848
01849
01850
01851
01852
01853
01854
01855
01856
01857
01858 INTS4 f_evt_timeout(s_evt_channel *ps_chan, INTS4 l_sec)
01859 {
01860 ps_chan->l_timeout = l_sec;
01861 return(GETEVT__SUCCESS);
01862 }
01863
01864
01865
01866
01867
01868
01869
01870
01871
01872
01873
01874
01875
01876
01877
01878 INTS4 f_evt_swap(CHARS * pc_source, INTS4 l_length)
01879 {
01880 CHARS * p_s, * p_d;
01881 INTS4 l_save;
01882 CHARS ch_temp;
01883
01884 if(l_length%4 == 2){
01885 ch_temp=*(pc_source+l_length-2);
01886 *(pc_source+l_length-2)=*(pc_source+l_length-1);
01887 *(pc_source+l_length-1)=ch_temp;
01888 }
01889 l_length=(l_length/4)*4;
01890 for(p_d=pc_source,p_s=(CHARS *)&l_save; p_d<pc_source+l_length;)
01891 {
01892 l_save = *((INTS4 *)p_d);
01893 p_s += 4;
01894 *(p_d++) = *(--p_s);
01895 *(p_d++) = *(--p_s);
01896 *(p_d++) = *(--p_s);
01897 *(p_d++) = *(--p_s);
01898 }
01899 return(0);
01900 }
01901
01902
01903
01904
01905
01906
01907
01908
01909
01910
01911
01912
01913
01914
01915 INTS4 f_evt_swap_filhe(s_bufhe *ps_bufhe)
01916 {
01917 CHARS * p_s, * p_d;
01918 INTS4 ii;
01919 INTS2 *pi;
01920 s_filhe *ps_filhe;
01921
01922 f_evt_swap((CHARS *)ps_bufhe,48);
01923 if(ps_bufhe->i_type == 2000)
01924 {
01925 ps_filhe=(s_filhe *)ps_bufhe;
01926 f_evt_swap((CHARS *)&ps_filhe->filhe_lines,4);
01927 ps_filhe->filhe_label_l=ps_filhe->filhe_label_l>>8;
01928 ps_filhe->filhe_file_l =ps_filhe->filhe_file_l >>8;
01929 ps_filhe->filhe_user_l =ps_filhe->filhe_user_l >>8;
01930 ps_filhe->filhe_run_l =ps_filhe->filhe_run_l >>8;
01931 ps_filhe->filhe_exp_l =ps_filhe->filhe_exp_l >>8;
01932 pi=(INTS2 *)&ps_filhe->s_strings;
01933 for(ii=0;ii<ps_filhe->filhe_lines;ii++)
01934 {
01935 *pi=*pi>>8;
01936 pi += 40;
01937 }
01938 }
01939
01940 return(0);
01941 }
01942
01943
01944
01945
01946
01947
01948
01949
01950
01951
01952
01953
01954
01955 CHARS * f_evt_get_buffer_ptr(s_evt_channel *ps_chan)
01956 {
01957 return(ps_chan->pc_io_buf);
01958 }
01959
01960
01961
01962
01963
01964
01965
01966
01967
01968
01969
01970
01971
01972
01973
01974
01975
01976 INTS4 f_evt_get_newbuf(s_evt_channel *ps_chan)
01977 {
01978 INTS4 l_temp;
01979 CHARS * pc_temp;
01980 INTS4 l_status;
01981
01982 pc_temp=(CHARS *)ps_chan->pc_io_buf;
01983 switch(ps_chan->l_server_type)
01984 {
01985 case GETEVT__FILE :
01986 while(1){
01987 l_temp=read(ps_chan->l_channel_no,pc_temp, ps_chan->l_io_buf_size);
01988 if(l_temp == 0) return(GETEVT__NOMORE);
01989 if(l_temp == -1) return(GETEVT__RDERR);
01990 if(l_temp < ps_chan->l_io_buf_size)return(GETEVT__RDERR);
01991 break;
01992 }
01993 break;
01994 case GETEVT__STREAM :
01995 if(f_stc_write("GETEVT", 12, ps_chan->l_channel_no)!=STC__SUCCESS)
01996 {
01997 return(GETEVT__FAILURE);
01998 }
01999
02000 for(l_temp=0; l_temp<ps_chan->l_bufs_in_stream; l_temp++)
02001 {
02002 l_status=f_stc_read(pc_temp, ps_chan->l_buf_size, ps_chan->l_channel_no,ps_chan->l_timeout);
02003 if(l_status == STC__TIMEOUT) return(GETEVT__TIMEOUT);
02004 if(l_status != STC__SUCCESS) return(GETEVT__RDERR);
02005 pc_temp+=ps_chan->l_buf_size;
02006 }
02007 l_temp=((s_bufhe *)(ps_chan->pc_io_buf))->l_evt;
02008 if( ((s_bufhe *)(ps_chan->pc_io_buf))->l_free[0] !=1)
02009 f_evt_swap((CHARS *)&l_temp,4);
02010 if(l_temp < 0) {
02011 printf("**** I-f_evt: Stream server request for disconnect!\n");
02012 f_evt_get_close(ps_chan);
02013 return(GETEVT__RDERR);
02014 }
02015
02016 if( ((s_bufhe *)(ps_chan->pc_io_buf))->l_evt == 0) return(GETEVT__TIMEOUT);
02017 break;
02018 case GETEVT__TRANS :
02019 l_status=f_stc_read(pc_temp, ps_chan->l_buf_size, ps_chan->l_channel_no,ps_chan->l_timeout);
02020 l_temp=((s_bufhe *)(ps_chan->pc_io_buf))->l_evt;
02021 if( ((s_bufhe *)(ps_chan->pc_io_buf))->l_free[0] !=1)
02022 f_evt_swap((CHARS *)&l_temp,4);
02023 if(l_temp < 0) {
02024 printf("**** I-f_evt: Transport server request for disconnect!\n");
02025 f_evt_get_close(ps_chan);
02026 return(GETEVT__RDERR);
02027 }
02028 if(l_status == STC__TIMEOUT) return(GETEVT__TIMEOUT);
02029 if(l_status != STC__SUCCESS) return(GETEVT__RDERR);
02030 break;
02031 case GETEVT__RFIO :
02032 l_temp=RFIO_read(ps_chan->l_channel_no,pc_temp, ps_chan->l_io_buf_size);
02033 if(l_temp == 0) return(GETEVT__NOMORE);
02034 if(l_temp == -1) return(GETEVT__RDERR);
02035 if(l_temp < ps_chan->l_io_buf_size)return(GETEVT__RDERR);
02036 break;
02037 case GETEVT__REVSERV :
02038 case GETEVT__EVENT :
02039 default :
02040 return(GETEVT__FAILURE);
02041 }
02042
02043 if( ((s_bufhe *)(ps_chan->pc_io_buf))->l_free[0] !=1)
02044 f_evt_swap(ps_chan->pc_io_buf, ps_chan->l_io_buf_size);
02045
02046 return(GETEVT__SUCCESS);
02047 }
02048
02049
02050
02051
02052
02053
02054
02055
02056
02057
02058
02059
02060
02061
02062
02063
02064
02065
02066
02067
02068 INTS4 f_evt_check_buf(CHARS *pc_head, INTS4 *pl_size, INTS4 *pl_is_goosybuf, INTS4 *pl_swap, INTS4 *pl_filehead)
02069 {
02070 INTU4 l_size;
02071
02072 *pl_is_goosybuf=0;
02073 *pl_filehead=0;
02074 *pl_size=0;
02075 *pl_swap=0;
02076
02077 if( (((s_filhe *)(pc_head))->filhe_subtype==1)&&
02078 (((s_filhe *)(pc_head))->filhe_type==2000) )
02079 {
02080 *pl_swap=0;
02081 *pl_is_goosybuf=0;
02082 *pl_filehead=1;
02083 l_size=((s_bufhe *)(pc_head))->l_dlen*2;
02084 if(l_size%512 > 0) l_size += sizeof(s_bufhe);
02085 if((l_size>>24) > 0) *pl_size=0;
02086 else *pl_size=l_size;
02087 return(PUTEVT__SUCCESS);
02088 }
02089 f_evt_swap(pc_head, sizeof(s_filhe));
02090 if( (((s_filhe *)(pc_head))->filhe_subtype==1)&&
02091 (((s_filhe *)(pc_head))->filhe_type==2000) )
02092 {
02093 *pl_swap=1;
02094 *pl_is_goosybuf=0;
02095 *pl_filehead=1;
02096 l_size=((s_bufhe *)(pc_head))->l_dlen*2;
02097 if(l_size%512 > 0) l_size += sizeof(s_bufhe);
02098 if((l_size>>24) > 0) *pl_size=0;
02099 else *pl_size=l_size;
02100 return(PUTEVT__SUCCESS);
02101 }
02102
02103
02104 l_size=((s_bufhe *)(pc_head))->l_dlen*2;
02105 if(l_size%512 > 0) l_size += sizeof(s_bufhe);
02106 if( (((l_size>>24)== 0)&&(l_size > 0))&&
02107 (((s_bufhe *)(pc_head))->h_begin<2)&&
02108 (((s_bufhe *)(pc_head))->h_begin>=0)&&
02109 (((s_bufhe *)(pc_head))->h_end<2)&&
02110 (((s_bufhe *)(pc_head))->h_end>=0)&&
02111
02112 ((((s_bufhe *)(pc_head))->i_used>0)||(((s_bufhe *)(pc_head))->l_free[2]>0))&&
02113
02114 ( (((s_bufhe *)(pc_head))->l_free[0]==1)||
02115 (((s_bufhe *)(pc_head))->l_free[0]==0)||
02116
02117 (((s_bufhe *)(pc_head))->l_free[0]==256*256*256) ) )
02118 {
02119 *pl_swap=1;
02120 *pl_is_goosybuf=1;
02121 *pl_size=l_size;
02122 return(PUTEVT__SUCCESS);
02123 }
02124 f_evt_swap(pc_head, sizeof(s_filhe));
02125 l_size=((s_bufhe *)(pc_head))->l_dlen*2+sizeof(s_bufhe);
02126 if( (((l_size>>24)== 0)&&(l_size > 0))&&
02127 (((s_bufhe *)(pc_head))->l_dlen>0)&&
02128 (((s_bufhe *)(pc_head))->h_begin<2)&&
02129 (((s_bufhe *)(pc_head))->h_begin>=0)&&
02130 (((s_bufhe *)(pc_head))->h_end<2)&&
02131 (((s_bufhe *)(pc_head))->h_end>=0)&&
02132
02133 ((((s_bufhe *)(pc_head))->i_used>0)||(((s_bufhe *)(pc_head))->l_free[2]>0))&&
02134
02135 ( (((s_bufhe *)(pc_head))->l_free[0]==1)||
02136 (((s_bufhe *)(pc_head))->l_free[0]==0)||
02137
02138 (((s_bufhe *)(pc_head))->l_free[0]==256*256*256) ) )
02139 {
02140 *pl_swap=0;
02141 *pl_is_goosybuf=1;
02142 *pl_size=l_size;
02143 return(PUTEVT__SUCCESS);
02144 }
02145 return(PUTEVT__SUCCESS);
02146 }
02147
02148
02149
02150
02151
02152
02153
02154
02155
02156
02157
02158
02159 INTS4 f_evt_ini_bufhe(s_evt_channel *ps_chan)
02160 {
02161 INTS4 l_temp;
02162 struct timeb s_timeb;
02163
02164
02165
02166 for(l_temp=0; l_temp<ps_chan->l_io_buf_size; l_temp += ps_chan->l_buf_size)
02167 {
02168 ps_chan->ps_bufhe=(s_bufhe *)(ps_chan->pc_io_buf + l_temp);
02169 ps_chan->ps_bufhe->l_dlen = (ps_chan->l_buf_size - sizeof(s_bufhe))/2;
02170 ps_chan->ps_bufhe->i_subtype = ps_chan->l_buf_subtype;
02171 ps_chan->ps_bufhe->i_type = ps_chan->l_buf_type;
02172 ps_chan->ps_bufhe->h_begin = 0;
02173 ps_chan->ps_bufhe->h_end = 0;
02174 ps_chan->ps_bufhe->i_used = 0;
02175 ps_chan->ps_bufhe->l_buf = ps_chan->l_buf_no; ps_chan->l_buf_no++;
02176 ps_chan->ps_bufhe->l_evt = 0;
02177 ps_chan->ps_bufhe->l_current_i = 0;
02178 ftime(&s_timeb);
02179 ps_chan->ps_bufhe->l_time[0]=(INTS4)s_timeb.time;
02180 ps_chan->ps_bufhe->l_time[1]=(INTS4)s_timeb.millitm;
02181 ps_chan->ps_bufhe->l_free[0] = 1;
02182 ps_chan->ps_bufhe->l_free[1] = 0;
02183 ps_chan->ps_bufhe->l_free[2] = 0;
02184 ps_chan->ps_bufhe->l_free[3] = 0;
02185 }
02186 return(PUTEVT__SUCCESS);
02187 }
02188
02189
02190
02191
02192
02193
02194
02195
02196
02197
02198
02199
02200
02201
02202
02203
02204
02205
02206
02207
02208
02209
02210
02211
02212
02213
02214
02215 INTS4 f_evt_tag_filter(s_ve10_1 *ps_ve10_1)
02216 {
02217
02218 return(1);
02219
02220
02221
02222
02223
02224
02225
02226
02227
02228
02229
02230
02231
02232 }
02233 INTS4 f_evt_cre_tagfile(CHARS *pc_lmd, CHARS *pc_tag,INTS4 (*e_filter)())
02234 {
02235 INTS4 ii,l_take_it,l_temp,l_chan,l_out,l_file_pos=0,l_bufnr=0,l_events=0;
02236 INTS4 l_firste,*pl,l_len,l_last=-1,l_lin=0,l_fragsize, la_head[2];
02237 INTS4 l_swap, l_swap_head, l_is_goosybuf, l_filehead=0, l_size, l_size_head, l_dummy, l_evsize,l_evt_buf_size=0;
02238 INTS2 *pi;
02239 INTU4 *ps,*pd;
02240 CHARS c_lmd[128], c_tag[128], *pc_temp,*pc_evt_buf=NULL;
02241 s_ve10_1 *ps_ve10_1;
02242 s_bufhe *ps_bufhe;
02243 s_taghe s_taghe;
02244 s_tag s_tag;
02245
02246 ps_bufhe = (s_bufhe *)c_temp;
02247 printf("LMD file %s, TAG file %s\n",pc_lmd,pc_tag);
02248
02249 if((l_chan=open(pc_lmd,GET__OPEN_FLAG))== -1) return(GETEVT__NOFILE);
02250
02251 if(read(l_chan,c_temp,MIN_BUF_LGTH)!=MIN_BUF_LGTH)
02252 {
02253 close(l_chan);
02254 return(GETEVT__RDERR);
02255 }
02256
02257 f_evt_check_buf(c_temp, &l_size_head, &l_is_goosybuf, &l_swap_head, &l_filehead);
02258 if(((l_is_goosybuf==0)&(l_filehead==0))|(l_size_head==0))
02259 {
02260 printf("LMD format error: swap=%d, header=%d, isLMD=%d, size=%d\n",l_swap_head,l_filehead,l_is_goosybuf,l_size_head);
02261 close(l_chan);
02262 return(GETEVT__NOLMDFILE);
02263 }
02264
02265 if(l_filehead == 1)
02266 {
02267 lseek(l_chan, 0, SEEK_SET);
02268 if(read(l_chan,c_temp,l_size_head)!=l_size_head)
02269 {
02270 close(l_chan);
02271 return(GETEVT__RDERR);
02272 }
02273 if(read(l_chan,c_temp,MIN_BUF_LGTH)!=MIN_BUF_LGTH)
02274 {
02275 close(l_chan);
02276 return(GETEVT__RDERR);
02277 }
02278 f_evt_check_buf(c_temp, &l_size, &l_is_goosybuf, &l_swap, &l_dummy);
02279 if((l_is_goosybuf==0)|(l_size!=l_size_head)|(l_swap!=l_swap_head))
02280 {
02281 printf("LMD format error: swap=%d, isLMD=%d, size=%d\n",l_swap,l_is_goosybuf,l_size);
02282 close(l_chan);
02283 return(GETEVT__NOLMDFILE);
02284 }
02285 }
02286
02287 lseek(l_chan, 0, SEEK_SET);
02288
02289 printf("Buffer swap %d, File header %d, LMD buffer %d, size %d[b]\n",l_swap,l_filehead,l_is_goosybuf,l_size);
02290
02291
02292 if(l_filehead == 1)
02293 {
02294 if(read(l_chan,c_temp,l_size)!=l_size)
02295 {
02296 close(l_chan);
02297 return(GETEVT__RDERR);
02298 }
02299 l_file_pos += l_size;
02300 l_bufnr++;
02301 }
02302
02303
02304 if((l_out=open(pc_tag,PUT__CRT_FLAG,DEF_FILE_ACCE))== -1) return(GETEVT__NOFILE);
02305 write(l_out,(CHARS *)&s_taghe,sizeof(s_taghe));
02306
02307
02308 if(e_filter != NULL) ii=(*e_filter)(NULL);
02309
02310 while(read(l_chan,c_temp,l_size)==l_size)
02311 {
02312 l_file_pos=l_bufnr*l_size;
02313 if(l_swap) f_evt_swap(c_temp,l_size);
02314 if((ps_bufhe->h_end)&(ps_bufhe->h_begin)&(ps_bufhe->l_evt==1))
02315 {
02316
02317
02318 l_bufnr++;
02319 continue;
02320 }
02321 ps_ve10_1=(s_ve10_1 *)(ps_bufhe + 1);
02322 pl = (INTS4 *)ps_ve10_1;
02323 l_file_pos += sizeof(s_bufhe);
02324
02325 if(ps_bufhe->h_end)
02326 {
02327 l_len = (*pl>>1)+2;
02328 l_file_pos += (l_len<<2);
02329 ps_ve10_1=(s_ve10_1 *)(pl+l_len);
02330 pl = (INTS4 *)ps_ve10_1;
02331 ps_bufhe->l_evt--;
02332
02333 }
02334 for(ii=1;ii<ps_bufhe->l_evt;ii++)
02335 {
02336
02337 if(e_filter != NULL)l_take_it=(*e_filter)(ps_ve10_1);
02338 else l_take_it=1;
02339 l_len = (*pl>>1)+2;
02340 s_tag.l_event=ps_ve10_1->l_count;
02341 s_tag.l_offset=l_file_pos;
02342 if(l_take_it)
02343 {
02344 l_events++;
02345 if(ps_ve10_1->l_count != (l_last+1))
02346 {
02347 l_lin++;
02348 if(l_lin == 1)l_firste=ps_ve10_1->l_count;
02349
02350 }
02351 l_last=ps_ve10_1->l_count;
02352 if(write(l_out,(CHARS *)&s_tag,sizeof(s_tag)) != sizeof(s_tag))
02353 {
02354 close(l_chan);
02355 close(l_out);
02356 return(GETEVT__TAGWRERR);
02357 }
02358 }
02359 l_file_pos += (l_len<<2);
02360 ps_ve10_1=(s_ve10_1 *)(pl+l_len);
02361 pl = (INTS4 *)ps_ve10_1;
02362 }
02363
02364 if(ps_bufhe->l_evt > 0)
02365 {
02366 if(ps_ve10_1->l_dlen < 4) printf("Buffer %d Event fragment %10d dlen %d ts %d %d trigger %d\n"
02367 ,l_bufnr,ps_ve10_1->l_count,ps_ve10_1->l_dlen,ps_ve10_1->i_type,
02368 ps_ve10_1->i_subtype,ps_ve10_1->i_trigger);
02369 s_tag.l_event=ps_ve10_1->l_count;
02370 if(ps_bufhe->h_begin)
02371 {
02372
02373 if(e_filter != NULL)
02374 {
02375
02376 l_evsize=ps_bufhe->l_free[1]+4;
02377 if(l_evt_buf_size < l_evsize*2)
02378 {
02379 if(pc_evt_buf != NULL)free(pc_evt_buf);
02380 l_evt_buf_size=l_evsize*2;
02381 pc_evt_buf=(CHARS *)malloc(l_evt_buf_size);
02382 }
02383
02384 ps=(INTU4 *)ps_ve10_1;
02385 pd=(INTU4 *)pc_evt_buf;
02386 l_fragsize = ps_ve10_1->l_dlen+4;
02387 for(ii=0;ii<l_fragsize/2;ii++) *pd++ = *ps++;
02388
02389 while(l_fragsize < l_evsize)
02390 {
02391 if(read(l_chan,c_temp,l_size) != l_size)break;
02392 l_bufnr++;
02393 if(l_swap) f_evt_swap(c_temp,l_size);
02394 ps = (INTU4 *) (ps_bufhe+1);
02395 l_temp=(INTS4)*ps;
02396 ps += 2;
02397 for(ii=0;ii<l_temp/2;ii++) *pd++ = *ps++;
02398 l_fragsize += l_temp;
02399 }
02400 if(l_fragsize < l_evsize)break;
02401 ps_ve10_1 = (s_ve10_1 *)pc_evt_buf;
02402 ps_ve10_1->l_dlen=l_evsize-4;
02403
02404 l_bufnr--;
02405 lseek(l_chan, -l_size, SEEK_CUR);
02406 }
02407 s_tag.l_offset=-l_file_pos;
02408
02409 }
02410 else
02411 {
02412 s_tag.l_offset=l_file_pos;
02413
02414 }
02415 if(e_filter != NULL)l_take_it=(*e_filter)(ps_ve10_1);
02416 else l_take_it=1;
02417 if(l_take_it)
02418 {
02419 l_events++;
02420 if(ps_ve10_1->l_count != (l_last+1))
02421 {
02422 l_lin++;
02423 if(l_lin == 1)l_firste=ps_ve10_1->l_count;
02424
02425 }
02426 l_last=ps_ve10_1->l_count;
02427 if(write(l_out,(CHARS *)&s_tag,sizeof(s_tag)) != sizeof(s_tag))
02428 {
02429 close(l_chan);
02430 close(l_out);
02431 return(GETEVT__TAGWRERR);
02432 }
02433 }
02434 }
02435 l_bufnr++;
02436
02437 }
02438 lseek(l_out, 0, SEEK_SET);
02439 s_taghe.l_endian = 1;
02440 s_taghe.l_version = 1;
02441 s_taghe.l_bufsize = l_size;
02442 s_taghe.l_buffers = l_bufnr;
02443 s_taghe.l_events = l_events;
02444 s_taghe.l_filesize = sizeof(s_tag)*l_events;
02445 s_taghe.l_linear = (l_lin == 1);
02446 s_taghe.l_first = l_firste;
02447 s_taghe.l_last = s_tag.l_event;
02448 if(write(l_out,(CHARS *)&s_taghe,sizeof(s_taghe)) != sizeof(s_taghe))
02449 {
02450 close(l_chan);
02451 close(l_out);
02452 return(GETEVT__TAGWRERR);
02453 }
02454 close(l_chan);
02455 close(l_out);
02456 printf("Buffers %6d, of size %d, Events %10d, first %d, last %d "
02457 ,s_taghe.l_buffers
02458 ,s_taghe.l_bufsize
02459 ,s_taghe.l_events
02460 ,s_taghe.l_first
02461 ,s_taghe.l_last);
02462 if(s_taghe.l_linear)printf("linear\n");
02463 else printf("not linear\n");
02464
02465 return(GETEVT__SUCCESS);
02466 }
02467
02468
02469
02470
02471
02472
02473
02474
02475
02476
02477
02478
02479
02480
02481
02482
02483
02484
02485
02486
02487
02488
02489
02490
02491
02492
02493
02494
02495 INTS4 f_evt_get_tagopen(s_evt_channel *ps_chan,CHARS *pc_tag,CHARS *pc_lmd, CHARS **ps_head, INTS4 l_prihe)
02496 {
02497 INTS4 l_temp,ii;
02498 s_bufhe *ps_bufhe;
02499
02500 ps_chan->ps_tag = NULL;
02501 ps_chan->ps_taghe = NULL;
02502 if(l_prihe)printf("LMD file %s, TAG file %s\n",pc_lmd,pc_tag);
02503
02504
02505 if ((pc_tag==0) || (*pc_tag==0))
02506 ps_chan->l_tagfile_no = -1;
02507 else
02508 ps_chan->l_tagfile_no = open(pc_tag, GET__OPEN_FLAG);
02509
02510
02511 if(ps_chan->l_tagfile_no == -1)
02512 {
02513
02514
02515 ii=f_evt_get_open(GETEVT__FILE, pc_lmd, ps_chan, (CHARS **) &ps_bufhe,0,0);
02516 *ps_head = (CHARS *) ps_bufhe;
02517 if(ii!=GETEVT__SUCCESS)
02518 {
02519 printf("Error opening input file %s\n",pc_lmd);
02520 return (ii);
02521 }
02522
02523 if(l_prihe) ii = f_evt_type(ps_bufhe,NULL,0,0,0,0);
02524 return(GETEVT__SUCCESS);
02525 }
02526
02527
02528 ps_chan->ps_taghe = (s_taghe *)malloc(sizeof(s_taghe));
02529 if(read(ps_chan->l_tagfile_no,(CHARS *)ps_chan->ps_taghe,sizeof(s_taghe))!=sizeof(s_taghe))
02530 {
02531 free(ps_chan->ps_taghe);
02532 ps_chan->ps_taghe = NULL;
02533 close(ps_chan->l_tagfile_no);
02534 return(GETEVT__TAGRDERR);
02535 }
02536 if(ps_chan->ps_taghe->l_endian != 1)ps_chan->l_tagswap=1;
02537 if(ps_chan->l_tagswap)f_evt_swap((CHARS *)ps_chan->ps_taghe,sizeof(s_taghe));
02538 if(l_prihe)
02539 {
02540 printf("Buffers %6d, of size %d, Events %10d, first %d, last %d"
02541 ,ps_chan->ps_taghe->l_buffers
02542 ,ps_chan->ps_taghe->l_bufsize
02543 ,ps_chan->ps_taghe->l_events
02544 ,ps_chan->ps_taghe->l_first
02545 ,ps_chan->ps_taghe->l_last);
02546 if(ps_chan->ps_taghe->l_linear)printf(" linear\n");
02547 else printf(" not linear\n");
02548 }
02549 if((ps_chan->l_channel_no=open(pc_lmd,GET__OPEN_FLAG))== -1)
02550 {
02551 if(ps_chan->ps_taghe != NULL) free(ps_chan->ps_taghe);
02552 ps_chan->ps_taghe = NULL;
02553 close(ps_chan->l_tagfile_no);
02554 return(GETEVT__NOFILE);
02555 }
02556
02557 ps_bufhe = (s_bufhe *)c_temp;
02558 if(read(ps_chan->l_channel_no,c_temp,ps_chan->ps_taghe->l_bufsize)!=ps_chan->ps_taghe->l_bufsize)
02559 {
02560 if(ps_chan->ps_taghe != NULL) free(ps_chan->ps_taghe);
02561 ps_chan->ps_taghe = NULL;
02562 if(ps_chan->ps_tag != NULL) free(ps_chan->ps_tag);
02563 ps_chan->ps_tag = NULL;
02564 close(ps_chan->l_tagfile_no);
02565 close(ps_chan->l_channel_no);
02566 return(GETEVT__RDERR);
02567 }
02568 if(ps_chan->ps_taghe->l_linear == 0)
02569 {
02570 ps_chan->ps_tag = (s_tag *)malloc(ps_chan->ps_taghe->l_filesize);
02571 if(read(ps_chan->l_tagfile_no,(CHARS *)ps_chan->ps_tag,ps_chan->ps_taghe->l_filesize)!=ps_chan->ps_taghe->l_filesize)
02572 {
02573 if(ps_chan->ps_taghe != NULL) free(ps_chan->ps_taghe);
02574 ps_chan->ps_taghe = NULL;
02575 if(ps_chan->ps_tag != NULL) free(ps_chan->ps_tag);
02576 ps_chan->ps_tag = NULL;
02577 close(ps_chan->l_tagfile_no);
02578 close(ps_chan->l_channel_no);
02579 return(GETEVT__TAGRDERR);
02580 }
02581 }
02582 if(ps_bufhe->l_free[0] != 1)ps_chan->l_lmdswap=1;
02583 if(ps_chan->l_lmdswap)f_evt_swap_filhe(ps_bufhe);
02584 if(l_prihe) ii = f_evt_type(ps_bufhe,NULL,0,0,0,0);
02585 if(ps_head != NULL)
02586 {
02587 if(ps_bufhe->i_type == 2000) *ps_head = (CHARS *)ps_bufhe;
02588 }
02589 ps_chan->l_evt_buf_size=0;
02590 ps_chan->pc_evt_buf=NULL;
02591 ps_chan->l_io_buf_posi=0;
02592 return(GETEVT__SUCCESS);
02593 }
02594
02595
02596
02597
02598
02599
02600
02601
02602
02603
02604
02605
02606
02607
02608
02609
02610
02611
02612
02613
02614
02615
02616
02617
02618
02619 INTS4 f_evt_get_tagnext(s_evt_channel *ps_chan,INTS4 l_skip, INTS4 **pl_event)
02620 {
02621 INTS4 ii,*pl,kk;
02622
02623
02624 if(ps_chan->ps_taghe == NULL)
02625 {
02626 for(kk=0;kk<=l_skip;kk++)
02627 {
02628 ii=f_evt_get_event(ps_chan, (INTS4 **) &pl, NULL);
02629 if(ii != GETEVT__SUCCESS) break;
02630 }
02631 }
02632
02633 else
02634 {
02635
02636 ii=f_evt_get_tagevent(ps_chan,ps_chan->l_io_buf_posi+l_skip+1,1,(INTS4 **)&pl);
02637 }
02638 if(pl_event != NULL) *pl_event=pl;
02639 return(ii);
02640 }
02641
02642
02643
02644
02645
02646
02647
02648
02649
02650
02651
02652
02653
02654
02655
02656
02657
02658
02659
02660
02661
02662
02663
02664
02665
02666
02667
02668 INTS4 f_evt_get_tagevent(s_evt_channel *ps_chan,INTS4 l_value, INTS4 l_type, INTS4 **pl_event)
02669 {
02670 INTS4 l_temp,l_chan,l_tag,ii,kk,lb,l_tagbufs,l_tagrest,l_evt,l_off,l_typ,l_val,l_evsize,l_fragsize;
02671 INTS4 la_head[2],*pl;
02672 CHARS *pc;
02673 s_ve10_1 *ps_ve10_1;
02674 s_bufhe *ps_bufhe;
02675 s_tag *ps_tag;
02676 s_tag s_tag_l;
02677 s_filhe *ps_filhe;
02678 s_evt_channel s_chan_i;
02679
02680 l_typ=l_type;
02681 l_val=l_value;
02682
02683
02684 if(ps_chan->ps_taghe == NULL)
02685 {
02686
02687 if(l_type == 1)
02688 {
02689 if(l_val == 0) l_val=1;
02690 for(kk=0;kk<l_val;kk++)
02691 {
02692 ii=f_evt_get_event(ps_chan, (INTS4 **) &pl, NULL);
02693 if(ii != GETEVT__SUCCESS)return(ii);
02694 }
02695 *pl_event=pl;
02696 }
02697 else
02698 {
02699 ii=f_evt_get_event(ps_chan, (INTS4 **) &ps_ve10_1, NULL);
02700 if(ii != GETEVT__SUCCESS)return(ii);
02701 while(ps_ve10_1->l_count != l_val)
02702 {
02703 ii=f_evt_get_event(ps_chan, (INTS4 **) &ps_ve10_1, NULL);
02704 if(ii != GETEVT__SUCCESS)return(ii);
02705 }
02706 *pl_event = (INTS4 *)ps_ve10_1;
02707 }
02708 return(GETEVT__SUCCESS);
02709 }
02710
02711 ps_ve10_1 = (s_ve10_1 *)c_temp;
02712 ps_bufhe = (s_bufhe *)c_temp;
02713
02714
02715
02716 if(ps_chan->ps_taghe->l_linear)
02717 {
02718 if(l_typ == 0)l_val=l_value-ps_chan->ps_taghe->l_first+1;
02719 l_typ=1;
02720 }
02721
02722 if(l_typ == 1)
02723 {
02724 if(l_val > ps_chan->ps_taghe->l_events)
02725 {
02726 printf("Event index %d not found\n",l_val);
02727 return(GETEVT__NOTAG);
02728 }
02729 if(l_val == 0) l_val=1;
02730 ps_tag=(s_tag *)&s_tag_l;
02731 lseek(ps_chan->l_tagfile_no, (l_val-1)*sizeof(s_tag)+sizeof(s_taghe), SEEK_SET);
02732 if(read(ps_chan->l_tagfile_no,(CHARS *)ps_tag,sizeof(s_tag))!=sizeof(s_tag))
02733 {
02734 return(GETEVT__TAGRDERR);
02735 }
02736 if(ps_chan->l_tagswap)f_evt_swap((CHARS *)ps_tag,sizeof(s_tag));
02737 ps_chan->l_io_buf_posi=l_val;
02738 }
02739 else
02740 {
02741 ps_tag=ps_chan->ps_tag;
02742 for(ii=1;ii<=ps_chan->ps_taghe->l_events;ii++)
02743 {
02744 if(ps_tag->l_event == l_val) break;
02745 ps_tag++;
02746 }
02747 if(ps_tag->l_event != l_val)
02748 {
02749 printf("Event number %d not found\n",l_val);
02750 return(GETEVT__NOTAG);
02751 }
02752 ps_chan->l_io_buf_posi=ii;
02753 }
02754
02755 l_off=ps_tag->l_offset;
02756 if(l_off < 0) l_off=((-l_off)/ps_chan->ps_taghe->l_bufsize)*ps_chan->ps_taghe->l_bufsize;
02757 l_evt=ps_tag->l_event;
02758
02759 if(ps_tag->l_offset > 0)
02760 {
02761 ps_ve10_1 = (s_ve10_1 *)c_temp;
02762 lseek(ps_chan->l_channel_no, l_off, SEEK_SET);
02763 if(read(ps_chan->l_channel_no,c_temp,8)!=8) return(GETEVT__RDERR);
02764 if(ps_chan->l_lmdswap)f_evt_swap(c_temp,8);
02765 if(read(ps_chan->l_channel_no,(CHARS *)&c_temp[8],ps_ve10_1->l_dlen*2)!=ps_ve10_1->l_dlen*2)return(GETEVT__RDERR);
02766 if(ps_chan->l_lmdswap)f_evt_swap((CHARS *)&c_temp[8],ps_ve10_1->l_dlen*2);
02767
02768 }
02769 else
02770
02771 {
02772 lseek(ps_chan->l_channel_no, l_off, SEEK_SET);
02773 if(read(ps_chan->l_channel_no,c_temp,sizeof(s_bufhe))!=sizeof(s_bufhe)) return(GETEVT__RDERR);
02774 if(ps_chan->l_lmdswap)f_evt_swap(c_temp,sizeof(s_bufhe));
02775
02776 l_evsize=ps_bufhe->l_free[1]+4;
02777 if(ps_chan->l_evt_buf_size < l_evsize*2)
02778 {
02779 if(ps_chan->pc_evt_buf != NULL)free(ps_chan->pc_evt_buf);
02780 ps_chan->l_evt_buf_size=l_evsize*2;
02781 ps_chan->pc_evt_buf=(CHARS *)malloc(ps_chan->l_evt_buf_size);
02782 }
02783 l_fragsize=0;
02784 ps_ve10_1 = (s_ve10_1 *)ps_chan->pc_evt_buf;
02785 lseek(ps_chan->l_channel_no, -ps_tag->l_offset, SEEK_SET);
02786 if(read(ps_chan->l_channel_no,ps_chan->pc_evt_buf,8)!=8) return(GETEVT__RDERR);
02787 if(ps_chan->l_lmdswap)f_evt_swap(ps_chan->pc_evt_buf,8);
02788 pc=ps_chan->pc_evt_buf+8;
02789
02790 if(read(ps_chan->l_channel_no,pc,ps_ve10_1->l_dlen*2)!=ps_ve10_1->l_dlen*2)return(GETEVT__RDERR);
02791 l_fragsize += ps_ve10_1->l_dlen+4;
02792 pc += ps_ve10_1->l_dlen*2;
02793 ps_ve10_1->l_dlen=l_evsize-4;
02794
02795 while(l_fragsize < l_evsize)
02796 {
02797 l_off += ps_chan->ps_taghe->l_bufsize;
02798 lseek(ps_chan->l_channel_no,l_off+sizeof(s_bufhe), SEEK_SET);
02799 if(read(ps_chan->l_channel_no,(CHARS *)&la_head,8)!=8) return(GETEVT__RDERR);
02800 if(ps_chan->l_lmdswap)f_evt_swap((CHARS *)&la_head,8);
02801 if(read(ps_chan->l_channel_no,pc,la_head[0]*2)!=la_head[0]*2) return(GETEVT__RDERR);
02802 pc += la_head[0]*2;
02803 l_fragsize += la_head[0];
02804 }
02805
02806 pc=ps_chan->pc_evt_buf+8;
02807 ps_ve10_1 = (s_ve10_1 *)ps_chan->pc_evt_buf;
02808 if(ps_chan->l_lmdswap)f_evt_swap(pc,ps_ve10_1->l_dlen*2);
02809 }
02810 *pl_event = (INTS4 *)ps_ve10_1;
02811 return(GETEVT__SUCCESS);
02812 }
02813
02814
02815
02816
02817
02818
02819
02820
02821
02822
02823
02824
02825
02826
02827
02828 INTS4 f_evt_get_tagclose(s_evt_channel *ps_chan)
02829 {
02830
02831 if(ps_chan->ps_taghe == NULL)
02832 {
02833 f_evt_get_close(ps_chan);
02834 return(GETEVT__SUCCESS);
02835 }
02836
02837 free(ps_chan->ps_taghe);
02838 if(ps_chan->ps_tag != NULL) free(ps_chan->ps_tag);
02839 if(ps_chan->pc_evt_buf != NULL) free(ps_chan->pc_evt_buf);
02840 close(ps_chan->l_tagfile_no);
02841 close(ps_chan->l_channel_no);
02842 memset((void *)ps_chan, 0, sizeof(s_evt_channel));
02843 return(GETEVT__SUCCESS);
02844 }
02845 s_evt_channel *f_evt_control(){
02846 s_evt_channel *x;
02847 x=(s_evt_channel *)malloc(sizeof(s_evt_channel));
02848 memset(x,0,sizeof(s_evt_channel));
02849 return(x);
02850 }