/******************************************************************** * Extract child program (master or slave) name and and * arguments from options. sSide should be 'master' or * 'slave', program and arguments are returned. * * Checks the "combo" options first (e.g. "master"). Then, if * these are not present, look for master-program and * master-arguments. *******************************************************************/ int GetChild(Feedback &fb, const std::string &sSide, std::string &sProgram, std::string &sArguments) { if (Options::Instance().IsUserSet(sSide)) { if (Options::Instance().Option(sSide, sProgram)) return fb.Error(E_CHILD_SETUP) << ": Unable to get " + sSide + " program and arguments from '" + sSide + "' option."; // Now split the option into sProgram and sArguments; std::vector<std::string> argv; if (CreateArgumentVector(sProgram, argv)) return fb.Error(E_CHILD_SETUP) << ": Failed to split '" + sSide + "' option into program name and arguments."; sProgram = argv[0]; for (size_t nArg = 1; nArg < argv.size(); nArg++) sArguments += (sArguments.empty() ? "" : " ") + argv[nArg]; } else { if (!Options::Instance().IsUserSet(sSide + "-program")) return fb.Error(E_CHILD_SETUP) << ": Either the '" + sSide + "' option or the '" + sSide + "-program' and optionally the '" + sSide + "-arguments' options must be specified."; if (Options::Instance().Option(sSide + "-program", sProgram) || Options::Instance().Option(sSide + "-arguments", sArguments)) return fb.Error(E_CHILD_SETUP) << ": Unable to get '" + sSide + "-program' and/or '" + sSide + "-arguments' from options."; } return 0; }
int main(int argc, char *argv[]) { QApplication app(argc, argv); Feedback mainWindow; mainWindow.show(); return app.exec(); }
void ProcessorRouter::connect(Processor* destination, const Output* source, int index) { if (isDownstream(destination, source->owner)) { // We are introducing a cycle so insert a Feedback node. Feedback* feedback = new Feedback(); feedback->plug(source); destination->plug(feedback, index); addFeedback(feedback); } else { // Not introducing a cycle so just make sure _destination_ is in order. reorder(destination); } }
void ProcessorRouter::disconnect(Processor* destination, const Output* source) { if (isDownstream(destination, source->owner)) { // We're fine unless there is a cycle and need to delete a Feedback node. for (int i = 0; i < destination->numInputs(); ++i) { const Processor* owner = destination->input(i)->source->owner; if (feedback_processors_.find(owner) != feedback_processors_.end()) { Feedback* feedback = feedback_processors_[owner]; if (feedback->input()->source == source) removeFeedback(feedback_processors_[owner]); destination->input(i)->source = &Processor::null_source_; } } } }
bool CommRemote::run(Messages & messages, Feedback & feedback) { // Delete all the previous remote messages to the robot messages.clearRemoteMessagesToRobot(); pthread_mutex_lock(&dataMutex); // Add all the received remote messages to the robot std::vector<RemoteMessageToRobot const *>::iterator toIter; for (toIter = messagesToRobot.begin(); toIter != messagesToRobot.end(); toIter++) { messages.addRemoteMessageToRobot(*toIter); } messagesToRobot.clear(); // Take ownership of all the remote messages to be sent from the robot messagesFromRobot.insert(messagesFromRobot.end(), messages.getRemoteMessagesToSend().begin(), messages.getRemoteMessagesToSend().end()); messages.clearRemoteMessagesFromRobot(); pthread_mutex_unlock(&dataMutex); // Are we connected to a client now? bool isConnectedToClient = (clientSocket >= 0); if (isConnectedToClient != wasConnectedToClient) { feedback.setConnectedToClient(isConnectedToClient); wasConnectedToClient = isConnectedToClient; } return false; }
/******************************************************************** * Optimized reading function: Read as large chunks as possible each * time. We can read at most as much as the length of the delimiter * at once. *******************************************************************/ int ReadDelimData(Feedback &fb, std::istream &s, std::string &sData, const std::string &sDelim) { if (sDelim.empty()) return fb.Error(E_UTILS_READJOB) << ": Empty delimiter."; const size_t nDelimLen = sDelim.size(); char buf[nDelimLen + 1]; s.read(buf, nDelimLen); if (s.gcount() != std::streamsize(nDelimLen) || s.eof() || !s.good()) return 1; int nCtr = 0; char *mit; while((mit = MatchDelim(buf, buf + nDelimLen, sDelim.begin(), sDelim.end())) != buf) { nCtr++; sData.append(buf, mit - buf); size_t nSubMatch = buf + nDelimLen - mit; if (nSubMatch > 0) memmove(buf, mit, nSubMatch); s.read(buf + nSubMatch, nDelimLen - nSubMatch); if (s.gcount() != std::streamsize(nDelimLen - nSubMatch) || s.eof() || !s.good()) { buf[std::max(nDelimLen, nSubMatch + static_cast<size_t>(s.gcount()))] = 0; return 1; } } return 0; }
void UIVR::update_device_lists() { VMDTracker *tracker = NULL; Buttons *buttons = NULL; tracker = new SpaceballTracker(app); trackerList.add_name(tracker->device_name(), tracker); buttons = new SpaceballButtons(app); buttonList.add_name(buttons->device_name(), buttons); tracker = new MobileTracker(app); trackerList.add_name(tracker->device_name(), tracker); buttons = new MobileButtons(app); buttonList.add_name(buttons->device_name(), buttons); #ifdef VMDVRPN Feedback *feedback = NULL; tracker = new VRPNTracker; trackerList.add_name(tracker->device_name(), tracker); feedback = new VRPNFeedback; feedbackList.add_name(feedback->device_name(), feedback); buttons = new VRPNButtons; buttonList.add_name(buttons->device_name(), buttons); #endif #ifdef VMDCAVE tracker = new CaveTracker; trackerList.add_name(tracker->device_name(), tracker); buttons = new CaveButtons; buttonList.add_name(buttons->device_name(), buttons); #endif #ifdef VMDFREEVR tracker = new FreeVRTracker(app); trackerList.add_name(tracker->device_name(), tracker); buttons = new FreeVRButtons(app); buttonList.add_name(buttons->device_name(), buttons); #endif #ifdef WINGMAN buttons = new JoystickButtons; buttonList.add_name(buttons->device_name(), buttons); #endif }
int main( int argc, char* argv[] ) { /* Initialize */ KAboutData aboutData( PACKAGE, description, VERSION, description, KAboutData::License_GPL, "(c) 2004 TUBITAK/UEKAE", 0, 0, "*****@*****.**" ); aboutData.addAuthor( "S.Çağlar Onur", 0, "*****@*****.**" ); KCmdLineArgs::init( argc, argv, &aboutData ); KCmdLineArgs::addCmdLineOptions( options ); KApplication app; Feedback *k = new Feedback(); k->setFixedSize( 650, 350 ); k->show(); /* Enter Main Loop */ return app.exec(); }
int ReadJobData(Feedback &fb, std::istream &s, const std::string &sChildOutputMode, std::string &sData) { std::stringstream ssMode(sChildOutputMode); std::string sMode1; ssMode >> sMode1; sData.clear(); if (sMode1 == "EOF") { std::string sLine, sEOF; if (!std::getline(s, sEOF)) return fb.Error(E_UTILS_READJOB) << ": Failed to read leading EOF mark. No more jobs?"; if (int nRet = ReadDelimData(fb, s, sData, "\n" + sEOF + "\n")) return nRet; } else if (sMode1 == "BYTES") { size_t nBytes; s.read(reinterpret_cast<char*>(&nBytes), sizeof(nBytes)); if (s.gcount() != sizeof(nBytes)) return fb.Error(E_UTILS_READJOB) << ": Failed to read byte count."; std::vector<char> v(nBytes); s.read(&(v[0]), nBytes); sData.resize(nBytes); std::copy(v.begin(), v.end(), sData.begin()); if (s.gcount() != nBytes) return fb.Error(E_UTILS_READJOB) << ": Failed to read " << nBytes << " bytes of job data."; } else if (sMode1 == "BIN-EOF") { int nTagLen; ssMode >> nTagLen; std::vector<char> tag(nTagLen); s.read(&tag[0], nTagLen); if (s.gcount() != nTagLen) return fb.Error(E_UTILS_READJOB) << ": Failed to read " << nTagLen << " bytes of leading binary eof tag."; if (int nRet = ReadDelimData(fb, s, sData, std::string(&tag[0]))) return nRet; }
QVariant FeedbackModel::data( const QModelIndex& index, int role ) const { if ( index.isValid() ) { const Feedback feedback = this->feedback( index ); switch ( role ) { case Qt::DisplayRole: case Qt::EditRole: { switch ( index.column() ) { case 0: return feedback.dateTime().toString( Qt::DefaultLocaleLongDate ); case 1: return feedback.message(); } break; } case Qt::ToolTipRole: case Qt::WhatsThisRole: { return QString( "<b>%1:</b> %2\n<b>%3:</b> %4" ) .arg( tr( "Date time" ) ) .arg( feedback.dateTime().toString( Qt::DefaultLocaleLongDate ) ) .arg( tr( "Message" ) ) .arg( feedback.message() ) .replace( "\n", "<br />" ) ; } case FeedbackModel::DateTimeRole: { return feedback.dateTime(); } case FeedbackModel::MessageRole: { return feedback.message(); } case FeedbackModel::FeedbackRole: { return feedback; } } } return QVariant(); }
// @todo We could move the implementation of compare() to a header file // and then implement a custom updater to do the filtering. CodewordList Engine::filterByFeedback( const CodewordList &list, const Codeword &guess, const Feedback &feedback) const { FeedbackList fblist; FeedbackFrequencyTable freq = compare(guess, list, fblist); // Count feedbacks equal to feedback. size_t count = freq[feedback.value()]; // Copy elements whose feedback are equal to fb. CodewordList result(count); size_t j = 0; for (size_t i = 0; i < fblist.size(); i++) { if (fblist[i] == feedback) result[j++] = list[i]; } return result; }
static bool greaterThanMessage( const Feedback& left, const Feedback& right ) { return left.message().compare( right.message(), Qt::CaseInsensitive ) > 0; }