コード例 #1
0
ファイル: btsdp.c プロジェクト: github188/SimpleCode
int svcBrowse(uuid_t *groupToExtract)
{
	int 		status = -1, i;
	uint16_t	count = 0;
	slist_t		*searchList = NULL;
	slist_t		*attrIdList = NULL;
	slist_t		*svcRecList = NULL;
	sdpsvc_t	*svcRec;

	s_list_append(&searchList, groupToExtract);
	s_list_append_uint(&attrIdList, 0x0000ffff);
	status = sdp_search_attr_req(srvHandle, searchList, 
			RangeOfAttributes, attrIdList, 0xFFFF, &svcRecList, &count);
	s_list_free(&attrIdList);
	s_list_free(&searchList);
	//printf("Status : %d Count : %d, list: %d\n", status, count, s_list_length(svcRecList));
	
	if (status || count == 0)
		return status;

	for (i = 0; i < s_list_length(svcRecList); i++) {
		printf("==============================\n");

		svcRec = (sdpsvc_t *)s_list_nth_data(svcRecList, i);
		print_info_attr(svcRec);
		printf("------------------------------\n");

		printf("SvcRecHdl: 0x%x\n", svcRec->serviceRecordHandle);

		if (!verboseflag) {
			print_svc_class(svcRec);
			print_access_proto(svcRec);
			print_profile_desc(svcRec);
			print_group(svcRec);
		} else {
			// print detailed info
		}

		if (sdp_is_group(svcRec)) {
			uuid_t	*groupId;

			// printf("SvcRec : 0x%x is a group\n", svcRecHandle);
			printf("This is a group.\n");
			groupId = sdp_get_group_attr(svcRec);
			printf("  0x%s\n", sdp_uuid2str(groupId));
			if (sdp_uuidcmp(groupId, groupToExtract) != 0) {
				printf("Extracting it\n");
				svcBrowse(groupId);
			}
		}
	}
	sdp_free_svclist(&svcRecList);
	return status;
}
コード例 #2
0
ファイル: str_list.c プロジェクト: Cyofanni/speect
/**
 * Append a string to end of the string list.
 */
S_API void s_str_list_append(s_str_list *self, const char *string, s_erc *error)
{
	char *new_string;


	S_CLR_ERR(error);
	if ((self == NULL) || (string == NULL))
		return;

	new_string = s_strdup(string, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "s_str_list_append",
				  "Call to \"s_strdup\" failed"))
		return;

	s_list_append(self, new_string, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "s_str_list_append",
				  "Call to \"s_list_append\" failed"))
	{
		S_FREE(new_string);
	}
}
コード例 #3
0
ファイル: read_thread.c プロジェクト: ems5311/OSproj2
void *read_trd_fn(void *trd_data)
{
    // A new thread has been created, only one of its kind.
    // It was created in p2_actions
    // trd_data points to a struct r_trd_data which contains
    // (1) a linked list of all the lines from the input file
    // (2) a struct foo iterator of all the -m options supplied by the command line.
    struct r_trd_dat *infile_m_lines = (struct r_trd_dat *)trd_data;

    printf("Initting semaphore variable\n");
/*    sem_init(&search_sem, 0, 1); // Initial value of search_sem set to 1
    sem_init(&n_sem, 0, 0);      // n_sem for producer/consumer, init to 0
    sem_init(&more_data_sem, 0, 0);

    sem_init(&empty, 0, 1);
    sem_init(&full, 0, 0);*/
    pthread_mutex_init(&mutex, NULL);

    struct foo *m = infile_m_lines->m_list;
    l_list *infile_list = infile_m_lines->infile_list;

    // Create list of search threads
    s_list *search_threads = s_list_init();

    // initialize p3_data:
    p3_data = l_list_init();

    int s_count = 0;

    for(; m != NULL; m = m->next)
        s_count++;


    int i = 0;
    // create each search thread:
    for(m = infile_m_lines->m_list; m != NULL; m = m->next)
    {
        s_node *s = (s_node *)malloc(sizeof(s_node));
        if(s == NULL)
            err_sys("malloc (read_trd_fn)");
    
        s->next = NULL;
        s->_m = strdup(m->string);
        if(s->_m == NULL)
            err_sys("strdup (read_trd_fn)");

        // Copy input file buffer over to this s node:
        s->infile_list = l_list_init();
        node *copy_iter = infile_list->head;
        for(; copy_iter != NULL; copy_iter = copy_iter->next)
        {
            l_list_append(s->infile_list, copy_iter->data);
        }

        // Append the newly created s_node to the list.
        if(s_list_append(search_threads, s) != 0)
            exit(0);

        pthread_create(&s->tid, NULL, search_trd_fn, (void *)s);

        pthread_join(s->tid, NULL);

        i++;
    }

    printf("s_count = %d\n", s_count);

    // Now all the search threads have been created (for 3 -m options supplied, there should be 3 threads)
    // Now put each line from the input file into each (search_thread's) s_node's _protected char*.

    node *end;
    for(end = p3_data->head; end != NULL; end = end->next)
        fprintf(infile_m_lines->fp, "%s", end->data);

    pthread_exit(NULL);
    return NULL;
}