-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinteractWithASV.tsx
More file actions
65 lines (57 loc) · 2.19 KB
/
Copy pathinteractWithASV.tsx
File metadata and controls
65 lines (57 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { Code } from "components/common"
import styles from 'styles/scss/articles/page.module.scss'
const builder_example =
`
GVariant *variant = NULL, *value = NULL;
GVariantBuilder builder;
g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);
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));
g_variant_builder_add(&builder, "{sv}", "title", g_variant_new_string("software engineer"));
g_variant_builder_add(&builder, "{sv}", "country", g_variant_new_string("Viet Nam"));
variant = g_variant_builder_end(&builder);
`
const etract_example =
`
const char *name, *title, *country;
uint32_t birth;
if ((value = g_variant_lookup_value(variant, "name", G_VARIANT_TYPE_STRING)) != NULL)
{
name = g_variant_get_string(value, NULL);
g_variant_unref(value);
}
if ((value = g_variant_lookup_value(variant, "birth", G_VARIANT_TYPE_UINT32)) != NULL)
{
birth = g_variant_get_uint32(value);
g_variant_unref(value);
}
if ((value = g_variant_lookup_value(variant, "title", G_VARIANT_TYPE_STRING)) != NULL)
{
title = g_variant_get_string(value, NULL);
g_variant_unref(value);
}
if ((value = g_variant_lookup_value(variant, "country", G_VARIANT_TYPE_STRING)) != NULL)
{
country = g_variant_get_string(value, NULL);
g_variant_unref(value);
}
`
const InteractWithASV = () => {
return (
<>
<div className={styles.root}>
<h1 className={styles.header}>Example show how to build gvariant using builder</h1>
<p>
When using dbus as an IPC protocol, you must use <p className={styles.quote}>GVariant</p> for comunication, example as argument of method or property.
Common use of <p className={styles.quote}>GVariant</p> is <p className={styles.quote}>a{sv}</p> becase of this dynamic, easy to add or get element.
</p>
<Code lang={'cpp'}>{builder_example}</Code>
<p>
For the extraction of gvariant, use <p className={styles.quote}>g_variant_lookup_value</p> to get value and don't forget to free it
</p>
<Code lang={'cpp'}>{etract_example}</Code>
</div>
</>
)
}
export default InteractWithASV