20 #include <rpc/pmap_clnt.h>
31 #include <sys/types.h>
48 extern "C" void rcdaq_1(
struct svc_req *rqstp, SVCXPRT *transp);
83 void *
v = dlopen(sharedlib, RTLD_GLOBAL | RTLD_NOW | RTLD_NOLOAD);
86 std::cout <<
"Plugin "
87 << sharedlib <<
" already loaded" << std::endl;
89 << sharedlib <<
" already loaded" << std::endl;
93 void * voidpointer = dlopen(sharedlib, RTLD_GLOBAL | RTLD_NOW);
96 std::cout <<
"Loading of the plugin "
97 << sharedlib <<
" failed: " << dlerror() << std::endl;
98 os <<
"Loading of the plugin "
99 << sharedlib <<
" failed: " << dlerror() << std::endl;
103 os <<
"Plugin " << sharedlib <<
" successfully loaded" << std::endl;
104 cout <<
"Plugin " << sharedlib <<
" successfully loaded" << std::endl;
121 os <<
" List of loaded Plugins:" << endl;
125 os <<
" No Plugins loaded" << endl;
129 std::vector<RCDAQPlugin *>::iterator
it;
144 static shortResult result,
error;
145 static char e_string[512];
146 static char r_string[512];
147 error.str = e_string;
148 result.str = r_string;
149 strcpy ( r_string,
" ");
153 strcpy(e_string,
"Run is active\n");
160 strcpy(e_string,
"Device needs at least 2 parameters\n");
176 strcpy(r_string,
"Device needs at least 2 parameters\n");
181 strcpy(r_string,
"Wrong number of parameters\n");
193 if ( strcasecmp(db->argv0,
"device_random") == 0 )
243 if ( strcasecmp(db->argv0,
"device_deadtime") == 0 )
285 else if ( strcasecmp(db->argv0,
"device_file") == 0 )
288 if ( db->npar < 4)
return &
error;
294 if ( s < 4*1024) s = 4*1024;
315 else if ( strcasecmp(db->argv0,
"device_file_delete") == 0 )
318 if ( db->npar < 4)
return &
error;
324 if ( s < 4*1024) s = 4*1024;
348 else if ( strcasecmp(db->argv0,
"device_filenumbers") == 0 )
351 if ( db->npar < 4)
return &
error;
356 if ( s < 256) s = 256;
379 else if ( strcasecmp(db->argv0,
"device_filenumbers_delete") == 0 )
382 if ( db->npar < 4)
return &
error;
387 if ( s < 256) s = 256;
409 else if ( strcasecmp(db->argv0,
"device_command") == 0 )
412 if ( db->npar < 4)
return &
error;
417 if ( s < 1280) s = 1280;
434 else if ( strcasecmp(db->argv0,
"device_rtclock") == 0 )
457 std::vector<RCDAQPlugin *>::iterator
it;
462 status = (*it)->create_device(db);
464 if (status == 0)
return &result;
465 else if ( status == 1)
return &
error;
470 strcpy(r_string,
"Unknown device");
480 static shortResult result;
482 static std::ostringstream outputstream;
483 static unsigned int currentmaxresultlength = 10*2048;
484 static char *resultstring =
new char[currentmaxresultlength+1];
492 if ( outputstream.str().size() > currentmaxresultlength )
494 currentmaxresultlength = outputstream.str().size();
495 std::cout << __LINE__<<
" " << __FILE__
496 <<
" *** warning: extended result string to " << currentmaxresultlength << std::endl;
497 delete [] resultstring;
498 resultstring =
new char[currentmaxresultlength+1];
503 result.str=resultstring;
504 strcpy(resultstring,
" ");
509 outputstream.str(
"");
521 result.status =
daq_begin ( ab->ipar[0], outputstream);
522 outputstream.str().copy(resultstring,outputstream.str().size());
523 resultstring[outputstream.str().size()] = 0;
524 result.str = resultstring;
532 outputstream.str().copy(resultstring,outputstream.str().size());
533 resultstring[outputstream.str().size()] = 0;
534 result.str = resultstring;
542 outputstream.str().copy(resultstring,outputstream.str().size());
543 resultstring[outputstream.str().size()] = 0;
544 result.str = resultstring;
552 outputstream.str().copy(resultstring,outputstream.str().size());
553 resultstring[outputstream.str().size()] = 0;
554 result.str = resultstring;
576 #ifdef HAVE_MOSQUITTO_H
582 outputstream.str().copy(resultstring,outputstream.str().size());
583 resultstring[outputstream.str().size()] = 0;
584 result.str = resultstring;
594 outputstream.str().copy(resultstring,outputstream.str().size());
595 resultstring[outputstream.str().size()] = 0;
596 result.str = resultstring;
607 outputstream.str().copy(resultstring,outputstream.str().size());
608 resultstring[outputstream.str().size()] = 0;
609 result.str = resultstring;
618 outputstream.str().copy(resultstring,outputstream.str().size());
619 resultstring[outputstream.str().size()] = 0;
620 result.str = resultstring;
632 outputstream.str().copy(resultstring,outputstream.str().size());
633 resultstring[outputstream.str().size()] = 0;
634 result.str = resultstring;
642 outputstream.str().copy(resultstring,outputstream.str().size());
643 resultstring[outputstream.str().size()] = 0;
644 result.str = resultstring;
652 result.status =
daq_open(outputstream);
655 outputstream.str().copy(resultstring,outputstream.str().size());
656 resultstring[outputstream.str().size()] = 0;
657 result.str = resultstring;
665 result.status =
daq_set_server(ab->spar, ab->ipar[0], outputstream);
668 outputstream.str().copy(resultstring,outputstream.str().size());
669 resultstring[outputstream.str().size()] = 0;
670 result.str = resultstring;
681 outputstream.str().copy(resultstring,outputstream.str().size());
682 resultstring[outputstream.str().size()] = 0;
683 result.str = resultstring;
692 outputstream.str().copy(resultstring,outputstream.str().size());
693 resultstring[outputstream.str().size()] = 0;
694 result.str = resultstring;
708 outputstream.str().copy(resultstring,outputstream.str().size());
709 resultstring[outputstream.str().size()] = 0;
710 result.str = resultstring;
718 outputstream.str().copy(resultstring,outputstream.str().size());
719 resultstring[outputstream.str().size()] = 0;
720 result.str = resultstring;
727 result.status =
daq_status(ab->ipar[0], outputstream);
728 outputstream.str().copy(resultstring,outputstream.str().size());
729 resultstring[outputstream.str().size()] = 0;
730 result.str = resultstring;
740 outputstream.str().copy(resultstring,outputstream.str().size());
741 resultstring[outputstream.str().size()] = 0;
742 result.str = resultstring;
753 outputstream.str().copy(resultstring,outputstream.str().size());
754 resultstring[outputstream.str().size()] = 0;
755 result.str = resultstring;
766 outputstream.str().copy(resultstring,outputstream.str().size());
767 resultstring[outputstream.str().size()] = 0;
768 result.str = resultstring;
779 outputstream.str().copy(resultstring,outputstream.str().size());
780 resultstring[outputstream.str().size()] = 0;
781 result.str = resultstring;
792 outputstream.str().copy(resultstring,outputstream.str().size());
793 resultstring[outputstream.str().size()] = 0;
794 result.str = resultstring;
810 outputstream.str().copy(resultstring,outputstream.str().size());
811 resultstring[outputstream.str().size()] = 0;
812 result.str = resultstring;
821 outputstream.str().copy(resultstring,outputstream.str().size());
822 resultstring[outputstream.str().size()] = 0;
823 result.str = resultstring;
837 outputstream.str().copy(resultstring,outputstream.str().size());
838 resultstring[outputstream.str().size()] = 0;
839 result.str = resultstring;
847 outputstream.str().copy(resultstring,outputstream.str().size());
848 resultstring[outputstream.str().size()] = 0;
849 result.str = resultstring;
860 outputstream.str().copy(resultstring,outputstream.str().size());
861 resultstring[outputstream.str().size()] = 0;
862 result.str = resultstring;
873 outputstream.str().copy(resultstring,outputstream.str().size());
874 resultstring[outputstream.str().size()] = 0;
875 result.str = resultstring;
884 outputstream.str().copy(resultstring,outputstream.str().size());
885 resultstring[outputstream.str().size()] = 0;
886 result.str = resultstring;
893 strcpy(resultstring,
"Unknown action");
909 static shortResult result;
911 static std::ostringstream outputstream;
913 static char resultstring[256];
922 outputstream.str(
"");
924 result.str = (
char *) outputstream.str().c_str();
927 cout <<
"daq_shutdown status = " << result.status << endl;
930 outputstream.str().copy(resultstring,outputstream.str().size());
931 resultstring[outputstream.str().size()] = 0;
932 result.str = resultstring;
949 mode_t
mask = umask(0);
950 int i = mkdir (
"/tmp/rcdaq", 0777);
951 if ( i && errno != EEXIST)
953 std::cerr <<
"Error accessing the lock directory /tmp/rcdaq" << std::endl;
966 sprintf (pidfilename,
"/tmp/rcdaq/rcdaq_%d", servernumber);
968 pid_fd =
open(pidfilename, O_CREAT | O_RDWR, 0666);
972 ifstream pidfile = ifstream(pidfilename);
973 if ( pidfile.is_open())
977 std::cerr <<
"Another server is already running, PID= " << ipid << std::endl;
981 std::cerr <<
"Error creating the lock file" << std::endl;
985 int rc = flock(
pid_fd, LOCK_EX | LOCK_NB);
988 if (errno == EWOULDBLOCK)
990 ifstream pidfile = ifstream(pidfilename);
991 if ( pidfile.is_open())
995 std::cerr <<
"Another server is already running, PID= " << ipid << std::endl;
999 std::cerr <<
"Another server is already running" << std::endl;
1006 int x = sprintf(pid,
"%d\n", getpid());
1010 std::cout <<
"Server number is " << servernumber << std::endl;
1027 transp = svctcp_create(RPC_ANYSOCK, 0, 0);
1028 if (transp == NULL) {
1029 fprintf (stderr,
"%s",
"cannot create tcp service.");
1033 fprintf (stderr,
"%s",
"unable to register (RCDAQ+servernumber, RCDAQ_VERS, tcp).");
1042 fprintf (stderr,
"%s",
"svc_run returned");