Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix make dist.
[simgrid.git] / examples / gras / mmrpc / mmrpc.c
index bfad502..fa9de31 100644 (file)
@@ -6,7 +6,7 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
-#define GRAS_DEFINE_TYPE_EXTERN
+#define XBT_DEFINE_TYPE_EXTERN
 #include "xbt/matrix.h"
 #include "mmrpc.h"
 
@@ -16,12 +16,12 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(MatMult, "Messages specific to this example");
    (common to client and server) */
 void mmrpc_register_messages(void)
 {
-  gras_datadesc_type_t matrix_type, request_type;
+  xbt_datadesc_type_t matrix_type, request_type;
 
-  matrix_type = gras_datadesc_matrix(gras_datadesc_by_name("double"),
+  matrix_type = xbt_datadesc_matrix(xbt_datadesc_by_name("double"),
                                      NULL);
   request_type =
-      gras_datadesc_array_fixed("s_matrix_t(double)[2]", matrix_type, 2);
+      xbt_datadesc_array_fixed("s_matrix_t(double)[2]", matrix_type, 2);
 
   gras_msgtype_declare("answer", matrix_type);
   gras_msgtype_declare("request", request_type);
@@ -32,7 +32,7 @@ static int server_cb_request_handler(gras_msg_cb_ctx_t ctx,
                                      void *payload_data)
 {
 
-  gras_socket_t expeditor = gras_msg_cb_ctx_from(ctx);
+  xbt_socket_t expeditor = gras_msg_cb_ctx_from(ctx);
 
   /* 1. Get the payload into the data variable */
   xbt_matrix_t *request = (xbt_matrix_t *) payload_data;
@@ -55,8 +55,7 @@ static int server_cb_request_handler(gras_msg_cb_ctx_t ctx,
 
 int server(int argc, char *argv[])
 {
-  xbt_ex_t e;
-  gras_socket_t sock = NULL;
+  xbt_socket_t sock = NULL;
   int port = 4000;
 
   /* 1. Init the GRAS infrastructure */
@@ -68,12 +67,12 @@ int server(int argc, char *argv[])
   }
 
   /* 3. Create my master socket */
-  INFO1("Launch server (port=%d)", port);
+  XBT_INFO("Launch server (port=%d)", port);
   TRY {
     sock = gras_socket_server(port);
   }
-  CATCH(e) {
-    RETHROW0("Unable to establish a server socket: %s");
+  CATCH_ANONYMOUS {
+    RETHROWF("Unable to establish a server socket: %s");
   }
 
   /* 4. Register the known messages and payloads. */
@@ -82,24 +81,23 @@ int server(int argc, char *argv[])
   /* 5. Register my callback */
   gras_cb_register("request", &server_cb_request_handler);
 
-  /* 6. Wait up to 10 minutes for an incomming message to handle */
+  /* 6. Wait up to 10 minutes for an incoming message to handle */
   gras_msg_handle(600.0);
 
   /* 7. Free the allocated resources, and shut GRAS down */
   gras_socket_close(sock);
   gras_exit();
 
-  INFO0("Done.");
+  XBT_INFO("Done.");
   return 0;
 }                               /* end_of_server */
 
 
 int client(int argc, char *argv[])
 {
-  xbt_ex_t e;
-  gras_socket_t toserver = NULL;        /* peer */
+  xbt_socket_t toserver = NULL;        /* peer */
 
-  gras_socket_t from;
+  xbt_socket_t from;
   xbt_matrix_t request[2], answer;
 
   int i, j;
@@ -116,7 +114,7 @@ int client(int argc, char *argv[])
     port = atoi(argv[2]);
   }
 
-  INFO2("Launch client (server on %s:%d)", host, port);
+  XBT_INFO("Launch client (server on %s:%d)", host, port);
 
   /* 3. Wait for the server startup */
   gras_os_sleep(1);
@@ -125,18 +123,18 @@ int client(int argc, char *argv[])
   TRY {
     toserver = gras_socket_client(host, port);
   }
-  CATCH(e) {
-    RETHROW0("Unable to connect to the server: %s");
+  CATCH_ANONYMOUS {
+    RETHROWF("Unable to connect to the server: %s");
   }
-  INFO2("Connected to %s:%d.", host, port);
+  XBT_INFO("Connected to %s:%d.", host, port);
 
 
   /* 5. Register the messages (before use) */
   mmrpc_register_messages();
 
   /* 6. Keep the user informed of what's going on */
-  INFO2(">>>>>>>> Connected to server which is on %s:%d <<<<<<<<",
-        gras_socket_peer_name(toserver), gras_socket_peer_port(toserver));
+  XBT_INFO(">>>>>>>> Connected to server which is on %s:%d <<<<<<<<",
+        xbt_socket_peer_name(toserver), xbt_socket_peer_port(toserver));
 
   /* 7. Prepare and send the request to the server */
 
@@ -152,8 +150,8 @@ int client(int argc, char *argv[])
 
   xbt_matrix_free(request[0]);
 
-  INFO2(">>>>>>>> Request sent to %s:%d <<<<<<<<",
-        gras_socket_peer_name(toserver), gras_socket_peer_port(toserver));
+  XBT_INFO(">>>>>>>> Request sent to %s:%d <<<<<<<<",
+        xbt_socket_peer_name(toserver), xbt_socket_peer_port(toserver));
 
   /* 8. Wait for the answer from the server, and deal with issues */
   gras_msg_wait(6000, "answer", &from, &answer);
@@ -163,21 +161,21 @@ int client(int argc, char *argv[])
    */
   for (i = 0; i < MATSIZE; i++)
     for (j = 0; i < MATSIZE; i++)
-      xbt_assert4(xbt_matrix_get_as(answer, i, j, double) ==
+      xbt_assert(xbt_matrix_get_as(answer, i, j, double) ==
                   xbt_matrix_get_as(request[1], i, j, double),
                   "Answer does not match expectations. Found %f at cell %d,%d instead of %f",
                   xbt_matrix_get_as(answer, i, j, double), i, j,
                   xbt_matrix_get_as(request[1], i, j, double));
 
   /* 9. Keep the user informed of what's going on, again */
-  INFO2(">>>>>>>> Got answer from %s:%d (values are right) <<<<<<<<",
-        gras_socket_peer_name(from), gras_socket_peer_port(from));
+  XBT_INFO(">>>>>>>> Got answer from %s:%d (values are right) <<<<<<<<",
+        xbt_socket_peer_name(from), xbt_socket_peer_port(from));
 
   /* 10. Free the allocated resources, and shut GRAS down */
   xbt_matrix_free(request[1]);
   xbt_matrix_free(answer);
   gras_socket_close(toserver);
   gras_exit();
-  INFO0("Done.");
+  XBT_INFO("Done.");
   return 0;
 }                               /* end_of_client */