Esempio n. 1
0
sc_memory_context* sc_memory_initialize(const sc_memory_params *params)
{
    g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL);

    sc_config_initialize(params->config_file);

    s_context_hash_table = g_hash_table_new(g_direct_hash, g_direct_equal);

    char *v_str = sc_version_string_new(&SC_VERSION);
    g_message("Version: %s", v_str);
    sc_version_string_free(v_str);

    g_message("Configuration:");
    g_message("\tmax_loaded_segments: %d", sc_config_get_max_loaded_segments());
    g_message("sc-element size: %zd", sizeof(sc_element));

    if (sc_storage_initialize(params->repo_path, params->clear) != SC_TRUE)
        return 0;

    s_memory_default_ctx = sc_memory_context_new(sc_access_lvl_make(SC_ACCESS_LVL_MAX_VALUE, SC_ACCESS_LVL_MAX_VALUE));
    sc_memory_context *helper_ctx = sc_memory_context_new(sc_access_lvl_make(SC_ACCESS_LVL_MIN_VALUE, SC_ACCESS_LVL_MAX_VALUE));
    if (sc_helper_init(helper_ctx) != SC_RESULT_OK)
        goto error;
    sc_memory_context_free(helper_ctx);

    if (sc_events_initialize() == SC_FALSE)
    {
        g_error("Error while initialize events module");
        goto error;
    }

    sc_result ext_res;
    ext_res = sc_ext_initialize(params->ext_path);

    switch (ext_res)
    {
    case SC_RESULT_OK:
        g_message("Modules initialization finished");
        return s_memory_default_ctx;

    case SC_RESULT_ERROR_INVALID_PARAMS:
        g_warning("Extensions directory '%s' doesn't exist", params->ext_path);
        break;

    default:
        g_warning("Unknown error while initialize extensions");
        break;
    }

    error:
    {
        if (helper_ctx)
            sc_memory_context_free(helper_ctx);
        sc_memory_context_free(s_memory_default_ctx);
    }
    return s_memory_default_ctx = 0;
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
    sc_uint item = -1;

    fflush(stdout);
    timer = g_timer_new();
    g_timer_start(timer);

    printf("MD5: %d\n", g_checksum_type_get_length(G_CHECKSUM_MD5) );
    printf("SHA1: %d\n", g_checksum_type_get_length(G_CHECKSUM_SHA1) );
    printf("SHA256: %d\n", g_checksum_type_get_length(G_CHECKSUM_SHA256) );

    sc_storage_initialize("repo");
    g_timer_stop(timer);
    printf("Segment loading speed: %f seg/sec\n", sc_storage_get_segments_count() / g_timer_elapsed(timer, 0));

    //test5();
    //test6();

    //test7();

    while (item != 0)
    {
        printf("Commands:\n"
               "0 - exit\n"
               "1 - test allocation\n"
               "2 - test sc-addr utilities\n"
               "3 - test arc deletion\n"
               "4 - test iterators\n"
               "5 - test contents\n"
               "6 - test content finding\n"
               "7 - test events\n"
               "\nCommand: ");
        scanf("%d", &item);

        printf("\n----- Test %d -----\n", item);

        switch(item)
        {
        case 1:
            test1();
            break;

        case 2:
            test2();
            break;

        case 3:
            test3();
            break;

        case 4:
            test4();
            break;

        case 5:
            test5();
            break;

        case 6:
            test6();
            break;

        case 7:
            test7();
            break;
        };

        printf("\n----- Finished -----\n");
    }

    timer = g_timer_new();
    item = sc_storage_get_segments_count();
    g_timer_reset(timer); // crash when uncomment

    sc_storage_shutdown();
    g_timer_stop(timer);
    printf("Segments save speed: %f seg/sec\n", item / g_timer_elapsed(timer, 0));
    g_timer_destroy(timer);

    return 0;
}