Skip to content

feat: add dbus document for get a{sv} #1

@TGLuong

Description

@TGLuong

For building a{sv} dbus message, i usally use GVariantBuilder because it have cleaning syntax and effective in preventing leak memory. Example:

GVariantBuilder builder;
g_variant_builder_add(&builder, "{sv}", "name", g_variant_new_string("gia luong"));
g_variant_builder_add(&builder, "{sv}", "birth", g_variant_new_uint32(2000));
GVariant *variant = g_variant_builder_end(&builder);

For get value from an a{sv}, just use g_variant_lookup_value because the simple of syntax

std::string name;
if ((value = g_variant_lookup_value(variant, "name", G_VARIANT_TYPE_STRING)) != nullptr)
{
    name = g_variant_get_uint32(value);
    g_variant_unref(value);
}

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions