+%wrapper %{
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+JNIEXPORT jobject JNICALL Java_org_simgrid_surf_SurfJNI_getAction(JNIEnv *env, jclass cls, jlong jarg1) {
+ Action * action = (Action *)jarg1;
+ jobject res;
+ CpuAction *cpu_action = dynamic_cast<CpuAction*>(action);
+ if (cpu_action) {
+ SwigDirector_CpuAction *dir_cpu_action = dynamic_cast<SwigDirector_CpuAction*>(cpu_action);
+ if (dir_cpu_action) {
+ res = dir_cpu_action->swig_get_self(env);\
+ } else {
+ jclass clss = env->FindClass("org/simgrid/surf/CpuAction");\
+ jmethodID constru = env->GetMethodID(clss, "<init>", "()V");\
+ res = env->NewObject(clss, constru);\
+ res = env->NewGlobalRef(res);\
+ }
+ } else {
+ jclass clss = env->FindClass("org/simgrid/surf/Action");\
+ jmethodID constru = env->GetMethodID(clss, "<init>", "()V");\
+ res = env->NewObject(clss, constru);\
+ res = env->NewGlobalRef(res);\
+ }
+ return res;
+}
+
+#define GETDIRECTOR(NAME) \
+JNIEXPORT jobject JNICALL Java_org_simgrid_surf_SurfJNI_get## NAME ## Director(JNIEnv *env, jclass cls, jlong jarg1)\
+{\
+ NAME * arg1 = (NAME*)jarg1;\
+ SwigDirector_ ##NAME *director = dynamic_cast<SwigDirector_ ##NAME *>(arg1);\
+ jobject res;\
+ if (director) {\
+ res = director->swig_get_self(env);\
+ } else {\
+ jclass clss = env->FindClass("org/simgrid/surf/NAME");\
+ jmethodID constru = env->GetMethodID(clss, "<init>", "()V");\
+ res = env->NewObject(clss, constru);\
+ res = env->NewGlobalRef(res);\
+ }\
+ return res;\
+}
+
+GETDIRECTOR(CpuModel)
+GETDIRECTOR(Cpu)
+GETDIRECTOR(CpuAction)
+
+#ifdef __cplusplus
+}
+#endif
+
+%}
+
+%typemap(freearg) char* name {
+}
+
+/* Handle xbt_dynar_t of Link */
+JAVA_ARRAYSOFCLASSES(Action);
+%apply Action[] {ActionArrayPtr};
+%typemap(jstype) ActionArrayPtr "Action[]"
+%typemap(javain) ActionArrayPtr "Action.cArrayUnwrap($javainput)"
+%typemap(javaout) ActionArrayPtr {
+ long[] cArray = $jnicall;
+ Action[] arrayWrapper = new Action[cArray.length];
+ for (int i=0; i<cArray.length; i++)
+ arrayWrapper[i] = (Action) Surf.getAction(cArray[i]);
+ return arrayWrapper;
+ // return Action.cArrayWrap($jnicall, $owner);
+}
+%typemap(out) ActionArrayPtr {
+ long l = 0;
+ for(ActionList::iterator it($1->begin()), itend($1->end()); it != itend ; ++it) {
+ l++;
+ }
+ $result = jenv->NewLongArray(l);
+ jlong *elts = jenv->GetLongArrayElements($result, NULL);
+ l = 0;
+ for(ActionList::iterator it($1->begin()), itend($1->end()); it != itend ; ++it) {
+ elts[l++] = (jlong)static_cast<Action*>(&*it);
+ }
+ jenv->ReleaseLongArrayElements($result, elts, 0);
+}
+
+class ActionList {
+public:
+ //void push_front(Action &action);
+ //void push_back(Action &action);
+%extend {
+ ActionArrayPtr getArray(){
+ return $self;
+ }
+}
+};