ULaserDevice::~ULaserDevice() { logFileClose(); if (pushData != NULL) delete pushData; }
/***************************************************************** * NAME: main * * DESCRIPTION: Main function of the leader host i.e. the contact * host that approves other hosts to join the * network and the member host. This binary is * invoked via a start up script. The parameters are * port no and ip address and node type. * * PARAMETERS: * (int) argc - number of command line arguments * (char *) argv - two command line arguments apart * from argv[0] namely: * i) Port No * ii) Ip Address of host * iii) Host Type * "leader" -> Leader Node * "member" -> Member Node * iv) Host ID * * RETURN: * (int) ZERO if success * ERROR otherwise * ****************************************************************/ int main(int argc, char *argv[]) { int rc = SUCCESS, // Return code i_rc; // Intermittent return code char leaderIpAddress[SMALL_BUF_SZ], // Buffer to hold leader ip leaderPortNo[SMALL_BUF_SZ]; // Buffer to hold leader port no /* * Init log file */ i_rc = logFileCreate(); if ( i_rc != SUCCESS ) { printf("\nLog file won't be created. There was an error\n"); rc = ERROR; goto rtn; } funcEntry(logF, "I am starting", "host::main"); /* * Command line arguments check */ i_rc = CLA_checker(argc, argv); if ( i_rc != SUCCESS ) { rc = ERROR; goto rtn; } /* * Copy ip address and port no to local buffer */ memset(ipAddress, '\0', SMALL_BUF_SZ); sprintf(ipAddress, "%s", argv[2]); memset(portNo, '\0', SMALL_BUF_SZ); sprintf(portNo, "%s", argv[1]); host_no = atoi(argv[4]); /* * Init local host heart beat table */ initialize_table(portNo, ipAddress, host_no); printToLog(logF, ipAddress, "Initialized my table"); /* * Get the node type based on third argument. By default it * is always member node. */ if ( SUCCESS == strcmp(argv[3], LEADER_STRING) ) { isLeader = true; printToLog(logF, ipAddress, "I am the leader node"); } else { printToLog(logF, ipAddress, "I am a member node"); } /* * Set up UDP */ i_rc = setUpUDP(portNo, ipAddress); if ( i_rc != SUCCESS ) { rc = ERROR; printToLog(logF, ipAddress, "UDP setup failure"); goto rtn; } // Log current status printToLog(logF, ipAddress, "UDP setup successfully"); /* * If current host is a LEADER then log that this host has * joined the distributed system */ if ( isLeader ) { printToLog(logF, ipAddress, "I, THE LEADER have joined the Daisy Distributed System"); } /* * Display the CLI UI if this host is a MEMBER host which * asks member if he wants to send join message to leader node * and calls the function requestMembershipToLeader() which * does the job */ if ( !isLeader ) { i_rc = CLI_UI(); if ( i_rc != SUCCESS ) { rc = ERROR; goto rtn; } } /* * If leader ask if this a new incarnation or a * reincarnation */ else { i_rc = askLeaderIfRejoinOrNew(); if ( i_rc != SUCCESS ) { rc = ERROR; goto rtn; } } /* * Set up infrastructure for node to leave * voluntarily */ signal(SIGABRT, leaveSystem); if ( errno != SUCCESS ) { printf("SIGINT set error %d \n", errno); } /* * Spawn the helper threads */ i_rc = spawnHelperThreads(); if ( i_rc != SUCCESS ) { rc = ERROR; goto rtn; } rtn: funcExit(logF, ipAddress, "Host::main", rc); /* * Close the log */ if ( logF != NULL ) { logFileClose(logF); } return rc; } // End of main