Example #1
0
void StatemachineServer::operator()(yami::incoming_message & im_)
{
    const std::string & msg_name_ = im_.get_message_name();

    if (msg_name_ == "check")
    {
        Status Res;

        Check(Res);

        yami::parameters Res_;
        Res.write(Res_);
        im_.reply(Res_);
    }
    else
    if (msg_name_ == "on")
    {
        Status Res;

        On(Res);

        yami::parameters Res_;
        Res.write(Res_);
        im_.reply(Res_);
    }
    else
    if (msg_name_ == "off")
    {
        Status Res;

        Off(Res);

        yami::parameters Res_;
        Res.write(Res_);
        im_.reply(Res_);
    }
    else
    if (msg_name_ == "initialise")
    {
        Config Conf;
        Conf.read(im_.get_parameters());

        Initialise(Conf);

        im_.reply();
    }
    else
    if (msg_name_ == "close")
    {
        Close();
    }
    else
    {
        throw yami::yami_runtime_error("Unknown operation name.");
    }
}
Example #2
0
void Yami::operator ()(yami::incoming_message &im)
{
    const yami::parameters & content =
            im.get_parameters();
    qDebug() << "msg name" << im.get_message_name().c_str();


        const int value = content.get_integer("value");
        qDebug() << "op";
    emit message(QString("%1").arg(value));
}
Example #3
0
void CLibraryStream::on_msg(yami::incoming_message & im)
{
  if (im.get_message_name() == "stream_part")
  {
    try
    {
      size_t len = 0;
      const void* buf = im.get_parameters().get_binary("payload", len);
      Append((BYTE*)buf, len);
    }
    catch (const std::exception& e)
    {
    }
  }
  else
  {
    home_system::service::on_msg(im);
  }
}
Example #4
0
void CLibraryStreamPush::operator()(yami::incoming_message & im)
{
  if (im.get_message_name() == "stream_part")
  {
    try
    {
      size_t len = 0;
      BYTE* buf = (BYTE*)im.get_parameters().get_binary("payload", len);

      // loop on arrived data until all gets copied into buffer
      // some may be left in temporary buffer until next portion of data arrives

      while (len != 0)
      {
        //LOG("len= " << len << " buffer_len_=" << buffer_len_ << " tmp_len_=" << tmp_len_ << " buffer_pos_=" << buffer_pos_);

        size_t available_in_tmp = BUFSIZE - tmp_len_;

        if (tmp_len_ == 0)
        {
          tmp_buf_.reset(new BYTE[BUFSIZE]);
        }

        if (len >= available_in_tmp)
        {
          // if arrived data fills remaining space in temporary buffer
          // copy all it fits into temporary buffer
          memcpy(tmp_buf_.get() + tmp_len_, buf, available_in_tmp);

          len -= available_in_tmp;
          buf += available_in_tmp;

          // add it to main buffer
          CAutoLock lock(&buffer_lock_);
          buffer_.push_back(tmp_buf_);
          buffer_len_ += BUFSIZE;
          tmp_len_ = 0;
        }
        else
        {
          // copy into temporary buffer
          memcpy(tmp_buf_.get() + tmp_len_, buf, len);
          tmp_len_ += len;
          len = 0;
        }
      }

      // removing already read elements
      while (buffer_pos_ >= BUFSIZE)
      {
        CAutoLock lock(&buffer_lock_);
        buffer_.erase_begin(1);
        buffer_pos_ -= BUFSIZE;
        buffer_len_ -= BUFSIZE;
      }
      //LOG("buffer_len_=" << buffer_len_ << " tmp_len_=" << tmp_len_ << " buffer_pos_=" << buffer_pos_);
    }
    catch (const std::exception& e)
    {
      LOG("CLibraryStreamPush: Exception: " << e.what());
    }
  }
}