void Membership::ackMsg( Message msg, std::string sender ) { msgQueueLock.lock(); pushMsgQueue(msg); msgQueueLock.unlock(); }
/** * Method to implement iLedlif responses to messages * @param msg The lifMsg to respond to */ void iLedlif::iLedlifMsgHandle(lifMsg msg) { int i; lifMsg rMsg; rMsg.set_target("MainComm"); rMsg.set_command("Output"); rMsg.set_source("iLedlif"); //When iLedlif receives the "Exit" command, it issues the "Stop" command to all devices if (msg.get_command() == "Exit") { int ex = 10; if (msg.get_num_params() == 0) { pushMsgQueue((std::string)"MainComm Output Exiting iLEDLIF. Issuing STOP to all devices."); pushMsgQueue((std::string)"ALL Stop"); #ifdef DSAAV std::vector<lifDevice*>::iterator ditr = getDeviceIteratorByName("DSAAVComm1"); std::cout << "iLedlif: " << (*ditr)->GetDeviceName() << " has exited." << std::endl; delete (*ditr); lifDevices.erase(ditr); #endif } else { ex = string2int(msg.get_param_at(0)) - 1; if (ex == 0) { for (i = 0; i < lifDevices.size(); i++) { lifDevices.at(i)->cancelDeviceThread(); } std::cout << "Exiting iLEDLIF" << std::endl; pthread_exit(NULL); } } rMsg.set_target("iLedlif"); rMsg.add_param(toString(ex)); std::cout << "Canceling remaining threads in " << ex << std::endl; rMsg.set_command("Exit"); pushMsgQueue(rMsg); lifDevice ld; ld.lifSleep(1000); //This command is issued by a device after being told to "Stop" //When iLedlif receives this command, it removes the device from the device vector //When the device vector is empty, iLedlif exits } else if (msg.get_command() == "Exited") { try { std::vector<lifDevice*>::iterator itr = getDeviceIteratorByName(msg.get_param_at(0)); std::cout << "iLedlif: " << (*itr)->GetDeviceName() << " has exited." << std::endl; delete (*itr); lifDevices.erase(itr); } catch (std::string s) { std::cout << s << std::endl; } if (lifDevices.empty()) { std::cout << "Exiting iLEDLIF" << std::endl; pthread_exit(NULL); } } else if (msg.get_command() == "ListDevices") { std::string devStr; devStr = ""; for (i = 0; i < lifDevices.size(); i++) { devStr = devStr + lifDevices.at(i)->GetDeviceName() + " "; } rMsg.add_params(devStr); pushMsgQueue(rMsg); } else { std::string msgStr; msgStr = "No command \"" + msg.get_command() + "\" defined."; rMsg.add_params(msgStr); pushMsgQueue(rMsg); } }