// Listing 04 code/ch18
int TextListener::play_message (ACE_FILE_Addr &addr)
{
  MessageType *type = Util::identify_message (addr);
  if (type->is_text ())
    {
      Command *c = new Command ();
      c->command_ = Command::CMD_PLAY_MESSAGE;
      c->extra_data_ = &addr;
      c = this->command_stream_->execute (c);
      return c->numeric_result_;
    }

  ACE_FILE_Addr temp (ACE_TEXT ("/tmp/outgoing_message.text"));
  ACE_FILE_IO *file;
  if (type->is_audio ())
    file = Util::audio_to_text (addr, temp);
  else if (type->is_video ())
    file = Util::video_to_text (addr, temp);
  else
    ACE_ERROR_RETURN
      ((LM_ERROR, ACE_TEXT ("Invalid message type %d\n"),
        type->get_codec ()), -1);
  int rval = this->play_message (temp);
  file->remove ();
  return rval;
}
Beispiel #2
0
  void IPC::setMessageHeaderID(MessageType& message, const uint64_t id)
  {
    const auto header_field = message.GetDescriptor()->FindFieldByName("header");
    auto reflection = message.GetReflection();
    auto header_message = reflection->MutableMessage(&message, header_field);

    if (header_message->GetTypeName() != IPC::MessageHeader::default_instance().GetTypeName()) {
      throw std::runtime_error("unknown message header type");
    }

    auto header = reinterpret_cast<IPC::MessageHeader*>(header_message);
    header->set_id(id);
  }
Beispiel #3
0
  uint64_t IPC::getMessageHeaderID(const MessageType& message)
  {
    const auto header_field = message.GetDescriptor()->FindFieldByName("header");
    const auto reflection = message.GetReflection();
    const auto& header_message = reflection->GetMessage(message, header_field);

    if (header_message.GetTypeName() != IPC::MessageHeader::default_instance().GetTypeName()) {
      throw std::runtime_error("unknown message header type");
    }

    const auto header = reinterpret_cast<const IPC::MessageHeader&>(header_message);

    return header.id();
  }
Beispiel #4
0
static bool
parseMessage(ZeroCopyInputStream& stream, MessageType& message)
{
  // We need to create a new `CodedInputStream` for each message so that the
  // 64MB limit is applied per-message rather than to the whole stream.
  CodedInputStream codedStream(&stream);

  // Because protobuf messages aren't self-delimiting, we serialize each message
  // preceeded by its size in bytes. When deserializing, we read this size and
  // then limit reading from the stream to the given byte size. If we didn't,
  // then the first message would consume the entire stream.

  uint32_t size = 0;
  if (NS_WARN_IF(!codedStream.ReadVarint32(&size)))
    return false;

  auto limit = codedStream.PushLimit(size);
  if (NS_WARN_IF(!message.ParseFromCodedStream(&codedStream)) ||
      NS_WARN_IF(!codedStream.ConsumedEntireMessage()))
  {
    return false;
  }

  codedStream.PopLimit(limit);
  return true;
}
Beispiel #5
0
 static void cb_func(const lcm_recv_buf_t *rbuf, const char *channel, 
         void *user_data)
 {
     typedef LCMTypedSubscription<MessageType,ContextClass> SubsClass;
     SubsClass *subs = static_cast<SubsClass *> (user_data);
     MessageType msg;
     int status = msg.decode(rbuf->data, 0, rbuf->data_size);
     if (status < 0) {
         fprintf (stderr, "error %d decoding %s!!!\n", status,
                 MessageType::getTypeName());
         return;
     }
     const ReceiveBuffer rb = {
         rbuf->data,
         rbuf->data_size,
         rbuf->recv_utime
     };
     subs->handler(&rb, channel, &msg, subs->context);
 }
Beispiel #6
0
 static void cb_func(const lcm_recv_buf_t *rbuf, const char *channel, 
         void *user_data)
 {
     LCMMHSubscription<MessageType,MessageHandlerClass> *subs = 
         static_cast<LCMMHSubscription<MessageType,MessageHandlerClass> *>(user_data);
     MessageType msg;
     int status = msg.decode(rbuf->data, 0, rbuf->data_size);
     if (status < 0) {
         fprintf (stderr, "error %d decoding %s!!!\n", status,
                 MessageType::getTypeName());
         return;
     }
     const ReceiveBuffer rb = {
         rbuf->data,
         rbuf->data_size,
         rbuf->recv_utime
     };
     std::string chan_str(channel);
     (subs->handler->*subs->handlerMethod)(&rb, chan_str, &msg);
 }
Beispiel #7
0
static bool
parseMessage(ZeroCopyInputStream& stream, MessageType& message)
{
  // We need to create a new `CodedInputStream` for each message so that the
  // 64MB limit is applied per-message rather than to the whole stream.
  CodedInputStream codedStream(&stream);

  // The protobuf message nesting that core dumps exhibit is dominated by
  // allocation stacks' frames. In the most deeply nested case, each frame has
  // two messages: a StackFrame message and a StackFrame::Data message. These
  // frames are on top of a small constant of other messages. There are a
  // MAX_STACK_DEPTH number of frames, so we multiply this by 3 to make room for
  // the two messages per frame plus some head room for the constant number of
  // non-dominating messages.
  codedStream.SetRecursionLimit(HeapSnapshot::MAX_STACK_DEPTH * 3);

  // Because protobuf messages aren't self-delimiting, we serialize each message
  // preceeded by its size in bytes. When deserializing, we read this size and
  // then limit reading from the stream to the given byte size. If we didn't,
  // then the first message would consume the entire stream.

  uint32_t size = 0;
  if (NS_WARN_IF(!codedStream.ReadVarint32(&size)))
    return false;

  auto limit = codedStream.PushLimit(size);
  if (NS_WARN_IF(!message.ParseFromCodedStream(&codedStream)) ||
      NS_WARN_IF(!codedStream.ConsumedEntireMessage()) ||
      NS_WARN_IF(codedStream.BytesUntilLimit() != 0))
  {
    return false;
  }

  codedStream.PopLimit(limit);
  return true;
}
 inline bool operator==(MessageType const& left, MessageType const& right)
 {
     return (left.value() == right.value());
 }