Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
1553e7706098db4b2ee2f4e25ec74ed58ac840ed
[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
12 %pragma(java) jniclassimports=%{
13 import org.simgrid.NativeLib;
14 %}
15 %pragma(java) jniclasscode=%{
16   static {
17     NativeLib.nativeInit("surf-java");
18     Runtime.getRuntime().addShutdownHook(
19       new Thread() {
20         public void run() {
21           Thread.currentThread().setName( "Destroyer" );
22           Surf.clean();
23         }
24       }
25     );
26   }
27 %}
28
29 %{
30 #include "src/surf/cpu_interface.hpp"
31 #include "src/surf/network_interface.hpp"
32 #include "src/bindings/java/surf_swig.hpp"
33 #include "src/xbt/dict_private.h"
34 typedef struct lmm_constraint *lmm_constraint_t;
35 %}
36
37 /* Handle xbt_dynar_t of NetworkLink */
38 JAVA_ARRAYSOFCLASSES(NetworkLink);
39 %apply NetworkLink[] {NetworkLinkDynar};
40 %typemap(jstype) NetworkLinkDynar "NetworkLink[]"
41 %typemap(javain) NetworkLinkDynar "NetworkLink.cArrayUnwrap($javainput)"
42
43 %typemap(javaout) NetworkLinkDynar {
44      return NetworkLink.cArrayWrap($jnicall, $owner);
45 }
46 %typemap(out) NetworkLinkDynar {
47   long l = xbt_dynar_length($1);
48   $result = jenv->NewLongArray(l);
49   unsigned i;
50   NetworkLink *link;
51   jlong *elts = jenv->GetLongArrayElements($result, NULL);
52   xbt_dynar_foreach($1, i, link) {
53     elts[i] = (jlong)link;
54   }
55   jenv->ReleaseLongArrayElements($result, elts, 0);
56   xbt_dynar_free(&$1);
57 }
58
59 /* Allow to subclass Plugin and send java object to C++ code */
60 %feature("director") Plugin;
61
62 %include "src/bindings/java/surf_swig.hpp"
63
64 %nodefaultctor Model;
65 class Model {
66 public:
67   const char *getName();
68 };
69
70 class Resource {
71 public:
72   Resource();
73   const char *getName();
74   virtual bool isUsed()=0;
75   lmm_constraint *getConstraint();
76   s_xbt_dict *getProperties();
77 };
78
79 class Cpu : public Resource {
80 public:
81   Cpu();
82   ~Cpu();
83   double getCurrentPowerPeak();
84 };
85
86 class NetworkLink : public Resource {
87 public:
88   NetworkLink();
89   ~NetworkLink();
90   double getBandwidth();
91   void updateBandwidth(double value, double date=surf_get_clock());
92   double getLatency();
93   void updateLatency(double value, double date=surf_get_clock());
94 };
95
96 %nodefaultctor Action;
97 class Action {
98 public:
99   Model *getModel();
100   lmm_variable *getVariable();
101   double getBound();
102   void setBound(double bound);
103 };
104
105 %nodefaultctor CpuAction;
106 class CpuAction : public Action {
107 public:
108 %extend {
109   Cpu *getCpu() {return getActionCpu($self);}
110 }
111 };
112
113 %nodefaultctor NetworkAction;
114 class NetworkAction : public Action {
115 public:
116 %extend {
117   double getLatency() {return $self->m_latency;}
118 }
119 };
120
121 %nodefaultctor RoutingEdge;
122 class RoutingEdge {
123 public:
124   virtual char *getName()=0;
125 };
126
127 %rename lmm_constraint LmmConstraint;
128 struct lmm_constraint {
129 %extend {
130   double getUsage() {return lmm_constraint_get_usage($self);}
131 }
132 };
133
134 %rename lmm_variable LmmVariable;
135 struct lmm_variable {
136 %extend {
137   double getValue() {return lmm_variable_getvalue($self);}
138 }
139 };
140
141 %rename s_xbt_dict XbtDict;
142 struct s_xbt_dict {
143 %extend {
144   char *getValue(char *key) {return (char*)xbt_dict_get_or_null($self, key);}
145 }
146 };
147
148 %rename e_surf_action_state_t ActionState;
149 typedef enum {
150   SURF_ACTION_READY = 0,        /**< Ready        */
151   SURF_ACTION_RUNNING,          /**< Running      */
152   SURF_ACTION_FAILED,           /**< Task Failure */
153   SURF_ACTION_DONE,             /**< Completed    */
154   SURF_ACTION_TO_FREE,          /**< Action to free in next cleanup */
155   SURF_ACTION_NOT_IN_THE_SYSTEM
156                                 /**< Not in the system anymore. Why did you ask ? */
157 } e_surf_action_state_t;
158
159 %rename e_surf_resource_state_t ResourceState;
160 typedef enum {
161   SURF_RESOURCE_ON = 1,                   /**< Up & ready        */
162   SURF_RESOURCE_OFF = 0                   /**< Down & broken     */
163 } e_surf_resource_state_t;