Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Factorize initializations for Action constructors.
[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 class Action {
97 public:
98   Model *getModel();
99   lmm_variable *getVariable();
100   double getBound();
101   void setBound(double bound);
102 };
103
104 class CpuAction : public Action {
105 public:
106 %extend {
107   Cpu *getCpu() {return getActionCpu($self);}
108 }
109 };
110
111 %nodefaultctor NetworkAction;
112 class NetworkAction : public Action {
113 public:
114 %extend {
115   double getLatency() {return $self->m_latency;}
116 }
117 };
118
119 %nodefaultctor RoutingEdge;
120 class RoutingEdge {
121 public:
122   virtual char *getName()=0;
123 };
124
125 %rename lmm_constraint LmmConstraint;
126 struct lmm_constraint {
127 %extend {
128   double getUsage() {return lmm_constraint_get_usage($self);}
129 }
130 };
131
132 %rename lmm_variable LmmVariable;
133 struct lmm_variable {
134 %extend {
135   double getValue() {return lmm_variable_getvalue($self);}
136 }
137 };
138
139 %rename s_xbt_dict XbtDict;
140 struct s_xbt_dict {
141 %extend {
142   char *getValue(char *key) {return (char*)xbt_dict_get_or_null($self, key);}
143 }
144 };
145
146 %rename e_surf_action_state_t ActionState;
147 typedef enum {
148   SURF_ACTION_READY = 0,        /**< Ready        */
149   SURF_ACTION_RUNNING,          /**< Running      */
150   SURF_ACTION_FAILED,           /**< Task Failure */
151   SURF_ACTION_DONE,             /**< Completed    */
152   SURF_ACTION_TO_FREE,          /**< Action to free in next cleanup */
153   SURF_ACTION_NOT_IN_THE_SYSTEM
154                                 /**< Not in the system anymore. Why did you ask ? */
155 } e_surf_action_state_t;
156
157 %rename e_surf_resource_state_t ResourceState;
158 typedef enum {
159   SURF_RESOURCE_ON = 1,                   /**< Up & ready        */
160   SURF_RESOURCE_OFF = 0                   /**< Down & broken     */
161 } e_surf_resource_state_t;