Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove useless declaration.
[simgrid.git] / src / bindings / java / surf.i
1 /* Copyright (c) 2014. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 /* File : example.i */
8 %module(directors="1") Surf
9
10 %include "arrays_java.i"
11 %include "std_string.i"
12
13 %pragma(java) jniclassimports=%{
14 import org.simgrid.NativeLib;
15 %}
16 %pragma(java) jniclasscode=%{
17   static {
18     NativeLib.nativeInit("surf-java");
19     Runtime.getRuntime().addShutdownHook(
20       new Thread() {
21         public void run() {
22           Thread.currentThread().setName( "Destroyer" );
23           Surf.clean();
24         }
25       }
26     );
27   }
28 %}
29
30 %{
31 #include "src/surf/cpu_interface.hpp"
32 #include "src/surf/network_interface.hpp"
33 #include "src/surf/trace_mgr_private.h"
34 #include "src/bindings/java/surf_swig.hpp"
35 #include "src/xbt/dict_private.h"
36 typedef struct lmm_constraint *lmm_constraint_t;
37 typedef xbt_dynar_t DoubleDynar;
38 /*class CpuModel : public CpuModel {
39
40 };*/
41 %}
42
43 /* Handle xbt_dynar_t of NetworkLink */
44 JAVA_ARRAYSOFCLASSES(NetworkLink);
45 %apply NetworkLink[] {NetworkLinkDynar};
46 %typemap(jstype) NetworkLinkDynar "NetworkLink[]"
47 %typemap(javain) NetworkLinkDynar "NetworkLink.cArrayUnwrap($javainput)"
48
49 %typemap(javaout) NetworkLinkDynar {
50      return NetworkLink.cArrayWrap($jnicall, $owner);
51 }
52 %typemap(out) NetworkLinkDynar {
53   long l = xbt_dynar_length($1);
54   $result = jenv->NewLongArray(l);
55   unsigned i;
56   NetworkLink *link;
57   jlong *elts = jenv->GetLongArrayElements($result, NULL);
58   xbt_dynar_foreach($1, i, link) {
59     elts[i] = (jlong)link;
60   }
61   jenv->ReleaseLongArrayElements($result, elts, 0);
62   xbt_dynar_free(&$1);
63 }
64
65 /*%typemap(out) DoubleDynar {
66     $result = (double[])$1;
67 }*/
68
69 //typedef xbt_dynar_t DoubleDynar;
70 %nodefault DoubleDynar;
71 %typemap(jni) DoubleDynar "jdoubleArray"
72 %rename(DoubleDynar) Double[];
73 %typemap(jtype) DoubleDynar "double[]"
74 %typemap(jstype) DoubleDynar "double[]"
75 %typemap(out) DoubleDynar {
76   long l = xbt_dynar_length($1);
77   $result = jenv->NewDoubleArray(l);
78   double *lout = (double *)xbt_dynar_to_array($1);
79   jenv->SetDoubleArrayRegion($result, 0, l, (const jdouble*)lout);
80   free(lout);
81 }
82 %typemap(javadirectorin) DoubleDynar "$jniinput"
83 %typemap(directorin,descriptor="[D") DoubleDynar %{
84   long l = xbt_dynar_length($1);
85   $input = jenv->NewDoubleArray(l);
86   double *lout = (double *)xbt_dynar_to_array($1);
87   jenv->SetDoubleArrayRegion($input, 0, l, (const jdouble*)lout);
88   free(lout);
89 %}
90 %typemap(javain) DoubleDynar "$javainput"
91 %typemap(javaout) DoubleDynar {return  $jnicall}
92
93 /* Allow to subclass Plugin and send java object to C++ code */
94 %feature("director") Plugin;
95
96 %include "src/bindings/java/surf_swig.hpp"
97
98 %rename tmgr_trace TmgrTrace;
99 %nodefaultctor tmgr_trace;
100 struct tmgr_trace {
101   //enum e_trace_type type;
102   /*union {
103     struct {
104       xbt_dynar_t event_list;
105     } s_list;
106     struct {
107       probabilist_event_generator_t event_generator[2];
108       int is_state_trace;
109       int next_event;
110     } s_probabilist;
111   };*/
112   %extend {
113   }
114 };
115
116 %rename tmgr_trace_event TmgrTraceEvent;
117 %nodefaultctor tmgr_trace_event;
118 struct tmgr_trace_event {
119   //tmgr_trace_t trace;
120   //unsigned int idx;
121   //void *model;
122   //int free_me;
123   %extend {
124     unsigned int getIdx() {return 0;}//$self->idx;}
125   }
126 };
127
128
129 %nodefaultctor Model;
130 class Model {
131 public:
132   Model(const char *name);
133   const char *getName();
134   virtual double shareResources(double now);
135   virtual double shareResourcesLazy(double now);
136   virtual double shareResourcesFull(double now);
137
138   virtual void updateActionsState(double now, double delta);
139   virtual void updateActionsStateLazy(double now, double delta);
140   virtual void updateActionsStateFull(double now, double delta);
141 };
142
143 %feature("director") CpuModel;
144 class CpuModel : public Model {
145 public:
146   CpuModel(const char *name);
147   virtual ~CpuModel();
148   virtual Cpu *createResource(const char *name, DoubleDynar power_peak,
149                               int pstate, double power_scale,
150                               tmgr_trace *power_trace, int core,
151                               e_surf_resource_state_t state_initial,
152                               tmgr_trace *state_trace,
153                               s_xbt_dict *cpu_properties)=0;
154   virtual void addTraces()=0;
155 };
156
157
158 class Resource {
159 public:
160   Resource();
161   const char *getName();
162   virtual bool isUsed()=0;
163   Model *getModel();
164
165   virtual e_surf_resource_state_t getState();
166   lmm_constraint *getConstraint();
167   s_xbt_dict *getProperties();
168   virtual void updateState(tmgr_trace_event *event_type, double value, double date)=0;
169 };
170
171 %feature("director") Cpu;
172 class Cpu : public Resource {
173 public:
174   Cpu(Model *model, const char *name, s_xbt_dict *props,
175     lmm_constraint *constraint, int core, double powerPeak, double powerScale);
176   Cpu(Model *model, const char *name, s_xbt_dict *props,
177     int core, double powerPeak, double powerScale);
178   virtual ~Cpu();
179   virtual double getCurrentPowerPeak()=0;
180   virtual CpuAction *execute(double size)=0;
181   virtual CpuAction *sleep(double duration)=0;
182   virtual int getCore();
183   virtual double getSpeed(double load);
184   virtual double getAvailableSpeed();
185   virtual double getPowerPeakAt(int pstate_index)=0;
186   virtual int getNbPstates()=0;
187   virtual void setPowerPeakAt(int pstate_index)=0;
188   void setState(e_surf_resource_state_t state);
189 };
190
191 class NetworkLink : public Resource {
192 public:
193   NetworkLink();
194   ~NetworkLink();
195   double getBandwidth();
196   void updateBandwidth(double value, double date=surf_get_clock());
197   double getLatency();
198   void updateLatency(double value, double date=surf_get_clock());
199 };
200
201 %nodefaultctor Action;
202 class Action {
203 public:
204   Model *getModel();
205   lmm_variable *getVariable();
206   double getBound();
207   void setBound(double bound);
208 };
209
210 %nodefaultctor CpuAction;
211 %feature("director") CpuAction;
212 class CpuAction : public Action {
213 public:
214 CpuAction(Model *model, double cost, bool failed);
215 %extend {
216   Cpu *getCpu() {return getActionCpu($self);}
217 }
218 };
219
220 %nodefaultctor NetworkAction;
221 class NetworkAction : public Action {
222 public:
223 %extend {
224   double getLatency() {return $self->m_latency;}
225 }
226 };
227
228
229 %nodefaultctor RoutingEdge;
230 class RoutingEdge {
231 public:
232   virtual char *getName()=0;
233 };
234
235 %rename lmm_constraint LmmConstraint;
236 struct lmm_constraint {
237 %extend {
238   double getUsage() {return lmm_constraint_get_usage($self);}
239 }
240 };
241
242 %rename lmm_variable LmmVariable;
243 struct lmm_variable {
244 %extend {
245   double getValue() {return lmm_variable_getvalue($self);}
246 }
247 };
248
249 %rename s_xbt_dict XbtDict;
250 struct s_xbt_dict {
251 %extend {
252   char *getValue(char *key) {return (char*)xbt_dict_get_or_null($self, key);}
253 }
254 };
255
256 %rename e_surf_action_state_t ActionState;
257 typedef enum {
258   SURF_ACTION_READY = 0,        /**< Ready        */
259   SURF_ACTION_RUNNING,          /**< Running      */
260   SURF_ACTION_FAILED,           /**< Task Failure */
261   SURF_ACTION_DONE,             /**< Completed    */
262   SURF_ACTION_TO_FREE,          /**< Action to free in next cleanup */
263   SURF_ACTION_NOT_IN_THE_SYSTEM
264                                 /**< Not in the system anymore. Why did you ask ? */
265 } e_surf_action_state_t;
266
267 %rename e_surf_resource_state_t ResourceState;
268 typedef enum {
269   SURF_RESOURCE_ON = 1,                   /**< Up & ready        */
270   SURF_RESOURCE_OFF = 0                   /**< Down & broken     */
271 } e_surf_resource_state_t;