mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-01-17 18:53:44 +01:00
in the process of rewriting detector client interface
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "sls_detector_defs.h"
|
||||
#include "slsDetectorServer_defs.h"
|
||||
|
||||
#include "logger.h"
|
||||
#include "communication_funcs.h"
|
||||
#include "slsDetectorServer_funcs.h"
|
||||
|
||||
@@ -12,8 +12,13 @@
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
|
||||
extern int sockfd;
|
||||
// Global variables from communication_funcs
|
||||
extern int isControlServer;
|
||||
extern int ret;
|
||||
|
||||
// Global variables from slsDetectorServer_funcs
|
||||
extern int sockfd;
|
||||
extern int debugflag;
|
||||
|
||||
void error(char *msg){
|
||||
perror(msg);
|
||||
@@ -22,9 +27,7 @@ void error(char *msg){
|
||||
int main(int argc, char *argv[]){
|
||||
int portno = DEFAULT_PORTNO;
|
||||
int retval = OK;
|
||||
int sd, fd;
|
||||
int debugflag = 0;
|
||||
int controlserver = 1;
|
||||
int fd = 0;
|
||||
|
||||
// if socket crash, ignores SISPIPE, prevents global signal handler
|
||||
// subsequent read/write to socket gives error - must handle locally
|
||||
@@ -35,21 +38,21 @@ int main(int argc, char *argv[]){
|
||||
int i;
|
||||
for (i = 1; i < argc; ++i) {
|
||||
if(!strcasecmp(argv[i],"-stopserver")) {
|
||||
cprintf(BLUE,"Detected stop server\n");
|
||||
controlserver = 0;
|
||||
FILE_LOG(logINFO, ("Detected stop server\n"));
|
||||
isControlServer = 0;
|
||||
}
|
||||
else if(!strcasecmp(argv[i],"-devel")){
|
||||
cprintf(BLUE,"Detected developer mode\n");
|
||||
FILE_LOG(logINFO, ("Detected developer mode\n"));
|
||||
debugflag = 1;
|
||||
}
|
||||
#ifdef JUNGFRAUD
|
||||
else if(!strcasecmp(argv[i],"-update")){
|
||||
cprintf(BLUE,"Detected update mode\n");
|
||||
FILE_LOG(logINFO, ("Detected update mode\n"));
|
||||
debugflag = PROGRAMMING_MODE;
|
||||
}
|
||||
#endif
|
||||
else if(strchr(argv[i],'-') != NULL) {
|
||||
cprintf(RED,"cannot scan program argument %s\n", argv[1]);
|
||||
FILE_LOG(logERROR, ("cannot scan program argument %s\n", argv[1]));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -59,79 +62,60 @@ int main(int argc, char *argv[]){
|
||||
char cmd[100];
|
||||
memset(cmd, 0, 100);
|
||||
#endif
|
||||
if (controlserver) {
|
||||
if (isControlServer) {
|
||||
portno = DEFAULT_PORTNO;
|
||||
cprintf(BLUE,
|
||||
"********************************************************\n"
|
||||
FILE_LOG(logINFOBLUE,
|
||||
("***************************************************\n"
|
||||
"********* opening control server on port %d **********\n"
|
||||
"********************************************************\n\n"
|
||||
, portno);
|
||||
, portno));
|
||||
#ifdef STOP_SERVER
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < argc; ++i)
|
||||
sprintf(cmd, "%s %s", cmd, argv[i]);
|
||||
sprintf(cmd,"%s -stopserver&", cmd);
|
||||
cprintf(BLUE,"cmd:%s\n", cmd);
|
||||
FILE_LOG(logINFO, ("Command to start stop server:%s\n", cmd));
|
||||
system(cmd);
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
portno = DEFAULT_PORTNO+1;
|
||||
cprintf(BLUE,
|
||||
"********************************************************\n"
|
||||
portno = DEFAULT_PORTNO + 1;
|
||||
FILE_LOG(logINFOBLUE,
|
||||
("***************************************************\n"
|
||||
"*********** opening stop server on port %d ***********\n"
|
||||
"********************************************************\n\n"
|
||||
, portno);
|
||||
, portno));
|
||||
}
|
||||
|
||||
setModeFlag(debugflag); //defined in slsDetectorServer_funcs
|
||||
init_detector(controlserver); //defined in slsDetectorServer_funcs
|
||||
init_detector();
|
||||
|
||||
sd=bindSocket(portno); //defined in communication_funcs
|
||||
sockfd=sd;
|
||||
if (getServerError(sd)) { //defined in communication_funcs
|
||||
printf("server error!\n");
|
||||
return -1;
|
||||
{ // bind socket
|
||||
sockfd = bindSocket(portno);
|
||||
if (ret == FAIL)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* assign function table */
|
||||
function_table(); //defined in slsDetectorServer_funcs
|
||||
#ifdef VERBOSE
|
||||
printf("function table assigned \n");
|
||||
#endif
|
||||
// assign function table
|
||||
function_table();
|
||||
|
||||
if (controlserver)
|
||||
printf("\nControl Server Ready...\n\n");
|
||||
else
|
||||
printf("\nStop Server Ready...\n\n");
|
||||
if (isControlServer) {
|
||||
FILE_LOG(logINFO, ("Control Server Ready...\n\n"));
|
||||
} else {
|
||||
FILE_LOG(logINFO, ("Stop Server Ready...\n\n"));
|
||||
}
|
||||
|
||||
/* waits for connection */
|
||||
while(retval!=GOODBYE) {
|
||||
#ifdef VERBOSE
|
||||
printf("\n");
|
||||
#endif
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("Waiting for client call\n");
|
||||
#endif
|
||||
fd=acceptConnection(sockfd); //defined in communication_funcs
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("Conenction accepted\n");
|
||||
#endif
|
||||
if (fd>0) {
|
||||
retval=decode_function(fd); //defined in slsDetectorServer_funcs
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("function executed\n");
|
||||
#endif
|
||||
closeConnection(fd); //defined in communication_funcs
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("connection closed\n");
|
||||
#endif
|
||||
// waits for connection
|
||||
while(retval != GOODBYE) {
|
||||
fd = acceptConnection(sockfd);
|
||||
if (fd > 0) {
|
||||
retval = decode_function(fd);
|
||||
closeConnection(fd);
|
||||
}
|
||||
}
|
||||
|
||||
exitServer(sockfd); //defined in communication_funcs
|
||||
printf("Goodbye!\n");
|
||||
exitServer(sockfd);
|
||||
FILE_LOG(logINFO,("Goodbye!\n"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user