Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
surfCpuModel add execute on host
[simgrid.git] / src / bindings / java / surf.i
index ecb4b12..2be8718 100644 (file)
@@ -28,24 +28,118 @@ import org.simgrid.NativeLib;
 %}
 
 %{
+#include "src/surf/surf_interface.hpp"
 #include "src/surf/cpu_interface.hpp"
 #include "src/surf/network_interface.hpp"
 #include "src/surf/trace_mgr_private.h"
 #include "src/bindings/java/surf_swig.hpp"
 #include "src/xbt/dict_private.h"
+
 typedef struct lmm_constraint *lmm_constraint_t;
 typedef xbt_dynar_t DoubleDynar;
-/*class CpuModel : public CpuModel {
+%}
+
+%wrapper %{
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+JNIEXPORT jobject JNICALL Java_org_simgrid_surf_SurfJNI_getAction(JNIEnv *env, jclass cls, jlong jarg1) {
+  Action * action = (Action *)jarg1;
+  jobject res;
+  CpuAction *cpu_action = dynamic_cast<CpuAction*>(action);
+  if (cpu_action) {
+    SwigDirector_CpuAction *dir_cpu_action = dynamic_cast<SwigDirector_CpuAction*>(cpu_action);
+    if (dir_cpu_action) {
+      res = dir_cpu_action->swig_get_self(env);\
+    } else {
+      jclass clss = env->FindClass("org/simgrid/surf/CpuAction");\
+      jmethodID constru = env->GetMethodID(clss, "<init>", "()V");\
+      res = env->NewObject(clss, constru);\
+      res = env->NewGlobalRef(res);\
+    }
+  } else {
+    jclass clss = env->FindClass("org/simgrid/surf/Action");\
+    jmethodID constru = env->GetMethodID(clss, "<init>", "()V");\
+    res = env->NewObject(clss, constru);\
+    res = env->NewGlobalRef(res);\
+  }
+  return res;
+}
+
+#define GETDIRECTOR(NAME) \
+JNIEXPORT jobject JNICALL Java_org_simgrid_surf_SurfJNI_get## NAME ## Director(JNIEnv *env, jclass cls, jlong jarg1)\
+{\
+  NAME * arg1 = (NAME*)jarg1;\
+  SwigDirector_ ##NAME *director = dynamic_cast<SwigDirector_ ##NAME *>(arg1);\
+  jobject res;\
+  if (director) {\
+    res = director->swig_get_self(env);\
+  } else {\
+    jclass clss = env->FindClass("org/simgrid/surf/NAME");\
+    jmethodID constru = env->GetMethodID(clss, "<init>", "()V");\
+    res = env->NewObject(clss, constru);\
+    res = env->NewGlobalRef(res);\
+  }\
+  return res;\
+}
+
+GETDIRECTOR(CpuModel)
+GETDIRECTOR(Cpu)
+GETDIRECTOR(CpuAction)
+
+#ifdef __cplusplus
+}
+#endif
 
-};*/
 %}
 
+%typemap(freearg) char* name {
+}
+
+/* Handle xbt_dynar_t of NetworkLink */
+JAVA_ARRAYSOFCLASSES(Action);
+%apply Action[] {ActionArrayPtr};
+%typemap(jstype) ActionArrayPtr "Action[]"
+%typemap(javain) ActionArrayPtr "Action.cArrayUnwrap($javainput)"
+%typemap(javaout) ActionArrayPtr {
+  long[] cArray = $jnicall;
+  Action[] arrayWrapper = new Action[cArray.length];
+  for (int i=0; i<cArray.length; i++)
+    arrayWrapper[i] = (Action) Surf.getAction(cArray[i]);
+  return arrayWrapper;
+  //   return Action.cArrayWrap($jnicall, $owner);
+}
+%typemap(out) ActionArrayPtr {
+  long l = 0;
+  for(ActionList::iterator it($1->begin()), itend($1->end()); it != itend ; ++it) {
+    l++;
+  }
+  $result = jenv->NewLongArray(l);
+  jlong *elts = jenv->GetLongArrayElements($result, NULL);
+  l = 0;
+  for(ActionList::iterator it($1->begin()), itend($1->end()); it != itend ; ++it) {
+    elts[l++] = (jlong)static_cast<ActionPtr>(&*it);
+  }
+  jenv->ReleaseLongArrayElements($result, elts, 0);
+}
+
+class ActionList {
+public:
+  //void push_front(Action &action);
+  //void push_back(Action &action);
+%extend {
+  ActionArrayPtr getArray(){
+    return $self;
+  }
+}
+};
+
 /* Handle xbt_dynar_t of NetworkLink */
 JAVA_ARRAYSOFCLASSES(NetworkLink);
 %apply NetworkLink[] {NetworkLinkDynar};
 %typemap(jstype) NetworkLinkDynar "NetworkLink[]"
 %typemap(javain) NetworkLinkDynar "NetworkLink.cArrayUnwrap($javainput)"
-
 %typemap(javaout) NetworkLinkDynar {
      return NetworkLink.cArrayWrap($jnicall, $owner);
 }
@@ -62,11 +156,6 @@ JAVA_ARRAYSOFCLASSES(NetworkLink);
   xbt_dynar_free(&$1);
 }
 
-/*%typemap(out) DoubleDynar {
-    $result = (double[])$1;
-}*/
-
-//typedef xbt_dynar_t DoubleDynar;
 %nodefault DoubleDynar;
 %typemap(jni) DoubleDynar "jdoubleArray"
 %rename(DoubleDynar) Double[];
@@ -93,6 +182,23 @@ JAVA_ARRAYSOFCLASSES(NetworkLink);
 /* Allow to subclass Plugin and send java object to C++ code */
 %feature("director") Plugin;
 
+%native(getAction) jobject getAction(jlong jarg1);
+%native(getCpuModelDirector) jobject getCpuModelDirector(jlong jarg1);
+%typemap(javaout) CpuModel * {
+  long cPtr = $jnicall;
+  return (CpuModel)Surf.getCpuModelDirector(cPtr);
+}
+%native(getCpuDirector) jobject getCpuDirector(jlong jarg1);
+%typemap(javaout) Cpu * {
+  long cPtr = $jnicall;
+  return (Cpu)Surf.getCpuDirector(cPtr);
+}
+%native(getCpuActionDirector) jobject getCpuActionDirector(jlong jarg1);
+%typemap(javaout) CpuAction * {
+  long cPtr = $jnicall;
+  return (CpuAction)Surf.getCpuDirector(cPtr);
+}
+
 %include "src/bindings/java/surf_swig.hpp"
 
 %rename tmgr_trace TmgrTrace;
@@ -125,7 +231,6 @@ struct tmgr_trace_event {
   }
 };
 
-
 %nodefaultctor Model;
 class Model {
 public:
@@ -138,6 +243,13 @@ public:
   virtual void updateActionsState(double now, double delta);
   virtual void updateActionsStateLazy(double now, double delta);
   virtual void updateActionsStateFull(double now, double delta);
+
+  virtual ActionList *getRunningActionSet();
+%extend {
+  Action *getRunningActionS() {
+    return (Action*)(&($self->getRunningActionSet()->front()));
+  }
+}
 };
 
 %feature("director") CpuModel;
@@ -154,7 +266,6 @@ public:
   virtual void addTraces()=0;
 };
 
-
 class Resource {
 public:
   Resource();
@@ -176,7 +287,7 @@ public:
   Cpu(Model *model, const char *name, s_xbt_dict *props,
     int core, double powerPeak, double powerScale);
   virtual ~Cpu();
-  virtual double getCurrentPowerPeak()=0;
+  virtual double getCurrentPowerPeak();
   virtual CpuAction *execute(double size)=0;
   virtual CpuAction *sleep(double duration)=0;
   virtual int getCore();
@@ -201,10 +312,18 @@ public:
 %nodefaultctor Action;
 class Action {
 public:
+  Action(Model *model, double cost, bool failed);
+  virtual ~Action();
   Model *getModel();
   lmm_variable *getVariable();
+  e_surf_action_state_t getState();
+  bool isSuspended();
   double getBound();
   void setBound(double bound);
+  void updateRemains(double delta);
+  virtual double getRemains();
+  virtual void setPriority(double priority);
+  virtual void setState(e_surf_action_state_t state);
 };
 
 %nodefaultctor CpuAction;