-
Notifications
You must be signed in to change notification settings - Fork 6
/
cib.go
103 lines (80 loc) · 2.62 KB
/
cib.go
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// The pacemaker package provides an API for reading the Pacemaker cluster configuration (CIB).
// Copyright (C) 2017 Kristoffer Gronlund <[email protected]>
// See LICENSE for license.
package pacemaker
/*
#include <crm/cib.h>
#include <crm/services.h>
#include <crm/common/util.h>
#include <crm/common/xml.h>
#include <crm/common/mainloop.h>
// Flags returned by go_cib_register_notify_callbacks
// indicating which notifications were actually
// available to register (different connection types
// enable different sets of notifications)
#define GO_CIB_NOTIFY_DESTROY 0x1
#define GO_CIB_NOTIFY_ADDREMOVE 0x2
extern int go_cib_signon(cib_t* cib, const char* name, enum cib_conn_type type);
extern int go_cib_signoff(cib_t* cib);
extern int go_cib_query(cib_t * cib, const char *section, xmlNode ** output_data, int call_options);
extern unsigned int go_cib_register_notify_callbacks(cib_t * cib);
extern void go_add_idle_scheduler(GMainLoop* loop);
#define F_CIB_UPDATE_RESULT "cib_update_result"
static cib_t *s_cib = NULL;
int go_cib_signon(cib_t* cib, const char* name, enum cib_conn_type type) {
int rc;
rc = cib->cmds->signon(cib, name, type);
return rc;
}
int go_cib_signoff(cib_t* cib) {
int rc;
rc = cib->cmds->signoff(cib);
return rc;
}
int go_cib_query(cib_t * cib, const char *section, xmlNode ** output_data, int call_options) {
int rc;
rc = cib->cmds->query(cib, section, output_data, call_options);
return rc;
}
static void go_cib_destroy_cb(gpointer user_data) {
extern void destroyNotifyCallback();
destroyNotifyCallback();
}
static void go_cib_notify_cb(const char *event, xmlNode * msg) {
int rc;
rc = pcmk_ok;
xmlNode *current_cib;
xmlNode *diff = get_message_xml(msg, F_CIB_UPDATE_RESULT);
s_cib->cmds->query(s_cib, NULL, ¤t_cib, cib_scope_local | cib_sync_call);
extern void diffNotifyCallback(xmlNode*);
diffNotifyCallback(current_cib);
free_xml(current_cib);
}
unsigned int go_cib_register_notify_callbacks(cib_t * cib) {
int rc;
unsigned int flags;
s_cib = cib;
flags = 0;
rc = cib->cmds->set_connection_dnotify(cib, go_cib_destroy_cb);
if (rc == pcmk_ok) {
flags |= GO_CIB_NOTIFY_DESTROY;
}
rc = cib->cmds->del_notify_callback(cib, T_CIB_DIFF_NOTIFY, go_cib_notify_cb);
if (rc == pcmk_ok) {
flags |= GO_CIB_NOTIFY_ADDREMOVE;
}
rc = cib->cmds->add_notify_callback(cib, T_CIB_DIFF_NOTIFY, go_cib_notify_cb);
if (rc == pcmk_ok) {
flags |= GO_CIB_NOTIFY_ADDREMOVE;
}
return flags;
}
static gboolean idle_callback(gpointer user_data) {
extern void goMainloopSched();
goMainloopSched();
}
void go_add_idle_scheduler(GMainLoop* loop) {
g_idle_add(&idle_callback, loop);
}
*/
import "C"