2 Copyright Red Hat, Inc. 2002-2003
4 The Red Hat Cluster Manager API Library is free software; you can
5 redistribute it and/or modify it under the terms of the GNU Lesser
6 General Public License as published by the Free Software Foundation;
7 either version 2.1 of the License, or (at your option) any later
10 The Red Hat Cluster Manager API Library is distributed in the hope
11 that it will be useful, but WITHOUT ANY WARRANTY; without even the
12 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 PURPOSE. See the GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 * Main user/client API driver routines.
23 * This contains the API routines which user/client applications use to
24 * talk directly to Red Hat Cluster Manager.
33 int memb_register(void); /** Defined in membership.c */
34 int quorum_register(void); /** Defined in quorum.c */
37 * Read a membership event from a file descriptor. The idea here is that the
38 * event itself is opaque to the user.
40 * @param fd The File descriptor we selected.
41 * @return The event, if any, present on fd.
47 cm_event_t
*msg
= NULL
;
62 rv
= select(fd
+ 1, &set
, NULL
, NULL
, &tv
);
66 msg
= malloc(sizeof(cm_event_t
));
70 rv
= tcp_receive(fd
, msg
, sizeof(cm_event_t
));
71 if ((rv
!= sizeof(cm_event_t
)) || (rv
== -1)) {
76 swab_cm_event_hdr_t(&msg
->em_header
);
78 if ((cm_ev_type(msg
) != EC_MEMBERSHIP
) &&
79 (cm_ev_type(msg
) != EC_QUORUM
)) {
85 if (msg
->em_header
.eh_length
< sizeof(cm_event_t
)) {
91 switch(cm_ev_event(msg
)) {
93 swab_cm_memb_event_t(&msg
->u
.ev_memb
, c
);
97 case EV_QUORUM_GAINED
:
99 swab_cm_quorum_event_t(&msg
->u
.ev_quorum
, c
);
110 * Free an event. Because the contents of a cluster event may change, we don't
111 * want users freeing them by hand.
113 * @param eventp The cluster event to free.
116 cm_ev_free(cm_event_t
*eventp
)
122 * Register for event(s). This contacts the appropriate daemon(s) and sends
123 * an EV_REGISTER with the appropriate flags to the daemon(s).
125 * @param event_class The class of events to register for.
126 * @return -1 on failure, 0 on success.
129 cm_ev_register(int event_class
)
133 if (event_class
== EC_MEMBERSHIP
) {
134 return memb_register();
135 } else if (event_class
== EC_QUORUM
) {
136 return quorum_register();
145 * Unregister for events on a given file descriptor. Right now, this simply
146 * closes the file descriptor.
148 * @param fd The file descriptor to unregister/close.
152 cm_ev_unregister(int fd
)