- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在使用 gdbus
和 gdbus-codegen
在 D-Bus 上创建服务。
自省(introspection)是这样的:
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="com.example.foo">
<property name="Bar" type="s" access="readwrite" />
</interface>
</node>
我正在像这样执行 gdbus-codegen
:
gdbus-codegen --interface-prefix com.example --generate-c-code=foo foo.xml
我的 main.cpp 看起来像这样:
#include <iostream>
#include "foo.h"
void OnBarChanged(GObject * gobject, GParamSpec * pspec, gpointer user_data)
{
std::cout << "Bar: " << foo_get_bar((Foo *)gobject) << std::endl;
}
void OnBusNameAquired(GDBusConnection * connection,
const gchar * name,
gpointer user_data)
{
Foo * foo = foo_skeleton_new();
g_signal_connect(foo, "notify::bar", G_CALLBACK(&OnBarChanged), NULL);
g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(foo),
connection,
"/com/example/foo",
NULL);
}
int main()
{
std::cout << "Testing DBus properties" << std::endl;
GMainLoop * loop;
loop = g_main_loop_new(NULL, FALSE);
g_bus_own_name(G_BUS_TYPE_SESSION,
"com.example.foo",
G_BUS_NAME_OWNER_FLAGS_NONE,
NULL,
OnBusNameAquired,
NULL,
NULL,
NULL);
g_main_loop_run(loop);
return 0;
}
这按预期工作,我能够使用以下方法设置和获取属性:
gdbus call --session --dest com.example.foo --object-path /com/example/foo --method org.freedesktop.DBus.Properties.Set "com.example.foo" "Bar" "<'baz'>"
和
gdbus call --session --dest com.example.foo --object-path /com/example/foo --method org.freedesktop.DBus.Properties.Get "com.example.foo" "Bar"
(<'baz'>,)
问题:
我想同步验证属性的设置,并在失败时返回错误。如何使用 gdbus-codegen
生成的代码来实现这一点?
附言:
代码泄露,通常不适合生产。我现在没问题:-)
编辑
经过继续研究,似乎 D-Bus 属性正在使用底层的 GObject
属性功能。当所有这些都由 gdbus-codegen
-code 设置时,是否可以安装自定义验证器?
最佳答案
连接到 GDBusInterfaceSkeleton::g-authorize-method
来自 foo
骨架的信号。您的回调将针对您导出的对象处理的每个 D-Bus 方法调用被调用——您可以在 org.freedesktop.DBus.Properties.Set
上匹配然后调用并进行验证。
在 flatpak 中有一个这样的例子(对于任意方法调用,不是 D-Bus 属性设置;但原理是一样的):https://github.com/flatpak/flatpak/blob/c915f73b41688a7dc2ec7f0ab2fbcf1a7c738841/system-helper/flatpak-system-helper.c#L1192
关于c++ - 使用 gdbus-codegen 骨架时如何验证 D-Bus 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37541857/
我需要一种方法来注释我的 openapi 3 规范,以便 swagger-codegen 将注释添加到我的 java 类中,例如 @JsonIgnoreProperties(ignoreUnknown
我升级到 swagger-codegen 3.0.10,屏幕上突然出现大量调试输出。似乎没有关闭它的命令行选项。 有谁知道如何关闭调试输出? 最佳答案 想通了。 Swagger-codegen 使用
我正在尝试使用 https://github.com/swagger-api/swagger-codegen 生成 nodejs 客户端 sdk这是我使用的命令 swagger-codegen gen
I would like to ask if there is a Swagger tool that can generate clients according to the latest
在我的 package.json 文件中,我有运行 graphql-codegen 的脚本条目,但它提示 --config 参数无效: $> yarn gen yarn run v1.21.1 $ g
我有一个.Net Core v2.1 Web API,它使用NSwag生成其Swagger Json。 我有一个这样的响应模型- public class LoginResponse { pu
我正在使用 slick 2.x's codegen从数据库模式生成 Scala 模型的功能。但是,是否可以遍历外键约束以生成相关模型,例如如果我有这个架构 CREATE TABLE people(id
我如何才能获得敏捷的代码生成器,以使用现有的类而不是创建新的类?这可能吗?例如,我想使用org.springframework.data.domain.Page而不是大张旗鼓地创建另一个页面类。 最佳
我正在寻找进入 Swagger,更具体地说,swagger-codegen 工具。我在 github 和 http://swagger.io/ 中都找到了提供的信息、文档和规范。相当困惑(另外,一些指
我正在使用 swagger codegen maven 插件从 swagger 规范生成服务器 stub 。如果我运行 mvn compile然后它正确生成并编译项目。但是,有时我只想运行生成。 具体
我正在尝试从包含的 yaml 生成客户端 acceptParam: name: Accept type: string required: true in: hea
我遇到了 apollo-codegen 未成功生成 typescript 代码的情况。 对于 graphql 文件( generated/schema.graphql ): type Author {
我已经为特定 API 生成了带有 swagger codegen 的客户端应用程序,javascript版本。用 npm 等初始化它。一切都拍手。 然而,当我尝试使用生成的 api 从我的本地主机向
我已经生成了一个 swagger 客户端 api: java -jar swagger-codegen-2.2.3/modules/swagger-codegen-cli/target/swagger
我在 Postgres 中有一个如下所示的设置: CREATE TYPE my_enum AS ENUM ( 'left', 'right'); CREATE TABLE my_table ( dir
我正在尝试使用 codegen 将以下 Matlab 代码转换为 C++。但是它在构建时失败了,我得到了错误: "??? Unless 'rows' is specified, the first i
我目前正在尝试建立一个 Maven 项目,该项目根据一些 WSDL 文件生成一些 Java 代码。 不幸的是,我遇到了一些问题,因为我的测试环境没有有效的 SSL 证书(我已使用 chrome 确认了
我正在使用 swagger/swagger-codegen 实现我的第二个 API。在有了第一个良好的开端之后,我有点陷入以下问题:我有多个定义,如下所示: TopIssueReference:
我需要根据提供的 swagger 文件生成类。不幸的是我对此文件的内容没有影响。 我在 Gladle 中的配置如下所示: task generateApi { doLast { def con
我想从 xml 文件创建 java 类。我用的是JIBX。我试试这个: java -cp C:\Documents and Settings\kliver\Мои документы\Загрузки
我是一名优秀的程序员,十分优秀!