Пример #1
0
/**
 * Capability Discover handler.
 *
 * @param msg Received message.
 * @param ec Error Code.
 */
void mih_user::capability_discover_confirm(odtone::mih::message& msg, const boost::system::error_code& ec)
{
    if (ec) {
        log_(0, __FUNCTION__, " error: ", ec.message());
        return;
    }

    odtone::mih::status st;
    boost::optional<odtone::mih::net_type_addr_list> ntal;
    boost::optional<odtone::mih::mih_evt_list> evt;

    msg >> odtone::mih::confirm()
        & odtone::mih::tlv_status(st)
        & odtone::mih::tlv_net_type_addr_list(ntal)
        & odtone::mih::tlv_event_list(evt);

    log_(0, "MIH-User has received a Capability_Discover.response with status ",
            st.get(), " and the following capabilities:");

    /*odtone::uint i = 0;
      odtone::uint size = ntal.size();
      for (;i < size; i++) {
      odtone::mih::mac_addr mac = boost::get<odtone::mih::mac_addr>(ntal[i].addr);
      odonte::mih::network_type type = ntal[i].nettype;
      switch type:
      case odtone::mih::link_type_802_11:
      log_(0, "detected wifi w/ addr = ", mac);
      break;
      case odtone::mih::link_type_ethernet:
      log_(0, "detected ethernet w/ addr = ", mac);
      break;
      }*/




    //log_(0, "prima for");
    for (odtone::mih::net_type_addr_list::iterator i = ntal->begin(); i != ntal->end(); ++i) {
        /*log_(0, "inizio");
          log_(0, *i);
          log_(0, "fine");*/
        //odtone::mih::link_tuple_id li;

        if (i->nettype.link.which() == 1)
        {
            odtone::mih::mac_addr mac = boost::get<odtone::mih::mac_addr>(i->addr);
            odtone::mih::link_type type = boost::get<odtone::mih::link_type>(i->nettype.link);
            this->links.add_interface(mac,type);
        }
    }
    this->links.print_interfaces();
    //
    // event subscription
    //
    // For every interface the MIHF sent in the
    // Capability_Discover.response send an Event_Subscribe.request
    // for all availabe events
    //
    if (ntal && evt) {
        for (odtone::mih::net_type_addr_list::iterator i = ntal->begin(); i != ntal->end(); ++i) {
            odtone::mih::message req;
            odtone::mih::link_tuple_id li;

            if (i->nettype.link.which() == 1)
            {
                li.addr = i->addr;
                li.type = boost::get<odtone::mih::link_type>(i->nettype.link);

                req << odtone::mih::request(odtone::mih::request::event_subscribe, _mihfid)
                    & odtone::mih::tlv_link_identifier(li)
                    & odtone::mih::tlv_event_list(evt);
                req.destination(msg.source());

                _mihf.async_send(req, boost::bind(&mih_user::event_subscribe_response, this, _1, _2));

                log_(0, "MIH-User has sent Event_Subscribe.request to ", req.destination().to_string());
            }
        }
    }
}
Пример #2
0
/**
 * Capability Discover handler.
 *
 * @param msg Received message.
 * @param ec Error Code.
 */
void mih_user::capability_discover_confirm(odtone::mih::message& msg, const boost::system::error_code& ec)
{
	if (ec) {
		log_(0, __FUNCTION__, " error: ", ec.message());
		return;
	}

	odtone::mih::status st;
	boost::optional<odtone::mih::net_type_addr_list> ntal;
	boost::optional<odtone::mih::mih_evt_list> evt;

	msg >> odtone::mih::confirm()
		& odtone::mih::tlv_status(st)
		& odtone::mih::tlv_net_type_addr_list(ntal)
		& odtone::mih::tlv_event_list(evt);

	log_(0, "MIH-User has received a Capability_Discover.response with status ",
			st.get(), " and the following capabilities:");

	if (ntal) {
		for (odtone::mih::net_type_addr_list::iterator i = ntal->begin(); i != ntal->end(); ++i)
			log_(0,  *i);

	} else {
		log_(0,  "none");
	}

	//
	// event subscription
	//
	// For every interface the MIHF sent in the
	// Capability_Discover.response send an Event_Subscribe.request
	// for all availabe events
	//
	if (ntal && evt) {
		for (odtone::mih::net_type_addr_list::iterator i = ntal->begin(); i != ntal->end(); ++i) {
			odtone::mih::message req;
			odtone::mih::link_tuple_id li;

			if (i->nettype.link.which() == 1)
				{
					li.addr = i->addr;
					li.type = boost::get<odtone::mih::link_type>(i->nettype.link);

					//yan-start-23/02/2012
					//_mihlid[_num_links] = li;
					//++_num_links;
					odtone::mih::octet_string ifname = mih_get_ifname(li);
					if (ifname != "")
					{
						_mihlnks.push_back(link_info(li, ifname));
					}
					//yan-end

					req << odtone::mih::request(odtone::mih::request::event_subscribe, _mihfid)
						& odtone::mih::tlv_link_identifier(li)
						& odtone::mih::tlv_event_list(evt);
					req.destination(msg.source());

					_mihf.async_send(req, boost::bind(&mih_user::event_subscribe_response, this, _1, _2));

					log_(0, "MIH-User has sent Event_Subscribe.request to ", req.destination().to_string());
				}
		}
	}
}