git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@2601
48e7efb5-ca39-0410-a469-
dd3cf9ba447f
#include <gras.h>
#include <amok/base.h>
#include <gras.h>
#include <amok/base.h>
* \brief Managing remote servers
*
* This module provide the main loop of servers designed to answer to
* \brief Managing remote servers
*
* This module provide the main loop of servers designed to answer to
* - declaring the messages (with gras_msgtype_declare() or gras_msgtype_declare_rpc())
* - attaching the right callbacks to the messages (with gras_cb_register())
* - declaring the right repetitive actions (see \ref GRAS_timer)
* - declaring the messages (with gras_msgtype_declare() or gras_msgtype_declare_rpc())
* - attaching the right callbacks to the messages (with gras_cb_register())
* - declaring the right repetitive actions (see \ref GRAS_timer)
- * - joining the group (with amok_hm_group_join(), so that the master now it)
- * - entering the endless loop (with amok_hm_mainloop()).
+ * - joining the group (with amok_pm_group_join(), so that the master now it)
+ * - entering the endless loop (with amok_pm_mainloop()).
* The <b>master</b>, on its side, should create declare the datatypes and
* messages just like slaves. It should then create a group with
* The <b>master</b>, on its side, should create declare the datatypes and
* messages just like slaves. It should then create a group with
* Afterward, there is two solutions.
* - If your master is a deamon which never stops itself (just like regular UNIX daemons), it should:
* Afterward, there is two solutions.
* - If your master is a deamon which never stops itself (just like regular UNIX daemons), it should:
* - entering the main loop.
* - If the master is not a deamon, it should:
* - wait a moment for the slaves registration (using gras_msg_handleall())
* - entering the main loop.
* - If the master is not a deamon, it should:
* - wait a moment for the slaves registration (using gras_msg_handleall())
- * - run its algorithm. For this, it may call RPC on slaves, or explicitely wait (with gras_msg_wait()) for the answers it expects.
+ * - run its algoritpm. For this, it may call RPC on slaves, or explicitely wait (with gras_msg_wait()) for the answers it expects.
*
* @{
*/
/* module handling */
*
* @{
*/
/* module handling */
-void amok_hm_init(void);
-void amok_hm_exit(void);
+void amok_pm_init(void);
+void amok_pm_exit(void);
-void amok_hm_mainloop(double timeOut);
+void amok_pm_mainloop(double timeOut);
-void amok_hm_kill_hp(char *name,int port);
-void amok_hm_kill(gras_socket_t buddy);
-void amok_hm_kill_sync(gras_socket_t buddy);
+void amok_pm_kill_hp(char *name,int port);
+void amok_pm_kill(gras_socket_t buddy);
+void amok_pm_kill_sync(gras_socket_t buddy);
-xbt_dynar_t amok_hm_group_new(const char *group_name);
-xbt_dynar_t amok_hm_group_get(gras_socket_t master, const char *group_name);
+xbt_dynar_t amok_pm_group_new(const char *group_name);
+xbt_dynar_t amok_pm_group_get(gras_socket_t master, const char *group_name);
-void amok_hm_group_join(gras_socket_t master, const char *group_name);
-void amok_hm_group_leave(gras_socket_t master, const char *group_name);
+void amok_pm_group_join(gras_socket_t master, const char *group_name);
+void amok_pm_group_leave(gras_socket_t master, const char *group_name);
-void amok_hm_group_shutdown(const char *group_name);
-void amok_hm_group_shutdown_remote(gras_socket_t master, const char *group_name);
+void amok_pm_group_shutdown(const char *group_name);
+void amok_pm_group_shutdown_remote(gras_socket_t master, const char *group_name);
#include "amok/peermanagement.h"
#include "gras/Virtu/virtu_interface.h" /* libdata */
#include "amok/peermanagement.h"
#include "gras/Virtu/virtu_interface.h" /* libdata */
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(amok_hm,amok,"peer management");
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(amok_pm,amok,"peer management");
-static int amok_hm_libdata_id=-1;
+static int amok_pm_libdata_id=-1;
typedef struct {
/* set headers */
unsigned int ID;
typedef struct {
/* set headers */
unsigned int ID;
/* payload */
int done;
xbt_dict_t groups;
/* payload */
int done;
xbt_dict_t groups;
-} s_amok_hm_libdata_t, *amok_hm_libdata_t;
+} s_amok_pm_libdata_t, *amok_pm_libdata_t;
-static void *amok_hm_libdata_new() {
- amok_hm_libdata_t res=xbt_new(s_amok_hm_libdata_t,1);
- res->name=xbt_strdup("amok_hm");
+static void *amok_pm_libdata_new() {
+ amok_pm_libdata_t res=xbt_new(s_amok_pm_libdata_t,1);
+ res->name=xbt_strdup("amok_pm");
res->name_len=0;
res->done = 0;
res->groups = xbt_dict_new();
return res;
}
res->name_len=0;
res->done = 0;
res->groups = xbt_dict_new();
return res;
}
-static void amok_hm_libdata_free(void *d) {
- amok_hm_libdata_t data=(amok_hm_libdata_t)d;
+static void amok_pm_libdata_free(void *d) {
+ amok_pm_libdata_t data=(amok_pm_libdata_t)d;
free(data->name);
xbt_dict_free(&data->groups);
free (data);
}
/* Message callbacks */
free(data->name);
xbt_dict_free(&data->groups);
free (data);
}
/* Message callbacks */
-static int amok_hm_cb_kill(gras_msg_cb_ctx_t ctx,
+static int amok_pm_cb_kill(gras_msg_cb_ctx_t ctx,
- amok_hm_libdata_t g=gras_libdata_by_id(amok_hm_libdata_id);
+ amok_pm_libdata_t g=gras_libdata_by_id(amok_pm_libdata_id);
-static int amok_hm_cb_killrpc(gras_msg_cb_ctx_t ctx,
+static int amok_pm_cb_killrpc(gras_msg_cb_ctx_t ctx,
- amok_hm_libdata_t g=gras_libdata_by_id(amok_hm_libdata_id);
+ amok_pm_libdata_t g=gras_libdata_by_id(amok_pm_libdata_id);
g->done = 1;
gras_msg_rpcreturn(30,ctx,NULL);
return 1;
}
g->done = 1;
gras_msg_rpcreturn(30,ctx,NULL);
return 1;
}
-static int amok_hm_cb_get(gras_msg_cb_ctx_t ctx, void *payload) {
- amok_hm_libdata_t g=gras_libdata_by_id(amok_hm_libdata_id);
+static int amok_pm_cb_get(gras_msg_cb_ctx_t ctx, void *payload) {
+ amok_pm_libdata_t g=gras_libdata_by_id(amok_pm_libdata_id);
char *name = *(void**)payload;
xbt_dynar_t res = xbt_dict_get(g->groups, name);
gras_msg_rpcreturn(30, ctx, &res);
return 1;
}
char *name = *(void**)payload;
xbt_dynar_t res = xbt_dict_get(g->groups, name);
gras_msg_rpcreturn(30, ctx, &res);
return 1;
}
-static int amok_hm_cb_join(gras_msg_cb_ctx_t ctx, void *payload) {
- amok_hm_libdata_t g=gras_libdata_by_id(amok_hm_libdata_id);
+static int amok_pm_cb_join(gras_msg_cb_ctx_t ctx, void *payload) {
+ amok_pm_libdata_t g=gras_libdata_by_id(amok_pm_libdata_id);
char *name = *(void**)payload;
xbt_dynar_t group = xbt_dict_get(g->groups, name);
char *name = *(void**)payload;
xbt_dynar_t group = xbt_dict_get(g->groups, name);
-static int amok_hm_cb_leave(gras_msg_cb_ctx_t ctx, void *payload) {
- amok_hm_libdata_t g=gras_libdata_by_id(amok_hm_libdata_id);
+static int amok_pm_cb_leave(gras_msg_cb_ctx_t ctx, void *payload) {
+ amok_pm_libdata_t g=gras_libdata_by_id(amok_pm_libdata_id);
char *name = *(void**)payload;
xbt_dynar_t group = xbt_dict_get(g->groups, name);
char *name = *(void**)payload;
xbt_dynar_t group = xbt_dict_get(g->groups, name);
-static int amok_hm_cb_shutdown(gras_msg_cb_ctx_t ctx, void *payload) {
+static int amok_pm_cb_shutdown(gras_msg_cb_ctx_t ctx, void *payload) {
char *name = *(void**)payload;
char *name = *(void**)payload;
- amok_hm_group_shutdown(name);
+ amok_pm_group_shutdown(name);
gras_msg_rpcreturn(30, ctx, NULL);
return 1;
gras_msg_rpcreturn(30, ctx, NULL);
return 1;
/* Initialization stuff */
/* Initialization stuff */
-static short amok_hm_used = 0;
+static short amok_pm_used = 0;
/** \brief Initialize the peer management module. Every process must run it before use */
/** \brief Initialize the peer management module. Every process must run it before use */
/* dependencies */
amok_base_init();
/* module data on each process */
/* dependencies */
amok_base_init();
/* module data on each process */
- amok_hm_libdata_id = gras_procdata_add("amok_hm",
- amok_hm_libdata_new,
- amok_hm_libdata_free);
+ amok_pm_libdata_id = gras_procdata_add("amok_pm",
+ amok_pm_libdata_new,
+ amok_pm_libdata_free);
/* Datatype and message declarations */
/* Datatype and message declarations */
- gras_msgtype_declare("amok_hm_kill",NULL);
- gras_msgtype_declare_rpc("amok_hm_killrpc",NULL,NULL);
+ gras_msgtype_declare("amok_pm_kill",NULL);
+ gras_msgtype_declare_rpc("amok_pm_killrpc",NULL,NULL);
- gras_msgtype_declare_rpc("amok_hm_get",
+ gras_msgtype_declare_rpc("amok_pm_get",
gras_datadesc_by_name("string"),
gras_datadesc_by_name("xbt_dynar_t"));
gras_datadesc_by_name("string"),
gras_datadesc_by_name("xbt_dynar_t"));
- gras_msgtype_declare_rpc("amok_hm_join",
+ gras_msgtype_declare_rpc("amok_pm_join",
gras_datadesc_by_name("string"),
NULL);
gras_datadesc_by_name("string"),
NULL);
- gras_msgtype_declare_rpc("amok_hm_leave",
+ gras_msgtype_declare_rpc("amok_pm_leave",
gras_datadesc_by_name("string"),
NULL);
gras_datadesc_by_name("string"),
NULL);
- gras_msgtype_declare_rpc("amok_hm_shutdown",
+ gras_msgtype_declare_rpc("amok_pm_shutdown",
gras_datadesc_by_name("string"),
NULL);
}
gras_datadesc_by_name("string"),
NULL);
}
- gras_cb_register(gras_msgtype_by_name("amok_hm_kill"),
- &amok_hm_cb_kill);
- gras_cb_register(gras_msgtype_by_name("amok_hm_killrpc"),
- &amok_hm_cb_killrpc);
-
- gras_cb_register(gras_msgtype_by_name("amok_hm_get"),
- &amok_hm_cb_get);
- gras_cb_register(gras_msgtype_by_name("amok_hm_join"),
- &amok_hm_cb_join);
- gras_cb_register(gras_msgtype_by_name("amok_hm_leave"),
- &amok_hm_cb_leave);
- gras_cb_register(gras_msgtype_by_name("amok_hm_shutdown"),
- &amok_hm_cb_shutdown);
+ gras_cb_register(gras_msgtype_by_name("amok_pm_kill"),
+ &amok_pm_cb_kill);
+ gras_cb_register(gras_msgtype_by_name("amok_pm_killrpc"),
+ &amok_pm_cb_killrpc);
+
+ gras_cb_register(gras_msgtype_by_name("amok_pm_get"),
+ &amok_pm_cb_get);
+ gras_cb_register(gras_msgtype_by_name("amok_pm_join"),
+ &amok_pm_cb_join);
+ gras_cb_register(gras_msgtype_by_name("amok_pm_leave"),
+ &amok_pm_cb_leave);
+ gras_cb_register(gras_msgtype_by_name("amok_pm_shutdown"),
+ &amok_pm_cb_shutdown);
}
/** \brief Finalize the peer management module. Every process should run it after use */
}
/** \brief Finalize the peer management module. Every process should run it after use */
- gras_cb_unregister(gras_msgtype_by_name("amok_hm_kill"),
- &amok_hm_cb_kill);
- gras_cb_unregister(gras_msgtype_by_name("amok_hm_killrpc"),
- &amok_hm_cb_killrpc);
-
- gras_cb_unregister(gras_msgtype_by_name("amok_hm_get"),
- &amok_hm_cb_get);
- gras_cb_unregister(gras_msgtype_by_name("amok_hm_join"),
- &amok_hm_cb_join);
- gras_cb_unregister(gras_msgtype_by_name("amok_hm_leave"),
- &amok_hm_cb_leave);
-
- gras_cb_unregister(gras_msgtype_by_name("amok_hm_shutdown"),
- &amok_hm_cb_shutdown);
+ gras_cb_unregister(gras_msgtype_by_name("amok_pm_kill"),
+ &amok_pm_cb_kill);
+ gras_cb_unregister(gras_msgtype_by_name("amok_pm_killrpc"),
+ &amok_pm_cb_killrpc);
+
+ gras_cb_unregister(gras_msgtype_by_name("amok_pm_get"),
+ &amok_pm_cb_get);
+ gras_cb_unregister(gras_msgtype_by_name("amok_pm_join"),
+ &amok_pm_cb_join);
+ gras_cb_unregister(gras_msgtype_by_name("amok_pm_leave"),
+ &amok_pm_cb_leave);
+
+ gras_cb_unregister(gras_msgtype_by_name("amok_pm_shutdown"),
+ &amok_pm_cb_shutdown);
}
/** \brief Enter the main loop of the program. It won't return until we get a kill message. */
}
/** \brief Enter the main loop of the program. It won't return until we get a kill message. */
-void amok_hm_mainloop(double timeOut) {
- amok_hm_libdata_t g=gras_libdata_by_id(amok_hm_libdata_id);
+void amok_pm_mainloop(double timeOut) {
+ amok_pm_libdata_t g=gras_libdata_by_id(amok_pm_libdata_id);
while (!g->done) {
gras_msg_handle(timeOut);
while (!g->done) {
gras_msg_handle(timeOut);
}
/** \brief kill a buddy identified by its peername and port */
}
/** \brief kill a buddy identified by its peername and port */
-void amok_hm_kill_hp(char *name,int port) {
+void amok_pm_kill_hp(char *name,int port) {
gras_socket_t sock=gras_socket_client(name,port);
gras_socket_t sock=gras_socket_client(name,port);
gras_socket_close(sock);
}
/** \brief kill a buddy to which we have a socket already */
gras_socket_close(sock);
}
/** \brief kill a buddy to which we have a socket already */
-void amok_hm_kill(gras_socket_t buddy) {
- gras_msg_send(buddy,gras_msgtype_by_name("amok_hm_kill"),NULL);
+void amok_pm_kill(gras_socket_t buddy) {
+ gras_msg_send(buddy,gras_msgtype_by_name("amok_pm_kill"),NULL);
}
/** \brief kill syncronously a buddy (do not return before its death) */
}
/** \brief kill syncronously a buddy (do not return before its death) */
-void amok_hm_kill_sync(gras_socket_t buddy) {
- gras_msg_rpccall(buddy,30,gras_msgtype_by_name("amok_hm_killrpc"),NULL,NULL);
+void amok_pm_kill_sync(gras_socket_t buddy) {
+ gras_msg_rpccall(buddy,30,gras_msgtype_by_name("amok_pm_killrpc"),NULL,NULL);
*
* The dynar elements are of type xbt_peer_t
*/
*
* The dynar elements are of type xbt_peer_t
*/
-xbt_dynar_t amok_hm_group_new(const char *group_name) {
- amok_hm_libdata_t g;
+xbt_dynar_t amok_pm_group_new(const char *group_name) {
+ amok_pm_libdata_t g;
xbt_dynar_t res = xbt_dynar_new(sizeof(xbt_peer_t),
xbt_peer_free_voidp);
xbt_dynar_t res = xbt_dynar_new(sizeof(xbt_peer_t),
xbt_peer_free_voidp);
- xbt_assert0(amok_hm_libdata_id != -1,"Run amok_hm_init first!");
- g=gras_libdata_by_id(amok_hm_libdata_id);
+ xbt_assert0(amok_pm_libdata_id != -1,"Run amok_pm_init first!");
+ g=gras_libdata_by_id(amok_pm_libdata_id);
xbt_dict_set(g->groups,group_name,res,NULL); /*FIXME: leaking xbt_dynar_free_voidp);*/
VERB1("Group %s created",group_name);
xbt_dict_set(g->groups,group_name,res,NULL); /*FIXME: leaking xbt_dynar_free_voidp);*/
VERB1("Group %s created",group_name);
return res;
}
/** \brief retrieve all members of the given remote group */
return res;
}
/** \brief retrieve all members of the given remote group */
-xbt_dynar_t amok_hm_group_get(gras_socket_t master, const char *group_name) {
+xbt_dynar_t amok_pm_group_get(gras_socket_t master, const char *group_name) {
- gras_msg_rpccall(master,30,gras_msgtype_by_name("amok_hm_get"),
+ gras_msg_rpccall(master,30,gras_msgtype_by_name("amok_pm_get"),
&group_name,&res);
return res;
}
/** \brief add current peer to the given remote group */
&group_name,&res);
return res;
}
/** \brief add current peer to the given remote group */
-void amok_hm_group_join(gras_socket_t master, const char *group_name) {
+void amok_pm_group_join(gras_socket_t master, const char *group_name) {
VERB3("Join group '%s' on %s:%d",
group_name,gras_socket_peer_name(master),gras_socket_peer_port(master));
VERB3("Join group '%s' on %s:%d",
group_name,gras_socket_peer_name(master),gras_socket_peer_port(master));
- gras_msg_rpccall(master,30,gras_msgtype_by_name("amok_hm_join"),
+ gras_msg_rpccall(master,30,gras_msgtype_by_name("amok_pm_join"),
&group_name,NULL);
VERB3("Joined group '%s' on %s:%d",
group_name,gras_socket_peer_name(master),gras_socket_peer_port(master));
&group_name,NULL);
VERB3("Joined group '%s' on %s:%d",
group_name,gras_socket_peer_name(master),gras_socket_peer_port(master));
*
* If not found, call is ignored
*/
*
* If not found, call is ignored
*/
-void amok_hm_group_leave(gras_socket_t master, const char *group_name) {
- gras_msg_rpccall(master,30,gras_msgtype_by_name("amok_hm_leave"),
+void amok_pm_group_leave(gras_socket_t master, const char *group_name) {
+ gras_msg_rpccall(master,30,gras_msgtype_by_name("amok_pm_leave"),
&group_name,NULL);
VERB3("Leaved group '%s' on %s:%d",
group_name,gras_socket_peer_name(master),gras_socket_peer_port(master));
}
/** \brief stops all members of the given local group */
&group_name,NULL);
VERB3("Leaved group '%s' on %s:%d",
group_name,gras_socket_peer_name(master),gras_socket_peer_port(master));
}
/** \brief stops all members of the given local group */
-void amok_hm_group_shutdown(const char *group_name) {
- amok_hm_libdata_t g=gras_libdata_by_id(amok_hm_libdata_id);
+void amok_pm_group_shutdown(const char *group_name) {
+ amok_pm_libdata_t g=gras_libdata_by_id(amok_pm_libdata_id);
xbt_dynar_t group = xbt_dict_get(g->groups, group_name);
int cpt;
xbt_peer_t peer_it;
xbt_dynar_foreach(group, cpt, peer_it) {
xbt_dynar_t group = xbt_dict_get(g->groups, group_name);
int cpt;
xbt_peer_t peer_it;
xbt_dynar_foreach(group, cpt, peer_it) {
- amok_hm_kill_hp(peer_it->name, peer_it->port);
+ amok_pm_kill_hp(peer_it->name, peer_it->port);
}
xbt_dynar_free(&group);
xbt_dict_remove(g->groups,group_name);
}
/** \brief stops all members of the given remote group */
}
xbt_dynar_free(&group);
xbt_dict_remove(g->groups,group_name);
}
/** \brief stops all members of the given remote group */
-void amok_hm_group_shutdown_remote(gras_socket_t master, const char *group_name){
- gras_msg_rpccall(master,30,gras_msgtype_by_name("amok_hm_shutdown"),
+void amok_pm_group_shutdown_remote(gras_socket_t master, const char *group_name){
+ gras_msg_rpccall(master,30,gras_msgtype_by_name("amok_pm_shutdown"),