Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
First wave of GRAS API breaking: gras_cb_register wants a message name (char*) as...
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 7 Mar 2007 11:03:04 +0000 (11:03 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 7 Mar 2007 11:03:04 +0000 (11:03 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@3202 48e7efb5-ca39-0410-a469-dd3cf9ba447f

12 files changed:
examples/gras/mmrpc/mmrpc_server.c
examples/gras/mutual_exclusion/simple_token/simple_token.c
examples/gras/p2p/can/can.c
examples/gras/p2p/chord/chord.c
examples/gras/ping/ping_server.c
examples/gras/pmm/pmm.c
examples/gras/rpc/rpc.c
include/gras/messages.h
src/amok/Bandwidth/bandwidth.c
src/amok/Bandwidth/saturate.c
src/amok/PeerManagement/peermanagement.c
src/gras/Msg/msg.c

index 671b97c..ebdf498 100644 (file)
@@ -64,7 +64,7 @@ int server (int argc,char *argv[]) {
   mmrpc_register_messages();
    
   /* 5. Register my callback */
-  gras_cb_register(gras_msgtype_by_name("request"),&server_cb_request_handler);
+  gras_cb_register("request",&server_cb_request_handler);
 
   /* 6. Wait up to 10 minutes for an incomming message to handle */
   gras_msg_handle(600.0);
index 06b0762..0ad688f 100644 (file)
@@ -146,7 +146,7 @@ int node (int argc,char *argv[]) {
   gras_msgtype_declare("stoken", gras_datadesc_by_name("int"));
    
   /* 7. Register my callback */
-  gras_cb_register(gras_msgtype_by_name("stoken"),&node_cb_stoken_handler);  
+  gras_cb_register("stoken",&node_cb_stoken_handler);  
 
   /* 8. One node has to create the token at startup. 
         It's specified by a command line argument */
index ccbb607..270c3ee 100644 (file)
@@ -287,8 +287,8 @@ int node(int argc,char **argv){
 
        // associating messages to handlers.
        register_messages();
-       gras_cb_register(gras_msgtype_by_name("can_get_suc"),&node_get_suc_handler);
-       gras_cb_register(gras_msgtype_by_name("can_nuke"),&node_nuke_handler);// can_test.c handler // include can_tests.c must be ON.
+       gras_cb_register("can_get_suc",&node_get_suc_handler);
+       gras_cb_register("can_nuke",&node_nuke_handler);// can_test.c handler // include can_tests.c must be ON.
        
        TRY{
          gras_msg_handle(10000.0); // waiting.. in case of someone has something to say.
index 2fd9b6a..04b92a4 100644 (file)
@@ -301,7 +301,6 @@ int node(int argc,char **argv){
   globals->sock=gras_socket_server(globals->port);
   gras_os_sleep(1.0);
 
-  register_messages();
   register_messages();
 
   globals->finger=(finger_elem*)calloc(1,sizeof(finger_elem));
@@ -358,10 +357,8 @@ int node(int argc,char **argv){
     }
   }
   
-  gras_cb_register(gras_msgtype_by_name("chord_get_suc"),
-                   &node_cb_get_suc_handler);
-  gras_cb_register(gras_msgtype_by_name("chord_notify"),
-                   &node_cb_notify_handler);
+  gras_cb_register("chord_get_suc", &node_cb_get_suc_handler);
+  gras_cb_register("chord_notify",  &node_cb_notify_handler);
   /*gras_cb_register(gras_msgtype_by_name("chord_ping"),&node_cb_ping_handler);*/
  /* gras_timer_repeat(600.,fix_fingers);*/
   /*while(1){*/
index 1a6c7e8..e59dee2 100644 (file)
@@ -84,7 +84,7 @@ int server (int argc,char *argv[]) {
   ping_register_messages(); /* just to make sure it works ;) */
    
   /* 5. Register my callback */
-  gras_cb_register(gras_msgtype_by_name("ping"),&server_cb_ping_handler);
+  gras_cb_register("ping",&server_cb_ping_handler);
 
   INFO1(">>>>>>>> Listening on port %d <<<<<<<<", gras_socket_my_port(globals->sock));
   globals->endcondition=0;
index 7d20b7c..6bdd14a 100755 (executable)
@@ -366,7 +366,7 @@ int slave(int argc,char *argv[]) {
 
   /*  Register the known messages and my callback */
   register_messages();
-  gras_cb_register(gras_msgtype_by_name("pmm_slave"),pmm_worker_cb);
+  gras_cb_register("pmm_slave",pmm_worker_cb);
 
   /* Create the connexions */
   mysock = gras_socket_server_range(3000,9999,0,0);
index 66c1b2e..d42614b 100644 (file)
@@ -255,10 +255,8 @@ int forwarder (int argc,char *argv[]) {
   fdata->server=gras_socket_client(argv[2],atoi(argv[3]));
 
   register_messages();
-  gras_cb_register(gras_msgtype_by_name("forward exception"),
-                  &forwarder_cb_forward_ex);
-  gras_cb_register(gras_msgtype_by_name("kill"),
-                  &forwarder_cb_kill);
+  gras_cb_register("forward exception", &forwarder_cb_forward_ex);
+  gras_cb_register("kill",              &forwarder_cb_kill);
 
   while (!fdata->done) {
     gras_msg_handle(600.0);
@@ -345,9 +343,9 @@ int server (int argc,char *argv[]) {
 
   /* 4. Register the known messages and register my callback */
   register_messages();
-  gras_cb_register(gras_msgtype_by_name("plain ping"),&server_cb_ping);
-  gras_cb_register(gras_msgtype_by_name("raise exception"),&server_cb_raise_ex);
-  gras_cb_register(gras_msgtype_by_name("kill"),&server_cb_kill);
+  gras_cb_register("plain ping",&server_cb_ping);
+  gras_cb_register("raise exception",&server_cb_raise_ex);
+  gras_cb_register("kill",&server_cb_kill);
 
   INFO1("Listening on port %d ", gras_socket_my_port(mysock));
 
index 44da65d..a6e42c4 100644 (file)
@@ -116,8 +116,30 @@ XBT_PUBLIC(gras_socket_t) gras_msg_cb_ctx_from(gras_msg_cb_ctx_t ctx);
   typedef int (*gras_msg_cb_t)(gras_msg_cb_ctx_t  ctx,
                               void             *payload);
 
-  XBT_PUBLIC(void) gras_cb_register  (gras_msgtype_t msgtype, gras_msg_cb_t cb);
-  XBT_PUBLIC(void) gras_cb_unregister(gras_msgtype_t msgtype, gras_msg_cb_t cb);
+ /**
+  * @brief Bind the given callback to the given message type (described by its name)
+  * @hideinitializer
+  * 
+  * Several callbacks can be attached to a given message type. The lastly added one will get the message first, and
+  * if it returns a non-null value, the message will be passed to the second one.
+  * And so on until one of the callbacks accepts the message.
+  * 
+  * Using gras_cb_register is a bit slower than using gras_cb_register_ since GRAS
+  * has to search for the given msgtype in the hash table, but you don't care in most case.
+  */
+#define gras_cb_register(msgtype_name, cb)   gras_cb_register_(gras_msgtype_by_name(msgtype_name),cb)
+
+ /**
+  * @brief Unbind the given callback to the given message type (described by its name)
+  * @hideinitializer
+  * 
+  * Using gras_cb_unregister is a bit slower than using gras_cb_unregister_ since GRAS
+  * has to search for the given msgtype in the hash table, but you don't care in most case.
+  */
+#define gras_cb_unregister(msgtype_name, cb) gras_cb_unregister_(gras_msgtype_by_name(msgtype_name),cb)
+
+  XBT_PUBLIC(void) gras_cb_register_  (gras_msgtype_t msgtype, gras_msg_cb_t cb);
+  XBT_PUBLIC(void) gras_cb_unregister_(gras_msgtype_t msgtype, gras_msg_cb_t cb);
 
 /** @} */  
 
index f816c41..475193c 100644 (file)
@@ -86,16 +86,12 @@ void amok_bw_bw_init() {
   gras_msgtype_declare_rpc("BW request",  bw_request_desc,bw_res_desc);
 }
 void amok_bw_bw_join() {
-  gras_cb_register(gras_msgtype_by_name("BW request"),
-                  &amok_bw_cb_bw_request);
-  gras_cb_register(gras_msgtype_by_name("BW handshake"),
-                  &amok_bw_cb_bw_handshake);
+  gras_cb_register("BW request",  &amok_bw_cb_bw_request);
+  gras_cb_register("BW handshake",&amok_bw_cb_bw_handshake);
 }
 void amok_bw_bw_leave() {
-  gras_cb_unregister(gras_msgtype_by_name("BW request"),
-                    &amok_bw_cb_bw_request);
-  gras_cb_unregister(gras_msgtype_by_name("BW handshake"),
-                    &amok_bw_cb_bw_handshake);
+  gras_cb_unregister("BW request",  &amok_bw_cb_bw_request);
+  gras_cb_unregister("BW handshake",&amok_bw_cb_bw_handshake);
 }
 
 /**
index 28a91dd..fe7745c 100644 (file)
@@ -36,16 +36,12 @@ void amok_bw_sat_init(void) {
 
 }
 void amok_bw_sat_join(void) {
-  gras_cb_register(gras_msgtype_by_name("amok_bw_sat start"),
-                  &amok_bw_cb_sat_start);
-  gras_cb_register(gras_msgtype_by_name("amok_bw_sat begin"),
-                  &amok_bw_cb_sat_begin);
+  gras_cb_register("amok_bw_sat start", &amok_bw_cb_sat_start);
+  gras_cb_register("amok_bw_sat begin", &amok_bw_cb_sat_begin);
 }
 void amok_bw_sat_leave(void) {
-  gras_cb_unregister(gras_msgtype_by_name("amok_bw_sat start"),
-                    &amok_bw_cb_sat_start);
-  gras_cb_unregister(gras_msgtype_by_name("amok_bw_sat begin"),
-                    &amok_bw_cb_sat_begin);
+  gras_cb_unregister("amok_bw_sat start", &amok_bw_cb_sat_start);
+  gras_cb_unregister("amok_bw_sat begin", &amok_bw_cb_sat_begin);
 }
 
 /* ***************************************************************************
index 5095a7d..1f14436 100644 (file)
@@ -239,19 +239,13 @@ static void _amok_pm_join(void *p) {
    mod->groups = xbt_dict_new();
    
    /* callbacks */
-  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);   
+  gras_cb_register("amok_pm_kill",   &amok_pm_cb_kill);
+  gras_cb_register("amok_pm_killrpc",&amok_pm_cb_killrpc);
+
+  gras_cb_register("amok_pm_get",      &amok_pm_cb_get);
+  gras_cb_register("amok_pm_join",     &amok_pm_cb_join);
+  gras_cb_register("amok_pm_leave",    &amok_pm_cb_leave);
+  gras_cb_register("amok_pm_shutdown", &amok_pm_cb_shutdown);   
 }
 static void _amok_pm_exit(void) {
   /* no world-wide globals */
@@ -264,20 +258,13 @@ static void _amok_pm_leave(void *p) {
      xbt_dict_free(&mod->groups);
    
    /* callbacks */
-   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);
+   gras_cb_unregister("amok_pm_kill",   &amok_pm_cb_kill);
+   gras_cb_unregister("amok_pm_killrpc",&amok_pm_cb_killrpc);
+
+   gras_cb_unregister("amok_pm_get",      &amok_pm_cb_get);
+   gras_cb_unregister("amok_pm_join",     &amok_pm_cb_join);
+   gras_cb_unregister("amok_pm_leave",    &amok_pm_cb_leave);
+   gras_cb_unregister("amok_pm_shutdown", &amok_pm_cb_shutdown);   
 }
 
 void amok_pm_modulecreate() {
index d8b6dc9..5306a32 100644 (file)
@@ -741,12 +741,12 @@ gras_cbl_free(void *data){
 /** \brief Bind the given callback to the given message type 
  *
  * Several callbacks can be attached to a given message type. The lastly added one will get the message first, and 
- * if it returns false, the message will be passed to the second one. 
+ * if it returns a non-null value, the message will be passed to the second one. 
  * And so on until one of the callbacks accepts the message.
  */
 void
-gras_cb_register(gras_msgtype_t msgtype,
-                gras_msg_cb_t cb) {
+gras_cb_register_(gras_msgtype_t msgtype,
+                 gras_msg_cb_t cb) {
   gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_by_id(gras_msg_libdata_id);
   gras_cblist_t *list=NULL;
   int cpt;
@@ -775,8 +775,8 @@ gras_cb_register(gras_msgtype_t msgtype,
 
 /** \brief Unbind the given callback from the given message type */
 void
-gras_cb_unregister(gras_msgtype_t msgtype,
-                  gras_msg_cb_t cb) {
+gras_cb_unregister_(gras_msgtype_t msgtype,
+                   gras_msg_cb_t cb) {
 
   gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_by_id(gras_msg_libdata_id);
   gras_cblist_t *list;