Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
"react-dom": "18.2.0",
"react-icons": "^4.4.0",
"react-syntax-highlighter": "^15.5.0",
"sass": "^1.54.0"
"sass": "^1.71.1"
},
"devDependencies": {
"@types/node": "18.6.3",
"@types/react": "18.0.15",
"@types/node": "20.11.24",
"@types/react": "18.2.61",
"@types/react-dom": "18.0.6",
"eslint": "8.20.0",
"eslint-config-next": "12.2.3",
"gh-pages": "^4.0.0",
"typescript": "4.7.4"
"typescript": "5.3.3"
}
}
6 changes: 6 additions & 0 deletions src/components/articles/glibTutorial/chapters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Installing from "./installing";
import GDBusServerExample from "./gdbusServerExample";
import ProxyClientExample from "./proxyClientExample";
import BindingInterfaceIntoObject from "./bindingInterfaceIntoObject";
import InteractWithASV from "./interactWithASV";

const routerData = [
{
Expand All @@ -29,6 +30,11 @@ const routerData = [
id: 4,
title: 'Binding Object',
component: <BindingInterfaceIntoObject/>
},
{
id: 5,
title: 'Interact with a{sv}',
component: <InteractWithASV/>
}
]

Expand Down
65 changes: 65 additions & 0 deletions src/components/articles/glibTutorial/chapters/interactWithASV.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,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&#123;sv&#125;</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
42 changes: 29 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -964,10 +964,12 @@
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.182.tgz#05301a4d5e62963227eaafe0ce04dd77c54ea5c2"
integrity sha512-/THyiqyQAP9AfARo4pF+aCGcyiQ94tX/Is2I7HofNRqoYLgN1PBoOWu2/zTA5zMxzP5EFutMtWtGAFRKUe961Q==

"@types/node@18.6.3":
version "18.6.3"
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.6.3.tgz#4e4a95b6fe44014563ceb514b2598b3e623d1c98"
integrity sha512-6qKpDtoaYLM+5+AFChLhHermMQxc3TOEFIDzrZLPRGHPrLEwqFkkT5Kx3ju05g6X7uDPazz3jHbKPX0KzCjntg==
"@types/node@20.11.24":
version "20.11.24"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.11.24.tgz#cc207511104694e84e9fb17f9a0c4c42d4517792"
integrity sha512-Kza43ewS3xoLgCEpQrsT+xRo/EJej1y0kVYGiLFE1NEODXGzTfwiC6tXTLMQskn1X4/Rjlh0MQUvx9W+L9long==
dependencies:
undici-types "~5.26.4"

"@types/parse-json@^4.0.0":
version "4.0.0"
Expand All @@ -993,7 +995,7 @@
dependencies:
"@types/react" "*"

"@types/react@*", "@types/react@18.0.15", "@types/react@^18.0.1":
"@types/react@*", "@types/react@^18.0.1":
version "18.0.15"
resolved "https://registry.yarnpkg.com/@types/react/-/react-18.0.15.tgz#d355644c26832dc27f3e6cbf0c4f4603fc4ab7fe"
integrity sha512-iz3BtLuIYH1uWdsv6wXYdhozhqj20oD4/Hk2DNXIn1kFsmp9x8d9QB6FnPhfkbhd2PgEONt9Q1x/ebkwjfFLow==
Expand All @@ -1002,6 +1004,15 @@
"@types/scheduler" "*"
csstype "^3.0.2"

"@types/react@18.2.61":
version "18.2.61"
resolved "https://registry.yarnpkg.com/@types/react/-/react-18.2.61.tgz#5607308495037436779939ec0348a5816c08799d"
integrity sha512-NURTN0qNnJa7O/k4XUkEW2yfygA+NxS0V5h1+kp9jPwhzZy95q3ADoGMP0+JypMhrZBTTgjKAUlTctde1zzeQA==
dependencies:
"@types/prop-types" "*"
"@types/scheduler" "*"
csstype "^3.0.2"

"@types/scheduler@*":
version "0.16.2"
resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.2.tgz#1a62f89525723dde24ba1b01b092bf5df8ad4d39"
Expand Down Expand Up @@ -2969,10 +2980,10 @@ safe-buffer@~5.1.1:
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==

sass@^1.54.0:
version "1.54.0"
resolved "https://registry.yarnpkg.com/sass/-/sass-1.54.0.tgz#24873673265e2a4fe3d3a997f714971db2fba1f4"
integrity sha512-C4zp79GCXZfK0yoHZg+GxF818/aclhp9F48XBu/+bm9vXEVAYov9iU3FBVRMq3Hx3OA4jfKL+p2K9180mEh0xQ==
sass@^1.71.1:
version "1.71.1"
resolved "https://registry.yarnpkg.com/sass/-/sass-1.71.1.tgz#dfb09c63ce63f89353777bbd4a88c0a38386ee54"
integrity sha512-wovtnV2PxzteLlfNzbgm1tFXPLoZILYAMJtvoXXkD7/+1uP41eKkIt1ypWq5/q2uT94qHjXehEYfmjKOvjL9sg==
dependencies:
chokidar ">=3.0.0 <4.0.0"
immutable "^4.0.0"
Expand Down Expand Up @@ -3204,10 +3215,10 @@ type-fest@^0.20.2:
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.20.2.tgz#1bf207f4b28f91583666cb5fbd327887301cd5f4"
integrity sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==

typescript@4.7.4:
version "4.7.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.7.4.tgz#1a88596d1cf47d59507a1bcdfb5b9dfe4d488235"
integrity sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==
typescript@5.3.3:
version "5.3.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.3.3.tgz#b3ce6ba258e72e6305ba66f5c9b452aaee3ffe37"
integrity sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==

unbox-primitive@^1.0.2:
version "1.0.2"
Expand All @@ -3219,6 +3230,11 @@ unbox-primitive@^1.0.2:
has-symbols "^1.0.3"
which-boxed-primitive "^1.0.2"

undici-types@~5.26.4:
version "5.26.5"
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617"
integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==

universalify@^0.1.0:
version "0.1.2"
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66"
Expand Down