本文整理汇总了C++中Publisher类的典型用法代码示例。如果您正苦于以下问题:C++ Publisher类的具体用法?C++ Publisher怎么用?C++ Publisher使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Publisher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: entryGroupCallback
void Publisher::entryGroupCallback(AvahiEntryGroup *g, AvahiEntryGroupState state, void *context) {
Publisher *publisher = (Publisher*) context;
const char* name = publisher->info.getServiceName().c_str();
const int port = publisher->info.getPort();
// callback called whenever our entry group state changes
switch (state) {
case AVAHI_ENTRY_GROUP_ESTABLISHED:
std::cout << "Registration ok:" << name <<":" << port << " (" << publisher->serviceType << ")" << std::endl;
break;
case AVAHI_ENTRY_GROUP_COLLISION:
// build new name
publisher->nextName();
// retry
publisher->createServices(avahi_entry_group_get_client(g));
break;
case AVAHI_ENTRY_GROUP_FAILURE:
std::cerr << "Registration failure ("
<< avahi_strerror(avahi_client_errno(avahi_entry_group_get_client(g)))
<< ")" << std::endl;
publisher->quit();
break;
case AVAHI_ENTRY_GROUP_UNCOMMITED:
case AVAHI_ENTRY_GROUP_REGISTERING:
;
}
}
示例2: handleRecievedData
void handleRecievedData(char recv_buf[],Publisher config_pub,Publisher arm_pub)
{
std_msgs::String msg;
char type[4]= {'\0'};
strncpy(type,recv_buf,3);
if(!strcmp(type,"CAM"))
{
int written;
char temp[20]= {'\0'};
strncpy(temp,recv_buf+4,strlen(recv_buf));
ROS_INFO("sent data : %s",temp);
msg.data = temp;
config_pub.publish(msg);
}
else if(!strcmp(type,"ARM"))
{
int written = strlen(recv_buf);
char temp[20]= {'\0'};
strncpy(temp,recv_buf+4,written);
ROS_INFO("sent data : %s",temp);
msg.data = temp;
arm_pub.publish(msg);
}
else if(!strcmp(type,"PTZ"))
{
int written = strlen(recv_buf);
char temp[20]= {'\0'};
strncpy(temp,recv_buf+4,written);
ROS_INFO("sent data : %s",temp);
msg.data = temp;
ptz_pub.publish(msg);
}
}
示例3: ACE_TMAIN
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
try
{
Publisher publisher (argc, argv);
publisher.run ();
}
catch (Publisher::InitError& ex)
{
std::string& msg = reinterpret_cast<std::string&>(ex);
std::cerr << "Initialization Error: "
<< msg.c_str() << std::endl;
return -1;
}
catch (const CORBA::Exception& ex)
{
ex._tao_print_exception (
"ERROR: Publisher caught exception");
return -1;
}
return 0;
}
示例4:
Publisher::Publisher(const Publisher& other)
{
MessageBuffer* tmp;
publisher_name = other.getName();
pub_msg_buf->copyFrom(*(other.getBuffer()) );
pub_msg_queue = other.getQueue();
}
示例5: testPublisherToSubscriber
void testPublisherToSubscriber() {
report(0,"Publisher to Subscriber test");
Node n("/node");
Publisher<Bottle> pout;
pout.topic("/very_interesting_topic");
{
Node n2("/node2");
Subscriber<Bottle> pin("/very_interesting_topic");
pin.read(false); // make sure we are in buffered mode
waitForOutput(pout,10);
Bottle& b = pout.prepare();
b.clear();
b.addInt(42);
pout.write();
pout.waitForWrite();
Bottle *bin = pin.read();
checkTrue(bin!=NULL,"message arrived");
if (!bin) return;
checkEqual(bin->get(0).asInt(),42,"message is correct");
}
}
示例6: main
int main(int argc, char *argv[])
{
init(argc, argv, "position");
int key = 0;
NodeHandle n;
Position_Node::Position pos;
Rate loop_rate(1); /* in Hz */
Subscriber sub = n.subscribe("MarkerInfo", 1000, markerCallback);
Publisher pub = n.advertise<Position_Node::Position>("Position", 1000);
while(ros::ok())
{
/* Publish our position */
pos.x = g_robot_x;
pos.y = g_robot_y;
pos.theta = g_robot_theta;
//ROS_INFO("Published position.\n");
pub.publish(pos);
spinOnce();
loop_rate.sleep();
}
return 0;
}
示例7:
Publisher::Publisher(const Publisher& other)
{
publisher_name = other.getName();
pub_msg_buf->copyFrom(*(other.getBuffer()) );
pub_msg_queue = other.getQueue();
pub_msg_queue->add_publisher(this,pub_msg_buf);
}
示例8: main
int main(int argc, char** argv)
{
QCoreApplication app(argc, argv);
Subscriber subscriber;
subscriber.connectToHost();
Publisher publisher;
publisher.connectToHost();
return app.exec();
}
示例9: publishStatus
void publishStatus(TimerEvent timerEvent) {
std_msgs::Int32 intMessage;
intMessage.data = _currentInput + 1;
_currentInputPublisher.publish(intMessage);
intMessage.data = _currentOutput + 1;
_currentOutputPublisher.publish(intMessage);
}
示例10: Publisher
/**
* Construct a new publisher, generate a keypair and set the required attributes
* @param string node_name name of the publisher
* @return Publisher
*/
Publisher* SecurityServer::addPublisher(bytestring client_name)
{
RSAKeyPair rsa_key_pair = this->generateKeyPair(RSAKeyPair::KeyLength);
this->clients[client_name] = rsa_key_pair.getPublic();
Publisher *pub = new Publisher(client_name, rsa_key_pair);
pub->setServer(this->key_pair.getPublic());
return pub;
}
示例11: publishMessage
ECL_KAFKA_API bool ECL_KAFKA_CALL publishMessage(ICodeContext* ctx, const char* brokers, const char* topic, const char* message, const char* key)
{
std::call_once(pubCacheInitFlag, setupPublisherCache, ctx->queryContextLogger().queryTraceLevel());
Publisher* pubObjPtr = publisherCache->getPublisher(brokers, topic, POLL_TIMEOUT);
pubObjPtr->sendMessage(message, key);
return true;
}
示例12: Wait
void DviSubscriptionManager::Run()
{
for (;;) {
Wait();
Publisher* publisher = iFree.Read();
iLock.Wait();
DviSubscription* subscription = iList.front();
iList.pop_front();
iLock.Signal();
publisher->Publish(subscription);
}
}
示例13: getSensor
/**
* Controls all the inner workings of the PID functionality
* Should be called by _timer
*
* Controls the heating element Relays manually, overriding the standard relay
* functionality
*
* The pid is designed to Output an analog value, but the relay can only be On/Off.
*
* "time proportioning control" it's essentially a really slow version of PWM.
* first we decide on a window size. Then set the pid to adjust its output between 0 and that window size.
* lastly, we add some logic that translates the PID output into "Relay On Time" with the remainder of the
* window being "Relay Off Time"
*
* PID Adaptive Tuning
* You can change the tuning parameters. this can be
* helpful if we want the controller to be agressive at some
* times, and conservative at others.
*
*/
void Ohmbrewer::Thermostat::doPID(){
getSensor()->work();
setPoint = getTargetTemp()->c(); //targetTemp
input = getSensor()->getTemp()->c();//currentTemp
double gap = abs(setPoint-input); //distance away from target temp
//SET TUNING PARAMETERS
if (gap<10) { //we're close to targetTemp, use conservative tuning parameters
_thermPID->SetTunings(cons.kP(), cons.kI(), cons.kD());
}else {//we're far from targetTemp, use aggressive tuning parameters
_thermPID->SetTunings(agg.kP(), agg.kI(), agg.kD());
}
//COMPUTATIONS
_thermPID->Compute();
if (millis() - windowStartTime>windowSize) { //time to shift the Relay Window
windowStartTime += windowSize;
}
//TURN ON
if (getState() && gap!=0) {//if we want to turn on the element (thermostat is ON)
//TURN ON state and powerPin
if (!(getElement()->getState())) {//if heating element is off
getElement()->setState(true);//turn it on
if (getElement()->getPowerPin() != -1) { // if powerPin enabled
digitalWrite(getElement()->getPowerPin(), HIGH); //turn it on (only once each time you switch state)
}
}
//RELAY MODULATION
if (output < millis() - windowStartTime) {
digitalWrite(getElement()->getControlPin(), HIGH);
} else {
digitalWrite(getElement()->getControlPin(), LOW);
}
}
//TURN OFF
if (gap == 0 || getTargetTemp()->c() <= getSensor()->getTemp()->c() ) {//once reached target temp
getElement()->setState(false); //turn off element
getElement()->work();
// if (getElement()->getPowerPin() != -1) { // if powerPin enabled
// digitalWrite(getElement()->getPowerPin(), LOW); //turn it off too TODO check this
// }
// Notify Ohmbrewer that the target temperature has been reached.
Publisher pub = Publisher(new String(getStream()),
String("msg"),
String("Target Temperature Reached."));
pub.add(String("last_read_time"),
String(getSensor()->getLastReadTime()));
pub.add(String("temperature"),
String(getSensor()->getTemp()->c()));
pub.publish();
}
}
示例14: main
int main (int argc, char* argv[]) {
gengetopt_args_info args;
cmdline_parser(argc,argv,&args);
double v = args.linearVelocity_arg;
double a = args.angularVelocity_arg;
double time = args.time_arg;
int count = 0;
init(argc, argv, "talker");
geometry_msgs::Twist msg;
msg.linear.x = v;
msg.angular.z = a;
NodeHandle n;
Publisher pub = n.advertise<geometry_msgs::Twist>("/cmd_vel_mux/input/navi", 1);
ros::Rate loop_rate(10);
while (ros::ok() && count < (int)time*10) {
ros::spinOnce();
pub.publish(msg);
loop_rate.sleep();
count++;
}
for (int i = 0; i < 5; i++) {
msg.linear.x = 0;
msg.angular.z = 0;
pub.publish(msg);
ros::spinOnce();
}
return 0;
//init(argc, argv, "talker");
//geometry_msgs::Twist msg;
//msg.linear.x = 1.0;
//msg.angular.z = .5;
//int max_count = 30;
//int count = 0;
//NodeHandle n;
//Publisher pub = n.advertise<geometry_msgs::Twist>("/cmd_vel_mux/input/navi", 1);
//ros::Rate loop_rate(10);
//while (ros::ok() && count < max_count) {
// ros::spinOnce();
// pub.publish(msg);
// loop_rate.sleep();
// count++;
//}
//return 0;
}
示例15: main
int main()
{
ParticipantAttributes participant_attributes;
Participant* participant = Domain::createParticipant(participant_attributes);
if(participant == nullptr)
return 1;
HelloWorldType type;
Domain::registerType(participant,&type);
PubListener listener;
//CREATE THE PUBLISHER
PublisherAttributes publisher_attributes;
publisher_attributes.topic.topicKind = NO_KEY;
publisher_attributes.topic.topicDataType = type.getName();
publisher_attributes.topic.topicName = "HelloWorldTopic";
publisher_attributes.qos.m_reliability.kind = RELIABLE_RELIABILITY_QOS;
Publisher* publisher = Domain::createPublisher(participant, publisher_attributes, &listener);
if(publisher == nullptr)
{
Domain::removeParticipant(participant);
return 1;
}
while(listener.matched_ == 0)
eClock::my_sleep(250);
HelloWorld data;
data.index(1);
data.message("HelloWorld");
while(1)
{
publisher->write((void*)&data);
if(data.index() == 4)
data.index() = 1;
else
++data.index();
eClock::my_sleep(250);
};
Domain::removeParticipant(participant);
return 0;
}