set(JMSG_C_SRC
src/bindings/java/jmsg.c
src/bindings/java/jmsg.h
+ src/bindings/java/jmsg_as.c
+ src/bindings/java/jmsg_as.h
src/bindings/java/jmsg_comm.c
src/bindings/java/jmsg_comm.h
src/bindings/java/jmsg_file.c
)
set(JMSG_JAVA_SRC
+ src/bindings/java/org/simgrid/msg/As.java
src/bindings/java/org/simgrid/msg/Comm.java
src/bindings/java/org/simgrid/msg/File.java
src/bindings/java/org/simgrid/msg/Host.java
Msg.info("Having write " + write + " on " + filename);
read = file.read(10000000,1);
- Msg.info("Having read " + read + " on " + filename);
+ Msg.info("Having read " + read + " on " + filename);
}
}
* want to send your task, but only the name of this mailbox. */
typedef struct s_smx_rvpoint *msg_mailbox_t;
+/* ******************************** Environment ************************************ */
+typedef struct s_as *msg_as_t;
/* ******************************** Host ************************************ */
XBT_PUBLIC(double) MSG_get_clock(void);
XBT_PUBLIC(unsigned long int) MSG_get_sent_msg(void);
+/************************** Environment ***********************************/
+XBT_PUBLIC(msg_as_t) MSG_environment_get_routing_root(void);
+XBT_PUBLIC(const char *) MSG_environment_as_get_name(msg_as_t as);
+XBT_PUBLIC(xbt_dict_t) MSG_environment_as_get_routing_sons(msg_as_t as);
+XBT_PUBLIC(const char *) MSG_environment_as_get_property_value(msg_as_t as, const char *name);
+XBT_PUBLIC(const char *) MSG_environment_as_get_model(msg_as_t as);
+XBT_PUBLIC(xbt_dynar_t) MSG_environment_as_get_hosts(msg_as_t as);
/************************** File handling ***********************************/
XBT_PUBLIC(size_t) MSG_file_read(void* ptr, size_t size, msg_file_t fd);
#include "jmsg_process.h"
+#include "jmsg_as.h"
+
#include "jmsg_host.h"
#include "jmsg_task.h"
#include "jxbt_utilities.h"
(*env)->ReleaseStringUTFChars(env, jplatformFile, platformFile);
}
+
+JNIEXPORT jobject JNICALL
+Java_org_simgrid_msg_Msg_environmentGetRoutingRoot(JNIEnv * env, jclass cls)
+{
+ msg_as_t as = MSG_environment_get_routing_root();
+ jobject jas = jas_new_instance(env);
+ if (!jas) {
+ jxbt_throw_jni(env, "java As instantiation failed");
+ return NULL;
+ }
+ jas = jas_ref(env, jas);
+ if (!jas) {
+ jxbt_throw_jni(env, "new global ref allocation failed");
+ return NULL;
+ }
+ jas_bind(jas, as, env);
+
+ return (jobject) jas;
+}
+
JNIEXPORT void JNICALL
Java_org_simgrid_msg_Msg_debug(JNIEnv * env, jclass cls, jstring js)
{
JNIEXPORT void JNICALL
Java_org_simgrid_msg_Msg_createEnvironment(JNIEnv * env, jclass cls,
jstring jplatformFile);
+JNIEXPORT jobject JNICALL
+Java_org_simgrid_msg_Msg_environmentGetRoutingRoot(JNIEnv * env, jclass cls);
JNIEXPORT void JNICALL
Java_org_simgrid_msg_Msg_deployApplication(JNIEnv * env, jclass cls,
jstring jdeploymentFile);
--- /dev/null
+/* Functions related to the java host instances. */
+
+/* Copyright (c) 2007-2012. The SimGrid Team.
+ * All rights reserved. */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include "xbt/str.h"
+#include "xbt/dict.h"
+#include "msg/msg.h"
+#include "jmsg_as.h"
+#include "jxbt_utilities.h"
+
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
+
+static jmethodID jas_method_As_constructor;
+static jfieldID jas_field_As_bind;
+
+jobject jas_new_instance(JNIEnv * env) {
+ jclass cls = jxbt_get_class(env, "org/simgrid/msg/As");
+ return (*env)->NewObject(env, cls, jas_method_As_constructor);
+}
+
+jobject jas_ref(JNIEnv * env, jobject jas) {
+ return (*env)->NewGlobalRef(env, jas);
+}
+
+void jas_unref(JNIEnv * env, jobject jas) {
+ (*env)->DeleteGlobalRef(env, jas);
+}
+
+void jas_bind(jobject jas, msg_as_t as, JNIEnv * env) {
+ (*env)->SetLongField(env, jas, jas_field_As_bind, (jlong) (long) (as));
+}
+
+msg_as_t jas_get_native(JNIEnv * env, jobject jas) {
+ return (msg_as_t) (long) (*env)->GetLongField(env, jas, jas_field_As_bind);
+}
+
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_As_nativeInit(JNIEnv *env, jclass cls) {
+ jclass class_As = (*env)->FindClass(env, "org/simgrid/msg/As");
+ jas_method_As_constructor = (*env)->GetMethodID(env, class_As, "<init>", "()V");
+ jas_field_As_bind = jxbt_get_jfield(env,class_As, "bind", "J");
+ if (!class_As || !jas_method_As_constructor || !jas_field_As_bind) {
+ jxbt_throw_native(env,bprintf("Can't find some fields in Java class. You should report this bug."));
+ }
+}
+
+JNIEXPORT jobject JNICALL
+Java_org_simgrid_msg_As_getName(JNIEnv * env, jobject jas) {
+ msg_as_t as = jas_get_native(env, jas);
+ return (*env)->NewStringUTF(env, MSG_environment_as_get_name(as));
+}
+
+JNIEXPORT jobjectArray JNICALL
+Java_org_simgrid_msg_As_getSons(JNIEnv * env, jobject jas) {
+ int index = 0;
+ jobjectArray jtable;
+ jobject tmp_jas;
+ msg_as_t tmp_as;
+ msg_as_t self_as = jas_get_native(env, jas);
+
+ xbt_dict_t dict = MSG_environment_as_get_routing_sons(self_as);
+ int count = xbt_dict_length(dict);
+ jclass cls = (*env)->FindClass(env, "org/simgrid/msg/As");
+
+ if (!cls) {
+ return NULL;
+ }
+
+ jtable = (*env)->NewObjectArray(env, (jsize) count, cls, NULL);
+
+ if (!jtable) {
+ jxbt_throw_jni(env, "Hosts table allocation failed");
+ return NULL;
+ }
+
+ xbt_dict_cursor_t cursor=NULL;
+ char *key;
+
+ xbt_dict_foreach(dict,cursor,key,tmp_as) {
+ tmp_jas = jas_new_instance(env);
+ if (!tmp_jas) {
+ jxbt_throw_jni(env, "java As instantiation failed");
+ return NULL;
+ }
+ tmp_jas = jas_ref(env, tmp_jas);
+ if (!tmp_jas) {
+ jxbt_throw_jni(env, "new global ref allocation failed");
+ return NULL;
+ }
+ jas_bind(tmp_jas, tmp_as, env);
+
+ (*env)->SetObjectArrayElement(env, jtable, index, tmp_jas);
+ index++;
+
+ }
+ return jtable;
+}
+
+JNIEXPORT jobject JNICALL
+Java_org_simgrid_msg_As_getProperty(JNIEnv *env, jobject jas, jobject jname) {
+ msg_as_t as = jas_get_native(env, jas);
+
+ if (!as) {
+ jxbt_throw_notbound(env, "as", jas);
+ return NULL;
+ }
+ const char *name = (*env)->GetStringUTFChars(env, jname, 0);
+
+ const char *property = MSG_environment_as_get_property_value(as, name);
+ if (!property) {
+ return NULL;
+ }
+
+ jobject jproperty = (*env)->NewStringUTF(env, property);
+
+ (*env)->ReleaseStringUTFChars(env, jname, name);
+
+ return jproperty;
+}
+
+JNIEXPORT jobject JNICALL
+Java_org_simgrid_msg_As_getModel(JNIEnv * env, jobject jas) {
+ msg_as_t as = jas_get_native(env, jas);
+ return (*env)->NewStringUTF(env, MSG_environment_as_get_model(as));
+}
+
+JNIEXPORT jobjectArray JNICALL
+Java_org_simgrid_msg_As_getHosts(JNIEnv * env, jobject jas)
+{
+ int index;
+ jobjectArray jtable;
+ jobject jhost;
+ jstring jname;
+ msg_host_t host;
+ msg_as_t as = jas_get_native(env, jas);
+
+ xbt_dynar_t table = MSG_environment_as_get_hosts(as);
+ int count = xbt_dynar_length(table);
+
+ jclass cls = jxbt_get_class(env, "org/simgrid/msg/Host");
+
+ if (!cls) {
+ return NULL;
+ }
+
+ jtable = (*env)->NewObjectArray(env, (jsize) count, cls, NULL);
+
+ if (!jtable) {
+ jxbt_throw_jni(env, "Hosts table allocation failed");
+ return NULL;
+ }
+
+ for (index = 0; index < count; index++) {
+
+ host = xbt_dynar_get_as(table,index,msg_host_t);
+
+ jhost = (jobject) (MSG_host_get_data(host));
+ if (!jhost) {
+ jname = (*env)->NewStringUTF(env, MSG_host_get_name(host));
+
+ jhost = Java_org_simgrid_msg_Host_getByName(env, cls, jname);
+
+ /* FIXME: leak of jname ? */
+ }
+
+ (*env)->SetObjectArrayElement(env, jtable, index, jhost);
+ }
+ xbt_dynar_free(&table);
+ return jtable;
+}
--- /dev/null
+/* Functions related to the java As instances. */
+
+/* Copyright (c) 2007-2012. The SimGrid Team.
+ * All rights reserved. */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+
+#ifndef MSG_JAS_H
+#define MSG_JAS_H
+#include <jni.h>
+#include "msg/msg.h"
+
+/* Functions related to the java host instances. */
+
+/* Copyright (c) 2007-2012. The SimGrid Team.
+ * All rights reserved. */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include "msg/msg.h"
+#include "jmsg.h"
+#include "jmsg_host.h"
+
+jobject jas_new_instance(JNIEnv * env);
+jobject jas_ref(JNIEnv * env, jobject jas);
+void jas_unref(JNIEnv * env, jobject jas);
+void jas_bind(jobject jas, msg_as_t as, JNIEnv * env);
+msg_as_t jas_get_native(JNIEnv * env, jobject jas);
+
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_As_nativeInit(JNIEnv *env, jclass cls);
+
+JNIEXPORT jobject JNICALL
+Java_org_simgrid_msg_As_getName(JNIEnv * env, jobject jas);
+
+JNIEXPORT jobjectArray JNICALL
+Java_org_simgrid_msg_As_getSons(JNIEnv * env, jobject jas);
+
+JNIEXPORT jobject JNICALL
+Java_org_simgrid_msg_As_getProperty(JNIEnv *env, jobject jhost, jobject jname);
+
+JNIEXPORT jobject JNICALL
+Java_org_simgrid_msg_As_getModel(JNIEnv * env, jobject jas);
+
+JNIEXPORT jobjectArray JNICALL
+Java_org_simgrid_msg_As_getHosts(JNIEnv * env, jobject jas);
+
+#endif /*!MSG_JAS_H */
JNIEXPORT void JNICALL
Java_org_simgrid_msg_VM_reboot(JNIEnv *env, jobject jvm);
+JNIEXPORT jobject JNICALL
+Java_org_simgrid_msg_VM_get_pm(JNIEnv *env, jobject jvm);
#endif
--- /dev/null
+/*
+ * Bindings to the MSG hosts
+ *
+ * Copyright 2006-2012 The SimGrid Team
+ * All right reserved.
+ *
+ * This program is free software; you can redistribute
+ * it and/or modify it under the terms of the license
+ *(GNU LGPL) which comes with this package.
+ *
+ */
+package org.simgrid.msg;
+
+public class As {
+
+ private long bind;
+
+ protected As() {
+ };
+
+ public String toString (){
+ return this.getName();
+ }
+ public native String getName();
+
+ public native As[] getSons();
+
+ public native String getProperty(String name);
+
+ public native String getModel();
+
+ public native Host[] getHosts();
+
+ /**
+ * Class initializer, to initialize various JNI stuff
+ */
+ public static native void nativeInit();
+ static {
+ nativeInit();
+ }
+}
*/
public final static native void createEnvironment(String platformFile);
+ public final static native As environmentGetRoutingRoot();
+
/**
* The method to deploy the simulation.
*
*/
XBT_PUBLIC_DATA(xbt_dynar_t) model_list;
+/*******************************************/
+/*** SURF Platform *************************/
+/*******************************************/
+typedef struct s_as *AS_t;
+
+XBT_PUBLIC_DATA(AS_t) surf_AS_get_routing_root(void);
+XBT_PUBLIC_DATA(const char *) surf_AS_get_name(AS_t as);
+XBT_PUBLIC_DATA(xbt_dict_t) surf_AS_get_routing_sons(AS_t as);
+XBT_PUBLIC_DATA(const char *) surf_AS_get_model(AS_t as);
+XBT_PUBLIC_DATA(xbt_dynar_t) surf_AS_get_hosts(AS_t as);
+
/*******************************************/
/*** SURF Globals **************************/
/*******************************************/
__MSG_host_create(xbt_dict_cursor_get_elm(cursor));
}
}
+
+msg_as_t MSG_environment_get_routing_root() {
+ return surf_AS_get_routing_root();
+}
+
+const char *MSG_environment_as_get_name(msg_as_t as) {
+ return surf_AS_get_name(as);
+}
+
+xbt_dict_t MSG_environment_as_get_routing_sons(msg_as_t as) {
+ xbt_dict_t res = surf_AS_get_routing_sons(as);
+ return res;
+}
+
+const char *MSG_environment_as_get_property_value(msg_as_t as, const char *name)
+{
+ xbt_dict_t dict = xbt_lib_get_or_null(as_router_lib, MSG_environment_as_get_name(as), ROUTING_PROP_ASR_LEVEL);
+ if (dict==NULL)
+ return NULL;
+ return xbt_dict_get_or_null(dict, name);
+}
+
+const char *MSG_environment_as_get_model(msg_as_t as) {
+ return surf_AS_get_model(as);
+}
+
+xbt_dynar_t MSG_environment_as_get_hosts(msg_as_t as) {
+ return surf_AS_get_hosts(as);
+}
*/
int __surf_is_absolute_file_path(const char *file_path);
-typedef struct s_as *AS_t;
typedef struct s_routing_edge {
AS_t rc_component;
e_surf_network_element_type_t rc_type;
finalize_rec(routing_platf->root);
xbt_free(routing_platf);
}
+
+AS_t surf_AS_get_routing_root() {
+ return routing_platf->root;
+}
+
+const char *surf_AS_get_name(AS_t as) {
+ return as->name;
+}
+
+xbt_dict_t surf_AS_get_routing_sons(AS_t as) {
+ return as->routing_sons;
+}
+
+const char *surf_AS_get_model(AS_t as) {
+ return as->model_desc->name;
+}
+
+xbt_dynar_t surf_AS_get_hosts(AS_t as) {
+ xbt_dynar_t elms = as->index_network_elm;
+ sg_routing_edge_t relm;
+ xbt_dictelm_t delm;
+ int index;
+ int count = xbt_dynar_length(elms);
+ xbt_dynar_t res = xbt_dynar_new(sizeof(xbt_dictelm_t), NULL);
+ for (index = 0; index < count; index++) {
+ relm = xbt_dynar_get_as(elms, index, sg_routing_edge_t);
+ delm = xbt_lib_get_elm_or_null(host_lib, relm->name);
+ if (delm!=NULL) {
+ xbt_dynar_push(res, &delm);
+ }
+ }
+ return res;
+}