当前位置: 首页>>代码示例>>C++>>正文


C++ Message::AddData方法代码示例

本文整理汇总了C++中Message::AddData方法的典型用法代码示例。如果您正苦于以下问题:C++ Message::AddData方法的具体用法?C++ Message::AddData怎么用?C++ Message::AddData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Message的用法示例。


在下文中一共展示了Message::AddData方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: on_surface_changed

void on_surface_changed(int width, int height) 
{
  Message* m = MESSAGE(Message::MSG_RESIZE);
  m->AddData(DAT(width));
  m->AddData(DAT(height));
  gCore->SendMessage(m);
}
开发者ID:innatewonder,项目名称:mythril,代码行数:7,代码来源:jni.cpp

示例2: ConvertFromAMessage

status_t ConvertFromAMessage(const os::Message & from, Message & to) 
{
   to.Clear();
   to.what = from.GetCode();

   int numNames = from.GetNumNames();
   for (int32 i=0; i<numNames; i++)
   {
      int type;
      int count;
      std::string name = from.GetName(i);
      if (from.GetNameInfo(name.c_str(), &type, &count) == B_NO_ERROR)
      {
         for (int j=0; j<count; j++)
         {
            const void * nextItem;
            size_t itemSize;
            if (from.FindData(name.c_str(), type, &nextItem, &itemSize, j) != B_NO_ERROR) return B_ERROR;

            // do any necessary translation from the AtheOS data types to Muscle data types
            switch(type)
            {
               case os::T_POINT:
               {
                  const os::Point * p = static_cast<const os::Point *>(nextItem);
                  Point pPoint(p->x, p->y);
                  if (to.AddPoint(name.c_str(), pPoint) != B_NO_ERROR) return B_ERROR;
               }
               break;

               case os::T_RECT:
               {
                  const os::Rect * r = static_cast<const os::Rect *>(nextItem);
                  Rect pRect(r->left, r->top, r->right, r->bottom);
                  if (to.AddRect(name.c_str(), pRect) != B_NO_ERROR) return B_ERROR;
               }
               break;

               case os::T_MESSAGE:
               {
                  os::Message amsg;
                  if (amsg.Unflatten(static_cast<const uint8 *>(nextItem)) != B_NO_ERROR) return B_ERROR;
                  Message * newMsg = newnothrow Message;
                  if (newMsg)
                  {
                     MessageRef msgRef(newMsg);
                     if (ConvertFromAMessage(amsg, *newMsg) != B_NO_ERROR) return B_ERROR;
                     if (to.AddMessage(name.c_str(), msgRef) != B_NO_ERROR) return B_ERROR;
                  }
                  else {WARN_OUT_OF_MEMORY; return B_ERROR;}
               }
               break;

               default:
                  if (to.AddData(name.c_str(), type, nextItem, itemSize) != B_NO_ERROR) return B_ERROR;
               break;
            }

         }
      }
   }
   return B_NO_ERROR;
}
开发者ID:ModeenF,项目名称:muscle,代码行数:63,代码来源:ConvertMessages.cpp

示例3: main

int main(int argc, char **argv)
{ // Testing standard message passing with short message {{{
  { string shortmsg="Hello World";
    Channel_FIFO *c1;
    try
    { c1=new Channel_FIFO();
    } catch (string s)
    { cerr << "Error in channel creation." << endl
           << "Message was: " << s << endl;
      return 1;
    }
    try // {{{
    { Message msg;
      msg.AddData(shortmsg.c_str(),shortmsg.size()+1);
      c1->SingleSend(msg);
      cout << "Short message sent." << endl;
    } catch (string s)
    { cerr << "Error sending message." << endl
           << "Message was: " << s << endl;
      return 1;
    } // }}}
    try // {{{
    { Message msg;
      c1->SingleReceive(msg);
      string msgstr=msg.GetData();
      if (msgstr==shortmsg)
        cout << "Received short message correctly." << endl;
      else
        throw (string)"Received wrong message:\n"
                    + "Original Message: " + shortmsg + "\n"
                    + "Received Message: " + msgstr;
    } catch (string s)
    { cerr << "Error receiving message." << endl
           << "Message was: " << s << endl;
      return 1;
    } // }}}
    try // {{{
    { Message msg;
      msg.AddData(shortmsg.c_str(),shortmsg.size()+1);
      c1->SingleSend(msg);
      cout << "Short message sent." << endl;
    } catch (string s)
    { cerr << "Error sending message." << endl
           << "Message was: " << s << endl;
      return 1;
    } // }}}
    try // {{{
    { Message msg;
      c1->SingleReceive(msg);
      string msgstr=msg.GetData();
      if (msgstr==shortmsg)
        cout << "Received short message correctly." << endl;
      else
        throw (string)"Received wrong message:\n"
                    + "Original Message: " + shortmsg + "\n"
                    + "Received Message: " + msgstr;
    } catch (string s)
    { cerr << "Error receiving message." << endl
           << "Message was: " << s << endl;
      return 1;
    } // }}}
    c1->Unlink();
    delete c1;
  }
  // }}}
  return 0;
}
开发者ID:,项目名称:,代码行数:67,代码来源:


注:本文中的Message::AddData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。