Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'mc++'
[simgrid.git] / src / bindings / java / surf.i
1 /* File : example.i */
2 %module(directors="1") Surf
3
4 %include "arrays_java.i"
5
6 %pragma(java) jniclassimports=%{
7 import org.simgrid.NativeLib;
8 %}
9 %pragma(java) jniclasscode=%{
10   static {
11     NativeLib.nativeInit("surf-java");
12     Runtime.getRuntime().addShutdownHook(
13       new Thread() {
14         public void run() {
15           Thread.currentThread().setName( "Destroyer" );
16           Surf.clean();
17         }
18       }
19     );
20   }
21 %}
22
23 %{
24 #include "src/surf/cpu_interface.hpp"
25 #include "src/surf/network_interface.hpp"
26 #include "src/bindings/java/surf_swig.hpp"
27 #include "src/xbt/dict_private.h"
28 typedef struct lmm_constraint *lmm_constraint_t;
29 %}
30
31 /* Handle xbt_dynar_t of NetworkLink */
32 JAVA_ARRAYSOFCLASSES(NetworkLink);
33 %apply NetworkLink[] {NetworkLinkDynar};
34 %typemap(jstype) NetworkLinkDynar "NetworkLink[]"
35 %typemap(javain) NetworkLinkDynar "NetworkLink.cArrayUnwrap($javainput)"
36
37 %typemap(javaout) NetworkLinkDynar {
38      return NetworkLink.cArrayWrap($jnicall, $owner);
39 }
40 %typemap(out) NetworkLinkDynar {
41   long l = xbt_dynar_length($1);
42   $result = jenv->NewLongArray(l);
43   NetworkLink **lout = (NetworkLink **)xbt_dynar_to_array($1);
44   jenv->SetLongArrayRegion($result, 0, l, (const jlong*)lout);
45   free(lout);
46 }
47
48 /* Allow to subclass Plugin and send java object to C++ code */
49 %feature("director") Plugin;
50
51 %include "src/bindings/java/surf_swig.hpp"
52
53 %nodefaultctor Model;
54 class Model {
55 public:
56   const char *getName();
57 };
58
59 class Resource {
60 public:
61   Resource();
62   const char *getName();
63   virtual bool isUsed()=0;
64   lmm_constraint *getConstraint();
65   s_xbt_dict *getProperties();
66 };
67
68 class Cpu : public Resource {
69 public:
70   Cpu();
71   ~Cpu();
72   double getCurrentPowerPeak();
73 };
74
75 class NetworkLink : public Resource {
76 public:
77   NetworkLink();
78   ~NetworkLink();
79 };
80
81 class Action {
82 public:
83   Model *getModel();
84 };
85
86 class CpuAction : public Action {
87 public:
88 %extend {
89   Cpu *getCpu() {return getActionCpu($self);}
90 }
91 };
92
93 %nodefaultctor NetworkAction;
94 class NetworkAction : public Action {
95 public:
96 %extend {
97   double getLatency() {return $self->m_latency;}
98 }
99 };
100
101 %rename lmm_constraint LmmConstraint;
102 struct lmm_constraint {
103 %extend {
104   double getUsage() {return lmm_constraint_get_usage($self);}
105 }
106 };
107
108 %rename s_xbt_dict XbtDict;
109 struct s_xbt_dict {
110 %extend {
111   char *getValue(char *key) {return (char*)xbt_dict_get_or_null($self, key);}
112 }
113 };