Пример #1
0
bool PubSubClient::_process_message(MQTT::Message* msg, uint8_t match_type, uint16_t match_pid) {
  lastInActivity = millis();
  if (msg->type() == match_type) {
    if (match_pid)
      return msg->packet_id() == match_pid;
    return true;
  }

  switch (msg->type()) {
  case MQTTPUBLISH:
    {
      auto pub = (MQTT::Publish*)msg;

      if (_callback)
	_callback(*pub);

      if (pub->qos() == 1) {
	MQTT::PublishAck puback(pub->packet_id());
	puback.send(_client);
	lastOutActivity = millis();

      } else if (pub->qos() == 2) {
	uint8_t retries = 0;

	{
	  MQTT::PublishRec pubrec(pub->packet_id());
	  if (!send_reliably(&pubrec))
	    return false;
	}

	{
	  MQTT::PublishComp pubcomp(pub->packet_id());
	  pubcomp.send(_client);
	  lastOutActivity = millis();
	}
      }
    }
    break;

  case MQTTPINGREQ:
    {
      MQTT::PingResp pr;
      pr.send(_client);
      lastOutActivity = millis();
    }
    break;

  case MQTTPINGRESP:
    pingOutstanding = false;
  }

  return false;
}
Пример #2
0
    Topic(const dds::domain::DomainParticipant& dp,
          const std::string& name,
          const std::string& type_name)
        : dds::topic::detail::TopicDescription<T>(dp, name, type_name),
          dp_(dp),
          qos_(),
          listener_(0),
          mask_(dds::core::status::StatusMask())
        {
        char* tn = ts_.get_type_name();
        ts_.register_type(dp->dp_.get(), tn);

        qos(dp.default_topic_qos());
        DDS::TopicQos tqos = convertQos(qos_);
        t_ = dp->dp_->create_topic(name.c_str(), tn, tqos, 0,
                                   mask_.to_ulong());

        if (t_ == 0)
            throw dds::core::NullReferenceError(
                        org::opensplice::core::exception_helper(
                            OSPL_CONTEXT_LITERAL(
                                "dds::core::NullReferenceError : Unable to create Topic! "
                                "Nil return from ::create_topic")));

        topic_ = org::opensplice::core::DDS_TOPIC_REF(t_, org::opensplice::core::TopicDeleter(dp->dp_));
    }
Пример #3
0
 message_type Publish::response_type(void) const {
   switch (qos()) {
   case 0:
     return None;
   case 1:
     return PUBACK;
   case 2:
     return PUBREC;
   }
 }
Пример #4
0
  Publish::Publish(uint8_t flags, uint8_t* data, uint32_t length) :
    Message(PUBLISH, flags),
    _payload(NULL), _payload_len(0),
    _payload_mine(false)
  {
    uint32_t pos = 0;
    _topic = read<String>(data, pos);
    if (qos() > 0)
      _packet_id = read<uint16_t>(data, pos);

    _payload_len = length - pos;
    if (_payload_len > 0) {
      _payload = new uint8_t[_payload_len];
      memcpy(_payload, data + pos, _payload_len);
      _payload_mine = true;
    }
  }
void XmlBlasterCommObject::connect()
{
	/* 
	 * Used to initialize the failsafe behaviour of the client.
	 * No failsafe behaviour implemented yet
	 */
	con.initFailsafe(this);
	/* Creates a connect qos where user and password fields ar empty  */
	ConnectQos qos(global_, "", "");
	log_.info(ME, "connecting to xmlBlaster...");
	/* 
	 * Connects to xmlBlaster and gives a pointer to this class to tell
	 * which update method to invoke when callbacks come from the server
	 */
	ConnectReturnQos retQos = con.connect(qos, this);
	log_.info(ME, "successfully connected to xmlBlaster");
};
Пример #6
0
  Publish::Publish(uint8_t flags, Client& client, uint32_t remaining_length) :
    Message(PUBLISH, flags),
    _payload(NULL), _payload_len(remaining_length),
    _payload_mine(false)
  {
    _stream_client = &client;

    // Read the topic
    _topic = read<String>(client);
    _payload_len -= 2 + _topic.length();

    if (qos() > 0) {
      // Read the packet id
      _packet_id = read<uint16_t>(client);
      _payload_len -= 2;
    }

    // Client stream is now at the start of the payload
  }
Пример #7
0
/** Save help entry to database */
void HelpOLC::save(void)
{
    QString query;
    QTextOStream qos(&query);
    QSqlQuery q;

    if (_entry == 0)
    {
        qos << "insert into helptext (title, keywords, body) values " << endl
            << "('" << _topic << "', '" << _keywords << "', '" << _body << "');";
    }
    else
    {
        qos << "update helptext " << endl
            << "set title='" << _topic << "', " << endl
            << "keywords='" << _keywords << "', " << endl
            << "body='" << Logger::escapeString(_body) << "'" << endl
            << "where helpid = " << _entry << ";";
    }
    if (q.exec(query))
    {
        if (_entry == 0)
        {
            /* Doesn't look like we can get the last insert ID, so we'll query for a
             * specific match to our title and keywords */
            QString q2;
            QTextOStream os2(&q2);
            os2 << "select helpid from helptext where " << endl
                << "title = '" << _topic << "' and keywords = '" << _keywords
                << "';";
            if (q.exec(q2) && q.next())
            {
                _entry = q.value(0).toUInt();
            }
        }
    } else {
        QString out;
        QTextOStream os(&out);
        os << "Failed save query in help editor: " << query;
        Logger::msg(out, Logger::LOG_ERROR);
    }
}
Пример #8
0
/** Load help entry from database for editing. */
bool HelpOLC::load(void)
{
    QString query;
    QTextOStream qos(&query);
    QSqlQuery q;

    qos << "select helpid, title, keywords, body from helptext " << endl
        << "where helpid = " << _entry << ";";
    if (q.exec(query) && q.numRowsAffected())
    {
        q.next();
        _entry = q.value(0).toUInt();
        _topic = q.value(1).toString();
        _keywords = q.value(2).toString();
        _body = q.value(3).toString();
        return true;
    }

    return false;
}
Пример #9
0
 void Publish::write_variable_header(uint8_t *buf, uint32_t& bufpos) const {
   write(buf, bufpos, _topic);
   if (qos())
     write_packet_id(buf, bufpos);
 }
Пример #10
0
 uint32_t Publish::variable_header_length(void) const {
   return 2 + _topic.length() + (qos() ? 2 : 0);
 }
Пример #11
0
    /** Run help command */
    virtual unsigned int run(QString args)
    {
        QString str;
        QTextOStream os(&str);
        QString topic = args.section(' ', 0, 0);
        QString searchargs = args.section(' ', 1);
        int topnum = topic.toInt();
        QSqlQuery q;

        /* If we didn't get any arguments, set topnum to display the first help
         * topic in the database which should be an overview page
         * @todo Don't display help pages that _ch does not have access to. */
        if (topic.isEmpty())
        {
            topnum = 1;
        }

        /* If we have a topic number, we just grab that entry and display it or
         * return an error */
        if (topnum)
        {
            QString query;
            QTextOStream qos(&query);

            qos << "select title, body from helptext where helpid = " << topnum
                << ";";
            if (q.exec(query))
            {
                if (q.numRowsAffected())
                {
                    q.next();
                    os << "|GHelp:|B " << q.value(0).toString() << "|x" <<endl<< endl
                       << q.value(1).toString() << endl;
                    _ch->sendtochar(str);
                    return 0;
                }
                os << "That help topic does not exist." << endl;
                _ch->sendtochar(str);
                return 0;
            }
        }

        /* if our help topic is 'search' check for additional data in args,
         * otherwise simply look for topic 'search' as usual. */
        if (topic.lower() == "search")
        {
            if (!searchargs.isEmpty())
            {
                /* Do a full text search and return the records in order of
                 * relevance */
                QString query;
                QTextOStream qos(&query);
                qos << "Select helpid, title from helptext " << endl;
                qos << "where match(title,keywords,body) " << endl;
                qos << "against ('" << searchargs << "');";
                if (q.exec(query))
                {
                    if (unsigned int total = q.numRowsAffected())
                    {
                        os << "Help topic search results matching: " << endl
                           << "'" << searchargs << "'" << endl;
                        os << "|mTopic Number|x     |bTitle|x" << endl;
                        unsigned int count = 0;
                        while (q.next() && count < 18)
                        {
                            count++;
                            os.width(12);
                            os << q.value(0).toString();
                            os.width(0);
                            os << "  " << q.value(1).toString() << endl;
                        }

                        os << endl << "Displayed first |r" << count <<"|x results of |r"
                           << total << "|x results total." << endl;
                        _ch->sendtochar(str);
                    } else {
                        os << "No help topics matched your query." << endl;
                        _ch->sendtochar(str);
                    }
                    return 0;
                }
            }
        }

        /* Do a normal help lookup.  If we get 1 result, display it.  If we get
         * more than one result, display a listing similar to our search
         * listing.  Otherwize say we couldn't find any matches */
        {
            QString query;
            QTextOStream qos(&query);
            qos << "Select helpid, title, body from helptext" << endl;
            qos << "where keywords like '%" << args << "%';";
            if (q.exec(query))
            {
                unsigned int total;
                if ((total = q.numRowsAffected()) == 1)
                {
                    q.next();
                    os << "|GHelp:|B " << q.value(1).toString()<< "|x" << endl << endl
                       << q.value(2).toString() << endl;
                    _ch->sendtochar(str);
                    return 0;
                } else if (total > 1) {
                    os << "Help topic search results matching: " << endl
                       << "'" << searchargs << "'" << endl;
                    os << "|mTopic Number      |bTitle|x" << endl;
                    unsigned int count = 0;
                    while (q.next() && count < 18)
                    {
                        count++;
                        os.width(12);
                        os << q.value(0).toString();
                        os.width(0);
                        os << "  " << q.value(1).toString() << endl;
                    }

                    os << endl << "Displayed first |r" << count << "|x results of |r"
                       << total << "|x results total." << endl;
                    _ch->sendtochar(str);
                    return 0;
                } else {
                    os << "That help topic was not found." << endl
                       << "Try '|Yhelp search " << args << "|x'" << endl;
                    _ch->sendtochar(str);
                    return 0;
                }
            }
        }
        return 1;
    }
Пример #12
0
    /** Run help edit command */
    virtual unsigned int run(QString args)
    {
        QString str;
        QTextOStream os(&str);
        QString topic = args.section(' ', 0, 0);
        int topnum = topic.toInt();
        QSqlQuery q;

        /* If we didn't get any arguments, set topnum to display the first help
         * topic in the database which should be an overview page
         * @todo Don't display help pages that _ch does not have access to. */
        if (topic.isEmpty())
        {
            os << "You must specify a help entry to edit" << endl;
            _ch->sendtochar(str);
            return 1;
        }

        /* if our help topic is 'search' check for additional data in args,
         * otherwise simply look for topic 'search' as usual. */
        if (topic.lower() == "new")
        {
            topnum = 0;
        }

        /* Do a normal help lookup.  If we get 1 result, display it.  If we get
         * more than one result, display a listing similar to our search
         * listing.  Otherwize say we couldn't find any matches */
        {
            QString query;
            QTextOStream qos(&query);
            qos << "Select helpid, title, body from helptext" << endl;
            qos << "where keywords like '%" << args << "%';";
            if (q.exec(query))
            {
                unsigned int total;
                if ((total = q.numRowsAffected()) == 1)
                {
                    q.next();
                    topnum = q.value(0).toInt();
                } else if (total > 1) {
                    topnum = -1;
                    os << "Help topic search results matching: " << endl
                       << "'" << args << "'" << endl;
                    os << "Topic Number      Title" << endl;
                    unsigned int count = 0;
                    while (q.next() && count < 18)
                    {
                        count++;
                        os.width(12);
                        os << q.value(0).toString();
                        os.width(0);
                        os << "  " << q.value(1).toString() << endl;
                    }

                    os << endl << "Displayed first " << count << " results of "
                       << total << " results total." << endl;
                    _ch->sendtochar(str);
                    return 0;
                }
            }
        }

        if (topnum >=0)
        {
            Parser *_oldparser = _ch->getDesc()->parser();
            _ch->getDesc()->setParser(
                new HelpOLC(_ch, _ch->getDesc(), _oldparser, topnum), false);
            return 0;
        }

        return 1;
    }
Пример #13
0
/**
   Write the content of the dictionary to the named file.  The existing
   content in the named file is overwritten.  The content of the dictionary
   file is laid out as follows.

   \li Signature "#IBIS Dictionary " and version number (currently
   0x020000). (20 bytes)

   \li N = Number of strings in the file. (4 bytes)

   \li uint64_t[N+1]: the starting positions of the strings in this file.

   \li uint32_t[N]: The integer code corresponding to each string value.

   \li the string values packed one after the other with their nil
   terminators.
*/
int ibis::dictionary::write(const char* name) const {
    std::string evt = "dictionary::write";
    if (name == 0 || *name == 0) {
        LOGGER(ibis::gVerbose > 1)
            << "Warning -- " << evt << " can not proceed with a "
            "null string as the file name";
        return -1;
    }
    if (ibis::gVerbose > 1) {
        evt += '(';
        evt += name;
        evt += ')';
    }
    if (key_.size() > raw_.size()) {
        LOGGER(ibis::gVerbose > 1)
            << "Warning -- " << evt
            << " can not write an inconsistent dictionary, key_.size("
            << key_.size() << "), raw_.size(" << raw_.size() << ")";
        return -2;
    }

    ibis::util::timer mytimer(evt.c_str(), 4);
    FILE* fptr = fopen(name, "wb");
    if (fptr == 0) {
        LOGGER(ibis::gVerbose > 1)
            << "Warning -- " << evt << " failed to open the file ... "
            << (errno ? strerror(errno) : "no free stdio stream");
        return -3;
    }

    IBIS_BLOCK_GUARD(fclose, fptr);
    int ierr = fwrite(_fastbit_dictionary_header, 1, 20, fptr);
    if (ierr != 20) {
        LOGGER(ibis::gVerbose > 1)
            << "Warning -- " << evt
            << " failed to write the header, fwrite returned " << ierr;
        return -4;
    }

    const uint32_t nkeys = key_.size();
    ierr = fwrite(&nkeys, sizeof(nkeys), 1, fptr);
    if (ierr != 1) {
        LOGGER(ibis::gVerbose > 1)
            << "Warning -- " << evt << " failed to write the size(" << nkeys
            << "), fwrite returned " << ierr;
        return -5;
    }
    if (nkeys == 0) // nothing else to write
        return 0;

    mergeBuffers();
    array_t<uint64_t> pos(nkeys+1);
    array_t<uint32_t> qos(nkeys);

    pos.clear();
    qos.clear();
    pos.push_back(0);
    if (buffer_.size() == 1) {
        for (uint32_t j = 0; j < raw_.size(); ++ j) {
            if (raw_[j] != 0) {
                pos.push_back(1U + strlen(raw_[j]));
                qos.push_back(j);
            }
        }
        ierr = writeBuffer(fptr, nkeys, pos, qos);
    }
    else {
        ierr = writeKeys(fptr, nkeys, pos, qos);
    }
    LOGGER(ibis::gVerbose > 1)
        << evt << " complete with ierr = " << ierr;
    return ierr;
} // ibis::dictionary::write
Пример #14
0
void
PersistenceUpdater::requestImage()
{
  if (um_ == NULL) {
    return;
  }

  DImage image;

  // Allocate space to hold the QOS sequences.
  std::vector<ArrDelAdapter<char> > qos_sequences;

  for (ParticipantIndex::ITERATOR iter = participant_index_->begin();
       iter != participant_index_->end(); iter++) {
    const PersistenceUpdater::Participant* participant
    = (*iter).int_id_;

    size_t qos_len = participant->participantQos.second.first;
    char *buf;
    ACE_NEW_NORETURN(buf, char[qos_len]);
    qos_sequences.push_back(ArrDelAdapter<char>(buf));

    if (buf == 0) {
      ACE_ERROR((LM_ERROR,
                 ACE_TEXT("PersistenceUpdater::requestImage(): allocation failed.\n")));
      return;
    }

    ACE_OS::memcpy(buf, participant->participantQos.second.second, qos_len);

    BinSeq in_seq(qos_len, buf);
    QosSeq qos(ParticipantQos, in_seq);
    DParticipant dparticipant(participant->domainId
                              , participant->owner
                              , participant->participantId
                              , qos);
    image.participants.push_back(dparticipant);
  }

  for (TopicIndex::ITERATOR iter = topic_index_->begin();
       iter != topic_index_->end(); iter++) {
    const PersistenceUpdater::Topic* topic = (*iter).int_id_;

    size_t qos_len = topic->topicQos.second.first;
    char *buf;
    ACE_NEW_NORETURN(buf, char[qos_len]);
    qos_sequences.push_back(ArrDelAdapter<char>(buf));

    if (buf == 0) {
      ACE_ERROR((LM_ERROR,
                 ACE_TEXT("PersistenceUpdater::requestImage(): allocation failed.\n")));
      return;
    }

    ACE_OS::memcpy(buf, topic->topicQos.second.second, qos_len);

    BinSeq in_seq(qos_len, buf);
    QosSeq qos(TopicQos, in_seq);
    DTopic dTopic(topic->domainId, topic->topicId
                  , topic->participantId, topic->name.c_str()
                  , topic->dataType.c_str(), qos);
    image.topics.push_back(dTopic);
  }

  for (ActorIndex::ITERATOR iter = actor_index_->begin();
       iter != actor_index_->end(); iter++) {
    const PersistenceUpdater::RWActor* actor = (*iter).int_id_;

    size_t qos_len = actor->pubsubQos.second.first;
    char *buf;
    ACE_NEW_NORETURN(buf, char[qos_len]);
    qos_sequences.push_back(ArrDelAdapter<char>(buf));

    if (buf == 0) {
      ACE_ERROR((LM_ERROR,
                 ACE_TEXT("PersistenceUpdater::requestImage(): allocation failed.\n")));
      return;
    }

    ACE_OS::memcpy(buf, actor->pubsubQos.second.second, qos_len);

    BinSeq in_pubsub_seq(qos_len, buf);
    QosSeq pubsub_qos(actor->pubsubQos.first, in_pubsub_seq);

    qos_len = actor->drdwQos.second.first;
    ACE_NEW_NORETURN(buf, char[qos_len]);
    qos_sequences.push_back(ArrDelAdapter<char>(buf));

    if (buf == 0) {
      ACE_ERROR((LM_ERROR,
                 ACE_TEXT("PersistenceUpdater::requestImage(): allocation failed.\n")));
      return;
    }

    ACE_OS::memcpy(buf, actor->drdwQos.second.second, qos_len);

    BinSeq in_drdw_seq(qos_len, buf);
    QosSeq drdw_qos(actor->drdwQos.first, in_drdw_seq);

    qos_len = actor->transportInterfaceInfo.first;
    ACE_NEW_NORETURN(buf, char[qos_len]);
    qos_sequences.push_back(ArrDelAdapter<char>(buf));

    if (buf == 0) {
      ACE_ERROR((LM_ERROR,
                 ACE_TEXT("PersistenceUpdater::requestImage(): allocation failed.\n")));
      return;
    }

    ACE_OS::memcpy(buf, actor->transportInterfaceInfo.second, qos_len);

    BinSeq in_transport_seq(qos_len, buf);

    ContentSubscriptionBin in_csp_bin;
    if (actor->type == DataReader) {
      in_csp_bin.filterClassName = actor->contentSubscriptionProfile.filterClassName;
      in_csp_bin.filterExpr = actor->contentSubscriptionProfile.filterExpr;
      BinSeq& params = in_csp_bin.exprParams;
      ACE_NEW_NORETURN(params.second, char[params.first]);
      if (params.second == 0) {
        ACE_ERROR((LM_ERROR,
                   ACE_TEXT("PersistenceUpdater::requestImage(): allocation ")
                   ACE_TEXT("failed.\n")));
        return;
      }
      qos_sequences.push_back(ArrDelAdapter<char>(params.second));
      ACE_OS::memcpy(params.second,
        actor->contentSubscriptionProfile.exprParams.second, params.first);
    }

    DActor dActor(actor->domainId, actor->actorId, actor->topicId
                  , actor->participantId
                  , actor->type, actor->callback.c_str()
                  , pubsub_qos, drdw_qos, in_transport_seq, in_csp_bin);
    image.actors.push_back(dActor);
  }