node_device: implement node device lifecycle event APIs

This commit is contained in:
Jovanka Gulicoska 2016-07-28 14:02:54 +02:00 committed by Cole Robinson
parent 9b13df379c
commit bb7513eae2
3 changed files with 56 additions and 0 deletions

View File

@ -31,6 +31,7 @@
# include "virthread.h"
# include "virpci.h"
# include "device_conf.h"
# include "object_event.h"
# include <libxml/tree.h>
@ -229,6 +230,9 @@ struct _virNodeDeviceDriverState {
virNodeDeviceObjList devs; /* currently-known devices */
void *privateData; /* driver-specific private data */
/* Immutable pointer, self-locking APIs */
virObjectEventStatePtr nodeDeviceEventState;
};

View File

@ -35,6 +35,7 @@
#include "virfile.h"
#include "virstring.h"
#include "node_device_conf.h"
#include "node_device_event.h"
#include "node_device_driver.h"
#include "node_device_hal.h"
#include "node_device_linux_sysfs.h"
@ -677,6 +678,47 @@ nodeDeviceDestroy(virNodeDevicePtr dev)
return ret;
}
int
nodeConnectNodeDeviceEventRegisterAny(virConnectPtr conn,
virNodeDevicePtr dev,
int eventID,
virConnectNodeDeviceEventGenericCallback callback,
void *opaque,
virFreeCallback freecb)
{
int callbackID = -1;
if (virConnectNodeDeviceEventRegisterAnyEnsureACL(conn) < 0)
goto cleanup;
if (virNodeDeviceEventStateRegisterID(conn, driver->nodeDeviceEventState,
dev, eventID, callback,
opaque, freecb, &callbackID) < 0)
callbackID = -1;
cleanup:
return callbackID;
}
int
nodeConnectNodeDeviceEventDeregisterAny(virConnectPtr conn,
int callbackID)
{
int ret = -1;
if (virConnectNodeDeviceEventDeregisterAnyEnsureACL(conn) < 0)
goto cleanup;
if (virObjectEventStateDeregisterID(conn,
driver->nodeDeviceEventState,
callbackID) < 0)
goto cleanup;
ret = 0;
cleanup:
return ret;
}
int nodedevRegister(void)
{
#ifdef WITH_UDEV

View File

@ -63,4 +63,14 @@ virNodeDevicePtr nodeDeviceCreateXML(virConnectPtr conn,
const char *xmlDesc, unsigned int flags);
int nodeDeviceDestroy(virNodeDevicePtr dev);
int
nodeConnectNodeDeviceEventRegisterAny(virConnectPtr conn,
virNodeDevicePtr dev,
int eventID,
virConnectNodeDeviceEventGenericCallback callback,
void *opaque,
virFreeCallback freecb);
int
nodeConnectNodeDeviceEventDeregisterAny(virConnectPtr conn,
int callbackID);
#endif /* __VIR_NODE_DEVICE_H__ */