bool TryWaitConnectToNovad(int timeout_ms) { if(ConnectToNovad()) { return true; } else { //usleep takes in microsecond argument. Convert to milliseconds usleep(timeout_ms *1000); return ConnectToNovad(); } }
void Connect() { if(!ConnectToNovad()) { cout << "ERROR: Unable to connect to Nova" << endl; exit(EXIT_FAILURE); } }
void StartNovaWrapper(bool debug) { if(!ConnectToNovad()) { if(StartNovad(debug)) { cout << "Started Novad" << endl; } else { cout << "Failed to start Novad" << endl; } } else { cout << "Novad is already running" << endl; CloseNovadConnection(); } }
void StatusNovaWrapper() { if(!ConnectToNovad()) { cout << "Novad Status: Not running" << endl; } else { if(IsNovadUp(false)) { cout << "Novad Status: Running and responding" << endl; } else { cout << "Novad Status: Not responding" << endl; } CloseNovadConnection(); } }
bool IsNovadUp(bool tryToConnect) { bool isUp = true; if(tryToConnect) { //If we couldn't connect, then it's definitely not up if(!ConnectToNovad()) { return false; } } //Funny syntax just so I can break; out of the context do { Ticket ticket = MessageManager::Instance().StartConversation(IPCSocketFD); RequestMessage ping(REQUEST_PING); if(!MessageManager::Instance().WriteMessage(ticket, &ping)) { //There was an error in sending the message isUp = false; break; } Message *reply = MessageManager::Instance().ReadMessage(ticket); if(reply->m_messageType == ERROR_MESSAGE && ((ErrorMessage*)reply)->m_errorType == ERROR_TIMEOUT) { LOG(WARNING, "Timeout error when waiting for message reply", ""); reply->DeleteContents(); delete reply; isUp = false; break; } if(reply->m_messageType == ERROR_MESSAGE ) { ErrorMessage *error = (ErrorMessage*)reply; if(error->m_errorType == ERROR_SOCKET_CLOSED) { // This was breaking things during the mess of isNovadUp calls // when the QT GUi starts and connects to novad. If there was some // important reason for it being here that I don't know about, we // might need to put it back and track down why exactly it was // causing problems. //CloseNovadConnection(); } delete error; isUp = false; break; } if(reply->m_messageType != REQUEST_MESSAGE ) { //Received the wrong kind of message reply->DeleteContents(); delete reply; isUp = false; break; } RequestMessage *pong = (RequestMessage*)reply; if(pong->m_requestType != REQUEST_PONG) { //Received the wrong kind of control message pong->DeleteContents(); isUp = false; } delete pong; }while(0); if(isUp == false) { DisconnectFromNovad(); } return isUp; }