本文整理汇总了C++中DataWriter_var类的典型用法代码示例。如果您正苦于以下问题:C++ DataWriter_var类的具体用法?C++ DataWriter_var怎么用?C++ DataWriter_var使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DataWriter_var类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getWriter
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;
}
示例2: recreate_data_writer_and_topic
void recreate_data_writer_and_topic(DataWriter_var& dw, const DataReader_var& dr)
{
DataWriterQos dw_qos;
dw->get_qos(dw_qos);
Topic_var topic = dw->get_topic();
TopicQos topic_qos;
topic->get_qos(topic_qos);
CORBA::String_var topic_name = topic->get_name(),
type_name = topic->get_type_name();
Publisher_var pub = dw->get_publisher();
DomainParticipant_var dp = pub->get_participant();
pub->delete_datawriter(dw);
dw = 0;
dp->delete_topic(topic);
topic = 0;
// Wait until the data reader is not associated with the writer.
wait_match (dr, 0);
topic = dp->create_topic(topic_name, type_name, topic_qos, 0, 0);
if (!topic) {
ACE_DEBUG((LM_ERROR, "ERROR: %P failed to re-create topic\n"));
return;
}
dw = pub->create_datawriter(topic, dw_qos, 0, 0);
if (!dw) {
ACE_DEBUG((LM_ERROR, "ERROR: %P failed to re-create data writer\n"));
}
}
示例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;
}
示例4: waitForMatch
void waitForMatch(const DataWriter_var& dw, int count = 1)
{
StatusCondition_var sc = dw->get_statuscondition();
sc->set_enabled_statuses(PUBLICATION_MATCHED_STATUS);
WaitSet_var ws = new WaitSet;
ws->attach_condition(sc);
const Duration_t infinite = {DURATION_INFINITE_SEC, DURATION_INFINITE_NSEC};
ConditionSeq active;
PublicationMatchedStatus pubmatched;
while (dw->get_publication_matched_status(pubmatched) == RETCODE_OK
&& pubmatched.current_count != count) {
ws->wait(active, infinite);
}
ws->detach_condition(sc);
}
示例5: test_setup
void test_setup(const DomainParticipant_var& dp,
const MessageTypeSupport_var& ts, const Publisher_var& pub,
const Subscriber_var& sub, const char* topicName, DataWriter_var& dw,
DataReader_var& dr)
{
Topic_var topic = dp->create_topic(topicName, ts->get_type_name(),
TOPIC_QOS_DEFAULT, 0,
DEFAULT_STATUS_MASK);
DataWriterQos dw_qos;
pub->get_default_datawriter_qos(dw_qos);
dw_qos.history.kind = KEEP_ALL_HISTORY_QOS;
dw = pub->create_datawriter(topic, dw_qos, 0, DEFAULT_STATUS_MASK);
DataReaderQos dr_qos;
sub->get_default_datareader_qos(dr_qos);
dr_qos.history.kind = KEEP_ALL_HISTORY_QOS;
dr = sub->create_datareader(topic, dr_qos, 0, DEFAULT_STATUS_MASK);
StatusCondition_var dw_sc = dw->get_statuscondition();
dw_sc->set_enabled_statuses(PUBLICATION_MATCHED_STATUS);
WaitSet_var ws = new WaitSet;
ws->attach_condition(dw_sc);
Duration_t infinite = {DURATION_INFINITE_SEC, DURATION_INFINITE_NSEC};
ConditionSeq active;
ws->wait(active, infinite);
ws->detach_condition(dw_sc);
}
示例6: run_test
int run_test(int argc, ACE_TCHAR *argv[])
{
using namespace DDS;
using namespace OpenDDS::DCPS;
WaitSet_var ws = new WaitSet;
DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv);
DomainParticipant_var dp = dpf->create_participant(23,
PARTICIPANT_QOS_DEFAULT, 0, ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
Messenger::MessageTypeSupport_var ts = new Messenger::MessageTypeSupportImpl;
ts->register_type(dp, ts->get_type_name());
Topic_var topic = dp->create_topic("MyTopic", ts->get_type_name(),
TOPIC_QOS_DEFAULT, 0, ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
Publisher_var pub = dp->create_publisher(PUBLISHER_QOS_DEFAULT, 0,
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
TransportImpl_rch pub_tport =
TheTransportFactory->create_transport_impl(1, AUTO_CONFIG);
PublisherImpl* pub_impl = dynamic_cast<PublisherImpl*> (pub.in());
pub_impl->attach_transport(pub_tport.in());
DataWriter_var dw = pub->create_datawriter(topic, DATAWRITER_QOS_DEFAULT, 0,
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
StatusCondition_var cond = dw->get_statuscondition();
cond->set_enabled_statuses(OFFERED_INCOMPATIBLE_QOS_STATUS);
ws->attach_condition(cond);
Subscriber_var sub = dp->create_subscriber(SUBSCRIBER_QOS_DEFAULT, 0,
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
TransportImpl_rch sub_tport =
TheTransportFactory->create_transport_impl(2, AUTO_CONFIG);
SubscriberImpl* sub_impl = dynamic_cast<SubscriberImpl*> (sub.in());
sub_impl->attach_transport(sub_tport.in());
DataReaderQos dr_qos;
sub->get_default_datareader_qos(dr_qos);
dr_qos.durability.kind = PERSISTENT_DURABILITY_QOS;
Waiter w(ws);
w.activate();
DataReader_var dr = sub->create_datareader(topic, dr_qos, 0,
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
w.wait();
bool passed = (w.result() == RETCODE_OK);
ws->detach_condition(cond);
dp->delete_contained_entities();
dpf->delete_participant(dp);
return passed ? 0 : 1;
}
示例7: 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;
}
示例8: ROS_ERROR
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;
}
//.........这里部分代码省略.........
示例9: run_test_instance
int run_test_instance(DDS::DomainParticipant_ptr dp)
{
using namespace DDS;
using namespace OpenDDS::DCPS;
using namespace Messenger;
WaitSet_var ws = new WaitSet;
MessageTypeSupport_var ts = new MessageTypeSupportImpl;
ts->register_type(dp, "");
CORBA::String_var type_name = ts->get_type_name();
Topic_var topic = dp->create_topic("MyTopic", type_name,
TOPIC_QOS_DEFAULT, 0, ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
Publisher_var pub = dp->create_publisher(PUBLISHER_QOS_DEFAULT, 0,
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
DataWriter_var dw = pub->create_datawriter(topic, DATAWRITER_QOS_DEFAULT, 0,
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
Subscriber_var sub = dp->create_subscriber(SUBSCRIBER_QOS_DEFAULT, 0,
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
DataReader_var dr = sub->create_datareader(topic, DATAREADER_QOS_DEFAULT, 0,
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
StatusCondition_var dw_sc = dw->get_statuscondition();
dw_sc->set_enabled_statuses(PUBLICATION_MATCHED_STATUS);
ws->attach_condition(dw_sc);
Duration_t infinite = {DURATION_INFINITE_SEC, DURATION_INFINITE_NSEC};
ConditionSeq active;
ReturnCode_t ret = ws->wait(active, infinite);
if (ret != RETCODE_OK) return ret;
ret = ws->detach_condition(dw_sc);
if (ret != RETCODE_OK) return ret;
MessageDataWriter_var mdw = MessageDataWriter::_narrow(dw);
Message msg = {0};
for (int i(0); i < 12; ++i) {
++msg.subject_id;
ret = mdw->write(msg, HANDLE_NIL);
if (ret != RETCODE_OK) return ret;
}
ReadCondition_var dr_rc = dr->create_readcondition(NOT_READ_SAMPLE_STATE,
NEW_VIEW_STATE, ALIVE_INSTANCE_STATE);
ReadCondition_var dr_rc2 = dr->create_readcondition(ANY_SAMPLE_STATE,
ANY_VIEW_STATE, NOT_ALIVE_DISPOSED_INSTANCE_STATE);
ws->attach_condition(dr_rc);
ws->attach_condition(dr_rc2);
MessageDataReader_var mdr = MessageDataReader::_narrow(dr);
bool passed = true, done = false;
while (!done) {
ret = ws->wait(active, infinite);
if (ret != RETCODE_OK) {
passed = false;
break;
}
cout << "wait returned" << endl;
for (CORBA::ULong i(0); i < active.length(); ++i) {
if (active[i] == dr_rc) {
// To test both take_w_condition and
// take_next_instance_w_condition, we'll limit the "take" to 3
// samples and then use take_next_instance_w_condition.
MessageSeq data;
SampleInfoSeq info;
ret = mdr->take_w_condition(data, info, 3, dr_rc);
if (ret == RETCODE_NO_DATA) break;
if (ret != RETCODE_OK) {
cout << "ERROR: take_w_condition returned " << ret << endl;
passed = false;
done = true;
}
InstanceHandle_t handle = HANDLE_NIL;
received_data(data, mdw, msg);
handle = info[info.length() - 1].instance_handle;
if (handle == HANDLE_NIL) {
cout << "ERROR: instance handle is nil" << endl;
passed = false;
done = true;
break;
}
cout << "testing take_instance_w_condition" << endl;
while (true) {
ret = mdr->take_instance_w_condition(data, info, 1,
handle, dr_rc);
if (ret == RETCODE_NO_DATA) break;
if (ret != RETCODE_OK) {
cout << "ERROR: take_instance_w_condition returned "
<< ret << endl;
passed = false;
done = true;
break;
}
received_data(data, mdw, msg);
}
} else if (active[i] == dr_rc2) {
cout << "an instance has been disposed, exiting" << endl;
done = true;
}
}
}
//.........这里部分代码省略.........
示例10: 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;
}
}
示例11: run_test
bool run_test(DomainParticipant_var& dp_sub,
DomainParticipant_var& dp_pub)
{
OpenDDS::DCPS::RepoId sub_repo_id, pub_repo_id;
{
OpenDDS::DCPS::DomainParticipantImpl* dp_impl =
dynamic_cast<OpenDDS::DCPS::DomainParticipantImpl*>(dp_sub.in());
sub_repo_id = dp_impl->get_id ();
OpenDDS::DCPS::GuidConverter converter(sub_repo_id);
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT("%P ")
ACE_TEXT("Sub Domain Participant GUID=%C\n"),
std::string(converter).c_str()));
}
{
OpenDDS::DCPS::DomainParticipantImpl* dp_impl =
dynamic_cast<OpenDDS::DCPS::DomainParticipantImpl*>(dp_pub.in());
pub_repo_id = dp_impl->get_id ();
OpenDDS::DCPS::GuidConverter converter(pub_repo_id);
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT("%P ")
ACE_TEXT("Pub Domain Participant GUID=%C\n"),
std::string(converter).c_str()));
}
// If we are running with an rtps_udp transport, it can't be shared between
// participants.
TransportConfig_rch cfg = TheTransportRegistry->get_config("dp1");
if (!cfg.is_nil()) {
TheTransportRegistry->bind_config(cfg, dp_sub);
}
cfg = TheTransportRegistry->get_config("dp2");
if (!cfg.is_nil()) {
TheTransportRegistry->bind_config(cfg, dp_pub);
}
Subscriber_var bit_sub = dp_sub->get_builtin_subscriber();
if (!read_participant_bit(bit_sub, dp_sub, pub_repo_id, TestConfig::PARTICIPANT_USER_DATA())) {
return false;
}
// Each domain participant's handle to the other
InstanceHandle_t dp_sub_ih, dp_pub_ih;
InstanceHandle_t pub_ih, sub_ih, ig_ih;
if (!(check_discovered_participants(dp_sub, dp_pub_ih) &&
check_discovered_participants(dp_pub, dp_sub_ih)))
{
return false;
}
DataWriter_var dw = create_data_writer(dp_pub);
if (!dw) {
ACE_DEBUG((LM_ERROR, "ERROR: %P could not create Data Writer (participant 2)\n"));
return false;
}
if (!read_publication_bit(bit_sub, dp_sub, pub_repo_id, pub_ih, TestConfig::DATA_WRITER_USER_DATA(), TestConfig::TOPIC_DATA(), 1, 1)) {
return false;
}
DataReader_var dr = create_data_reader(dp_sub);
if (!dr) {
ACE_DEBUG((LM_ERROR, "ERROR: %P could not create Data Reader (participant 1)\n"));
return false;
}
if (!read_subscription_bit(dp_pub->get_builtin_subscriber(), dp_pub, sub_repo_id, sub_ih, TestConfig::DATA_READER_USER_DATA(), TestConfig::TOPIC_DATA())) {
return false;
}
// Wait for the reader to associate with the writer.
WriterSync::wait_match(dw);
// Remove the writer and its topic, then re-create them. The writer's
// participant should still have discovery info about the reader so that
// the association between the new writer and old reader can be established.
recreate_data_writer_and_topic(dw, dr);
// Wait for the reader to associate with the writer.
WriterSync::wait_match(dw);
// The new writer is associated with the reader, but the reader may still
// also be associated with the old writer.
wait_match(dr, 1);
// Get the new instance handle as pub_ih
if (!read_publication_bit(bit_sub, dp_sub, pub_repo_id, pub_ih, TestConfig::DATA_WRITER_USER_DATA(), TestConfig::TOPIC_DATA(), 1, 2)) {
return false;
}
TestMsgDataWriter_var tmdw = TestMsgDataWriter::_narrow(dw);
const TestMsg msg = {42};
tmdw->write(msg, HANDLE_NIL);
ReadCondition_var rc = dr->create_readcondition(ANY_SAMPLE_STATE,
ANY_VIEW_STATE,
ALIVE_INSTANCE_STATE);
//.........这里部分代码省略.........
示例12: 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");
//.........这里部分代码省略.........
示例13: 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.
//.........这里部分代码省略.........
示例14: 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;
}