void ServerClient::send( const std::string& message ) { if(needsToConnect()) { queueMessage(message); return; } if(!connected() && !connecting()) connect(); if(connected()) getClient()->write(message.c_str()); else queueMessage(message); }
void Trivia::Update() { const clock_t timeDiff = clock() - m_ctLastUpdate; // We need at least 1 ms change since we aren't dealing with nanoseconds here! if (!timeDiff) return; m_ctLastUpdate = clock(); // Process delayed messages before anything below. // What we don't want is to queue something then subtract time right after. auto itr = m_vDelayedMsgs.begin(); while (itr != m_vDelayedMsgs.end()) { (*itr).timer -= int32(timeDiff); if ((*itr).timer <= 0) { m_pOwner->SendChatMsg((*itr).msg); itr = m_vDelayedMsgs.erase(itr); } else ++itr; } // The timer for when a question expires (no one answered in time) if (m_iQuestionExpireTimer > 0) { m_iQuestionExpireTimer -= int32(timeDiff); if (m_iQuestionExpireTimer <= 0) { const TriviaQA& triviaRef = m_vQuestions[m_uiCurQuestion]; std::string answerString; for (size_t i = 0; i < triviaRef.answers.size(); ++i) answerString.append(triviaRef.answers[i]); m_vDelayedMsgs.clear(); // Some randomization so that twitch doesn't see us sending messages at exact intervals m_pOwner->SendChatMsg("Time has expired!"); queueMessage("The answer(s): " + answerString, randomChoice(1000, 2000)); queueNextQuestion(); } } // Is it time for another question? if (m_iNextQuestionTimer > 0) { m_iNextQuestionTimer -= int32(timeDiff); if (m_iNextQuestionTimer <= 0) BeginNewQA(); } }
void Robot::setFront(const Vector& aVector, bool aNotifyObservers /*= true*/) { front = aVector; if (!isRemote()) { std::ostringstream body; body << "robot-front " << front.x << " " << front.y << " " << name; queueMessage(body.str()); } if (aNotifyObservers == true) { notifyObservers(); } }
void Trivia::ProcessAnswer(const std::string name, const std::string answer) { if (!isQuestionInProgress()) return; if (isAnswerCorrect(m_uiCurQuestion, answer)) { m_vDelayedMsgs.clear(); uint8 points = m_vQuestions[m_uiCurQuestion].points; m_uoScore[name] += points; std::string answerString; for (size_t i = 0; i < m_vQuestions[m_uiCurQuestion].answers.size(); ++i) answerString.append(m_vQuestions[m_uiCurQuestion].answers[i]); queueMessage("He has done it! User " + name + " gains " + std::to_string(points) + " points for a total of " + std::to_string(m_uoScore[name]) + "!", 1000); queueMessage("The answer(s): " + answerString, randomChoice(3000, 4000)); SaveScore(); queueNextQuestion(false); } }
/** * Emit log message. * @param [in] module Module ID. * @param [in] severity Log severity (warning, info, error, ...). * @param [in] infos Source information (file, line number, ...). * @param [in] format Format string. * @param [in] ... Format string arguments. */ void LogProcessor::write(Dumb::Module::Identifier const & module, Dumb::Severity const & severity, SourceInfos const & infos, char const * format, ...) { if(NULL == _builder) { return; } std::string buffer; va_list args; va_start(args, format); if(_builder->build(buffer, module, severity, infos, format, args)) { queueMessage(buffer); } va_end(args); }
void MQTT::messageReceived(std::vector<char>& message) { try { BaseLib::PVariable result = _jsonDecoder->decode(message); std::string methodName; std::string clientId; int32_t messageId = 0; BaseLib::PVariable parameters; if(result->type == BaseLib::VariableType::tStruct) { if(result->structValue->find("method") == result->structValue->end()) { _out.printWarning("Warning: Could not decode JSON RPC packet from MQTT payload."); return; } methodName = result->structValue->at("method")->stringValue; if(result->structValue->find("id") != result->structValue->end()) messageId = result->structValue->at("id")->integerValue; if(result->structValue->find("clientid") != result->structValue->end()) clientId = result->structValue->at("clientid")->stringValue; if(result->structValue->find("params") != result->structValue->end()) parameters = result->structValue->at("params"); else parameters.reset(new BaseLib::Variable()); } else { _out.printWarning("Warning: Could not decode MQTT RPC packet."); return; } GD::out.printInfo("Info: MQTT RPC call received. Method: " + methodName); BaseLib::PVariable response = GD::rpcServers.begin()->second.callMethod(methodName, parameters); std::shared_ptr<std::pair<std::string, std::vector<char>>> responseData(new std::pair<std::string, std::vector<char>>()); _jsonEncoder->encodeMQTTResponse(methodName, response, messageId, responseData->second); responseData->first = (!clientId.empty()) ? clientId + "/rpcResult" : "rpcResult"; queueMessage(responseData); } catch(const std::exception& ex) { _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what()); } catch(BaseLib::Exception& ex) { _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what()); } catch(...) { _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__); } }
void Robot::setPosition(const Point& aPosition, bool aNotifyObservers /*= true*/) { if (position == aPosition) { return; } position = aPosition; if (!isRemote()) { std::ostringstream body; body << "robot-position " << position.x << " " << position.y << " " << name; queueMessage(body.str()); } if (aNotifyObservers == true) { notifyObservers(); } }
void Trivia::BeginNewQA() { m_vDelayedMsgs.clear(); // Move on to next question ++m_uiCurQuestion; if (m_uiCurQuestion >= m_vQuestions.size()) m_uiCurQuestion = 0; // You get 60 seconds to answer, but it takes 10 seconds for the preamble to occur. m_iQuestionExpireTimer = 70000; // Send the header for a new trivia m_pOwner->SendChatMsg(getTopScorePrint()); queueMessage("Trivia #" + std::to_string(m_uiCurQuestion) + " is worth " + std::to_string(m_vQuestions[m_uiCurQuestion].points) + " points!", randomChoice(2000, 3000)); queueMessage("-- TRIVIA #" + std::to_string(m_uiCurQuestion) + " --", randomChoice(6000, 7000)); queueMessage(m_vQuestions[m_uiCurQuestion].question, randomChoice(10000, 11000)); // These messages would let people know how much time is left. queueMessage("Time will expire in 30 seconds!", 10000 + randomChoice(28000, 30000)); queueMessage("Hurry, time will expire in 15 seconds!", 10000 + randomChoice(43000, 44000)); queueMessage("Only five seconds remain!", 10000 + randomChoice(52000, 54000)); }
void usb_receive_interrupt(uint8_t endpoint, void* buffer, int bufferLen) { queueMessage(endpoint, USBOut, USBInterrupt, buffer, bufferLen); }
/** * Debug * Output a debug log message to our output tab. * * @param message - message to output. */ void Actions::Debug(std::string message) { queueMessage(DebugMessage, message); }
/** * Output * Output a normal message to our output tab. * * @param message - the message to to output. */ void Actions::Output(std::string message) { queueMessage(OutputMessage, message); }
/** * Warning * Display a warning message on our readout gui tabl * * @param message - message to display. */ void Actions::Warning(std::string message) { queueMessage(WarningMessage, message); }
/** * Log * Display a log message on our readout gui tab. * * @param message - message to display. */ void Actions::Log(std::string message) { queueMessage(LogMessage, message); }
/** * Error * Display an error message on our ReadoutGUI tab. * * @param message - the message to display */ void Actions::Error(std::string message) { queueMessage(ErrorMessage, message); }
void usb_receive_bulk(uint8_t endpoint, void* buffer, int bufferLen) { queueMessage(endpoint, USBOut, USBBulk, buffer, bufferLen); }
void usb_send_interrupt(uint8_t endpoint, void* buffer, int bufferLen) { queueMessage(endpoint, USBIn, USBInterrupt, buffer, bufferLen); }
void usb_send_bulk(uint8_t endpoint, void* buffer, int bufferLen) { queueMessage(endpoint, USBIn, USBBulk, buffer, bufferLen); }
status_t MessageQueue::postMessage( const sp<MessageBase>& message, nsecs_t relTime, uint32_t flags) { return queueMessage(message, relTime, flags); }
/** * TCLCommand * Request the execution of a Tcl command by the ReadoutGui. * * @param command - command to execute. */ void Actions::TCLCommand(std::string command) { queueMessage(TclCommand, command); }