Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add MSG_get_as_by_name call, answering [#17311]
authorAugustin Degomme <degomme@idpann.imag.fr>
Mon, 5 May 2014 12:11:37 +0000 (14:11 +0200)
committerAugustin Degomme <degomme@idpann.imag.fr>
Tue, 6 May 2014 13:56:16 +0000 (15:56 +0200)
include/msg/msg.h
src/include/surf/surf.h
src/msg/msg_environment.c
src/surf/surf_routing.cpp

index 9a585fd..0269493 100644 (file)
@@ -75,6 +75,7 @@ XBT_PUBLIC(unsigned long int) MSG_get_sent_msg(void);
 /************************** Environment ***********************************/
 XBT_PUBLIC(msg_as_t) MSG_environment_get_routing_root(void);
 XBT_PUBLIC(const char *) MSG_environment_as_get_name(msg_as_t as);
+XBT_PUBLIC(msg_as_t) MSG_environment_as_get_by_name(const char * name);
 XBT_PUBLIC(xbt_dict_t) MSG_environment_as_get_routing_sons(msg_as_t as);
 XBT_PUBLIC(const char *) MSG_environment_as_get_property_value(msg_as_t as, const char *name);
 XBT_PUBLIC(const char *) MSG_environment_as_get_model(msg_as_t as);
index 1da385d..2903c05 100644 (file)
@@ -1229,6 +1229,7 @@ XBT_PUBLIC(xbt_dict_t) watched_hosts_lib;
 /*******************************************/
 XBT_PUBLIC_DATA(AS_t) surf_AS_get_routing_root(void);
 XBT_PUBLIC_DATA(const char *) surf_AS_get_name(AS_t as);
+XBT_PUBLIC_DATA(AS_t) surf_AS_get_by_name(const char * name);
 XBT_PUBLIC_DATA(xbt_dict_t) surf_AS_get_routing_sons(AS_t as);
 XBT_PUBLIC_DATA(const char *) surf_AS_get_model(AS_t as);
 XBT_PUBLIC_DATA(xbt_dynar_t) surf_AS_get_hosts(AS_t as);
index 74fc81b..fef3604 100644 (file)
@@ -64,6 +64,10 @@ const char *MSG_environment_as_get_name(msg_as_t as) {
   return surf_AS_get_name(as);
 }
 
+msg_as_t MSG_environment_as_get_by_name(const char * name) {
+  return surf_AS_get_by_name(name);
+}
+
 xbt_dict_t MSG_environment_as_get_routing_sons(msg_as_t as) {
   xbt_dict_t res = surf_AS_get_routing_sons(as);
   return res;
index a4bbe30..4947757 100644 (file)
@@ -1325,6 +1325,32 @@ const char *surf_AS_get_name(AsPtr as) {
   return as->p_name;
 }
 
+static AsPtr surf_AS_recursive_get_by_name(AsPtr current, const char * name) {
+  xbt_dict_cursor_t cursor = NULL;
+  char *key;
+  AS_t elem;
+  AsPtr tmp = NULL;
+
+  if(!strcmp(current->p_name, name))
+    return current;
+
+  xbt_dict_foreach(current->p_routingSons, cursor, key, elem) {
+    tmp = surf_AS_recursive_get_by_name(elem, name);
+    if(tmp != NULL ) {
+        break;
+    }
+  }
+  return tmp;
+}
+
+
+AsPtr surf_AS_get_by_name(const char * name) {
+  AsPtr as = surf_AS_recursive_get_by_name(routing_platf->p_root, name);
+  if(as == NULL)
+    XBT_WARN("Impossible to find an AS with name %s, please check your input", name);
+  return as;
+}
+
 xbt_dict_t surf_AS_get_routing_sons(AsPtr as) {
   return as->p_routingSons;
 }