Example #1
0
/*
 * Get a list of nodes of the specified classname under nodeh
 * Once a node of the specified class is found, it's children are not
 * searched.
 */
static node_list_t *
get_node_list_by_class(picl_nodehdl_t nodeh, const char *classname,
	node_list_t *listp)
{
	int		err;
	char		clname[PICL_CLASSNAMELEN_MAX+1];
	picl_nodehdl_t	chdh;

	/*
	 * go through the children
	 */
	err = ptree_get_propval_by_name(nodeh, PICL_PROP_CHILD, &chdh,
	    sizeof (picl_nodehdl_t));

	while (err == PICL_SUCCESS) {
		err = ptree_get_propval_by_name(chdh, PICL_PROP_CLASSNAME,
		    clname, strlen(classname) + 1);

		if ((err == PICL_SUCCESS) && (strcmp(clname, classname) == 0))
			listp = add_node_to_list(chdh, listp);
		else
			listp = get_node_list_by_class(chdh, classname, listp);

		err = ptree_get_propval_by_name(chdh, PICL_PROP_PEER, &chdh,
		    sizeof (picl_nodehdl_t));
	}
	return (listp);
}
Example #2
0
struct nli *join_lists(struct nli *local, struct nli *foreign)
{
	if (foreign) {
		struct nli *head_local = local;
		struct nli *match = NULL;
		struct nodeinfo *nfo;
		char *hn, *kn, *ih, *eh, *id, *uq;
		int i = 0;
		do
		{
			hn = foreign->info->hostname;
			kn = foreign->info->keynode;
			ih = foreign->info->internalhost;
			eh = foreign->info->externalhost;
			id = foreign->info->identifier;
			uq = foreign->info->unique;
			if (strcmp(hn, na) == 0) hn = NULL;
			if (strcmp(kn, na) == 0) kn = NULL;
			if (strcmp(ih, na) == 0) ih = NULL;
			if (strcmp(eh, na) == 0) eh = NULL;
			if (strcmp(id, na) == 0) id = NULL;
			if (strcmp(uq, na) == 0) uq = NULL;

			// update nodeinfo from broadcasting node,
			// add other nodes if it they don't locally
			// exist yet
			match 	= node_by_identifier(id, head_local);
			if (match) {
				nfo 	= match->info;	
			} else if (!match){
				local = add_node_to_list(local);
				nfo = local->info = create_node();
			}
			if (hn) {
				set_node_element(&nfo->hostname,	hn);
			}
			if (kn) {
				set_node_element(&nfo->keynode, 	kn);
			}
			if (ih) {
				set_node_element(&nfo->internalhost, 	ih);
			}
			if (eh) {
				set_node_element(&nfo->externalhost, 	eh);
			}
			if (id) {
				set_node_element(&nfo->identifier, 	id);
			}
			if (uq) {
				set_node_element(&nfo->unique, 		uq);
			}
			update_node_timestamp(nfo);

			i++;

		} while (foreign = foreign->next);
	}
	return local;
}
Example #3
0
/*
 * Parse netlist
 */
int parse_netlist(char* filename , LIST* list){

  char line[ MAX_LINE_SIZE + 1];
  NODE element_node;
  int element_type;
  int line_number;
  int res;

  if( !filename || !list  )
    return 0;

  FILE* file;
  file = fopen(filename,"r");
  if( !file )
    return 0;

  line_number = 1 ;
  /*Read until EOF */
  while( !feof(file)){

    /* Get a single line */
    if( fgets( line , MAX_LINE_SIZE , file) != NULL ) {

      /* check for comment,else process */
      if( line[0] != '*'){
        res = get_node_from_line( list, line , &element_node , &element_type);
        if( res == 1 ){

          /* add node read and store at list */
          //printf("NODE READ: %s , %d , %d , %g \n",element_node.resistance.name , element_node.resistance.node1 , element_node.resistance.node2 , element_node.resistance.value);
          res = add_node_to_list(list , &element_node , element_type);
          if( !res ){
            printf("NO MEMORY\n");
            return 0;
          }
        }
        else if( res == 0 ){

          /* Error while parsing line */
          fclose(file);
          printf("Error while parsing.Line %d : %s\n",line_number , line);
          return 0;
        }
      }

    }
    line_number++;
  }

  if( list->has_reference == 1 ){
   return 1;
  }
  else{
    printf("No reference node (ground) specified\n");
    return 0;
  }
}
Example #4
0
void append_to_received_command_list(struct nodeinfo *nfo)
{
	int rl = count_nodelist(rec_head);
	if (rl > 9) {
		remove_node_from_list(rec_head->next);
	}
	rec_tail = add_node_to_list(rec_tail);
	rec_tail->info = dup_nodeinfo(nfo);
	print_received_command_list();
}
Example #5
0
void Ktree::add_kmer (string kmer) {
    
    // cerr << "Adding kmer: " << kmer << endl;
    
    long pos = 0; // start with root node.


    for (unsigned int i = 0; i < kmer.length(); i++) {

        KtreeNode& node = ktree_node_list[pos];
                
        char c = kmer[i];
        // cerr << "k-char: " << c << " at pos: " << i << endl;
        // cerr << " corresponds to parent node: " << node.toString();
        
        if (node.has_child(c)) {
            
            pos = node.get_child(c);
            //cerr << "\thas child for: " << c << " at pos: " << pos << ".\n";
            
        }
        else {
            //cerr << "no child, adding it." << endl;
            KtreeNode newNode (c, 0);
            long orig_pos = pos;
            pos = add_node_to_list(newNode); // invalidates earlier node reference, so re-retrieve it below

            KtreeNode& node = ktree_node_list[orig_pos];
            node.add_child(c, pos);

            // cerr << "\tnode now described as: " << node.toString();
            // cerr << "\tOR: " << ktree_node_list[orig_pos].toString();
            
        }
        
        //cerr << "KmerTree:\n" << toString();
        
        //cerr << "reporting kmer counts:" << endl;
        //report_kmer_counts();
    }
    
    // node is now leaf node

    // update the leaf count.
    KtreeNode& node = ktree_node_list[pos];
    node.set_count( node.get_count() + 1);
    ktree_node_list[pos] = node;
    
    // cerr << "-kmer added.\n\n";

}
Example #6
0
File: main.c Project: IOIOI/nRF51
/**@brief Process ANT message on ANT scanner
 *
 * @param[in] p_ant_event ANT message content.
 */
void continuous_scan_event_handler(ant_evt_t * p_ant_evt)
{
    uint32_t err_code;
    uint8_t  message_rssi;
    uint16_t message_device_number;

    ANT_MESSAGE * p_ant_message = (ANT_MESSAGE *) p_ant_evt->msg.evt_buffer;

    switch(p_ant_evt->event)
    {
        case EVENT_RX:
            if(p_ant_message->ANT_MESSAGE_aucPayload[0] == DEVICE_STATUS_PAGE)
            {
                LEDS_INVERT(BSP_LED_1_MASK);
                if(p_ant_message->ANT_MESSAGE_stExtMesgBF.bANTDeviceID && p_ant_message->ANT_MESSAGE_stExtMesgBF.bANTRssi)
                {
                    message_device_number = (uint16_t)(p_ant_message->ANT_MESSAGE_aucExtData[0] | ((uint16_t)p_ant_message->ANT_MESSAGE_aucExtData[1] << 8));
                    message_rssi = p_ant_message->ANT_MESSAGE_aucExtData[5];
                    add_node_to_list(message_device_number, message_rssi);
                }
            }
            break;

        case EVENT_TRANSFER_TX_COMPLETED:
            LEDS_OFF(BSP_LED_0_MASK | BSP_LED_1_MASK);
            err_code = sd_ant_channel_close(ANT_SCAN_CHANNEL_NUMBER);
            APP_ERROR_CHECK(err_code);
            break;

        case EVENT_TRANSFER_TX_FAILED:
            if(m_retries > 0)
            {
                send_command();
                m_retries--;
            }
            else
            {
                LEDS_OFF(BSP_LED_0_MASK | BSP_LED_1_MASK);
                err_code = sd_ant_channel_close(ANT_SCAN_CHANNEL_NUMBER);
                APP_ERROR_CHECK(err_code);
            }
            break;

        default:
            break;
    }
}
Example #7
0
void
parse_command(char* buff)
{
        char* tmp = (char*)malloc(get_input_buffer_size(1024));
        memcpy(tmp, buff, 1024);

        char* cmd = strtok(tmp, " \0");
        char* t;

        node* root = (node*)malloc(sizeof(node));
        root->next = NULL;
        root->data = cmd;

        while((t = strtok(NULL, " \0")) != NULL) {
                add_node_to_list(root, t);
        }

        node* ptr = root;
        do {
                printf("%s\n", ptr->data);
                ptr = ptr->next;
        } while(ptr != NULL);
        
}
Example #8
0
int save_pic_path(char *path){

	int len = 0;
	
	char pathname[512];

	strcpy(pathname, path);

	dir_list* list = NULL;
	
	while (1){

		DIR *d = opendir(pathname);
		if (d == NULL){
			
			printf("opendir error:%s  %d  \n !",__FILE__,__LINE__);
			return  -1;
		}

		struct dirent *dt = NULL;
		while (dt = readdir(d)){
			
			char filename[512];											
			
			sprintf(filename, "%s/%s", pathname, dt->d_name);

			struct stat st;
			stat(filename, &st);

			if (S_ISREG(st.st_mode)){
							
				len = strlen(dt->d_name);
				
				char str[5] = {0};
				strncpy(str,&(dt->d_name[len-4]),4);
				
				if ( (strcmp(str,".bmp")==0) || (strcmp(str,".BMP")==0)	|| 	\
					(strcmp(str,".jpg") == 0) || (strcmp(str,".JPG") == 0) ){
					
					add_node_to_list( create_node(filename, len) );
					
				}
				
			} else if (S_ISDIR(st.st_mode)){
				
				if (strcmp(dt->d_name, ".") == 0  ||(strcmp(dt->d_name, "..") == 0 )){
					
					continue;
				}

				dir_list* p = (dir_list*) malloc(sizeof(dir_list));

				if (p == NULL){	
					
					printf("system error:%s  %d  is malloc is fault !",__FILE__,__LINE__);
					return -1;
				}
				
				p->next = NULL;
				strcpy(p->filename, filename);
				
				p->next = list;
				list = p;
					
				
			}
		}
		closedir(d);

		if (list == NULL){
			
			break;
		}
			
		dir_list* r = list;
		list = list ->next;
		r->next = NULL;

		strcpy(pathname, r->filename);
		free(r);
		
		
	}

}
Example #9
0
// create new node list, returns pointer to first item in new list
struct nli *create_nodelist()
{
	return add_node_to_list(NULL);
}