Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
dabaa05d
L
libvirt
项目概览
openeuler
/
libvirt
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libvirt
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
dabaa05d
编写于
12月 22, 2016
作者:
D
Daniel P. Berrange
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
examples: add secret events to event demo program
Signed-off-by:
N
Daniel P. Berrange
<
berrange@redhat.com
>
上级
06fcee63
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
72 addition
and
0 deletion
+72
-0
examples/object-events/event-test.c
examples/object-events/event-test.c
+72
-0
未找到文件。
examples/object-events/event-test.c
浏览文件 @
dabaa05d
...
...
@@ -370,6 +370,24 @@ nodeDeviceEventToString(int event)
}
static
const
char
*
secretEventToString
(
int
event
)
{
switch
((
virSecretEventLifecycleType
)
event
)
{
case
VIR_SECRET_EVENT_DEFINED
:
return
"Defined"
;
case
VIR_SECRET_EVENT_UNDEFINED
:
return
"Undefined"
;
case
VIR_SECRET_EVENT_LAST
:
break
;
}
return
"unknown"
;
}
static
int
myDomainEventCallback1
(
virConnectPtr
conn
ATTRIBUTE_UNUSED
,
virDomainPtr
dom
,
...
...
@@ -728,6 +746,23 @@ myNodeDeviceEventUpdateCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
}
static
int
mySecretEventCallback
(
virConnectPtr
conn
ATTRIBUTE_UNUSED
,
virSecretPtr
secret
,
int
event
,
int
detail
,
void
*
opaque
ATTRIBUTE_UNUSED
)
{
char
uuid
[
VIR_UUID_STRING_BUFLEN
];
virSecretGetUUIDString
(
secret
,
uuid
);
printf
(
"%s EVENT: Secret %s %s %d
\n
"
,
__func__
,
uuid
,
secretEventToString
(
event
),
detail
);
return
0
;
}
static
void
eventTypedParamsPrint
(
virTypedParameterPtr
params
,
int
nparams
)
...
...
@@ -1038,10 +1073,25 @@ struct nodeDeviceEventData nodeDeviceEvents[] = {
NODE_DEVICE_EVENT
(
VIR_NODE_DEVICE_EVENT_ID_UPDATE
,
myNodeDeviceEventUpdateCallback
),
};
struct
secretEventData
{
int
event
;
int
id
;
virConnectSecretEventGenericCallback
cb
;
const
char
*
name
;
};
#define SECRET_EVENT(event, callback) \
{event, -1, VIR_SECRET_EVENT_CALLBACK(callback), #event}
struct
secretEventData
secretEvents
[]
=
{
SECRET_EVENT
(
VIR_SECRET_EVENT_ID_LIFECYCLE
,
mySecretEventCallback
),
};
/* make sure that the events are kept in sync */
verify
(
ARRAY_CARDINALITY
(
domainEvents
)
==
VIR_DOMAIN_EVENT_ID_LAST
);
verify
(
ARRAY_CARDINALITY
(
storagePoolEvents
)
==
VIR_STORAGE_POOL_EVENT_ID_LAST
);
verify
(
ARRAY_CARDINALITY
(
nodeDeviceEvents
)
==
VIR_NODE_DEVICE_EVENT_ID_LAST
);
verify
(
ARRAY_CARDINALITY
(
secretEvents
)
==
VIR_SECRET_EVENT_ID_LAST
);
int
main
(
int
argc
,
char
**
argv
)
...
...
@@ -1149,6 +1199,22 @@ main(int argc, char **argv)
}
}
/* register common secret callbacks */
for
(
i
=
0
;
i
<
ARRAY_CARDINALITY
(
secretEvents
);
i
++
)
{
struct
secretEventData
*
event
=
secretEvents
+
i
;
event
->
id
=
virConnectSecretEventRegisterAny
(
dconn
,
NULL
,
event
->
event
,
event
->
cb
,
strdup
(
event
->
name
),
myFreeFunc
);
if
(
event
->
id
<
0
)
{
fprintf
(
stderr
,
"Failed to register event '%s'
\n
"
,
event
->
name
);
goto
cleanup
;
}
}
if
((
callback1ret
==
-
1
)
||
(
callback16ret
==
-
1
))
goto
cleanup
;
...
...
@@ -1191,6 +1257,12 @@ main(int argc, char **argv)
virConnectNodeDeviceEventDeregisterAny
(
dconn
,
nodeDeviceEvents
[
i
].
id
);
}
printf
(
"Deregistering secret event callbacks
\n
"
);
for
(
i
=
0
;
i
<
ARRAY_CARDINALITY
(
secretEvents
);
i
++
)
{
if
(
secretEvents
[
i
].
id
>
0
)
virConnectSecretEventDeregisterAny
(
dconn
,
secretEvents
[
i
].
id
);
}
virConnectUnregisterCloseCallback
(
dconn
,
connectClose
);
ret
=
EXIT_SUCCESS
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录