Esempio n. 1
0
void MDNetworkParticipant::network_datagram(Datagram &dg)
{
	DatagramIterator dgi(dg);
	unsigned short channels = dgi.read_uint8();
	if(channels == 1 && dgi.read_uint64() == CONTROL_MESSAGE)
	{
		unsigned short msg_type = dgi.read_uint16();
		switch(msg_type)
		{
			case CONTROL_ADD_CHANNEL:
			{
				subscribe_channel(dgi.read_uint64());
			}
			break;
			case CONTROL_REMOVE_CHANNEL:
			{
				unsubscribe_channel(dgi.read_uint64());
			}
			break;
			case CONTROL_ADD_RANGE:
			{
				channel_t lo = dgi.read_uint64();
				channel_t hi = dgi.read_uint64();
				subscribe_range(lo, hi);
			}
			break;
			case CONTROL_REMOVE_RANGE:
			{
				channel_t lo = dgi.read_uint64();
				channel_t hi = dgi.read_uint64();
				unsubscribe_range(lo, hi);
			}
			break;
			case CONTROL_ADD_POST_REMOVE:
			{
				add_post_remove(dgi.read_string());
			}
			break;
			case CONTROL_CLEAR_POST_REMOVE:
			{
				clear_post_removes();
			}
			break;
			default:
				logger().error() << "MDNetworkParticipant got unknown control message, type : " << msg_type << std::endl;
		}
		return;
	}
	send(dg);
}
Esempio n. 2
0
void ChannelMap::unsubscribe_all(ChannelSubscriber* p)
{
    std::lock_guard<std::recursive_mutex> guard(m_lock);

    // Unsubscribe from indivually subscribed channels
    auto channels = std::set<channel_t>(p->channels());
    for(auto it = channels.begin(); it != channels.end(); ++it) {
        channel_t channel = *it;
        unsubscribe_channel(p, channel);
    }

    // Unsubscribe from subscribed channel ranges
    auto ranges = boost::icl::interval_set<channel_t>(p->ranges());
    for(auto it = ranges.begin(); it != ranges.end(); ++it) {
        channel_t lower;
        channel_t upper;
        get_closed_bounds(*it, lower, upper);
        unsubscribe_range(p, lower, upper);
    }
}
Esempio n. 3
0
void MDNetworkParticipant::receive_datagram(DatagramHandle dg)
{
	DatagramIterator dgi(dg);
	uint16_t channels = dgi.read_uint8();
	if(channels == 1 && dgi.read_channel() == CONTROL_MESSAGE)
	{
		uint16_t msg_type = dgi.read_uint16();
		switch(msg_type)
		{
			case CONTROL_ADD_CHANNEL:
			{
				subscribe_channel(dgi.read_channel());
				break;
			}
			case CONTROL_REMOVE_CHANNEL:
			{
				unsubscribe_channel(dgi.read_channel());
				break;
			}
			case CONTROL_ADD_RANGE:
			{
				channel_t lo = dgi.read_channel();
				channel_t hi = dgi.read_channel();
				subscribe_range(lo, hi);
				break;
			}
			case CONTROL_REMOVE_RANGE:
			{
				channel_t lo = dgi.read_channel();
				channel_t hi = dgi.read_channel();
				unsubscribe_range(lo, hi);
				break;
			}
			case CONTROL_ADD_POST_REMOVE:
			{
				add_post_remove(dgi.read_datagram());
				break;
			}
			case CONTROL_CLEAR_POST_REMOVE:
			{
				clear_post_removes();
				break;
			}
			case CONTROL_SET_CON_NAME:
			{
				set_con_name(dgi.read_string());
				break;
			}
			case CONTROL_SET_CON_URL:
			{
				set_con_url(dgi.read_string());
				break;
			}
			default:
				logger().error() << "MDNetworkParticipant got unknown control message, type : "
				                 << msg_type << std::endl;
		}
		return;
	}
	route_datagram(dg);
}