示例#1
0
/**
 *	We allocate the vhash pointer; caller owns thereafter
 */
void SG_dbrecord__to_vhash(SG_context* pCtx, SG_dbrecord* prec, SG_vhash** ppVh)
{
	SG_NULLARGCHECK_RETURN(prec);
	SG_NULLARGCHECK_RETURN(ppVh);

	SG_ERR_CHECK_RETURN(  SG_vhash__sort(pCtx, prec->pvh, SG_FALSE, SG_vhash_sort_callback__increasing)  );
	SG_ERR_CHECK(  SG_VHASH__ALLOC__COPY(pCtx, ppVh, prec->pvh)  );

	return;

fail:
	SG_VHASH_NULLFREE(pCtx, *ppVh);
}
示例#2
0
void SG_localsettings__foreach(
	SG_context* pCtx,
	const char* szPattern,
	SG_bool bIncludeDefaults,
	SG_localsettings_foreach_callback* pCallback,
	void* pCallerData
	)
{
	SG_vhash* pValues = NULL;
	SG_vhash* pDefaults = NULL;
	provide_matching_values__data ProvideMatchingValuesData = {NULL, NULL, NULL, NULL};

	SG_UNUSED(pCallback);
	SG_UNUSED(pCallerData);

	// get the settings
	SG_ERR_CHECK(  SG_localsettings__list__vhash(pCtx, &pValues)  );

	// if defaults were requested, get those too
	if (bIncludeDefaults)
	{
		SG_ERR_CHECK(  SG_localsettings__factory__list__vhash(pCtx, &pDefaults)  );
		SG_ERR_CHECK(  SG_vhash__add__vhash(pCtx, pValues, SG_LOCALSETTING__SCOPE__DEFAULT + 1, &pDefaults)  ); // +1 to remove the slash at the beginning
	}

	// sort the settings
	SG_ERR_CHECK(  SG_vhash__sort(pCtx, pValues, SG_TRUE, SG_vhash_sort_callback__increasing)  );

	// setup our callback data
	SG_ERR_CHECK(  SG_STRING__ALLOC(pCtx, &(ProvideMatchingValuesData.pPrefix))  );
	ProvideMatchingValuesData.szPattern = szPattern;
	ProvideMatchingValuesData.pCallback = pCallback;
	ProvideMatchingValuesData.pCallerData = pCallerData;

	// iterate through the vhash
	SG_ERR_CHECK(  SG_vhash__foreach(pCtx, pValues, provide_matching_values, &ProvideMatchingValuesData)  );

fail:
	SG_VHASH_NULLFREE(pCtx, pValues);
	SG_VHASH_NULLFREE(pCtx, pDefaults);
	SG_STRING_NULLFREE(pCtx, ProvideMatchingValuesData.pPrefix);
}
示例#3
0
/**
 * Write a vhash table in JSON format.  This function handles all the details of
 * setting up the SG_jsonwriter and places the output stream in the given string.
 */
void SG_dbrecord__to_json(SG_context* pCtx, SG_dbrecord* prec, SG_string* pStr)
{
	SG_NULLARGCHECK_RETURN(prec);
	SG_ERR_CHECK_RETURN(  SG_vhash__sort(pCtx, prec->pvh, SG_FALSE, SG_vhash_sort_callback__increasing)  );
	SG_ERR_CHECK_RETURN(  SG_vhash__to_json(pCtx, prec->pvh, pStr)  );
}
static void SG_db__make_delta_from_path(
    SG_context* pCtx,
    SG_repo* pRepo,
    SG_uint64 dagnum,
    SG_varray* pva_path,
    SG_uint32 flags,
    SG_vhash* pvh_add,
    SG_vhash* pvh_remove
    )
{
#if SG_DOUBLE_CHECK__CALC_DELTA
    SG_int64 t1 = -1;
    SG_int64 t2 = -1;
    SG_vhash* new_pvh_add = NULL;
    SG_vhash* new_pvh_remove = NULL;
    SG_vhash* old_pvh_add = NULL;
    SG_vhash* old_pvh_remove = NULL;
    SG_string* old_pstr = NULL;
    SG_string* new_pstr = NULL;

    SG_ERR_CHECK(  SG_vhash__alloc__copy(pCtx, &new_pvh_add, pvh_add)  );
    SG_ERR_CHECK(  SG_vhash__alloc__copy(pCtx, &new_pvh_remove, pvh_remove)  );
    SG_ERR_CHECK(  SG_vhash__alloc__copy(pCtx, &old_pvh_add, pvh_add)  );
    SG_ERR_CHECK(  SG_vhash__alloc__copy(pCtx, &old_pvh_remove, pvh_remove)  );

    SG_ERR_CHECK(  SG_time__get_milliseconds_since_1970_utc(pCtx, &t1)  );
    SG_ERR_CHECK(  old_SG_db__make_delta_from_path(
                pCtx,
                pRepo,
                dagnum,
                pva_path,
                old_pvh_add,
                old_pvh_remove
                )  );
    SG_ERR_CHECK(  SG_time__get_milliseconds_since_1970_utc(pCtx, &t2)  );
    {
        SG_uint32 path_length = 0;
        SG_ERR_CHECK(  SG_varray__count(pCtx, pva_path, &path_length)  );
        fprintf(stderr, "make_delta_from_path (%d)\n", path_length);
    }
    fprintf(stderr, "  time old %d ms\n", (int) (t2 - t1));

    SG_ERR_CHECK(  SG_vhash__sort(pCtx, old_pvh_add, SG_FALSE, SG_vhash_sort_callback__increasing)  );
    SG_ERR_CHECK(  SG_vhash__sort(pCtx, old_pvh_remove, SG_FALSE, SG_vhash_sort_callback__increasing)  );

    SG_ERR_CHECK(  SG_time__get_milliseconds_since_1970_utc(pCtx, &t1)  );
    SG_ERR_CHECK(  SG_repo__dbndx__make_delta_from_path(
                pCtx,
                pRepo,
                dagnum,
                pva_path,
                0,
                new_pvh_add,
                new_pvh_remove
                )  );
    SG_ERR_CHECK(  SG_time__get_milliseconds_since_1970_utc(pCtx, &t2)  );
    fprintf(stderr, "  time new %d ms\n", (int) (t2 - t1));
    SG_ERR_CHECK(  SG_vhash__sort(pCtx, new_pvh_add, SG_FALSE, SG_vhash_sort_callback__increasing)  );
    SG_ERR_CHECK(  SG_vhash__sort(pCtx, new_pvh_remove, SG_FALSE, SG_vhash_sort_callback__increasing)  );

    SG_ERR_CHECK(  SG_string__alloc(pCtx, &old_pstr)  );
    SG_ERR_CHECK(  SG_vhash__to_json(pCtx, old_pvh_add, old_pstr)  );
    SG_ERR_CHECK(  SG_string__alloc(pCtx, &new_pstr)  );
    SG_ERR_CHECK(  SG_vhash__to_json(pCtx, new_pvh_add, new_pstr)  );

    if (0 != strcmp(SG_string__sz(old_pstr), SG_string__sz(new_pstr)))
    {
        fprintf(stderr, "oldway:\n");
        SG_VHASH_STDERR(old_pvh_add);
        fprintf(stderr, "new:\n");
        SG_VHASH_STDERR(new_pvh_add);

        SG_ERR_THROW(  SG_ERR_UNSPECIFIED  );
    }

    SG_STRING_NULLFREE(pCtx, old_pstr);
    SG_STRING_NULLFREE(pCtx, new_pstr);

    SG_ERR_CHECK(  SG_string__alloc(pCtx, &old_pstr)  );
    SG_ERR_CHECK(  SG_vhash__to_json(pCtx, old_pvh_remove, old_pstr)  );
    SG_ERR_CHECK(  SG_string__alloc(pCtx, &new_pstr)  );
    SG_ERR_CHECK(  SG_vhash__to_json(pCtx, new_pvh_remove, new_pstr)  );

    if (0 != strcmp(SG_string__sz(old_pstr), SG_string__sz(new_pstr)))
    {
        fprintf(stderr, "oldway:\n");
        SG_VHASH_STDERR(old_pvh_remove);
        fprintf(stderr, "new:\n");
        SG_VHASH_STDERR(new_pvh_remove);

        SG_ERR_THROW(  SG_ERR_UNSPECIFIED  );
    }
#endif

#if SG_DOUBLE_CHECK__CALC_DELTA
    SG_ERR_CHECK(  SG_time__get_milliseconds_since_1970_utc(pCtx, &t1)  );
#endif
    SG_ERR_CHECK(  SG_repo__dbndx__make_delta_from_path(
                pCtx,
                pRepo,
                dagnum,
                pva_path,
                flags,
                pvh_add,
                pvh_remove
                )  );
#if SG_DOUBLE_CHECK__CALC_DELTA
    SG_ERR_CHECK(  SG_time__get_milliseconds_since_1970_utc(pCtx, &t2)  );
    fprintf(stderr, "  time NEW %d ms\n", (int) (t2 - t1));
#endif

fail:
#if SG_DOUBLE_CHECK__CALC_DELTA
    SG_STRING_NULLFREE(pCtx, old_pstr);
    SG_STRING_NULLFREE(pCtx, new_pstr);

    SG_VHASH_NULLFREE(pCtx, old_pvh_add);
    SG_VHASH_NULLFREE(pCtx, old_pvh_remove);
    SG_VHASH_NULLFREE(pCtx, new_pvh_add);
    SG_VHASH_NULLFREE(pCtx, new_pvh_remove);
#endif
    ;
}