void ps_pubsub_class::process_observed_data(ps_root_class *_pst, const void *message, int len) { ps_transport_class *pst = dynamic_cast<ps_transport_class *>(_pst); //incoming from Transport const ps_pubsub_header_t *prefix = static_cast<const ps_pubsub_header_t*>(message); pst->transport_source = static_cast<Source_t>(prefix->packet_source); if (prefix->packet_type < PACKET_TYPES_COUNT) { if (prefix->packet_type == PUBLISH_PACKET) { if (prefix->topic_id >= topic_count) { PS_DEBUG("pub: rx topic %i from %s", prefix->topic_id, pst->name.c_str()); } else { PS_DEBUG("pub: rx topic %s from %s", topic_names[prefix->topic_id], pst->name.c_str()); } } else { PS_DEBUG("pub: rx %s from %s",packet_type_names[prefix->packet_type], pst->name.c_str()); } switch(prefix->packet_type) { case SEND_SUBS_PACKET: send_subscriptions(pst); break; case SUBSCRIBE_PACKET: //its a list of topics needed { ps_subscribe_message_t *msg = (ps_subscribe_message_t*) ((uint8_t*) message + sizeof(ps_pubsub_header_t)); int i = 0; //process subscribe while (msg->topicIds[i] && i < PS_MAX_TOPIC_LIST) { //subscribe to each topic listed subscribe(msg->topicIds[i], pst); i++; }; } break; default: //queue it for the broker thread brokerQueue->copy_message_to_q(message, len); break; } } else { PS_DEBUG("pub: rx bad pkt %i from %s", prefix->packet_type, pst->name.c_str()); //discard } }
void zmq::dish_t::xattach_pipe (pipe_t *pipe_, bool subscribe_to_all_) { LIBZMQ_UNUSED (subscribe_to_all_); zmq_assert (pipe_); fq.attach (pipe_); dist.attach (pipe_); // Send all the cached subscriptions to the new upstream peer. send_subscriptions (pipe_); }
void ps_pubsub_class::process_observed_event(ps_root_class *_pst, int _ev) { ps_transport_class *pst = dynamic_cast<ps_transport_class *>(_pst); ps_transport_event_enum ev = (ps_transport_event_enum) _ev; PS_DEBUG("pub: status %s from %s", transport_event_names[ev], pst->name.c_str()); bool send_subs {false}; LOCK_MUTEX(pubsubMtx); switch(ev) { case PS_TRANSPORT_ONLINE: send_subs = true; break; case PS_TRANSPORT_OFFLINE: break; case PS_TRANSPORT_ADDED: { transports.insert(pst); pst->add_data_observer(this); send_subs = true; } break; case PS_TRANSPORT_REMOVED: { //remove transports entry auto pos = transports.find(pst); if (pos != transports.end()) { transports.erase(pos); } } break; default: break; } UNLOCK_MUTEX(pubsubMtx); if (send_subs) { request_subscriptions(pst); send_subscriptions(pst); } }
void zmq::dish_t::xhiccuped (pipe_t *pipe_) { // Send all the cached subscriptions to the hiccuped pipe. send_subscriptions (pipe_); }