Пример #1
0
static int uhci_driver_init(hcd_t *hcd, const hw_res_list_parsed_t *res, bool irq)
{
    assert(hcd);
    assert(hcd_get_driver_data(hcd) == NULL);

    hc_t *instance = malloc(sizeof(hc_t));
    if (!instance)
        return ENOMEM;

    const int ret = hc_init(instance, res, irq);
    if (ret == EOK) {
        hcd_set_implementation(hcd, instance, &uhci_hc_driver.ops);
    } else {
        free(instance);
    }
    return ret;
}
Пример #2
0
int main() {
	int na = 6;
	HTN ht;

	ht = hc_init(na);
	hc_print_ht(ht, na);

	hc_create(ht, na);
	hc_print_ht(ht, na);
	hc_print_cw(hc_encode(ht, na), na);
	puts(hc_uncode(ht, na, "1101001"));

	hc_destory(ht);

	system("pause");
	return 0;
}
Пример #3
0
int main(int argc, char* argv[])
{
	hc_session_t *session = NULL;

	hc_oid returnedOid;
	hc_long_t count = 0;
	int finished = 0;
	int32_t response_code = RETURN_SUCCESS;
	hc_query_result_set_t *rset = NULL;
	hc_nvr_t *nvr = NULL;
	hc_long_t query_integrity_time;
	int query_complete;

	
	hcerr_t	res = HCERR_OK;

	int parametersUsed = USES_SERVERADDRESS | USES_QUERY | USES_SELECT_METADATA | USES_MAXRESULTS;

	/* Initialize commandline structure */
	cmdLine.storagetekServerAddress = NULL;
	cmdLine.query = NULL;
	cmdLine.help = 0;
	cmdLine.debug_flags = 0;
	cmdLine.storagetekPort = 0;
	cmdLine.maxResults = DEFAULT_MAX_RESULTS;

	/* Initialize metadata map.  The metadata map structure is not part of the API but common */
	/* code written for the convenience of these examples.  See example_metadata.c. */
        if (initMetadataMap(&cmdLine.cmdlineMetadata) == 0)
        {
                return exitApp(RETURN_MAPINITERROR);
        }       /* if initMetadataMap == 0 */

	/* Get commandline (see example_commandline.c) */
	if (parseCommandline(	argc,
				argv,
				parametersUsed) == 0)
	{
		printUsage();
		return RETURN_COMMANDLINE_ERROR;
	}	/* if parseCommandline failed */
	else
	{
		if (cmdLine.help == 1)
		{
			printUsage();
			return RETURN_SUCCESS;
		}	/* if help requested */
	}	/* else parseCommandline succeeded */

	/* Initialize @HoneycombProductName@ API */
        res = hc_init(malloc,free,realloc);
        if (res != HCERR_OK)
        {
                printf("An error occurred while initializing the API.\n");
                return res;
        }  /* if error */

       if (cmdLine.debug_flags) {
		/* Internal debug flags */
		hc_set_global_parameter(HCOPT_DEBUG_FLAGS, cmdLine.debug_flags);
       }

	res = hc_session_create_ez(cmdLine.storagetekServerAddress, 
				(cmdLine.storagetekPort > 0 ? 
				 cmdLine.storagetekPort : 
				 STORAGETEK_PORT),
				&session);
	
	if (res != HCERR_OK)
	{
		HandleError(session,res);
		return RETURN_STORAGETEK_ERROR;
	}	/* if initialization failed */

	/* Run queryplus if we have a select clause (-s option on the commandline), otherwise run query */
	if (cmdLine.cmdlineMetadata.mapSize > 0)
	{
		res = hc_query_ez(session,
				cmdLine.query,
				cmdLine.cmdlineMetadata.namePointerArray,	
				cmdLine.cmdlineMetadata.mapSize,
                                100,
				&rset);
	}	/* if outputing metadata */
	else
	{	
		res = hc_query_ez(session,
				cmdLine.query,
                                NULL,
                                0,
                                100,
				&rset);
	}

	if (res != HCERR_OK)
        {
                HandleError(session, res);
                hc_session_free(session);
                hc_cleanup();
                return RETURN_STORAGETEK_ERROR;
        }       /* if not successful */

	/* Loop up until the maximum result size */
	for (count = 0; count < cmdLine.maxResults; count++) 
	{
		/* Get the next result */
		res = hc_qrs_next_ez(rset, &returnedOid, &nvr, &finished);	

 		if (res != HCERR_OK)
   		{
			HandleError(session, res);
			hc_session_free(session);
			hc_cleanup();
			return RETURN_STORAGETEK_ERROR;
    		}	/* if not successful */

                if (finished)
                        break;

		/* Print the next result to standard output */
		if (cmdLine.cmdlineMetadata.mapSize > 0)
		{
			printMetadataResults(nvr, session);
		}
		else
		{
    			printOIDResults((char *) &returnedOid);
		}
	}	/* loop through results */

	res = hc_qrs_is_query_complete(rset,&query_complete);
	if (res != HCERR_OK) 
	{
    		HandleError(session, res);
    		response_code = RETURN_STORAGETEK_ERROR;
	}
	res = hc_qrs_get_query_integrity_time(rset,&query_integrity_time);
	if (res != HCERR_OK) 
	{
    		HandleError(session, res);
    		response_code = RETURN_STORAGETEK_ERROR;
	}

	printf("Query Integrity Status %s at time %lld\n",
	       query_complete ? "true" : "false",
	       query_integrity_time);

        res = hc_qrs_free(rset);

	if (res != HCERR_OK) 
	{
    		HandleError(session, res);
    		response_code = RETURN_STORAGETEK_ERROR;
	}

	hc_session_free(session);
	hc_cleanup();

        return exitApp(response_code);
}	/* main */
Пример #4
0
int hcez_mcellqry_simpletest_exec(test_case_t *tc) {
	char **argv = NULL;
	char *test_vip = NULL; 
	hcerr_t expected_res, res;
	hc_test_result_t test_res;
	int port;
	int32_t response_code;
	hc_system_record_t sys_rec, sys_rec2;
	hc_random_file_t *stored_r_file = NULL; 
	hctest_env_t *test_env;
	hc_nvr_t *nvr = NULL;
	hc_session_t *session;
	hc_oid oid;	
	hc_value_t value = HC_EMPTY_VALUE_INIT;
	hc_long_t long_return;
	int i, j, nPerFetch, nStored, nGotten;
	time_t t, t1, t2;
	hc_hashlist_t *stored = NULL;
	char query[1024];
	hc_query_result_set_t *rset = NULL;
	int finished;

	argv = tc->argv;
	expected_res = atoi(argv[0]);
	test_res = TEST_PASS;

	test_env = tc->test_env;
        if (test_env->n_cells == 0) {
		printf("Multicell cells not defined: SKIPPING\n");
		return TEST_PASS;
        }
	test_vip = test_env->data_vip;
	port = test_env->data_vip_port;
	
	hc_init(malloc,free,realloc);
	res = hc_session_create_ez(test_vip,port,&session);
	if (res != HCERR_OK) {
		hc_test_log(LOG_ERROR_LEVEL, test_env,
			"Session Create failed. Returned code of %s\n",
			hc_decode_hcerr(res));
		test_res = TEST_ERROR;
		goto done;
	}

	res = hc_nvr_create(session, 4, &nvr); 

	// Initialize test metadata value 

	time(&t);

        res = hc_nvr_add_long(nvr, LONG_NAME, t);
	if (res != HCERR_OK) {
		hc_test_log(LOG_ERROR_LEVEL, test_env,
			"hc_nvr_add_long failed. Returned code of %s\n",
			hc_decode_hcerr(res));
		test_res = TEST_ERROR;
		goto done;
	}
	res = hc_nvr_add_string(nvr, STRING_NAME, "hcezMulticellQuery.c all");
	if (res != HCERR_OK) {
		hc_test_log(LOG_ERROR_LEVEL, test_env,
			"hc_nvr_add_string failed. Returned code of %s\n",
			hc_decode_hcerr(res));
		test_res = TEST_ERROR;
		goto done;
	}

	sprintf(query, "%s=%d", LONG_NAME, t);

	// do stores

	printf("storing %d to each cell\n", MAX_PER_CELL);
	stored = create_hashlist(1024);
	nStored = 0;
	for (i=0; i<test_env->n_cells; i++) {
	    for (j=0; j<MAX_PER_CELL; j++) {
		
	        stored_r_file  = create_random_file(4); 

	        res = hc_store_both_cell_ez(session, 
                                test_env->cell_ids[i],
				read_from_random_data_generator, 
				stored_r_file, nvr, &sys_rec);
	        if (res != HCERR_OK) {
		    hc_test_log(LOG_ERROR_LEVEL, test_env,
			"Store of file to cell %d failed: %s\n",
	                test_env->cell_ids[i],
			hc_decode_hcerr(res));
		    test_res = TEST_ERROR;
		    goto done;
	        } 
	        hash_put(sys_rec.oid, "noval", stored);

	        if (j == 0)
	            printf("first in cell %d (hex %x): %s\n",
	                   test_env->cell_ids[i], test_env->cell_ids[i],
	                   sys_rec.oid);

		free_r_file(stored_r_file);
	        stored_r_file = NULL;
	        nStored++;
	    }
	}
	printf("Total stored %d\n", nStored);

	// do queries
	printf("Query: [%s]\n", query);
	for (nPerFetch=1; nPerFetch<MAX_PER_CELL+2; nPerFetch++) {
	    hc_hashlist_t *gotten = create_hashlist(1024);
	    printf("Fetch size = %d\n", nPerFetch);
	    nGotten = 0;

	    res = hc_query_ez(session, query, NULL, 0, nPerFetch, &rset);
	    if (res != HCERR_OK) {
		hc_test_log(LOG_ERROR_LEVEL, test_env,
	             "Query failed: %s\n", hc_decode_hcerr(res));
		test_res = TEST_FAIL;
		goto done;
	    }
	    finished = 0;
	    while (1) {
	        hc_oid return_oid;
	        res = hc_qrs_next_ez(rset, &return_oid, NULL, &finished);
	        if (res != HCERR_OK) {
		    hc_test_log(LOG_ERROR_LEVEL, test_env,
	                 "hc_qrs_next_ez failed: %s\n", hc_decode_hcerr(res));
		    test_res = TEST_FAIL;
		    goto done;
	        }
	        if (finished)
	            break;
	        if (!hashlist_contains_key(return_oid, stored)) {
	            hc_test_log(LOG_ERROR_LEVEL, test_env,
	                 "Unexpected oid returned [%s]\n", return_oid);
		    test_res = TEST_FAIL;
		    goto done;
	        }
                //printf("got %s\n", return_oid);
	        if (hashlist_contains_key(return_oid, gotten)) {
	            hc_test_log(LOG_ERROR_LEVEL, test_env,
	                 "Duplicate oid returned (oid %d) [%s]\n", 
	                 nGotten, return_oid);
		    test_res = TEST_FAIL;
	        }
	        hash_put(return_oid, "noval", gotten);
	        nGotten++;
	    }
	    res = hc_qrs_free(rset);
	    if (res != HCERR_OK) {
		hc_test_log(LOG_ERROR_LEVEL, test_env,
	             "hc_qrs_free failed: %s\n", hc_decode_hcerr(res));
		test_res = TEST_FAIL;
	    }
	    free_hashlist(gotten);

	    if (nGotten != nStored) {
		hc_test_log(LOG_ERROR_LEVEL, test_env,
	             "Stored %d but got %d\n", nStored, nGotten);
		test_res = TEST_FAIL;
	    }
	    if (test_res != TEST_PASS)
	        goto done;
	}
	free_hashlist(stored);
	stored = NULL;


	// Initialize test metadata value 

	time(&t);

        res = hc_nvr_add_long(nvr, LONG_NAME, t);
	if (res != HCERR_OK) {
		hc_test_log(LOG_ERROR_LEVEL, test_env,
			"hc_nvr_add_long failed. Returned code of %s\n",
			hc_decode_hcerr(res));
		test_res = TEST_ERROR;
		goto done;
	}
	res = hc_nvr_add_string(nvr, STRING_NAME, "hcezMulticellQuery.c odd");
	if (res != HCERR_OK) {
		hc_test_log(LOG_ERROR_LEVEL, test_env,
			"hc_nvr_add_string failed. Returned code of %s\n",
			hc_decode_hcerr(res));
		test_res = TEST_ERROR;
		goto done;
	}
	sprintf(query, "%s=%d", LONG_NAME, t);

	// do stores

	printf("storing %d to odd cells\n", MAX_PER_CELL);
	stored = create_hashlist(1024);
	nStored = 0;
	for (i=0; i<test_env->n_cells; i++) {
	    if (i % 2 == 0)
	        continue;

	    for (j=0; j<MAX_PER_CELL; j++) {
		
	        stored_r_file  = create_random_file(4); 

	        res = hc_store_both_cell_ez(session, 
                                test_env->cell_ids[i],
				read_from_random_data_generator, 
				stored_r_file, nvr, &sys_rec);
	        if (res != HCERR_OK) {
		    hc_test_log(LOG_ERROR_LEVEL, test_env,
			"Store of file to cell %d failed: %s\n",
	                test_env->cell_ids[i],
			hc_decode_hcerr(res));
		    test_res = TEST_ERROR;
		    goto done;
	        } 
	        hash_put(sys_rec.oid, "noval", stored);

	        if (j == 0)
	            printf("first in cell %d (hex %x): %s\n",
	                   test_env->cell_ids[i], test_env->cell_ids[i],
	                   sys_rec.oid);

		free_r_file(stored_r_file);
	        stored_r_file = NULL;
	        nStored++;
	    }
	}
	printf("Total stored %d\n", nStored);

	// do queries
	printf("Query: [%s]\n", query);
	for (nPerFetch=1; nPerFetch<MAX_PER_CELL+2; nPerFetch++) {
	    hc_hashlist_t *gotten = create_hashlist(1024);
	    printf("Fetch size = %d\n", nPerFetch);
	    nGotten = 0;

	    res = hc_query_ez(session, query, NULL, 0, nPerFetch, &rset);
	    if (res != HCERR_OK) {
		hc_test_log(LOG_ERROR_LEVEL, test_env,
	             "Query failed: %s\n", hc_decode_hcerr(res));
		test_res = TEST_FAIL;
		goto done;
	    }
	    finished = 0;
	    while (1) {
	        hc_oid return_oid;
	        res = hc_qrs_next_ez(rset, &return_oid, NULL, &finished);
	        if (res != HCERR_OK) {
		    hc_test_log(LOG_ERROR_LEVEL, test_env,
	                 "hc_qrs_next_ez failed: %s\n", hc_decode_hcerr(res));
		    test_res = TEST_FAIL;
		    goto done;
	        }
	        if (finished)
	            break;
	        if (!hashlist_contains_key(return_oid, stored)) {
	            hc_test_log(LOG_ERROR_LEVEL, test_env,
	                 "Unexpected oid returned [%s]\n", return_oid);
		    test_res = TEST_FAIL;
		    goto done;
	        }
                //printf("got %s\n", return_oid);
	        if (hashlist_contains_key(return_oid, gotten)) {
	            hc_test_log(LOG_ERROR_LEVEL, test_env,
	                 "Duplicate oid returned (oid %d) [%s]\n", 
	                 nGotten, return_oid);
		    test_res = TEST_FAIL;
	        }
	        hash_put(return_oid, "noval", gotten);
	        nGotten++;
	    }
	    free_hashlist(gotten);

	    res = hc_qrs_free(rset);
	    if (res != HCERR_OK) {
		hc_test_log(LOG_ERROR_LEVEL, test_env,
	             "hc_qrs_free failed: %s\n", hc_decode_hcerr(res));
		test_res = TEST_FAIL;
	    }
	    if (nGotten != nStored) {
		hc_test_log(LOG_ERROR_LEVEL, test_env,
	             "Stored %d but got %d\n", nStored, nGotten);
		test_res = TEST_FAIL;
	    }
	    if (test_res != TEST_PASS)
	        goto done;
	}

	// Initialize test metadata value 

	time(&t);

        res = hc_nvr_add_long(nvr, LONG_NAME, t);
	if (res != HCERR_OK) {
		hc_test_log(LOG_ERROR_LEVEL, test_env,
			"hc_nvr_add_long failed. Returned code of %s\n",
			hc_decode_hcerr(res));
		test_res = TEST_ERROR;
		goto done;
	}
	res = hc_nvr_add_string(nvr, STRING_NAME, "hcezMulticellQuery.c even");
	if (res != HCERR_OK) {
		hc_test_log(LOG_ERROR_LEVEL, test_env,
			"hc_nvr_add_string failed. Returned code of %s\n",
			hc_decode_hcerr(res));
		test_res = TEST_ERROR;
		goto done;
	}
	sprintf(query, "%s=%d", LONG_NAME, t);

	// do stores

	printf("storing %d to even cells\n", MAX_PER_CELL);
	stored = create_hashlist(1024);
	nStored = 0;
	for (i=0; i<test_env->n_cells; i++) {
	    if (i % 2 != 0)
	        continue;

	    for (j=0; j<MAX_PER_CELL; j++) {
		
	        stored_r_file  = create_random_file(4); 

	        res = hc_store_both_cell_ez(session, 
                                test_env->cell_ids[i],
				read_from_random_data_generator, 
				stored_r_file, nvr, &sys_rec);
	        if (res != HCERR_OK) {
		    hc_test_log(LOG_ERROR_LEVEL, test_env,
			"Store of file to cell %d failed: %s\n",
	                test_env->cell_ids[i],
			hc_decode_hcerr(res));
		    test_res = TEST_ERROR;
		    goto done;
	        } 
	        hash_put(sys_rec.oid, "noval", stored);

	        if (j == 0)
	            printf("first in cell %d (hex %x): %s\n",
	                   test_env->cell_ids[i], test_env->cell_ids[i],
	                   sys_rec.oid);

		free_r_file(stored_r_file);
	        stored_r_file = NULL;
	        nStored++;
	    }
	}
	printf("Total stored %d\n", nStored);

	// do queries
	printf("Query: [%s]\n", query);
	for (nPerFetch=1; nPerFetch<MAX_PER_CELL+2; nPerFetch++) {
	    hc_hashlist_t *gotten = create_hashlist(1024);
	    printf("Fetch size = %d\n", nPerFetch);
	    nGotten = 0;

	    res = hc_query_ez(session, query, NULL, 0, nPerFetch, &rset);
	    if (res != HCERR_OK) {
		hc_test_log(LOG_ERROR_LEVEL, test_env,
	             "Query failed: %s\n", hc_decode_hcerr(res));
		test_res = TEST_FAIL;
		goto done;
	    }
	    finished = 0;
	    while (1) {
	        hc_oid return_oid;
	        res = hc_qrs_next_ez(rset, &return_oid, NULL, &finished);
	        if (res != HCERR_OK) {
		    hc_test_log(LOG_ERROR_LEVEL, test_env,
	                 "hc_qrs_next_ez failed: %s\n", hc_decode_hcerr(res));
		    test_res = TEST_FAIL;
		    goto done;
	        }
	        if (finished)
	            break;
	        if (!hashlist_contains_key(return_oid, stored)) {
	            hc_test_log(LOG_ERROR_LEVEL, test_env,
	                 "Unexpected oid returned [%s]\n", return_oid);
		    test_res = TEST_FAIL;
		    goto done;
	        }
                //printf("got %s\n", return_oid);
	        if (hashlist_contains_key(return_oid, gotten)) {
	            hc_test_log(LOG_ERROR_LEVEL, test_env,
	                 "Duplicate oid returned (oid %d) [%s]\n", 
	                 nGotten, return_oid);
		    test_res = TEST_FAIL;
	        }
	        hash_put(return_oid, "noval", gotten);
	        nGotten++;
	    }
	    res = hc_qrs_free(rset);
	    if (res != HCERR_OK) {
		hc_test_log(LOG_ERROR_LEVEL, test_env,
	             "hc_qrs_free failed: %s\n", hc_decode_hcerr(res));
		test_res = TEST_FAIL;
	    }
	    free_hashlist(gotten);

	    if (nGotten != nStored) {
		hc_test_log(LOG_ERROR_LEVEL, test_env,
	             "Stored %d but got %d\n", nStored, nGotten);
		test_res = TEST_FAIL;
	    }
	    if (test_res != TEST_PASS)
	        goto done;
	}

done:
	if (nvr != NULL)
		hc_nvr_free(nvr);
	if (stored_r_file != NULL)
		free_r_file(stored_r_file);
	free_hashlist(stored);
	hc_session_free(session);
	return test_res;
}