From 75cdcd2ec1f8f1e40c17aa19a4716037e4ccfc27 Mon Sep 17 00:00:00 2001 From: Gia Luong Date: Sat, 23 Mar 2024 00:06:24 +0700 Subject: [PATCH] feat: update asv --- package.json | 8 +-- .../articles/glibTutorial/chapters/index.tsx | 6 ++ .../glibTutorial/chapters/interactWithASV.tsx | 65 +++++++++++++++++++ yarn.lock | 42 ++++++++---- 4 files changed, 104 insertions(+), 17 deletions(-) create mode 100644 src/components/articles/glibTutorial/chapters/interactWithASV.tsx diff --git a/package.json b/package.json index 804d152..645d0d3 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/src/components/articles/glibTutorial/chapters/index.tsx b/src/components/articles/glibTutorial/chapters/index.tsx index b377500..afda83b 100644 --- a/src/components/articles/glibTutorial/chapters/index.tsx +++ b/src/components/articles/glibTutorial/chapters/index.tsx @@ -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 = [ { @@ -29,6 +30,11 @@ const routerData = [ id: 4, title: 'Binding Object', component: + }, + { + id: 5, + title: 'Interact with a{sv}', + component: } ] diff --git a/src/components/articles/glibTutorial/chapters/interactWithASV.tsx b/src/components/articles/glibTutorial/chapters/interactWithASV.tsx new file mode 100644 index 0000000..0e33a09 --- /dev/null +++ b/src/components/articles/glibTutorial/chapters/interactWithASV.tsx @@ -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 ( + <> +
+

Example show how to build gvariant using builder

+

+ When using dbus as an IPC protocol, you must use

GVariant

for comunication, example as argument of method or property. + Common use of

GVariant

is

a{sv}

becase of this dynamic, easy to add or get element. +

+ {builder_example} +

+ For the extraction of gvariant, use

g_variant_lookup_value

to get value and don't forget to free it +

+ {etract_example} +
+ + ) +} + +export default InteractWithASV \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 02b211c..e856fa5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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== @@ -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" @@ -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" @@ -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" @@ -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"