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


C++ DataWriter_var::in方法代码示例

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


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

示例1: publishMsg

bool DDSBroker::publishMsg(std::string topicName, const ros::SerializedMessage& content)
{
  DataWriter_var writer = getWriter(topicName);
  if (!writer.in())
  {
    ROS_ERROR("[DDS] Failed to get writer on topic %s.", topicName.c_str());
    return false;
  }
  ROSDDS::MsgDataWriter_var message_writer = ROSDDS::MsgDataWriter::_narrow(writer);

  //encapsulate a ros message into a dds message
  Msg msgInstance;
  unsigned int bufsize = content.num_bytes;

  msgInstance.message.replace(bufsize, bufsize, (unsigned char*)content.buf.get(), false);

  DDS::ReturnCode_t status;
  status = message_writer->write(msgInstance, DDS::HANDLE_NIL);
  if (status != DDS::RETCODE_OK)
  {
    ROS_ERROR("[DDS] Failed to write a message with len %d on topic %s (%s).", bufsize, topicName.c_str(),
              RETCODE_DESC(status));
    return false;
  }

  return true;
}
开发者ID:1ee7,项目名称:micROS-drt,代码行数:27,代码来源:dds_broker.cpp

示例2: hasSubscribers

bool DDSBroker::hasSubscribers(std::string topicName)
{
  DataWriter_var writer = getWriter(topicName);
  if (!writer.in())
    return 0;

  DDS::InstanceHandleSeq_var is = new DDS::InstanceHandleSeq;
  writer->get_matched_subscriptions(is);
  return (is->length() != 0);
}
开发者ID:1ee7,项目名称:micROS-drt,代码行数:10,代码来源:dds_broker.cpp

示例3: OSPL_MAIN

int OSPL_MAIN (int argc, char *argv[])
{
  os_time delay_2s = { 2, 0 };
  DDSEntityManager mgr;

  // create domain participant
  char partition_name[] = "Listener example";
  mgr.createParticipant(partition_name);

  //create type
  MsgTypeSupport_var mt = new MsgTypeSupport();
  mgr.registerType(mt.in());

  //create Topic
  char topic_name[] = "ListenerData_Msg";
  mgr.createTopic(topic_name);

  //create Publisher
  mgr.createPublisher();

  // create DataWriter
  mgr.createWriter();

  // Publish Events
  DataWriter_var dwriter = mgr.getWriter();
  MsgDataWriter_var listenerWriter = MsgDataWriter::_narrow(dwriter.in());

  Msg msgInstance; /* Example on Stack */
  msgInstance.userID = 1;
  msgInstance.message = DDS::string_dup("Hello World");
  cout << "=== [ListenerDataPublisher] writing a message containing :" << endl;
  cout << "    userID  : " << msgInstance.userID << endl;
  cout << "    Message : \"" << msgInstance.message << "\"" << endl;

  ReturnCode_t status = listenerWriter->write(msgInstance, NULL);
  checkStatus(status, "MsgDataWriter::write");
  os_nanoSleep(delay_2s);

  /* Remove the DataWriters */
  mgr.deleteWriter(listenerWriter.in ());

  /* Remove the Publisher. */
  mgr.deletePublisher();

  /* Remove the Topics. */
  mgr.deleteTopic();

  /* Remove Participant. */
  mgr.deleteParticipant();

  return 0;
}
开发者ID:AmitShah,项目名称:opensplice,代码行数:52,代码来源:ListenerDataPublisher.cpp

示例4: write

int write ()
{
  ACE_DEBUG((LM_DEBUG,
              ACE_TEXT("(%P|%t) write begins.\n")));

  try
  {
    ::Xyz::Foo foo;
    foo.x = -1;
    foo.y = -1;
    foo.key = default_key;

    ::Xyz::FooDataWriter_var foo_dw
      = ::Xyz::FooDataWriter::_narrow(datawriter.in ());
    TEST_CHECK (! CORBA::is_nil (foo_dw.in ()));

    ::DDS::InstanceHandle_t handle
        = foo_dw->register_instance(foo);

    for (int i = 0; i< num_writes; i ++)
    {

      foo.x = (float)i;

      foo_dw->write(foo,
                    handle);
    }

    ACE_DEBUG((LM_DEBUG,
             ACE_TEXT("(%P|%t) write  done\n")));
  }
  catch (...)
  {
    ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) Exception caught in write."), -1);
  }

  return 0;
}
开发者ID:CapXilinx,项目名称:OpenDDS,代码行数:38,代码来源:common.cpp

示例5: createWriter

bool DDSBroker::createWriter(std::string topicName, bool latch, const ros::AdvertiseQoSOptions& qos_ops)
{
  DDS::ReturnCode_t status;

  if (CORBA::is_nil(publisher))
  {
    PublisherQos pub_qos;
    //create a default publisher
    status = participant->get_default_publisher_qos(pub_qos);
    if (status != DDS::RETCODE_OK)
    {
      ROS_ERROR("[DDS] Failed to get the default DDS publisher qos (%s).", RETCODE_DESC(status));
      return false;
    }

    pub_qos.partition.name.length(1);
    pub_qos.partition.name[0] = PARTITION_NAME;
    publisher = participant->create_publisher(pub_qos, NULL, STATUS_MASK_NONE);
    if (!publisher.in())
    {
      ROS_ERROR("Failed to create DDS publisher.");
      return false;
    }
  }

  std::string ddsTopicName = ros2ddsName(topicName);
  Topic_var topic = getTopic(ddsTopicName);
  if (!topic.in())
  {
    ROS_ERROR("[DDS] Failed to get DDS topic %s while creating a writer.", topicName.c_str());
    return false;
  }

  DataWriter_var writer;
  std::map<std::string, DataWriter_var>::iterator iterWriterMap;

  iterWriterMap = writer_map.find(ddsTopicName);
  if (iterWriterMap != writer_map.end())
  {
    writer = iterWriterMap->second;
    return writer;
  }

  {
    boost::mutex::scoped_lock lock(writer_map_mutex);
    iterWriterMap = writer_map.find(ddsTopicName);
    if (iterWriterMap != writer_map.end())
      writer = iterWriterMap->second;
    else
    {
      DataWriterQos dw_qos;

      status = publisher->get_default_datawriter_qos(dw_qos);
      if (status != DDS::RETCODE_OK)
      {
        ROS_ERROR("[DDS] Failed to get the default DDS data writer qos (%s).", RETCODE_DESC(status));
        return false;
      }

      //set polices, convert ros policy to dds policy
      //set by source timestamp to be compatible with all kinds of receivers's destination order
      dw_qos.destination_order.kind = BY_SOURCE_TIMESTAMP_DESTINATIONORDER_QOS;
      dw_qos.transport_priority.value = qos_ops.transport_priority;

      if (qos_ops.using_best_effort_protocol)
        dw_qos.reliability.kind = BEST_EFFORT_RELIABILITY_QOS;
      else
        dw_qos.reliability.kind = RELIABLE_RELIABILITY_QOS;

      if (qos_ops.latency_budget != ros::DURATION_MIN)
      {
        dw_qos.latency_budget.duration.sec = qos_ops.latency_budget.sec;
        dw_qos.latency_budget.duration.nanosec = qos_ops.latency_budget.nsec;
      }

      if (qos_ops.data_centric_update)
        dw_qos.history.kind = KEEP_LAST_HISTORY_QOS;
      else
        dw_qos.history.kind = KEEP_ALL_HISTORY_QOS;

      //keep compatibility with ros latch flag
      if (latch)
      {
        dw_qos.durability.kind = TRANSIENT_LOCAL_DURABILITY_QOS;
      }
      else
        dw_qos.durability.kind = VOLATILE_DURABILITY_QOS;

      if (qos_ops.msg_valid_period!= ros::DURATION_MAX)
      {
        dw_qos.lifespan.duration.sec=qos_ops.msg_valid_period.sec;
        dw_qos.lifespan.duration.nanosec=qos_ops.msg_valid_period.nsec;
      }

      writer = publisher->create_datawriter(topic.in(), dw_qos, NULL, STATUS_MASK_NONE);
      if (!writer.in())
      {
        ROS_ERROR("[DDS] Failed to create writer on topic %s.", topicName.c_str());
        return false;
      }
//.........这里部分代码省略.........
开发者ID:1ee7,项目名称:micROS-drt,代码行数:101,代码来源:dds_broker.cpp

示例6: OSPL_MAIN

int OSPL_MAIN (int argc, char *argv[])
{
  bool automatic = true;
  ReturnCode_t status =  - 1;
  os_time delay = { 20, 0 };
  os_time delay_1s = { 1, 0 };
  char buf[MAX_MSG_LEN];

  if (argc < 4)
  {
    usage();
  }
  if ((strcmp(argv[1], "transient") && strcmp(argv[1], "persistent")) ||
    (strcmp(argv[2], "false") && strcmp(argv[2], "true")))
  {
    usage();
  }
  string durability_kind(argv[1]);
  bool autodispose_unregistered_instances = (strcmp(argv[2], "true") == 0);
  DDSEntityManager mgr (durability_kind, autodispose_unregistered_instances);

  automatic = (strcmp(argv[3], "true") == 0);

  // Wait for the Subscriber (case of transient = true && auto_dispose = true)
  os_nanoSleep(delay_1s);

  // create domain participant
  char partition_name[] = "Durability example";
  mgr.createParticipant(partition_name);

  //create type
  MsgTypeSupport_var mt = new MsgTypeSupport();
  mgr.registerType(mt.in());

  //create Topic
  char topic_name[] = "DurabilityData_Msg";
  mgr.createTopic(topic_name);

  //create Publisher
  mgr.createPublisher();

  // create DataWriter
  mgr.createWriter();

  // Publish Events
  DataWriter_var dwriter = mgr.getWriter();
  MsgDataWriter_var DurabilityDataWriter = MsgDataWriter::_narrow(dwriter.in());

  Msg *instances[10];
  InstanceHandle_t userHandle[10];
  for (int x = 0; x < 10; x++)
  {
    instances[x] = new Msg();
    instances[x]->id = x;
    snprintf(buf, MAX_MSG_LEN, "%d", x);
    userHandle[x] = DurabilityDataWriter->register_instance(*instances[x]);
    instances[x]->content = DDS::string_dup(buf);
    cout << instances[x]->content << endl;
    DurabilityDataWriter->write(*instances[x], userHandle[x]);

  }
  if (! automatic) {
     char c = 0;
     cout << "Enter E to exit" << endl;
     while (c != 'E')
     {
       cin >> c;
     }
  }
开发者ID:AmitShah,项目名称:opensplice,代码行数:69,代码来源:DurabilityDataPublisher.cpp

示例7: NodeBtHandler

int NodeBtHandler (int argc, char *argv[])
{
  // DDS değişkenleri
  DDSEntityManager                    mgrBtPub;
  DDSEntityManager                    mgrReqSub;
  ReturnCode_t                        status;
  SampleInfoSeq_var                   infoSeq = new SampleInfoSeq();
  BtSeq*                              btSeqInstance = new BtSeq();
  ServerReqSeq                        serverReqSeq;

  // Zaman ile alakalı değişkenler
  long int                            messageIDCount = 0;
  Time_t                              tsBeforeTheScan = { 0, 0 };
  Time_t                              tsAfterTheScan = { 0, 0 };
  //Time_t                              tsWifiPub = { 0, 0 };
  struct timeval                      tsConverter;
  DDS::Duration_t                     waitAckTime = { 0, 800000000 }; //800ms
  int                                 refreshRate = 60;

  // Veri tutucular (data structures)
  vector<string>                      btMacHolder;
  vector<int>                         btRssiHolder;
  string                              btFileContenHolder;

  // Bluetooth tarama sonuçlarının yazdırıldığı dosyadan okuma yapacak
  // olan değişken
  boost::filesystem::ifstream         fIn;

  // Bluetooth tarama sıklığı ayarlayan değişken
  int                                 refreshRateCounter = -1;

  char                                hostName[1024];
  gethostname(hostName, 1024);


  // !!! Bluetooth tarama mesajlarını Publish edecek Topic yaratılıyor
  // ve o Topic'e ait konfigürasyon ayarları yapılıyor.

  // Domain participant yaratılıyor
  mgrBtPub.createParticipant ("KonSens_BtSeq_Participant");

  // BtSeq tipi yaratılıyor
  BtSeqTypeSupport_var btSeqTs = new BtSeqTypeSupport();
  mgrBtPub.registerType(btSeqTs.in());

  // Topic yaratılıyor
  char btPubTopicName[] = "KonSensData_BtSeq_Topic";
  mgrBtPub.createTopic(btPubTopicName);

  // Publisher yaratılıyor
  mgrBtPub.createPublisher();

  // DataWriter yaratılıyor
  bool autodispose_unregistered_instances = false;
  mgrBtPub.createWriter(autodispose_unregistered_instances,
                        KEEP_ALL_HISTORY_QOS,
                        BY_SOURCE_TIMESTAMP_DESTINATIONORDER_QOS);

  // Yaratılan DataWriter, BtSeq tipi için özelleştiriliyor
  DataWriter_var dWriter = mgrBtPub.getWriter ();
  BtSeqDataWriter_var btSeqWriter = BtSeqDataWriter::_narrow(dWriter.in());

  // Düğüm numarasını atanıyor
  btSeqInstance->userID = 13;

  // Publish edilecek olan mesajlara zaman etiketi takabilmek için
  // btSeqInstance değişkeni register ediliyor
  //userHandle = btSeqWriter->register_instance_w_timestamp(*btSeqInstance,
  //                                                        tsWifiPub);

  cout << "=== [Publisher of KonSensData_BtSeq_Topic] Ready ..." << endl;


  // !!! Sunucudan gelen komutlara Subscribe olacak olan Topic yaratılıyor
  // ve o Topic için gerekli konfigürasyon ayarları yapılıyor

  // Domain participant yaratılıyor
  mgrReqSub.createParticipant(
        "KonSensData_ServerReq_Participant_Server_to_Node");

  // ServerReq tipi yaratılıyor.
  ServerReqTypeSupport_var mgrSubscriberTS = new ServerReqTypeSupport();
  mgrReqSub.registerType(mgrSubscriberTS.in());

  // Topic yaratılıyor
  char reqSubTopicName[] = "KonSensData_ServerReq_Topic_Server_to_Node";
  mgrReqSub.createTopic(reqSubTopicName, RELIABLE_RELIABILITY_QOS,
                        VOLATILE_DURABILITY_QOS);

  // Subscriber yaratılıyor
  mgrReqSub.createSubscriber();

  // DataReader yaratılıyor
  mgrReqSub.createReader(KEEP_LAST_HISTORY_QOS, 1);

  // Yaratılan DataReader, ServerReq tipi için özelleştiriliyor.
  DataReader_var dReaderSub = mgrReqSub.getReader();
  ServerReqDataReader_var serverReqReader =
      ServerReqDataReader::_narrow(dReaderSub.in());
  checkHandle(serverReqReader.in(), "ServerReqDataReader::_narrow");
//.........这里部分代码省略.........
开发者ID:snmbzkrt,项目名称:rfkon,代码行数:101,代码来源:NodeBtHandler.cpp

示例8: NodeWifiHandler

int NodeWifiHandler (int argc, char *argv[])
{

  // DDS değişkenleri
  ReturnCode_t                        status;
  InstanceHandle_t                    userHandle;
  DDSEntityManager                    mgrReqSub;
  DDSEntityManager                    mgrReqPub;
  DDSEntityManager                    mgrWifiPub;
  WifiSeq                             *wifiSeqInstance = new WifiSeq();;
  ServerReqSeq                        serverReqSeq;
  ServerReq                           *serverReq = new ServerReq();
  SampleInfoSeq_var                   infoSeq = new SampleInfoSeq();

  // Zaman ile alakalı değişkenler
  DDS::Duration_t                     waitAckTime = { 0, 800000000 }; //800ms
  int                                 refreshRate = 60;
  long int                            messageIDCount = 0;
  Time_t                              tsBeforeTheScan = { 0, 0 };
  Time_t                              tsAfterTheScan = { 0, 0 };
  struct timeval                      tsConverter;

  // Veri tutucular (data structures)
  vector<string>                      modemIdHolder;
  vector<int>                         dbmHolder;
  string                              wifiFileContenHolder;
  string                              ifconfigFileContentHolder;


  // Wifi tarama sonuçlarının yazdırıldığı dosyadan okuma yapacak
  // olan değişken
  boost::filesystem::ifstream         fInWifiScan, fInIfconfig;

  // Matlab komutları ayrıştırılmasında kullanılacak olan değişkenler
  string                              ip, subnet, gateway, dns, nodeName;

  char                                hostName[1024];
  gethostname(hostName, 1024);

  // Bluetooth tarama sıklığı ayarlayan değişken
  int refreshRateCounter = -1;


  // !!! Wifi tarama mesajlarını Publish edecek Topic yaratılıyor
  // ve o Topic'e ait konfigürasyon ayarları yapılıyor

  // Domain participant yaratılıyor
  mgrWifiPub.createParticipant("KonSensData_WifiSeq_Participant");

  // WifiSeq tipi yaratılıyor
  WifiSeqTypeSupport_var wifiSeqTS = new WifiSeqTypeSupport();
  mgrWifiPub.registerType(wifiSeqTS.in());

  // Topic yaratılıyor
  char wifiPubTopicName[] = "KonSensData_WifiSeq_Topic";
  mgrWifiPub.createTopic(wifiPubTopicName);

  // Publisher yaratılıyor
  mgrWifiPub.createPublisher();

  // DataWriter yaratılıyor
  bool autodisposeUnregisteredInstances = false;
  mgrWifiPub.createWriter(autodisposeUnregisteredInstances,
                          KEEP_ALL_HISTORY_QOS,
                          BY_SOURCE_TIMESTAMP_DESTINATIONORDER_QOS);

  // Yaratılan DataWriter, WifiSeq tipi için özelleştiriliyor
  DataWriter_var dWriterWifPub = mgrWifiPub.getWriter();
  WifiSeqDataWriter_var wifiSeqWriter =
      WifiSeqDataWriter::_narrow(dWriterWifPub.in());

  // Düğüm numarası atanıyor
  wifiSeqInstance->userID = 13;

  cout << "=== [Publisher of KonSensData_WifiSeq_Topic] Ready ..." << endl;


  // !!! Sunucudan gelen komutlara Subscribe olacak olan Topic yaratılıyor
  // ve o Topic için gerekli konfigürasyon ayarları yapılıyor

  // Domain participant yaratılıyor
  mgrReqSub.createParticipant(
        "KonSensData_ServerReq_Participant_Server_to_Node");

  // ServerReq tipi yaratılıyor.
  ServerReqTypeSupport_var mgrSubscriberTS = new ServerReqTypeSupport();
  mgrReqSub.registerType(mgrSubscriberTS.in());

  // Topic yaratılıyor
  char reqSubTopicName[] = "KonSensData_ServerReq_Topic_Server_to_Node";
  mgrReqSub.createTopic(reqSubTopicName, RELIABLE_RELIABILITY_QOS,
                        VOLATILE_DURABILITY_QOS);

  // Subscriber yaratılıyor
  mgrReqSub.createSubscriber();

  // DataReader yaratılıyor
  mgrReqSub.createReader(KEEP_LAST_HISTORY_QOS, 1);

  // Yaratılan DataReader, ServerReq tipi için özelleştiriliyor.
//.........这里部分代码省略.........
开发者ID:snmbzkrt,项目名称:rfkon,代码行数:101,代码来源:NodeWifiHandler.cpp

示例9: OSPL_MAIN

int OSPL_MAIN (int argc, char *argv[])
{
  os_time delay_100ms = { 0, 100000000 };
  DDSEntityManager mgr;

  // create domain participant
  char partition_name[] = "ContentFilteredTopic example";
  mgr.createParticipant(partition_name);

  StockTypeSupport_var st = new StockTypeSupport();
  mgr.registerType(st.in());

  //create Topic
  char topic_name[] = "StockTrackerExclusive";
  mgr.createTopic(topic_name);

  //create Publisher
  mgr.createPublisher();

  // create DataWriter
  mgr.createWriter();
  DataWriter_var dWriter = mgr.getWriter();
  StockDataWriter_var ContentFilteredTopicDataWriter = StockDataWriter::_narrow(dWriter.in());

  Stock geQuote;
  Stock msftQuote;

  geQuote.ticker = DDS::string_dup("GE");
  geQuote.price = 12.00f;
  msftQuote.ticker = DDS::string_dup("MSFT");
  msftQuote.price = 25.00f;


  InstanceHandle_t geHandle = ContentFilteredTopicDataWriter->register_instance(geQuote);
  InstanceHandle_t msftHandle = ContentFilteredTopicDataWriter->register_instance(msftQuote);

  // Publish Events
  ReturnCode_t status;
  // update ContentFilteredTopicData price every second
  for (int x = 0; x < 20; x++)
  {
    geQuote.price = geQuote.price + 0.5f;
    msftQuote.price = msftQuote.price + 1.5f;
    cout << "=== [ContentFilteredTopicDataPublisher] sends 2 stockQuotes : (GE, " << geQuote.price << ") (MSFT, " << msftQuote.price << ")" << endl;
    status = ContentFilteredTopicDataWriter->write(geQuote, geHandle);
    checkStatus(status, "StockDataWriter::write");
    status = ContentFilteredTopicDataWriter->write(msftQuote, msftHandle);
    checkStatus(status, "StockDataWriter::write");
    os_nanoSleep(delay_100ms);
  }
  // signal to terminate
  geQuote.price =  - 1;
  msftQuote.price =  - 1;
  ContentFilteredTopicDataWriter->write(geQuote, geHandle);
  ContentFilteredTopicDataWriter->write(msftQuote, msftHandle);
  cout << "Market Closed" << endl;

  /* Unregister the instances */
  ContentFilteredTopicDataWriter->unregister_instance(geQuote, geHandle);
  ContentFilteredTopicDataWriter->unregister_instance(msftQuote, msftHandle);

  /* Remove the DataWriters */
  mgr.deleteWriter(ContentFilteredTopicDataWriter.in ());

  /* Remove the Publisher. */
  mgr.deletePublisher();

  /* Remove the Topics. */
  mgr.deleteTopic();

  /* Remove Participant. */
  mgr.deleteParticipant();

  return 0;
}
开发者ID:S73417H,项目名称:opensplice,代码行数:75,代码来源:ContentFilteredTopicDataPublisher.cpp


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