void PlaybackActionClient::playbackDoneCallback(const actionlib::SimpleClientGoalState &goal,
								 const pumpkin_messages::PlaybackResultConstPtr &result) {
	_running = false;
	if (_scene)
		Q_EMIT(blockOnScene(false));
	else
		Q_EMIT(blockOnPlayback(false));

	switch (static_cast<pumpkin_messages::IOState>(result->state)) {
		case pumpkin_messages::IOState::BadFile:
			Q_EMIT(sendStatusMessage(QString("Error: BAD. The playback file should be corrupted."), 1000));
			ROS_ERROR("BAD FILE");
		break;
		case pumpkin_messages::IOState::EndOfFile:
			Q_EMIT(sendStatusMessage(QString("Error: EOF. Reached End Of File before finishing the playback. Maybe ocurred some problems in recording."), 1000));
			ROS_ERROR("END OF FILE");
		break;
		case pumpkin_messages::IOState::ErrorOpening:
			Q_EMIT(sendStatusMessage(QString("Error: OPEN. There was an error opening file."), 1000));
			ROS_ERROR("ERROR OPENING FILE");
		break;
		case pumpkin_messages::IOState::OK:
			Q_EMIT(sendStatusMessage(QString("Playback terminated successfully."), 1000));
			ROS_INFO("Playback executed with success.");
		break;
		default:
			Q_EMIT(sendStatusMessage(QString("Fatal: UNKNOWN ERROR!"), 1000));
			ROS_FATAL("UNKNOWN ERROR");
	}
	if (_scene)
		Q_EMIT(scenePercentage(0, 0, 0));
	else
		Q_EMIT(playbackPercentage(0));
	Q_EMIT(playbackFinished(result->state));
}
Exemple #2
0
bool ChatServer::processSigningInData(QTcpSocket * const connection, const QVariantMap &data)
{
    QString peeraddr = connection->peerAddress().toString();
    quint16 peerport = connection->peerPort();

    if (findChatUser(connection)) {
        // пользователь уже подключен
        emit alert(tr("User %1:%2 is already logged").arg(peeraddr).arg(peerport));
        sendStatusMessage(connection, "signin", MessageStatus::Error, tr("You are already logged"));
        return false;
    }

//    if (!data.contains("name") || !data["name"].toString().length()) {
//        emit alert(tr("SigningIn message from %1:%2 should have 'name' key").arg(peeraddr).arg(peerport));
//        sendStatusMessage(connection, "signin", MessageStatus::Error, tr("Name was not provided"));
//        connection->disconnectFromHost();
//        return false;
//    }
//    if (!data.contains("password") || !data["name"].toString().length()) {
//        emit alert(tr("SigningIn message from %1:%2 should have 'password' key").arg(peeraddr).arg(peerport));
//        sendStatusMessage(connection, "signin", MessageStatus::Error, tr("Password was not provided"));
//        connection->disconnectFromHost();
//        return false;
//    }

    QString name = data["name"].toString();
    QString password = data["password"].toString();

    for(const ChatUserLogin& login: _chatUserLogins) {
        if (login.name == name) {
            emit alert(tr("User %1:%2 is already registered").arg(peeraddr).arg(peerport));
            sendStatusMessage(connection, "signin", MessageStatus::Error, tr("Username is already registered"));
            connection->disconnectFromHost();
            return false;
        }
    }

    ChatUserLogin newUserLogin(_chatUserLogins.length(), name, password);
    _chatUserLogins << newUserLogin;
    emit chatUserLoginsChanged();

    ChatUser * newUser = new ChatUser(newUserLogin.id, name);
    _chatUsers[newUser] = connection;
    sendStatusMessage(connection, "signin", MessageStatus::OK);
//    broadcastUsers(newUser); // TODO UPDATE USER LIST!
    broadcastUsers(_chatUsers.uniqueKeys());
    sendOfflineMessages(newUser);
    return true;
}
void PlaybackActionClient::sceneActiveCallback()
{
	_running = true;
	_scene = true;
	Q_EMIT(blockOnScene(true));
	Q_EMIT(sendStatusMessage(QString("Start playing scene with %0 movements.").arg(_goal.filenames.size()), 0));
}
Exemple #4
0
bool ChatServer::processLoggingOutData(QTcpSocket * const connection, const QVariantMap &data)
{
    QString peeraddr = connection->peerAddress().toString();
    quint16 peerport = connection->peerPort();

    ChatUser * logoutUser = findChatUser(connection);
    if (!logoutUser) {
        // пользователь не подключен
        emit alert(tr("User %1:%2 is not logged").arg(peeraddr).arg(peerport));
        sendStatusMessage(connection, "logout", MessageStatus::Error, tr("You are not logged"));
        return false;
    }

    sendStatusMessage(connection, "logout", MessageStatus::OK);
    connection->disconnectFromHost();
    return true;
}
//--------------------------------------------------------------
void DonutCop::update(int size) {
  if (currentSecond() != lastSecond) {
    sendStatusMessage(size);
    if (id == 0) {
      sendControlMessage();
      removeExpiredIds();
    }
    lastSecond = currentSecond();
    createdSprinkles = 0;
  }
  checkForMessages();
}
Exemple #6
0
  void TOPPASWidget::dropEvent(QDropEvent * event)
  {
    // TODO: test mime type/source? where?
    //std::cerr << "Drop Event with data:\n  " << String( event->mimeData()->formats().join("\n  ")) << "\n\n";

    if (event->mimeData()->hasUrls())
    {
      String filename = String(event->mimeData()->urls().front().toLocalFile());
      emit sendStatusMessage("loading drop file '" + filename + "' (press CRTL while dropping to insert into current window)", 0);
      // open pipeline in new window (or in current if CTRL is pressed)
      emit pipelineDroppedOnWidget(filename, event->keyboardModifiers() != Qt::ControlModifier);
    }
    else
    {
      QPointF scene_pos = mapToScene(event->pos());
      emit toolDroppedOnWidget(scene_pos.x(), scene_pos.y());
    }
    event->acceptProposedAction();
  }
bool UFunctionSeq::handleCommand(UServerInMsg * msg, void * extra)
{ // extract parameters
  bool result = true;
  // decode vars
  char attName[MAX_SML_NAME_LENGTH];
  const int VAL_BUFF_LNG = 1000;
  char attValue[VAL_BUFF_LNG];
  // camera and source image variables
  bool ask4help = false;
  bool loadFile = false;
  bool appendFile = false;
  bool getMissions = false;
  bool getStatus = false;
  bool getPgm = false;
  const char * label = NULL;
  bool sendReply = false;
  const int MNL = MAX_FILENAME_LENGTH;
  char loadName[MNL];
  FILE * errLog = NULL;
  const char * errLogName = "loadPlanErr.log";
  const int MELL = 300;
  char se[MELL];
  int i, n;
  FILE * mf;
  char * pMf;
  const int MFL = 100;
  char mfn[MFL];
  USeqLine * line;
  const int MRL = 300;
  char reply[MRL];
  char lineXml[MRL];
  //
  // extract parameters
  while (msg->tag.getNextAttribute(attName, attValue, VAL_BUFF_LNG))
  { // camera device
    if (strcasecmp(attName, "help") == 0)
      ask4help = true;
    else if (strcasecmp(attName, "load") == 0)
    {
      strncpy(loadName, attValue, MNL);
      loadFile = true;
    }
    else if (strcasecmp(attName, "append") == 0)
    {
      strncpy(loadName, attValue, MNL);
      appendFile = true;
    }
    else if (strcasecmp(attName, "add") == 0)
    { // new mission line
      sendReply = addCmdLine(msg, attValue);
    }
    else if (strcasecmp(attName, "goto") == 0)
    { // new mission line
      if (label == NULL)
        label = seq->addLabel();
      sendReply = addCmdLine(msg, attValue);
    }
    else if (strcasecmp(attName, "clear") == 0)
    { // clear current pgm
      seq->clear();
    }
    else if (strcasecmp(attName, "sim") == 0)
    { // set simulation flag - if true, logfile must be set from cmd-line
      seq->setSimulated(str2bool(attValue));
    }
    else if (strcasecmp(attName, "missions") == 0)
      getMissions = true;
    else if (strcasecmp(attName, "status") == 0)
      getStatus = true;
    else if (strcasecmp(attName, "pgm") == 0)
      getPgm = true;
    else if (strcasecmp(attName, "list") == 0)
      getPgm = true;
    else
      // unknown attribute
      result = false;
  }
  //
  if (ask4help)
  {
    sendHelpStart(msg, "SEQ");
    sendText(msg, "---- Available SEQ options:\n");
    sendText(msg, "missions           Get list of all mission files\n");
    sendText(msg, "status             Get plan sequencer status\n");
    sendText(msg, "pgm | list         Get list of all loaded statements\n");
    sendText(msg, "goto=\"cmd\"         Give a manual mission line (in quotes), and skip to this\n");
    sendText(msg, "load=\"file\"        Load a mission file, and skip to this\n");
    sendText(msg, "append=\"file\"      Append a mission file, and skip to this\n");
    sendText(msg, "add=\"command\"      Add a manual command line\n");
    sendText(msg, "stop               Stop current mission (goto end of mission)\n");
    sendText(msg, "clear              remove all mission lines\n");
    sendText(msg, "sim=true | false   Set simulation flag (not implemented yet)\n");
    sendMsg(msg, "</help>\n");
    sendHelpDone(msg);
  }
  else
  {
    if (loadFile or appendFile)
    {
      errLog = fopen(errLogName, "w");
      if (seq->loadPlan(loadName, errLog, appendFile))
      { // loaded OK
        sendInfo(msg, "Loaded without errors");
      }
      else
      {
        if (errLog != NULL)
        {
          fclose(errLog);
          errLog = fopen(errLogName, "r");
          if (errLog != NULL)
          { // there is a file
            sendInfo(msg, "Load error list:");
            while (fgets(se, MELL, errLog) != NULL)
            { // return all filenames in separate frames
              i = strlen(se);
              if (i > 1)
              { // cut off the linefeed at end of line
                se[i-1] = 0;
                result = sendInfo(msg, se);
              }
              if (not result)
                break;
            }
          }
          else
            result = sendWarning(msg, "Could not read error file");
          if (errLog != NULL)
            fclose(errLog);
        }
        else
          sendWarning(msg, "There were errors, but could not create a logfile");
        sendReply = true;
      }
    }
    if (label != NULL)
    { // start execution from label
      result = seq->skipToLabel(label, false);
    }
  }
  if (getMissions)
  {  // return a list of available missions
    n = system("ls *.txt >missions.list");
    if (n >= 0)
    { // there should be a file
      mf = fopen("missions.list", "r");
      n = -1;
      if (mf != NULL)
      { // there is a file
        while (true)
        { // return all filenames in separate frames
          pMf = fgets(mfn, MFL, mf);
          if (pMf == NULL)
            break;
          if (n < 0)
            sendInfo(msg, "List of mission files:");
          i = strlen(pMf);
          if (i > 1)
          { // cut off the linefeed at end of line
            pMf[i-1] = 0;
            result = sendInfo(msg, pMf);
            n++;
          }
          if (not result)
            break;
        }
        if (n < 0)
          result = sendWarning(msg, "No mission files in default dir");
      }
      else
        result = sendWarning(msg, "Could not create listing of mission files");
      if (mf != NULL)
        fclose(mf);
      sendReply = true;
    }
  }
  if (getStatus)
  {
    sendStatusMessage(msg, msg->tag.getTagName());
    sendReply = true;
  }
    // last if - if noone else has send a reply ...
  if (getPgm)
  {
    if (seq->getLineCnt() > 0)
    { // make start tag for lines
      snprintf(reply, MRL,
               "<%s lineCnt=\"%d\" cmdLineNum=\"%d\" file=\"%s\">\n",
               msg->tag.getTagName(),
               seq->getLineCnt(),
               seq->getActiveLine(),
               seq->getPlanName());
      sendMsg(msg, reply);
      for (i = 0; i < seq->getLineCnt(); i++)
      {
        line = seq->getLine(i);
        str2xml(lineXml, MRL, line->getCmdLine());
        snprintf(reply, MRL,
                 "<seqLine ln=\"%d\" cmd=\"%s\"/>\n",
                 i, lineXml);
        result = sendMsg(msg, reply);
        if (not result)
            // stop if line-buffers are full
          break;
      }
        // and end tag (always try)
      snprintf(reply, MRL, "</%s>\n", msg->tag.getTagName());
      result = sendMsg(msg, reply);
    }
    else
    { // no plan lines - send status only
      snprintf(reply, MRL,
               "<%s lineCnt=\"%d\" cmdLineNum=\"%d\"/>\n",
               msg->tag.getTagName(),
               seq->getLineCnt(),
               seq->getActiveLine());
      sendMsg(msg, reply);
    }
    sendReply = true;
  }
  if (result and not sendReply)
    sendInfo(msg, "done");
  if (not result)
    sendWarning(msg, "One or more attributes to SEQ is not used!");
  return result;
}
void PlaybackActionClient::playbackActiveCallback() {
	_running = true;
	_scene = false;
	Q_EMIT(blockOnPlayback(true));
	Q_EMIT(sendStatusMessage(QString("Start playback file %0.").arg(QString::fromStdString(_goal.filenames[0])), 1000));
}
Exemple #9
0
bool ChatServer::processSendingData(QTcpSocket * const connection, const QVariantMap &data)
{
    QString peeraddr = connection->peerAddress().toString();
    quint16 peerport = connection->peerPort();

    ChatUser * sender = findChatUser(connection);
    if (!sender) {
        // пользователь не подключен
        emit alert(tr("User %1:%2 has not logon").arg(peeraddr).arg(peerport));
        sendStatusMessage(connection, "messagesent", MessageStatus::Error, tr("User has not logon"));
        return false;
    }

//    if (!data.contains("messageId")) {
//        emit alert(tr("Sending message from %1:%2 should have 'messageId' key").arg(peeraddr).arg(peerport));
//        sendStatusMessage(connection, "messagesent", MessageStatus::Error, tr("'messageId' was not provided"));
//        return false;
//    }
//    if (!data.contains("receiverId")) {
//        emit alert(tr("Sending message from %1:%2 should have 'receiverId' key").arg(peeraddr).arg(peerport));
//        sendStatusMessage(connection, "messagesent", MessageStatus::Error, tr("'receiverId' was not provided"));
//        return false;
//    }
//    if (!data.contains("text") || !data["text"].toString().length()) {
//        emit alert(tr("Sending message from %1:%2 should have 'text' key").arg(peeraddr).arg(peerport));
//        sendStatusMessage(connection, "messagesent", MessageStatus::Error, tr("'text' was not provided"));
//        return false;
//    }

    int messageId = data["messageId"].toInt();
    int receiverId = data["receiverId"].toInt();
    QString text = data["text"].toString();

    ChatUser* receiver = findChatUser(receiverId);

    if (!receiver) {
        emit alert(tr("No such receiverId %1").arg(receiverId));
        return false;
    }

    QTcpSocket* receiverConnection = _chatUsers[receiver];

    // формируем сообщение о доставке
    QJsonObject rObj;

    rObj["type"] = QString("receivemessage");
    rObj["messageId"] = messageId;
    rObj["senderId"] = sender->id();
    rObj["text"] = text;

    QJsonDocument rDoc(rObj);
    QByteArray rData = rDoc.toBinaryData();

    if (receiverConnection) {
        // получатель в сети, отправляем ему
        receiverConnection->write(rData);
    } else {
        // получатель не в сети, ставим в очередь
        _offlineMessages[receiver].append(rData);
    }

    // отчитываемся отправителю
    QJsonObject sObj;
    sObj["status"] = static_cast<int>(MessageStatus::OK);
    sObj["type"] = QString("messagesent");
    sObj["messageId"] = messageId;
    QJsonDocument sDoc(sObj);
    connection->write(sDoc.toBinaryData());

    return true;
}
Exemple #10
0
bool ChatServer::processLoggingInData(QTcpSocket * const connection, const QVariantMap &data)
{
    QString peeraddr = connection->peerAddress().toString();
    quint16 peerport = connection->peerPort();

//    if (!data.contains("name")) {
//        emit alert(tr("LoggingIn message from %1:%2 should have 'name' key").arg(peeraddr).arg(peerport));
//        sendStatusMessage(connection, "login", MessageStatus::Error, tr("Name was not provided"));
//        connection->disconnectFromHost();
//        return false;
//    }
//    if (!data.contains("password")) {
//        emit alert(tr("LoggingIn message from %1:%2 should have 'password' key").arg(peeraddr).arg(peerport));
//        sendStatusMessage(connection, "login", MessageStatus::Error, tr("Password was not provided"));
//        connection->disconnectFromHost();
//        return false;
//    }

    QString name = data["name"].toString();
    QString password = data["password"].toString();

    ChatUser * loggingUser = findChatUser(name);

    ChatUserLogin userLogin;
    bool userFound = false;
    for(const ChatUserLogin& login: _chatUserLogins) {
        if (login.name == name) {
            if (login.password != password) {
                emit alert(tr("User %1:%2 bad password").arg(peeraddr).arg(peerport));
                sendStatusMessage(connection, "login", MessageStatus::Error, tr("Bad username or password"));
                connection->disconnectFromHost();
                return false;
            }
            userLogin = login;
            userFound = true;
            break;
        }
    }

    if (loggingUser) {
        // пользователь существует в списке, а значит уже подключен, отключим старого пользователя
        emit alert(tr("User %1:%2 is already logged, disconnect old").arg(peeraddr).arg(peerport));
        if (_chatUsers[loggingUser])
            _chatUsers[loggingUser]->disconnectFromHost();
    }

    if (!userFound) {
        emit alert(tr("User %1:%2 is not registered").arg(peeraddr).arg(peerport));
        sendStatusMessage(connection, "login", MessageStatus::Error, tr("You are not registered"));
        connection->disconnectFromHost();
        return false;
    }

    if (!loggingUser) {
        emit alert(tr("User %1:%2 exists in logins, but not in chat users. WTF?!").arg(peeraddr).arg(peerport));
        sendStatusMessage(connection, "login", MessageStatus::Error, tr("Other server error"));
        connection->disconnectFromHost();
        return false;
    }

    loggingUser->setIsOnline(true);

    _chatUsers[loggingUser] = connection;
    sendStatusMessage(connection, "login", MessageStatus::OK);

//    broadcastUsers(loggingUser); // шлем список всех пользователей, кроме себя самого
    broadcastUsers(_chatUsers.uniqueKeys()); // , loggingUser

    sendOfflineMessages(loggingUser);
    return true;
}