mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-23 06:50:02 +02:00
WIP
This commit is contained in:
parent
47b0e46f15
commit
80e55cd4da
@ -10,7 +10,7 @@ add_executable(mythen3DetectorServer_virtual
|
|||||||
../slsDetectorServer/src/LTC2620_Driver.c
|
../slsDetectorServer/src/LTC2620_Driver.c
|
||||||
../slsDetectorServer/src/ALTERA_PLL_CYCLONE10.c
|
../slsDetectorServer/src/ALTERA_PLL_CYCLONE10.c
|
||||||
../slsDetectorServer/src/programFpgaNios.c
|
../slsDetectorServer/src/programFpgaNios.c
|
||||||
../slsDetectorServer/src/clogger.c
|
../slsDetectorServer/src/communication_virtual.c
|
||||||
)
|
)
|
||||||
|
|
||||||
include_directories(
|
include_directories(
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include "ALTERA_PLL_CYCLONE10.h"
|
#include "ALTERA_PLL_CYCLONE10.h"
|
||||||
#ifdef VIRTUAL
|
#ifdef VIRTUAL
|
||||||
#include "communication_funcs_UDP.h"
|
#include "communication_funcs_UDP.h"
|
||||||
|
#include "communication_virtual.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -33,7 +34,6 @@ int initCheckDone = 0;
|
|||||||
char initErrorMessage[MAX_STR_LENGTH];
|
char initErrorMessage[MAX_STR_LENGTH];
|
||||||
|
|
||||||
#ifdef VIRTUAL
|
#ifdef VIRTUAL
|
||||||
//int pipeFDs[2];
|
|
||||||
pthread_t pthread_virtual_tid;
|
pthread_t pthread_virtual_tid;
|
||||||
int virtual_status = 0;
|
int virtual_status = 0;
|
||||||
int virtual_stop = 0;
|
int virtual_stop = 0;
|
||||||
@ -326,6 +326,12 @@ void initStopServer() {
|
|||||||
LOG(logERROR, ("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n"));
|
LOG(logERROR, ("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n"));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
#ifdef VIRTUAL
|
||||||
|
virtual_stop = 0;
|
||||||
|
if (!isControlServer) {
|
||||||
|
ComVirtual_writeStop(virtual_stop);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -350,6 +356,12 @@ void setupDetector() {
|
|||||||
dacValues[i] = 0;
|
dacValues[i] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef VIRTUAL
|
||||||
|
virtual_status = 0;
|
||||||
|
if (isControlServer) {
|
||||||
|
ComVirtual_writeStatus(virtual_status);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// pll defines
|
// pll defines
|
||||||
ALTERA_PLL_C10_SetDefines(REG_OFFSET, BASE_READOUT_PLL, BASE_SYSTEM_PLL, PLL_RESET_REG, PLL_RESET_REG, PLL_RESET_READOUT_MSK, PLL_RESET_SYSTEM_MSK, READOUT_PLL_VCO_FREQ_HZ, SYSTEM_PLL_VCO_FREQ_HZ);
|
ALTERA_PLL_C10_SetDefines(REG_OFFSET, BASE_READOUT_PLL, BASE_SYSTEM_PLL, PLL_RESET_REG, PLL_RESET_REG, PLL_RESET_READOUT_MSK, PLL_RESET_SYSTEM_MSK, READOUT_PLL_VCO_FREQ_HZ, SYSTEM_PLL_VCO_FREQ_HZ);
|
||||||
@ -1353,16 +1365,21 @@ int startStateMachine(){
|
|||||||
LOG(logINFOBLUE, ("Starting State Machine\n"));
|
LOG(logINFOBLUE, ("Starting State Machine\n"));
|
||||||
// set status to running
|
// set status to running
|
||||||
virtual_status = 1;
|
virtual_status = 1;
|
||||||
/*if (isControlServer) {
|
if (isControlServer) {
|
||||||
//write(pipeFDs[PIPE_WRITE], &virtual_status, sizeof(virtual_status));
|
ComVirtual_writeStatus(virtual_status);
|
||||||
}*/
|
ComVirtual_readStop(&virtual_stop);
|
||||||
virtual_stop = 0;
|
if (virtual_stop != 0) {
|
||||||
|
LOG(logERROR, ("Cant start acquisition. "
|
||||||
|
"Stop server has not updated stop status to 0\n"));
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
if(pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) {
|
if(pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) {
|
||||||
LOG(logERROR, ("Could not start Virtual acquisition thread\n"));
|
LOG(logERROR, ("Could not start Virtual acquisition thread\n"));
|
||||||
virtual_status = 0;
|
virtual_status = 0;
|
||||||
/*if (isControlServer) {
|
if (isControlServer) {
|
||||||
//write(pipeFDs[PIPE_WRITE], &virtual_status, sizeof(virtual_status));
|
ComVirtual_writeStatus(virtual_status);
|
||||||
}*/
|
}
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
LOG(logINFOGREEN, ("Virtual Acquisition started\n"));
|
LOG(logINFOGREEN, ("Virtual Acquisition started\n"));
|
||||||
@ -1383,6 +1400,10 @@ int startStateMachine(){
|
|||||||
|
|
||||||
#ifdef VIRTUAL
|
#ifdef VIRTUAL
|
||||||
void* start_timer(void* arg) {
|
void* start_timer(void* arg) {
|
||||||
|
if (!isControlServer) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
int64_t periodNs = getPeriod();
|
int64_t periodNs = getPeriod();
|
||||||
int numFrames = (getNumFrames() *
|
int numFrames = (getNumFrames() *
|
||||||
getNumTriggers() );
|
getNumTriggers() );
|
||||||
@ -1409,6 +1430,8 @@ void* start_timer(void* arg) {
|
|||||||
// loop over number of frames
|
// loop over number of frames
|
||||||
for (frameNr = 0; frameNr != numFrames; ++frameNr) {
|
for (frameNr = 0; frameNr != numFrames; ++frameNr) {
|
||||||
|
|
||||||
|
// update the virtual stop from stop server
|
||||||
|
ComVirtual_readStop(&virtual_stop);
|
||||||
//check if virtual_stop is high
|
//check if virtual_stop is high
|
||||||
if(virtual_stop == 1){
|
if(virtual_stop == 1){
|
||||||
break;
|
break;
|
||||||
@ -1463,9 +1486,9 @@ void* start_timer(void* arg) {
|
|||||||
closeUDPSocket(0);
|
closeUDPSocket(0);
|
||||||
|
|
||||||
virtual_status = 0;
|
virtual_status = 0;
|
||||||
/*if (isControlServer) {
|
if (isControlServer) {
|
||||||
//write(pipeFDs[PIPE_WRITE], &virtual_status, sizeof(virtual_status));
|
ComVirtual_writeStatus(virtual_status);
|
||||||
} */
|
}
|
||||||
LOG(logINFOBLUE, ("Finished Acquiring\n"));
|
LOG(logINFOBLUE, ("Finished Acquiring\n"));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -1475,7 +1498,18 @@ void* start_timer(void* arg) {
|
|||||||
int stopStateMachine(){
|
int stopStateMachine(){
|
||||||
LOG(logINFORED, ("Stopping State Machine\n"));
|
LOG(logINFORED, ("Stopping State Machine\n"));
|
||||||
#ifdef VIRTUAL
|
#ifdef VIRTUAL
|
||||||
|
if (!isControlServer) {
|
||||||
|
virtual_stop = 1;
|
||||||
|
ComVirtual_writeStop(virtual_stop);
|
||||||
|
// read till status is idle
|
||||||
|
int tempStatus = 1;
|
||||||
|
while(tempStatus == 1) {
|
||||||
|
ComVirtual_readStatus(&tempStatus);
|
||||||
|
}
|
||||||
virtual_stop = 0;
|
virtual_stop = 0;
|
||||||
|
ComVirtual_writeStop(virtual_stop);
|
||||||
|
LOG(logINFO, ("Stopped State Machine\n"));
|
||||||
|
}
|
||||||
return OK;
|
return OK;
|
||||||
#endif
|
#endif
|
||||||
//stop state machine
|
//stop state machine
|
||||||
@ -1486,13 +1520,9 @@ int stopStateMachine(){
|
|||||||
|
|
||||||
enum runStatus getRunStatus(){
|
enum runStatus getRunStatus(){
|
||||||
#ifdef VIRTUAL
|
#ifdef VIRTUAL
|
||||||
/*if (!isControlServer) {
|
if (!isControlServer) {
|
||||||
LOG(logINFORED, ("***** reading\n"));
|
ComVirtual_readStatus(&virtual_status);
|
||||||
while (read(pipeFDs[PIPE_READ], &virtual_status, sizeof(virtual_status)) > 0) {
|
|
||||||
LOG(logINFORED, ("virtual status:%d\n", virtual_status));
|
|
||||||
}
|
}
|
||||||
LOG(logINFORED, ("***** final %d\n", virtual_status));
|
|
||||||
}*/
|
|
||||||
if(virtual_status == 0){
|
if(virtual_status == 0){
|
||||||
LOG(logINFOBLUE, ("Status: IDLE\n"));
|
LOG(logINFOBLUE, ("Status: IDLE\n"));
|
||||||
return IDLE;
|
return IDLE;
|
||||||
@ -1568,12 +1598,9 @@ void readFrame(int *ret, char *mess) {
|
|||||||
|
|
||||||
u_int32_t runBusy() {
|
u_int32_t runBusy() {
|
||||||
#ifdef VIRTUAL
|
#ifdef VIRTUAL
|
||||||
/*if (!isControlServer) {
|
if (!isControlServer) {
|
||||||
LOG(logINFORED, ("runbusy \n"));
|
ComVirtual_readStatus(&virtual_status);
|
||||||
while (read(pipeFDs[PIPE_READ], &virtual_status, sizeof(virtual_status)) > 0) {
|
|
||||||
LOG(logINFORED, ("runbusy virtual status:%d\n", virtual_status));
|
|
||||||
}
|
}
|
||||||
}*/
|
|
||||||
return virtual_status;
|
return virtual_status;
|
||||||
#endif
|
#endif
|
||||||
u_int32_t s = (bus_r(PAT_STATUS_REG) & PAT_STATUS_RUN_BUSY_MSK);
|
u_int32_t s = (bus_r(PAT_STATUS_REG) & PAT_STATUS_RUN_BUSY_MSK);
|
||||||
|
@ -5,9 +5,6 @@
|
|||||||
|
|
||||||
#define CTRL_SRVR_INIT_TIME_US (300 * 1000)
|
#define CTRL_SRVR_INIT_TIME_US (300 * 1000)
|
||||||
|
|
||||||
#define PIPE_WRITE 1
|
|
||||||
#define PIPE_READ 0
|
|
||||||
|
|
||||||
/* Hardware Definitions */
|
/* Hardware Definitions */
|
||||||
#define NCOUNTERS (3)
|
#define NCOUNTERS (3)
|
||||||
#define MAX_COUNTER_MSK (0x7)
|
#define MAX_COUNTER_MSK (0x7)
|
||||||
|
@ -11,6 +11,13 @@ typedef enum{
|
|||||||
OTHER
|
OTHER
|
||||||
}intType;
|
}intType;
|
||||||
|
|
||||||
|
// communciate with stop server
|
||||||
|
#ifdef VIRTUAL
|
||||||
|
#define FILE_STATUS "/tmp/Sls_virtual_server_status_"
|
||||||
|
#define FILE_STOP "/tmp/Sls_virtual_server_stop_"
|
||||||
|
#define FD_STATUS 0
|
||||||
|
#define FD_STOP 1
|
||||||
|
#endif
|
||||||
|
|
||||||
int bindSocket(unsigned short int port_number);
|
int bindSocket(unsigned short int port_number);
|
||||||
int acceptConnection(int socketDescriptor);
|
int acceptConnection(int socketDescriptor);
|
||||||
|
14
slsDetectorServers/slsDetectorServer/include/communication_virtual.h
Executable file
14
slsDetectorServers/slsDetectorServer/include/communication_virtual.h
Executable file
@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
#ifdef VIRTUAL
|
||||||
|
// communciate between control and stop server
|
||||||
|
|
||||||
|
int ComVirtual_createFiles(const int port);
|
||||||
|
void ComVirtual_setFileNames(const int port);
|
||||||
|
int ComVirtual_writeStatus(int value);
|
||||||
|
int ComVirtual_readStatus(int* value);
|
||||||
|
int ComVirtual_writeStop(int value);
|
||||||
|
int ComVirtual_readStop(int* value);
|
||||||
|
int ComVirtual_writeToFile(int value, const char* fname, const char* serverName);
|
||||||
|
int ComVirtual_readFromFile(int* value, const char* fname, const char* serverName);
|
||||||
|
|
||||||
|
#endif
|
107
slsDetectorServers/slsDetectorServer/src/communication_virtual.c
Executable file
107
slsDetectorServers/slsDetectorServer/src/communication_virtual.c
Executable file
@ -0,0 +1,107 @@
|
|||||||
|
#ifdef VIRTUAL
|
||||||
|
#include "communication_virtual.h"
|
||||||
|
#include "clogger.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define FILE_STATUS "/tmp/sls_virtual_server_status_"
|
||||||
|
#define FILE_STOP "/tmp/sls_virtual_server_stop_"
|
||||||
|
#define FD_STATUS 0
|
||||||
|
#define FD_STOP 1
|
||||||
|
#define FILE_NAME_LENGTH 1000
|
||||||
|
|
||||||
|
FILE* fd[2] = {NULL, NULL};
|
||||||
|
char fnameStatus[FILE_NAME_LENGTH];
|
||||||
|
char fnameStop[FILE_NAME_LENGTH];
|
||||||
|
int portNumber = 0;
|
||||||
|
|
||||||
|
int ComVirtual_createFiles(const int port) {
|
||||||
|
portNumber = port;
|
||||||
|
// control server writign status file
|
||||||
|
memset(fnameStatus, 0, FILE_NAME_LENGTH);
|
||||||
|
sprintf(fnameStatus, "%s%d", FILE_STATUS, port);
|
||||||
|
FILE* fd = NULL;
|
||||||
|
if (NULL == (fd = fopen(fnameStatus, "w"))) {
|
||||||
|
LOG(logERROR, ("Could not open the file %s for virtual communication\n",
|
||||||
|
fnameStatus));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
fclose(fd);
|
||||||
|
LOG(logINFOBLUE, ("Created status file %s\n", fnameStatus));
|
||||||
|
|
||||||
|
// stop server writing stop file
|
||||||
|
memset(fnameStop, 0, FILE_NAME_LENGTH);
|
||||||
|
sprintf(fnameStop, "%s%d", FILE_STOP, port);
|
||||||
|
if (NULL == (fd = fopen(fnameStop, "w"))) {
|
||||||
|
LOG(logERROR, ("Could not open the file %s for virtual communication\n",
|
||||||
|
fnameStop));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
fclose(fd);
|
||||||
|
LOG(logINFOBLUE, ("Created stop file %s\n", fnameStop));
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ComVirtual_setFileNames(const int port) {
|
||||||
|
portNumber = port;
|
||||||
|
memset(fnameStatus, 0, FILE_NAME_LENGTH);
|
||||||
|
memset(fnameStop, 0, FILE_NAME_LENGTH);
|
||||||
|
sprintf(fnameStatus, "%s%d", FILE_STATUS, port);
|
||||||
|
sprintf(fnameStatus, "%s%d", FILE_STOP, port);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ComVirtual_writeStatus(int value) {
|
||||||
|
return ComVirtual_writeToFile(value, FILE_STATUS, "Control");
|
||||||
|
}
|
||||||
|
|
||||||
|
int ComVirtual_readStatus(int* value) {
|
||||||
|
return ComVirtual_readFromFile(value, FILE_STATUS, "Control");
|
||||||
|
}
|
||||||
|
|
||||||
|
int ComVirtual_writeStop(int value) {
|
||||||
|
return ComVirtual_writeToFile(value, FILE_STOP, "Stop");
|
||||||
|
}
|
||||||
|
|
||||||
|
int ComVirtual_readStop(int* value) {
|
||||||
|
return ComVirtual_readFromFile(value, FILE_STOP, "Stop");
|
||||||
|
}
|
||||||
|
|
||||||
|
int ComVirtual_writeToFile(int value, const char* fname, const char* serverName) {
|
||||||
|
FILE* fd = NULL;
|
||||||
|
if (NULL == (fd = fopen(fname, "w"))) {
|
||||||
|
LOG(logERROR, ("Vritual %s Server [%d] could not open "
|
||||||
|
"the file %s for writing\n",
|
||||||
|
serverName, portNumber, fname));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
while (fwrite(&value, sizeof(value), 1, fd) < 1) {
|
||||||
|
LOG(logERROR, ("Vritual %s Server [%d] could not write "
|
||||||
|
"to file %s\n",
|
||||||
|
serverName, portNumber, fname));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
fclose(fd);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ComVirtual_readFromFile(int* value, const char* fname, const char* serverName) {
|
||||||
|
FILE* fd = NULL;
|
||||||
|
if (NULL == (fd = fopen(fname, "r"))) {
|
||||||
|
LOG(logERROR, ("Vritual %s Server [%d] could not open "
|
||||||
|
"the file %s for reading\n",
|
||||||
|
serverName, portNumber, fname));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
while (fread(value, sizeof(int), 1, fd) < 1) {
|
||||||
|
LOG(logERROR, ("Vritual %s Server [%d] could not read "
|
||||||
|
"from file %s\n",
|
||||||
|
serverName, portNumber, fname));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
fclose(fd);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
@ -7,11 +7,13 @@
|
|||||||
#include "slsDetectorServer_funcs.h"
|
#include "slsDetectorServer_funcs.h"
|
||||||
#include "slsDetectorServer_defs.h"
|
#include "slsDetectorServer_defs.h"
|
||||||
#include "versionAPI.h"
|
#include "versionAPI.h"
|
||||||
|
#ifdef VIRTUAL
|
||||||
|
#include "communication_virtual.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
|
||||||
|
|
||||||
// Global variables from communication_funcs
|
// Global variables from communication_funcs
|
||||||
extern int isControlServer;
|
extern int isControlServer;
|
||||||
@ -24,9 +26,6 @@ extern int checkModuleFlag;
|
|||||||
|
|
||||||
|
|
||||||
// Global variables from slsDetectorFunctionList
|
// Global variables from slsDetectorFunctionList
|
||||||
#ifdef VIRTUAL
|
|
||||||
//extern int pipeFDs[2];
|
|
||||||
#endif
|
|
||||||
#ifdef GOTTHARDD
|
#ifdef GOTTHARDD
|
||||||
extern int phaseShift;
|
extern int phaseShift;
|
||||||
#endif
|
#endif
|
||||||
@ -55,8 +54,9 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int portno = DEFAULT_PORTNO;
|
int portno = DEFAULT_PORTNO;
|
||||||
int retval = OK;
|
isControlServer = 1;
|
||||||
int fd = 0;
|
debugflag = 0;
|
||||||
|
checkModuleFlag = 1;
|
||||||
|
|
||||||
// if socket crash, ignores SISPIPE, prevents global signal handler
|
// if socket crash, ignores SISPIPE, prevents global signal handler
|
||||||
// subsequent read/write to socket gives error - must handle locally
|
// subsequent read/write to socket gives error - must handle locally
|
||||||
@ -66,7 +66,11 @@ int main(int argc, char *argv[]) {
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = 1; i < argc; ++i) {
|
for (i = 1; i < argc; ++i) {
|
||||||
if(!strcasecmp(argv[i],"-devel")){
|
if(!strcasecmp(argv[i],"-stopserver")) {
|
||||||
|
LOG(logINFO, ("Detected stop server\n"));
|
||||||
|
isControlServer = 0;
|
||||||
|
}
|
||||||
|
else if(!strcasecmp(argv[i],"-devel")){
|
||||||
LOG(logINFO, ("Detected developer mode\n"));
|
LOG(logINFO, ("Detected developer mode\n"));
|
||||||
debugflag = 1;
|
debugflag = 1;
|
||||||
}
|
}
|
||||||
@ -83,7 +87,7 @@ int main(int argc, char *argv[]) {
|
|||||||
LOG(logERROR, ("cannot decode port value %s. Exiting.\n", argv[i + 1]));
|
LOG(logERROR, ("cannot decode port value %s. Exiting.\n", argv[i + 1]));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
LOG(logINFO, ("Detected control port: %d\n", portno));
|
LOG(logINFO, ("Detected port: %d\n", portno));
|
||||||
}
|
}
|
||||||
#ifdef GOTTHARDD
|
#ifdef GOTTHARDD
|
||||||
else if(!strcasecmp(argv[i],"-phaseshift")){
|
else if(!strcasecmp(argv[i],"-phaseshift")){
|
||||||
@ -101,62 +105,51 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// control server
|
||||||
// stop server
|
if (isControlServer) {
|
||||||
#ifdef STOP_SERVER
|
#ifdef STOP_SERVER
|
||||||
|
// start stop server process
|
||||||
|
char cmd[MAX_STR_LENGTH];
|
||||||
|
memset(cmd, 0, MAX_STR_LENGTH);
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < argc; ++i) {
|
||||||
|
if (i > 0) {
|
||||||
|
strcat(cmd, " ");
|
||||||
|
}
|
||||||
|
strcat(cmd, argv[i]);
|
||||||
|
}
|
||||||
|
char temp[50];
|
||||||
|
memset(temp, 0, sizeof(temp));
|
||||||
|
sprintf(temp, " -stopserver -port %d &", portno + 1);
|
||||||
|
strcat(cmd, temp);
|
||||||
|
|
||||||
// create pipes to communicate with stop server
|
LOG(logDEBUG1, ("Command to start stop server:%s\n", cmd));
|
||||||
|
system(cmd);
|
||||||
|
}
|
||||||
|
LOG(logINFOBLUE, ("Control Server [%d]\n", portno));
|
||||||
#ifdef VIRTUAL
|
#ifdef VIRTUAL
|
||||||
/*if (pipe(pipeFDs) < 0) {
|
// creating files for virtual servers to communicate with each other
|
||||||
LOG(logERROR, ("Could not create pipes to communicate with stop server\n"));
|
if (!ComVirtual_createFiles(portno)) {
|
||||||
return -1;
|
|
||||||
}*/
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// fork stop server
|
|
||||||
pid_t cpid = fork();
|
|
||||||
if (cpid < 0) {
|
|
||||||
LOG(logERROR, ("Could not create fork a stop server\n"));
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
//fcntl(pipeFDs[PIPE_READ], F_SETFL, O_NONBLOCK);
|
|
||||||
//fcntl(pipeFDs[PIPE_WRITE], F_SETFL, O_NONBLOCK);
|
|
||||||
|
|
||||||
// stop server (child process)
|
|
||||||
if (cpid == 0) {
|
|
||||||
isControlServer = 0;
|
|
||||||
++portno;
|
|
||||||
LOG(logINFOBLUE, ("Stop server [%d]\n", portno));
|
|
||||||
// change name of stop server to distinguish
|
|
||||||
char stopServerSuffix[30];
|
|
||||||
memset(stopServerSuffix, 0, sizeof(stopServerSuffix));
|
|
||||||
sprintf(stopServerSuffix, " Stop_Server %d", portno);
|
|
||||||
//strcat(argv[0], stopServerSuffix);
|
|
||||||
#ifdef VIRTUAL
|
|
||||||
//close(pipeFDs[PIPE_WRITE]);
|
|
||||||
//fcntl(pipeFDs[PIPE_READ], F_SETFL, O_NONBLOCK);
|
|
||||||
#endif
|
#endif
|
||||||
} else {
|
|
||||||
isControlServer = 1;
|
|
||||||
LOG(logINFOBLUE, ("Control server [%d]\n", portno));
|
|
||||||
#ifdef VIRTUAL
|
|
||||||
//close(pipeFDs[PIPE_READ]);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
// stop server
|
||||||
|
else {
|
||||||
|
LOG(logINFOBLUE, ("Stop Server [%d]\n", portno));
|
||||||
|
#ifdef VIRTUAL
|
||||||
|
ComVirtual_setFileNames(portno);
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
init_detector();
|
init_detector();
|
||||||
|
// bind socket
|
||||||
{ // bind socket
|
|
||||||
sockfd = bindSocket(portno);
|
sockfd = bindSocket(portno);
|
||||||
if (ret == FAIL)
|
if (ret == FAIL)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
// assign function table
|
// assign function table
|
||||||
function_table();
|
function_table();
|
||||||
|
|
||||||
@ -167,8 +160,9 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// waits for connection
|
// waits for connection
|
||||||
|
int retval = OK;
|
||||||
while(retval != GOODBYE && retval != REBOOT) {
|
while(retval != GOODBYE && retval != REBOOT) {
|
||||||
fd = acceptConnection(sockfd);
|
int fd = acceptConnection(sockfd);
|
||||||
if (fd > 0) {
|
if (fd > 0) {
|
||||||
retval = decode_function(fd);
|
retval = decode_function(fd);
|
||||||
closeConnection(fd);
|
closeConnection(fd);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user