Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
moving dynar up in the stack
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 8 Mar 2017 15:55:15 +0000 (16:55 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 8 Mar 2017 15:55:15 +0000 (16:55 +0100)
include/simgrid/s4u/host.hpp
src/bindings/java/jmsg_host.cpp
src/msg/msg_host.cpp
src/s4u/s4u_host.cpp
src/simgrid/host.cpp
src/surf/HostImpl.cpp
src/surf/HostImpl.hpp

index 77147d3..7c48221 100644 (file)
@@ -94,7 +94,7 @@ public:
   void setPstate(int pstate_index);
   int pstate();
   xbt_dict_t mountedStoragesAsDict(); // HACK
   void setPstate(int pstate_index);
   int pstate();
   xbt_dict_t mountedStoragesAsDict(); // HACK
-  xbt_dynar_t attachedStorages();
+  std::vector<const char*> attachedStorages();
 
   /** Get an associative list [mount point]->[Storage] of all local mount points.
    *
 
   /** Get an associative list [mount point]->[Storage] of all local mount points.
    *
index f3f0fc5..6a095c5 100644 (file)
@@ -272,15 +272,13 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_getAttachedStorage(JNIE
   }
   jobjectArray jtable;
 
   }
   jobjectArray jtable;
 
-  xbt_dynar_t dyn = MSG_host_get_attached_storage_list(host);
-  int count = xbt_dynar_length(dyn);
-  jclass cls = jxbt_get_class(env, "java/lang/String");
-  jtable = env->NewObjectArray((jsize) count, cls, nullptr);
-  int index;
-  char *storage_name;
+  xbt_dynar_t dyn = sg_host_get_attached_storage_list(host);
+  jclass cls      = jxbt_get_class(env, "java/lang/String");
+  jtable          = env->NewObjectArray(static_cast<jsize>(xbt_dynar_length(dyn)), cls, nullptr);
+  unsigned int index;
+  const char* storage_name;
   jstring jstorage_name;
   jstring jstorage_name;
-  for (index = 0; index < count; index++) {
-    storage_name = xbt_dynar_get_as(dyn,index,char*);
+  xbt_dynar_foreach (dyn, index, storage_name) {
     jstorage_name = env->NewStringUTF(storage_name);
     env->SetObjectArrayElement(jtable, index, jstorage_name);
   }
     jstorage_name = env->NewStringUTF(storage_name);
     env->SetObjectArrayElement(jtable, index, jstorage_name);
   }
index e8f6518..3d68513 100644 (file)
@@ -5,6 +5,7 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "simgrid/s4u/host.hpp"
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "simgrid/s4u/host.hpp"
+#include "simgrid/s4u/storage.hpp"
 #include "src/msg/msg_private.h"
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(msg);
 #include "src/msg/msg_private.h"
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(msg);
@@ -255,8 +256,7 @@ xbt_dict_t MSG_host_get_mounted_storage_list(msg_host_t host)
  */
 xbt_dynar_t MSG_host_get_attached_storage_list(msg_host_t host)
 {
  */
 xbt_dynar_t MSG_host_get_attached_storage_list(msg_host_t host)
 {
-  xbt_assert((host != nullptr), "Invalid parameters");
-  return host->attachedStorages();
+  return sg_host_get_attached_storage_list(host);
 }
 
 /** \ingroup m_host_management
 }
 
 /** \ingroup m_host_management
index d821972..dcfa890 100644 (file)
@@ -257,7 +257,7 @@ xbt_dict_t Host::mountedStoragesAsDict()
  * \brief Returns the list of storages attached to an host.
  * \return a dict containing all storages attached to the host
  */
  * \brief Returns the list of storages attached to an host.
  * \return a dict containing all storages attached to the host
  */
-xbt_dynar_t Host::attachedStorages()
+std::vector<const char*> Host::attachedStorages()
 {
   return simgrid::simix::kernelImmediate([this] {
     return this->pimpl_->getAttachedStorageList();
 {
   return simgrid::simix::kernelImmediate([this] {
     return this->pimpl_->getAttachedStorageList();
index 901e0bd..51bc85e 100644 (file)
@@ -121,10 +121,12 @@ xbt_dict_t sg_host_get_mounted_storage_list(sg_host_t host){
 }
 
 xbt_dynar_t sg_host_get_attached_storage_list(sg_host_t host){
 }
 
 xbt_dynar_t sg_host_get_attached_storage_list(sg_host_t host){
-  return host->pimpl_->getAttachedStorageList();
+  xbt_dynar_t storage_dynar = xbt_dynar_new(sizeof(const char*), nullptr);
+  for (auto name : host->attachedStorages())
+    xbt_dynar_push(storage_dynar, &name);
+  return storage_dynar;
 }
 
 }
 
-
 // =========== user-level functions ===============
 // ================================================
 /** @brief Returns the total speed of a host */
 // =========== user-level functions ===============
 // ================================================
 /** @brief Returns the total speed of a host */
index d74dfd2..5366a5d 100644 (file)
@@ -138,19 +138,19 @@ xbt_dict_t HostImpl::getMountedStorageList()
   return storage_list;
 }
 
   return storage_list;
 }
 
-xbt_dynar_t HostImpl::getAttachedStorageList()
+std::vector<const char*> HostImpl::getAttachedStorageList()
 {
   xbt_lib_cursor_t cursor;
   char* key;
   void** data;
 {
   xbt_lib_cursor_t cursor;
   char* key;
   void** data;
-  xbt_dynar_t result = xbt_dynar_new(sizeof(void*), nullptr);
+  std::vector<const char*> result;
   xbt_lib_foreach(storage_lib, cursor, key, data)
   {
     if (xbt_lib_get_level(xbt_lib_get_elm_or_null(storage_lib, key), SURF_STORAGE_LEVEL) != nullptr) {
       simgrid::surf::Storage* storage = static_cast<simgrid::surf::Storage*>(
           xbt_lib_get_level(xbt_lib_get_elm_or_null(storage_lib, key), SURF_STORAGE_LEVEL));
       if (!strcmp(static_cast<const char*>(storage->attach_), piface_->cname())) {
   xbt_lib_foreach(storage_lib, cursor, key, data)
   {
     if (xbt_lib_get_level(xbt_lib_get_elm_or_null(storage_lib, key), SURF_STORAGE_LEVEL) != nullptr) {
       simgrid::surf::Storage* storage = static_cast<simgrid::surf::Storage*>(
           xbt_lib_get_level(xbt_lib_get_elm_or_null(storage_lib, key), SURF_STORAGE_LEVEL));
       if (!strcmp(static_cast<const char*>(storage->attach_), piface_->cname())) {
-        xbt_dynar_push_as(result, void*, (void*)storage->cname());
+        result.push_back(storage->cname());
       }
     }
   }
       }
     }
   }
index 70887a8..4c28215 100644 (file)
@@ -73,7 +73,7 @@ public:
   virtual xbt_dict_t getMountedStorageList();
 
   /** @brief Get the xbt_dynar_t of storages attached to the Host */
   virtual xbt_dict_t getMountedStorageList();
 
   /** @brief Get the xbt_dynar_t of storages attached to the Host */
-  virtual xbt_dynar_t getAttachedStorageList();
+  virtual std::vector<const char*> getAttachedStorageList();
 
   /**
    * @brief Open a file
 
   /**
    * @brief Open a file