domain_event.h 8.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*
 * domain_event.h: domain event queue processing helpers
 *
 * Copyright (C) 2008 VirtualIron
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 *
 * Author: Ben Guthro
 */

#include "internal.h"

#ifndef __DOMAIN_EVENT_H__
26
# define __DOMAIN_EVENT_H__
27

28
# include "domain_conf.h"
29

30 31 32 33
typedef struct _virDomainEventCallback virDomainEventCallback;
typedef virDomainEventCallback *virDomainEventCallbackPtr;

struct _virDomainEventCallbackList {
34
    unsigned int nextID;
35 36 37 38 39 40 41 42 43 44 45
    unsigned int count;
    virDomainEventCallbackPtr *callbacks;
};
typedef struct _virDomainEventCallbackList virDomainEventCallbackList;
typedef virDomainEventCallbackList *virDomainEventCallbackListPtr;

void virDomainEventCallbackListFree(virDomainEventCallbackListPtr list);

int virDomainEventCallbackListAdd(virConnectPtr conn,
                                  virDomainEventCallbackListPtr cbList,
                                  virConnectDomainEventCallback callback,
46
                                  void *opaque,
47 48
                                  virFreeCallback freecb)
    ATTRIBUTE_NONNULL(1);
49 50 51 52 53 54 55 56 57
int virDomainEventCallbackListAddID(virConnectPtr conn,
                                    virDomainEventCallbackListPtr cbList,
                                    virDomainPtr dom,
                                    int eventID,
                                    virConnectDomainEventGenericCallback cb,
                                    void *opaque,
                                    virFreeCallback freecb)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(5);

58 59 60

int virDomainEventCallbackListRemove(virConnectPtr conn,
                                     virDomainEventCallbackListPtr cbList,
61 62
                                     virConnectDomainEventCallback callback)
    ATTRIBUTE_NONNULL(1);
63 64 65 66
int virDomainEventCallbackListRemoveID(virConnectPtr conn,
                                       virDomainEventCallbackListPtr cbList,
                                       int callbackID)
    ATTRIBUTE_NONNULL(1);
67
int virDomainEventCallbackListRemoveConn(virConnectPtr conn,
68 69
                                         virDomainEventCallbackListPtr cbList)
    ATTRIBUTE_NONNULL(1);
70

71

72 73
int virDomainEventCallbackListMarkDelete(virConnectPtr conn,
                                         virDomainEventCallbackListPtr cbList,
74 75
                                         virConnectDomainEventCallback callback)
    ATTRIBUTE_NONNULL(1);
76 77 78 79 80
int virDomainEventCallbackListMarkDeleteID(virConnectPtr conn,
                                           virDomainEventCallbackListPtr cbList,
                                           int callbackID)
    ATTRIBUTE_NONNULL(1);

81

82 83
int virDomainEventCallbackListPurgeMarked(virDomainEventCallbackListPtr cbList);

84
int virDomainEventCallbackListCount(virDomainEventCallbackListPtr cbList);
85 86 87 88 89 90 91 92
int virDomainEventCallbackListCountID(virConnectPtr conn,
                                      virDomainEventCallbackListPtr cbList,
                                      int eventID)
    ATTRIBUTE_NONNULL(1);
int virDomainEventCallbackListEventID(virConnectPtr conn,
                                      virDomainEventCallbackListPtr cbList,
                                      int callbackID)
    ATTRIBUTE_NONNULL(1);
93

94 95 96 97 98 99 100 101 102 103 104 105 106 107
/**
 * Dispatching domain events that come in while
 * in a call / response rpc
 */
typedef struct _virDomainEvent virDomainEvent;
typedef virDomainEvent *virDomainEventPtr;

struct _virDomainEventQueue {
    unsigned int count;
    virDomainEventPtr *events;
};
typedef struct _virDomainEventQueue virDomainEventQueue;
typedef virDomainEventQueue *virDomainEventQueuePtr;

108 109 110 111 112 113 114
virDomainEventQueuePtr virDomainEventQueueNew(void);

virDomainEventPtr virDomainEventNew(int id, const char *name, const unsigned char *uuid, int type, int detail);
virDomainEventPtr virDomainEventNewFromDom(virDomainPtr dom, int type, int detail);
virDomainEventPtr virDomainEventNewFromObj(virDomainObjPtr obj, int type, int detail);
virDomainEventPtr virDomainEventNewFromDef(virDomainDefPtr def, int type, int detail);

115 116 117
virDomainEventPtr virDomainEventRebootNewFromDom(virDomainPtr dom);
virDomainEventPtr virDomainEventRebootNewFromObj(virDomainObjPtr obj);

118 119 120
virDomainEventPtr virDomainEventRTCChangeNewFromDom(virDomainPtr dom, long long offset);
virDomainEventPtr virDomainEventRTCChangeNewFromObj(virDomainObjPtr obj, long long offset);

121 122 123
virDomainEventPtr virDomainEventWatchdogNewFromDom(virDomainPtr dom, int action);
virDomainEventPtr virDomainEventWatchdogNewFromObj(virDomainObjPtr obj, int action);

124 125 126 127 128 129 130 131 132
virDomainEventPtr virDomainEventIOErrorNewFromDom(virDomainPtr dom,
                                                  const char *srcPath,
                                                  const char *devAlias,
                                                  int action);
virDomainEventPtr virDomainEventIOErrorNewFromObj(virDomainObjPtr obj,
                                                  const char *srcPath,
                                                  const char *devAlias,
                                                  int action);

133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
virDomainEventPtr virDomainEventGraphicsNewFromDom(virDomainPtr dom,
                                                   int phase,
                                                   virDomainEventGraphicsAddressPtr local,
                                                   virDomainEventGraphicsAddressPtr remote,
                                                   const char *authScheme,
                                                   virDomainEventGraphicsSubjectPtr subject);
virDomainEventPtr virDomainEventGraphicsNewFromObj(virDomainObjPtr obj,
                                                   int phase,
                                                   virDomainEventGraphicsAddressPtr local,
                                                   virDomainEventGraphicsAddressPtr remote,
                                                   const char *authScheme,
                                                   virDomainEventGraphicsSubjectPtr subject);



148 149
int virDomainEventQueuePush(virDomainEventQueuePtr evtQueue,
                            virDomainEventPtr event);
150 151

virDomainEventPtr
152
virDomainEventQueuePop(virDomainEventQueuePtr evtQueue);
153

154
void virDomainEventFree(virDomainEventPtr event);
155 156
void virDomainEventQueueFree(virDomainEventQueuePtr queue);

157 158
typedef void (*virDomainEventDispatchFunc)(virConnectPtr conn,
                                           virDomainEventPtr event,
159
                                           virConnectDomainEventGenericCallback cb,
160 161 162 163
                                           void *cbopaque,
                                           void *opaque);
void virDomainEventDispatchDefaultFunc(virConnectPtr conn,
                                       virDomainEventPtr event,
164
                                       virConnectDomainEventGenericCallback cb,
165 166 167 168 169 170 171 172 173 174 175
                                       void *cbopaque,
                                       void *opaque);

void virDomainEventDispatch(virDomainEventPtr event,
                            virDomainEventCallbackListPtr cbs,
                            virDomainEventDispatchFunc dispatch,
                            void *opaque);
void virDomainEventQueueDispatch(virDomainEventQueuePtr queue,
                                 virDomainEventCallbackListPtr cbs,
                                 virDomainEventDispatchFunc dispatch,
                                 void *opaque);
176 177

#endif