Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix bug with Java bindings on 32-bit systems.
[simgrid.git] / src / bindings / java / surf.i
index 4d69190..91e75dc 100644 (file)
@@ -1,13 +1,22 @@
 /* File : example.i */
 %module(directors="1") Surf
 
+%include "arrays_java.i"
+
 %pragma(java) jniclassimports=%{
 import org.simgrid.NativeLib;
-
 %}
 %pragma(java) jniclasscode=%{
   static {
     NativeLib.nativeInit("surf-java");
+    Runtime.getRuntime().addShutdownHook(
+      new Thread() {
+        public void run() {
+          Thread.currentThread().setName( "Destroyer" );
+          Surf.clean();
+        }
+      }
+    );
   }
 %}
 
@@ -19,6 +28,29 @@ import org.simgrid.NativeLib;
 typedef struct lmm_constraint *lmm_constraint_t;
 %}
 
+/* 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);
+}
+%typemap(out) NetworkLinkDynar {
+  long l = xbt_dynar_length($1);
+  $result = jenv->NewLongArray(l);
+  unsigned i;
+  NetworkLink *link;
+  jlong *elts = jenv->GetLongArrayElements($result, NULL);
+  xbt_dynar_foreach($1, i, link) {
+    elts[i] = (jlong)link;
+  }
+  jenv->ReleaseLongArrayElements($result, elts, 0);
+  xbt_dynar_free(&$1);
+}
+
+/* Allow to subclass Plugin and send java object to C++ code */
 %feature("director") Plugin;
 
 %include "src/bindings/java/surf_swig.hpp"
@@ -49,11 +81,18 @@ class NetworkLink : public Resource {
 public:
   NetworkLink();
   ~NetworkLink();
+  double getBandwidth();
+  void updateBandwidth(double value, double date=surf_get_clock());
+  double getLatency();
+  void updateLatency(double value, double date=surf_get_clock());
 };
 
 class Action {
 public:
   Model *getModel();
+  lmm_variable *getVariable();
+  double getBound();
+  void setBound(double bound);
 };
 
 class CpuAction : public Action {
@@ -71,6 +110,11 @@ public:
 }
 };
 
+%nodefaultctor RoutingEdge;
+class RoutingEdge {
+public:
+  virtual char *getName()=0;
+};
 
 %rename lmm_constraint LmmConstraint;
 struct lmm_constraint {
@@ -79,6 +123,13 @@ struct lmm_constraint {
 }
 };
 
+%rename lmm_variable LmmVariable;
+struct lmm_variable {
+%extend {
+  double getValue() {return lmm_variable_getvalue($self);}
+}
+};
+
 %rename s_xbt_dict XbtDict;
 struct s_xbt_dict {
 %extend {
@@ -86,3 +137,19 @@ struct s_xbt_dict {
 }
 };
 
+%rename e_surf_action_state_t ActionState;
+typedef enum {
+  SURF_ACTION_READY = 0,        /**< Ready        */
+  SURF_ACTION_RUNNING,          /**< Running      */
+  SURF_ACTION_FAILED,           /**< Task Failure */
+  SURF_ACTION_DONE,             /**< Completed    */
+  SURF_ACTION_TO_FREE,          /**< Action to free in next cleanup */
+  SURF_ACTION_NOT_IN_THE_SYSTEM
+                                /**< Not in the system anymore. Why did you ask ? */
+} e_surf_action_state_t;
+
+%rename e_surf_resource_state_t ResourceState;
+typedef enum {
+  SURF_RESOURCE_ON = 1,                   /**< Up & ready        */
+  SURF_RESOURCE_OFF = 0                   /**< Down & broken     */
+} e_surf_resource_state_t;