1 /* Copyright (c) 2014. The SimGrid Team.
2 * All rights reserved. */
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. */
8 %module(directors="1") Surf
10 %include "arrays_java.i"
11 %include "std_string.i"
13 %pragma(java) jniclassimports=%{
14 import org.simgrid.NativeLib;
16 %pragma(java) jniclasscode=%{
18 NativeLib.nativeInit("surf-java");
19 Runtime.getRuntime().addShutdownHook(
22 Thread.currentThread().setName( "Destroyer" );
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 {
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)"
49 %typemap(javaout) NetworkLinkDynar {
50 return NetworkLink.cArrayWrap($jnicall, $owner);
52 %typemap(out) NetworkLinkDynar {
53 long l = xbt_dynar_length($1);
54 $result = jenv->NewLongArray(l);
57 jlong *elts = jenv->GetLongArrayElements($result, NULL);
58 xbt_dynar_foreach($1, i, link) {
59 elts[i] = (jlong)link;
61 jenv->ReleaseLongArrayElements($result, elts, 0);
65 /*%typemap(out) DoubleDynar {
66 $result = (double[])$1;
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);
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);
90 %typemap(javain) DoubleDynar "$javainput"
91 %typemap(javaout) DoubleDynar {return $jnicall}
93 /* Allow to subclass Plugin and send java object to C++ code */
94 %feature("director") Plugin;
96 %include "src/bindings/java/surf_swig.hpp"
98 %rename tmgr_trace TmgrTrace;
99 %nodefaultctor tmgr_trace;
101 //enum e_trace_type type;
104 xbt_dynar_t event_list;
107 probabilist_event_generator_t event_generator[2];
116 %rename tmgr_trace_event TmgrTraceEvent;
117 %nodefaultctor tmgr_trace_event;
118 struct tmgr_trace_event {
119 //tmgr_trace_t trace;
124 unsigned int getIdx() {return 0;}//$self->idx;}
129 %nodefaultctor Model;
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);
138 virtual void updateActionsState(double now, double delta);
139 virtual void updateActionsStateLazy(double now, double delta);
140 virtual void updateActionsStateFull(double now, double delta);
143 %feature("director") CpuModel;
144 class CpuModel : public Model {
146 CpuModel(const char *name);
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;
161 const char *getName();
162 virtual bool isUsed()=0;
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;
171 %feature("director") Cpu;
172 class Cpu : public Resource {
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);
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);
191 class NetworkLink : public Resource {
195 double getBandwidth();
196 void updateBandwidth(double value, double date=surf_get_clock());
198 void updateLatency(double value, double date=surf_get_clock());
201 %nodefaultctor Action;
205 lmm_variable *getVariable();
207 void setBound(double bound);
210 %nodefaultctor CpuAction;
211 %feature("director") CpuAction;
212 class CpuAction : public Action {
214 CpuAction(Model *model, double cost, bool failed);
216 Cpu *getCpu() {return getActionCpu($self);}
220 %nodefaultctor NetworkAction;
221 class NetworkAction : public Action {
224 double getLatency() {return $self->m_latency;}
229 %nodefaultctor RoutingEdge;
232 virtual char *getName()=0;
235 %rename lmm_constraint LmmConstraint;
236 struct lmm_constraint {
238 double getUsage() {return lmm_constraint_get_usage($self);}
242 %rename lmm_variable LmmVariable;
243 struct lmm_variable {
245 double getValue() {return lmm_variable_getvalue($self);}
249 %rename s_xbt_dict XbtDict;
252 char *getValue(char *key) {return (char*)xbt_dict_get_or_null($self, key);}
256 %rename e_surf_action_state_t ActionState;
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;
267 %rename e_surf_resource_state_t ResourceState;
269 SURF_RESOURCE_ON = 1, /**< Up & ready */
270 SURF_RESOURCE_OFF = 0 /**< Down & broken */
271 } e_surf_resource_state_t;