本文整理汇总了C++中Topic::getTopicId方法的典型用法代码示例。如果您正苦于以下问题:C++ Topic::getTopicId方法的具体用法?C++ Topic::getTopicId怎么用?C++ Topic::getTopicId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Topic
的用法示例。
在下文中一共展示了Topic::getTopicId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getTopicId
uint16_t Topics::getTopicId(MQString* topic){
Topic *p = getTopic(topic);
if ( p != NULL) {
return p->getTopicId();
}
return 0;
}
示例2: handleSnSubscribe
/*-------------------------------------------------------
Upstream MQTTSnSubscribe
-------------------------------------------------------*/
void GatewayControlTask::handleSnSubscribe(Event* ev, ClientNode* clnode, MQTTSnMessage* msg){
printf(FORMAT2, currentDateTime(), "SUBSCRIBE", LEFTARROW, clnode->getNodeId()->c_str(), msgPrint(msg));
MQTTSnSubscribe* sSubscribe = new MQTTSnSubscribe();
MQTTSubscribe* subscribe = new MQTTSubscribe();
sSubscribe->absorb(msg);
uint8_t topicIdType = sSubscribe->getFlags() & 0x03;
subscribe->setMessageId(sSubscribe->getMsgId());
if(sSubscribe->getFlags() & MQTTSN_FLAG_DUP ){
subscribe->setDup();
}
if(sSubscribe->getFlags() & MQTTSN_FLAG_RETAIN){
subscribe->setRetain();
}
subscribe->setQos(sSubscribe->getQos());
if(topicIdType != MQTTSN_FLAG_TOPICID_TYPE_RESV){
if(topicIdType == MQTTSN_FLAG_TOPICID_TYPE_PREDEFINED){
/*----- Predefined TopicId ------*/
MQTTSnSubAck* sSuback = new MQTTSnSubAck();
if(sSubscribe->getMsgId()){ // MessageID
sSuback->setQos(sSubscribe->getQos());
sSuback->setTopicId(sSubscribe->getTopicId());
sSuback->setMsgId(sSubscribe->getMsgId());
if(sSubscribe->getTopicId() == MQTTSN_TOPICID_PREDEFINED_TIME){
sSuback->setReturnCode(MQTT_RC_ACCEPTED);
}else{
sSuback->setReturnCode(MQTT_RC_REFUSED_IDENTIFIER_REJECTED);
}
clnode->setClientSendMessage(sSuback);
Event* evsuback = new Event();
evsuback->setClientSendEvent(clnode);
printf(FORMAT1, currentDateTime(), "SUBACK", RIGHTARROW, clnode->getNodeId()->c_str(), msgPrint(sSuback));
_res->getClientSendQue()->post(evsuback);
}
if(sSubscribe->getTopicId() == MQTTSN_TOPICID_PREDEFINED_TIME){
MQTTSnPublish* pub = new MQTTSnPublish();
pub->setTopicIdType(1); // pre-defined
pub->setTopicId(MQTTSN_TOPICID_PREDEFINED_TIME);
pub->setMsgId(clnode->getNextSnMsgId());
uint8_t buf[4];
uint32_t tm = time(0);
setUint32(buf,tm);
pub->setData(buf, 4);
printf(GREEN_FORMAT1, currentDateTime(), "PUBLISH", RIGHTARROW, clnode->getNodeId()->c_str(), msgPrint(pub));
clnode->setClientSendMessage(pub);
Event *evpub = new Event();
evpub->setClientSendEvent(clnode);
_res->getClientSendQue()->post(evpub);
}
delete subscribe;
}else{
uint16_t tpId;
Topic* tp = clnode->getTopics()->getTopic(sSubscribe->getTopicName());
if (tp){
tpId = tp->getTopicId();
}else{
tpId = clnode->getTopics()->createTopic(sSubscribe->getTopicName());
}
subscribe->setTopic(sSubscribe->getTopicName(), sSubscribe->getQos());
if(sSubscribe->getMsgId()){
MQTTSnSubAck* sSuback = new MQTTSnSubAck();
sSuback->setMsgId(sSubscribe->getMsgId());
sSuback->setTopicId(tpId);
clnode->setWaitedSubAck(sSuback);
}
clnode->setBrokerSendMessage(subscribe);
Event* ev1 = new Event();
ev1->setBrokerSendEvent(clnode);
_res->getBrokerSendQue()->post(ev1);
delete sSubscribe;
return;
}
}else{
/*-- Irregular TopicIdType --*/
if(sSubscribe->getMsgId()){
MQTTSnSubAck* sSuback = new MQTTSnSubAck();
sSuback->setMsgId(sSubscribe->getMsgId());
sSuback->setTopicId(sSubscribe->getTopicId());
//.........这里部分代码省略.........