2 * Copyright (c) 2004 MontaVista Software, Inc.
3 * Copyright (c) 2006 Sun Microsystems, Inc.
7 * Author: Steven Dake (sdake@mvista.com)
9 * This software licensed under BSD license, the text of which follows:
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
14 * - Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 * - Redistributions in binary form must reproduce the above copyright notice,
17 * this list of conditions and the following disclaimer in the documentation
18 * and/or other materials provided with the distribution.
19 * - Neither the name of the MontaVista Software, Inc. nor the names of its
20 * contributors may be used to endorse or promote products derived from this
21 * software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
33 * THE POSSIBILITY OF SUCH DAMAGE.
37 #include <sys/socket.h>
38 #include <netinet/in.h>
39 #include <arpa/inet.h>
41 #include "../include/evs.h"
43 char *delivery_string
;
54 // printf ("Delivery callback\n");
55 printf ("API '%s' msg '%s'\n", delivery_string
, buf
);
60 unsigned int *member_list
, int member_list_entries
,
61 unsigned int *left_list
, int left_list_entries
,
62 unsigned int *joined_list
, int joined_list_entries
)
66 printf ("CONFIGURATION CHANGE\n");
67 printf ("--------------------\n");
68 printf ("New configuration\n");
69 for (i
= 0; i
< member_list_entries
; i
++) {
70 printf ("%x\n", member_list
[i
]);
72 printf ("Members Left:\n");
73 for (i
= 0; i
< left_list_entries
; i
++) {
74 printf ("%x\n", left_list
[i
]);
76 printf ("Members Joined:\n");
77 for (i
= 0; i
< joined_list_entries
; i
++) {
78 printf ("%x\n", joined_list
[i
]);
82 evs_callbacks_t callbacks
= {
87 struct evs_group groups
[3] = {
96 .iov_len
= sizeof (buffer
)
105 unsigned int member_list
[32];
106 unsigned int local_nodeid
;
107 unsigned int member_list_entries
= 32;
109 result
= evs_initialize (&handle
, &callbacks
);
110 if (result
!= EVS_OK
) {
111 printf ("Couldn't initialize EVS service %d\n", result
);
115 result
= evs_membership_get (handle
, &local_nodeid
,
116 member_list
, &member_list_entries
);
117 printf ("Current membership from evs_membership_get entries %d\n",
118 member_list_entries
);
119 for (i
= 0; i
< member_list_entries
; i
++) {
120 printf ("member [%d] is %x\n", i
, member_list
[i
]);
122 printf ("local processor from evs_membership_get %x\n", local_nodeid
);
124 printf ("Init result %d\n", result
);
125 result
= evs_join (handle
, groups
, 3);
126 printf ("Join result %d\n", result
);
127 result
= evs_leave (handle
, &groups
[0], 1);
128 printf ("Leave result %d\n", result
);
129 delivery_string
= "evs_mcast_joined";
132 * Demonstrate evs_mcast_joined
134 for (i
= 0; i
< 500; i
++) {
135 sprintf (buffer
, "evs_mcast_joined: This is message %d", i
);
138 "%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d",
139 i
, i
, i
, i
, i
, i
, i
, i
, i
, i
, i
, i
, i
, i
, i
, i
, i
, i
, i
, i
, i
, i
, i
, i
, i
,
140 i
, i
, i
, i
, i
, i
, i
, i
, i
, i
, i
, i
, i
, i
, i
, i
, i
, i
, i
, i
, i
, i
, i
, i
, i
);
143 result
= evs_mcast_joined (handle
, EVS_TYPE_AGREED
,
145 if (result
== EVS_ERR_TRY_AGAIN
) {
146 //printf ("try again\n");
149 result
= evs_dispatch (handle
, EVS_DISPATCH_ALL
);
153 result
= evs_dispatch (handle
, EVS_DISPATCH_ALL
);
154 } while (deliveries
< 20);
156 * Demonstrate evs_mcast_joined
158 delivery_string
= "evs_mcast_groups";
159 for (i
= 0; i
< 500; i
++) {
160 sprintf (buffer
, "evs_mcast_groups: This is message %d", i
);
162 result
= evs_mcast_groups (handle
, EVS_TYPE_AGREED
,
163 &groups
[1], 1, &iov
, 1);
164 if (result
== EVS_ERR_TRY_AGAIN
) {
168 result
= evs_dispatch (handle
, EVS_DISPATCH_ALL
);
171 * Flush any pending callbacks
174 result
= evs_dispatch (handle
, EVS_DISPATCH_ALL
);
175 } while (deliveries
< 900);
177 evs_fd_get (handle
, &fd
);
179 evs_finalize (handle
);