Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
447d55c1
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,发现更多精彩内容 >>
You need to sign in or sign up before continuing.
提交
447d55c1
编写于
12月 11, 2013
作者:
D
Daniel P. Berrange
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update event demo program to support network events too
上级
950c2a55
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
43 addition
and
2 deletion
+43
-2
examples/object-events/event-test.c
examples/object-events/event-test.c
+43
-2
未找到文件。
examples/object-events/event-test.c
浏览文件 @
447d55c1
...
@@ -223,6 +223,27 @@ static const char *eventDetailToString(int event, int detail) {
...
@@ -223,6 +223,27 @@ static const char *eventDetailToString(int event, int detail) {
return
ret
;
return
ret
;
}
}
static
const
char
*
networkEventToString
(
int
event
)
{
const
char
*
ret
=
""
;
switch
((
virNetworkEventLifecycleType
)
event
)
{
case
VIR_NETWORK_EVENT_DEFINED
:
ret
=
"Defined"
;
break
;
case
VIR_NETWORK_EVENT_UNDEFINED
:
ret
=
"Undefined"
;
break
;
case
VIR_NETWORK_EVENT_STARTED
:
ret
=
"Started"
;
break
;
case
VIR_NETWORK_EVENT_STOPPED
:
ret
=
"Stopped"
;
break
;
}
return
ret
;
}
static
int
myDomainEventCallback1
(
virConnectPtr
conn
ATTRIBUTE_UNUSED
,
static
int
myDomainEventCallback1
(
virConnectPtr
conn
ATTRIBUTE_UNUSED
,
virDomainPtr
dom
,
virDomainPtr
dom
,
int
event
,
int
event
,
...
@@ -432,6 +453,18 @@ myDomainEventDeviceRemovedCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
...
@@ -432,6 +453,18 @@ myDomainEventDeviceRemovedCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
return
0
;
return
0
;
}
}
static
int
myNetworkEventCallback
(
virConnectPtr
conn
ATTRIBUTE_UNUSED
,
virNetworkPtr
dom
,
int
event
,
int
detail
,
void
*
opaque
ATTRIBUTE_UNUSED
)
{
printf
(
"%s EVENT: Network %s %s %d
\n
"
,
__func__
,
virNetworkGetName
(
dom
),
networkEventToString
(
event
),
detail
);
return
0
;
}
static
void
myFreeFunc
(
void
*
opaque
)
static
void
myFreeFunc
(
void
*
opaque
)
{
{
char
*
str
=
opaque
;
char
*
str
=
opaque
;
...
@@ -472,6 +505,7 @@ int main(int argc, char **argv)
...
@@ -472,6 +505,7 @@ int main(int argc, char **argv)
int
callback13ret
=
-
1
;
int
callback13ret
=
-
1
;
int
callback14ret
=
-
1
;
int
callback14ret
=
-
1
;
int
callback15ret
=
-
1
;
int
callback15ret
=
-
1
;
int
callback16ret
=
-
1
;
struct
sigaction
action_stop
;
struct
sigaction
action_stop
;
memset
(
&
action_stop
,
0
,
sizeof
(
action_stop
));
memset
(
&
action_stop
,
0
,
sizeof
(
action_stop
));
...
@@ -510,7 +544,7 @@ int main(int argc, char **argv)
...
@@ -510,7 +544,7 @@ int main(int argc, char **argv)
sigaction
(
SIGTERM
,
&
action_stop
,
NULL
);
sigaction
(
SIGTERM
,
&
action_stop
,
NULL
);
sigaction
(
SIGINT
,
&
action_stop
,
NULL
);
sigaction
(
SIGINT
,
&
action_stop
,
NULL
);
VIR_DEBUG
(
"Registering
domain
event cbs"
);
VIR_DEBUG
(
"Registering event cbs"
);
/* Add 2 callbacks to prove this works with more than just one */
/* Add 2 callbacks to prove this works with more than just one */
callback1ret
=
virConnectDomainEventRegister
(
dconn
,
myDomainEventCallback1
,
callback1ret
=
virConnectDomainEventRegister
(
dconn
,
myDomainEventCallback1
,
...
@@ -585,6 +619,11 @@ int main(int argc, char **argv)
...
@@ -585,6 +619,11 @@ int main(int argc, char **argv)
VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED
,
VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED
,
VIR_DOMAIN_EVENT_CALLBACK
(
myDomainEventDeviceRemovedCallback
),
VIR_DOMAIN_EVENT_CALLBACK
(
myDomainEventDeviceRemovedCallback
),
strdup
(
"device removed"
),
myFreeFunc
);
strdup
(
"device removed"
),
myFreeFunc
);
callback16ret
=
virConnectNetworkEventRegisterAny
(
dconn
,
NULL
,
VIR_NETWORK_EVENT_ID_LIFECYCLE
,
VIR_NETWORK_EVENT_CALLBACK
(
myNetworkEventCallback
),
strdup
(
"net callback"
),
myFreeFunc
);
if
((
callback1ret
!=
-
1
)
&&
if
((
callback1ret
!=
-
1
)
&&
(
callback2ret
!=
-
1
)
&&
(
callback2ret
!=
-
1
)
&&
...
@@ -599,7 +638,8 @@ int main(int argc, char **argv)
...
@@ -599,7 +638,8 @@ int main(int argc, char **argv)
(
callback12ret
!=
-
1
)
&&
(
callback12ret
!=
-
1
)
&&
(
callback13ret
!=
-
1
)
&&
(
callback13ret
!=
-
1
)
&&
(
callback14ret
!=
-
1
)
&&
(
callback14ret
!=
-
1
)
&&
(
callback15ret
!=
-
1
))
{
(
callback15ret
!=
-
1
)
&&
(
callback16ret
!=
-
1
))
{
if
(
virConnectSetKeepAlive
(
dconn
,
5
,
3
)
<
0
)
{
if
(
virConnectSetKeepAlive
(
dconn
,
5
,
3
)
<
0
)
{
virErrorPtr
err
=
virGetLastError
();
virErrorPtr
err
=
virGetLastError
();
fprintf
(
stderr
,
"Failed to start keepalive protocol: %s
\n
"
,
fprintf
(
stderr
,
"Failed to start keepalive protocol: %s
\n
"
,
...
@@ -630,6 +670,7 @@ int main(int argc, char **argv)
...
@@ -630,6 +670,7 @@ int main(int argc, char **argv)
virConnectDomainEventDeregisterAny
(
dconn
,
callback13ret
);
virConnectDomainEventDeregisterAny
(
dconn
,
callback13ret
);
virConnectDomainEventDeregisterAny
(
dconn
,
callback14ret
);
virConnectDomainEventDeregisterAny
(
dconn
,
callback14ret
);
virConnectDomainEventDeregisterAny
(
dconn
,
callback15ret
);
virConnectDomainEventDeregisterAny
(
dconn
,
callback15ret
);
virConnectNetworkEventDeregisterAny
(
dconn
,
callback16ret
);
if
(
callback8ret
!=
-
1
)
if
(
callback8ret
!=
-
1
)
virConnectDomainEventDeregisterAny
(
dconn
,
callback8ret
);
virConnectDomainEventDeregisterAny
(
dconn
,
callback8ret
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录