void lldp_msg_handler(struct q_node* qn, uint32_t xid, char* buffer, uint16_t total_len) { ovs_be32 in_port_num = 0; in_port_num = packet_in_msg_get_in_port_num(qn); struct ofp11_port * port = get_switch_port_by_port_num(qn->sw, in_port_num); if(unlikely(port == NULL)) { log_warn("Bad Port"); return; } struct link_node * right_node = link_node_create(qn->sw, port); uint64_t dpid = get_dpid_from_LLDP_packet(qn->rx_packet + qn->packet_length - total_len); struct mf_switch *sw = get_switch_by_dpid_from_list(dpid); if(unlikely(sw == NULL)) { log_warn("Bad dpid, can Not get switch"); return; } uint16_t outport = get_outport_from_LLDP_packet(qn->rx_packet + qn->packet_length - total_len); struct ofp11_port * port_out = get_switch_port_by_port_num(sw, outport); if(unlikely(port_out == NULL)) { log_warn("Bad Port"); return; } struct link_node * left_node = link_node_create(sw, port_out); uint32_t rst = 0; struct network_link * netlink = network_link_create(right_node, left_node); if(netlink != NULL) rst = sw_link_insert(&(qn->sw->link_list), netlink); //if(rst == 1) //print_switch_link(qn->sw); //print_all_switches(); }
int BLECharacteristicImp::addDescriptor(const bt_uuid_t* uuid, unsigned char property, uint16_t handle) { BLEDescriptorImp* descriptorImp = descrptor(uuid); if (NULL != descriptorImp) { return BLE_STATUS_SUCCESS; } descriptorImp = new BLEDescriptorImp(uuid, property, handle, _ble_device); pr_debug(LOG_MODULE_BLE, "%s-%d",__FUNCTION__, __LINE__); if (NULL == descriptorImp) { return BLE_STATUS_NO_MEMORY; } BLEDescriptorNodePtr node = link_node_create(descriptorImp); if (NULL == node) { delete descriptorImp; return BLE_STATUS_NO_MEMORY; } link_node_insert_last(&_descriptors_header, node); pr_debug(LOG_MODULE_BLE, "%s-%d",__FUNCTION__, __LINE__); return BLE_STATUS_SUCCESS; }
int BLECharacteristicImp::addDescriptor(BLEDescriptor& descriptor) { BLEDescriptorImp* descriptorImp = descrptor(descriptor.uuid()); if (NULL != descriptorImp) { return BLE_STATUS_SUCCESS; } descriptorImp = new BLEDescriptorImp(_ble_device, descriptor); pr_debug(LOG_MODULE_BLE, "%s-%d",__FUNCTION__, __LINE__); if (NULL == descriptorImp) { return BLE_STATUS_NO_MEMORY; } pr_debug(LOG_MODULE_BLE, "%s-%d",__FUNCTION__, __LINE__); BLEDescriptorNodePtr node = link_node_create(descriptorImp); if (NULL == node) { delete descriptorImp; return BLE_STATUS_NO_MEMORY; } link_node_insert_last(&_descriptors_header, node); pr_debug(LOG_MODULE_BLE, "%s-%d",__FUNCTION__, __LINE__); return BLE_STATUS_SUCCESS; }
/** * Add one pair to the dom * @param p the pair to add * @param p_parent the pair parent ("pairs") * @param parents a hashmap of parents looking for children * @param orphans a hashmap of children looking for parents * @param id VAR param: parent ID to update * @return 1 if it worked OK else 0 */ int write_one_pair( pair *p, dom_item *p_parent, hashmap *parents, hashmap *orphans, int *id ) { int res = 1; dom_item *p_element = dom_object_create( "pair" ); if ( p_element != NULL ) { if ( pair_is_parent(p) ) { char id_str[32]; char p_key[32]; UChar u_key[32]; snprintf( id_str, 32, "%d", *id ); dom_add_attribute( p_element, dom_attribute_create("id",id_str) ); snprintf( p_key, 32, "%lx",(long)p ); ascii_to_uchar( p_key, u_key, 32 ); hashmap_put( parents, u_key, id_str ); (*id)++; // check if any orphans belong to this parent link_node *ln = hashmap_get( orphans, u_key ); if ( ln != NULL ) { char *id_str = hashmap_get( parents, u_key ); dom_item *child = link_node_obj( ln ); while ( child != NULL ) { dom_add_attribute( child, dom_attribute_create("parent", id_str) ); ln = link_node_next( ln ); if ( ln != NULL ) child = link_node_obj( ln ); else child = NULL; } hashmap_remove( orphans, u_key, NULL ); link_node_dispose( ln ); } } else if ( pair_is_child(p) ) { UChar u_key[32]; char p_key[32]; snprintf( p_key, 32, "%lx",(long)pair_parent(p) ); ascii_to_uchar( p_key, u_key, 32 ); char *id_str = hashmap_get( parents, u_key ); if ( id_str != NULL ) dom_add_attribute( p_element, dom_attribute_create("parent", id_str) ); else { link_node *children = hashmap_get( orphans, u_key ); if ( children == NULL ) { children = link_node_create(); if ( children != NULL ) { link_node_set_obj( children, p_element ); res = hashmap_put( orphans, u_key, children ); } } else { link_node *ln = link_node_create(); if ( ln != NULL ) { link_node_set_obj( ln, p_element ); link_node_append( children, ln ); } else res = 0; } } } if ( res ) { if ( pair_is_hint(p) ) { dom_add_attribute( p_element, dom_attribute_create("hint","true") ); } int bytes = bitset_allocated(pair_versions(p))*8; char *bit_str = calloc( bytes+1, 1 ); if ( bit_str != NULL ) { bitset_tostring( pair_versions(p), bit_str, bytes ); res = dom_add_attribute( p_element, dom_attribute_create("versions",bit_str) ); free( bit_str ); } if ( res && !pair_is_child(p) ) { char *utf8_data = to_utf8( pair_data(p), pair_len(p) ); if ( utf8_data != NULL ) { res = dom_add_text( p_element, utf8_data ); free( utf8_data ); } } dom_add_child( p_parent, p_element ); } } else res = 0; return res; }