Created
March 31, 2012 10:47
-
-
Save vasilakisfil/2261919 to your computer and use it in GitHub Desktop.
C++ code (the patch is the last file )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*************************************************************************** | |
** This file is part of the generic algorithm library Wiselib. ** | |
** Copyright (C) 2008,2012 by the Wisebed (www.wisebed.eu) project. ** | |
** ** | |
** The Wiselib is free software: you can redistribute it and/or modify ** | |
** it under the terms of the GNU Lesser General Public License as ** | |
** published by the Free Software Foundation, either version 3 of the ** | |
** License, or (at your option) any later version. ** | |
** ** | |
** The Wiselib is distributed in the hope that it will be useful, ** | |
** but WITHOUT ANY WARRANTY; without even the implied warranty of ** | |
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** | |
** GNU Lesser General Public License for more details. ** | |
** ** | |
** You should have received a copy of the GNU Lesser General Public ** | |
** License along with the Wiselib. ** | |
** If not, see <http://www.gnu.org/licenses/>. ** | |
***************************************************************************/ | |
#ifndef ANDROID_DEBUG_H | |
#define ANDROID_DEBUG_H | |
#include <jni.h> | |
#include <cstdio> | |
#include <cstdlib> | |
#include <iostream> | |
#include <string> | |
#include <cstdarg> | |
#include "jni_essentials.h" | |
namespace wiselib | |
{ | |
/** \brief AndroidOs Implementation of \ref debug_concept "Debug Concept". | |
* | |
* \ingroup debug_concept | |
* | |
* AndroidOs implementation of the \ref debug_concept "Debug Concept" ... | |
*/ | |
template < typename OsModel_P > class AndroidDebug | |
{ | |
public: | |
AndroidDebug() | |
{ | |
} | |
// function that implements the debug concept | |
void debug(const char *msg, ...) | |
{ | |
va_list fmtargs; | |
char buffer[1024]; | |
va_start(fmtargs, msg); | |
vsnprintf(buffer, sizeof(buffer) - 1, msg, fmtargs); | |
va_end(fmtargs); | |
jmethodID debug_from_native; | |
jstring java_string; | |
JNIEnv *java_environment; | |
jobject java_object = Jni_.java_object(); | |
java_environment = Jni_.java_environment(); | |
// getting the class that | |
// represents the java object | |
jclass main_class = java_environment->GetObjectClass(java_object); | |
// if the pointer is NULL set the error and return | |
if (main_class == NULL) | |
{ | |
Jni_.set_jni_custom_error("GetObjectClass error"); | |
return; | |
} | |
// getting the id of method | |
// debugFromNative which has | |
// parameter String | |
// and returns void | |
debug_from_native = | |
java_environment->GetMethodID(main_class, | |
"debugFromNative", | |
"(Ljava/lang/String;)V"); | |
// if the pointer is null set the error and return | |
if (debug_from_native == NULL) | |
{ | |
Jni_.set_jni_custom_error("GetMethodID error"); | |
return; | |
} | |
java_string = | |
java_environment->NewStringUTF((const char *) buffer); | |
// calling the method debugFromNative | |
java_environment->CallVoidMethod(java_object, | |
debug_from_native, java_string); | |
Jni_.set_jni_custom_error("OK"); | |
} | |
private: | |
JniEssentials Jni_; | |
}; | |
} | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*************************************************************************** | |
** This file is part of the generic algorithm library Wiselib. ** | |
** Copyright (C) 2008,2012 by the Wisebed (www.wisebed.eu) project. ** | |
** ** | |
** The Wiselib is free software: you can redistribute it and/or modify ** | |
** it under the terms of the GNU Lesser General Public License as ** | |
** published by the Free Software Foundation, either version 3 of the ** | |
** License, or (at your option) any later version. ** | |
** ** | |
** The Wiselib is distributed in the hope that it will be useful, ** | |
** but WITHOUT ANY WARRANTY; without even the implied warranty of ** | |
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** | |
** GNU Lesser General Public License for more details. ** | |
** ** | |
** You should have received a copy of the GNU Lesser General Public ** | |
** License along with the Wiselib. ** | |
** If not, see <http://www.gnu.org/licenses/>. ** | |
***************************************************************************/ | |
// vim: set noexpandtab ts=4 sw=4: | |
#ifndef ANDROID_OS_MODEL_H | |
#define ANDROID_OS_MODEL_H | |
#define path | |
#include <stdint.h> | |
#include "jni_essentials.h" | |
#include "android_debug.h" | |
#include "external_interface/default_return_values.h" | |
namespace wiselib | |
{ | |
/** | |
* \brief AndroidOs implementation of \ref os_concept "Os Concept". | |
* \ingroup os_concept | |
* \ingroup basic_return_values_concept | |
*/ | |
class AndroidOsModel:public DefaultReturnValues < AndroidOsModel > | |
{ | |
public: | |
int argc; | |
const char **argv; | |
typedef AndroidDebug < AndroidOsModel > Debug; | |
}; | |
} // ns wiselib | |
#endif // ANDROID_OS_MODEL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*************************************************************************** | |
** This file is part of the generic algorithm library Wiselib. ** | |
** Copyright (C) 2008,2012 by the Wisebed (www.wisebed.eu) project. ** | |
** ** | |
** The Wiselib is free software: you can redistribute it and/or modify ** | |
** it under the terms of the GNU Lesser General Public License as ** | |
** published by the Free Software Foundation, either version 3 of the ** | |
** License, or (at your option) any later version. ** | |
** ** | |
** The Wiselib is distributed in the hope that it will be useful, ** | |
** but WITHOUT ANY WARRANTY; without even the implied warranty of ** | |
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** | |
** GNU Lesser General Public License for more details. ** | |
** ** | |
** You should have received a copy of the GNU Lesser General Public ** | |
** License along with the Wiselib. ** | |
** If not, see <http://www.gnu.org/licenses/>. ** | |
***************************************************************************/ | |
#include <jni.h> | |
#include "jni_essentials.h" | |
namespace wiselib | |
{ | |
// string that holds the error(not used yet) | |
string JniEssentials::jni_custom_error_; | |
// global variable that holds the Java environment | |
JNIEnv *JniEssentials::java_environment_; | |
// global variable that holds the Java object | |
jobject JniEssentials::java_object_; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*************************************************************************** | |
** This file is part of the generic algorithm library Wiselib. ** | |
** Copyright (C) 2008,2012 by the Wisebed (www.wisebed.eu) project. ** | |
** ** | |
** The Wiselib is free software: you can redistribute it and/or modify ** | |
** it under the terms of the GNU Lesser General Public License as ** | |
** published by the Free Software Foundation, either version 3 of the ** | |
** License, or (at your option) any later version. ** | |
** ** | |
** The Wiselib is distributed in the hope that it will be useful, ** | |
** but WITHOUT ANY WARRANTY; without even the implied warranty of ** | |
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** | |
** GNU Lesser General Public License for more details. ** | |
** ** | |
** You should have received a copy of the GNU Lesser General Public ** | |
** License along with the Wiselib. ** | |
** If not, see <http://www.gnu.org/licenses/>. ** | |
***************************************************************************/ | |
#ifndef JNI_ESSENTIALS_H | |
#define JNI_ESSENTIALS_H | |
#include <jni.h> | |
#include <string> | |
using namespace std; | |
namespace wiselib | |
{ | |
/** \brief JniEssentials types and variables needed by of \ref os_concept | |
* "Os Concept". | |
*/ | |
class JniEssentials | |
{ | |
public: | |
// method that sets the Java object to a global variable | |
jobject java_object(void) | |
{ | |
return java_object_; | |
} | |
// method that returns the Java environment | |
void set_java_object(jobject j_object) | |
{ | |
java_object_ = j_object; | |
} | |
// method that returns the Java environment | |
JNIEnv *java_environment(void) | |
{ | |
return java_environment_; | |
} | |
// method that sets the Java environment to a global variable | |
void set_java_environment(JNIEnv * envir) | |
{ | |
java_environment_ = envir; | |
} | |
// method that returns the JNI error (if any) | |
string jni_custom_error(void) | |
{ | |
return jni_custom_error_; | |
} | |
// method that sets the JNI error | |
void set_jni_custom_error(string error) | |
{ | |
jni_custom_error_ = error; | |
} | |
private: | |
// string that holds the error(custom error) | |
static string jni_custom_error_; | |
// global variable that holds the Java environment | |
static JNIEnv *java_environment_; | |
// global variable that holds the Java object | |
static jobject java_object_; | |
}; | |
} | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/apps/generic_apps/Makefile b/apps/generic_apps/Makefile | |
index 3f99415..8e073e1 100644 | |
--- a/apps/generic_apps/Makefile | |
+++ b/apps/generic_apps/Makefile | |
@@ -31,6 +31,8 @@ endif | |
## | |
## Compile Application for specific OSs | |
##### | |
+android: | |
+ make -f $(WISELIB_BASE)/apps/generic_apps/Makefile.android | |
contiki_msb: | |
make -f $(WISELIB_BASE)/apps/generic_apps/Makefile.contiki contiki_msp TARGET=msb430 ADD_CXXFLAGS=$(ADD_CXXFLAGS) | |
diff --git a/apps/generic_apps/Makefile.android b/apps/generic_apps/Makefile.android | |
new file mode 100644 | |
index 0000000..590a0b5 | |
--- /dev/null | |
+++ b/apps/generic_apps/Makefile.android | |
@@ -0,0 +1,6 @@ | |
+all: android | |
+ | |
+android: | |
+ @echo "compiling..." | |
+ $(ANDROID_NDK_PATH)/ndk-build -C $(PROJECT_PATH) -B | |
+ | |
diff --git a/apps/generic_apps/Makefile.template b/apps/generic_apps/Makefile.template | |
index 2f48013..f1c71d5 100644 | |
--- a/apps/generic_apps/Makefile.template | |
+++ b/apps/generic_apps/Makefile.template | |
@@ -84,3 +84,8 @@ export LORIEN=/home/username/lorienos | |
export SCATTERWEB_PATH=/home/username/msb-scatterweb2/1.1/Libraries | |
export FEUERWARE_PATH=/home/username/FeuerWare/tags/2009-04-14 | |
+ | |
+############################################################################# | |
+##### Android ##### | |
+############################################################################# | |
+export ANDROID_NDK_PATH=/home/username/android-ndk-rxx | |
diff --git a/wiselib.testing/external_interface/android/android_debug.h b/wiselib.testing/external_interface/android/android_debug.h | |
new file mode 100644 | |
index 0000000..8726d14 | |
--- /dev/null | |
+++ b/wiselib.testing/external_interface/android/android_debug.h | |
@@ -0,0 +1,96 @@ | |
+/*************************************************************************** | |
+ ** This file is part of the generic algorithm library Wiselib. ** | |
+ ** Copyright (C) 2008,2012 by the Wisebed (www.wisebed.eu) project. ** | |
+ ** ** | |
+ ** The Wiselib is free software: you can redistribute it and/or modify ** | |
+ ** it under the terms of the GNU Lesser General Public License as ** | |
+ ** published by the Free Software Foundation, either version 3 of the ** | |
+ ** License, or (at your option) any later version. ** | |
+ ** ** | |
+ ** The Wiselib is distributed in the hope that it will be useful, ** | |
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** | |
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** | |
+ ** GNU Lesser General Public License for more details. ** | |
+ ** ** | |
+ ** You should have received a copy of the GNU Lesser General Public ** | |
+ ** License along with the Wiselib. ** | |
+ ** If not, see <http://www.gnu.org/licenses/>. ** | |
+ ***************************************************************************/ | |
+#ifndef ANDROID_DEBUG_H | |
+#define ANDROID_DEBUG_H | |
+ | |
+#include <jni.h> | |
+#include <cstdio> | |
+#include <cstdlib> | |
+#include <iostream> | |
+#include <string> | |
+#include <cstdarg> | |
+#include "jni_essentials.h" | |
+ | |
+namespace wiselib | |
+{ | |
+/** \brief AndroidOs Implementation of \ref debug_concept "Debug Concept". | |
+* | |
+* \ingroup debug_concept | |
+* | |
+* AndroidOs implementation of the \ref debug_concept "Debug Concept" ... | |
+*/ | |
+ template < typename OsModel_P > class AndroidDebug | |
+ { | |
+ public: | |
+ AndroidDebug() | |
+ { | |
+ } | |
+ // function that implements the debug concept | |
+ void debug(const char *msg, ...) | |
+ { | |
+ va_list fmtargs; | |
+ char buffer[1024]; | |
+ | |
+ va_start(fmtargs, msg); | |
+ vsnprintf(buffer, sizeof(buffer) - 1, msg, fmtargs); | |
+ va_end(fmtargs); | |
+ | |
+ jmethodID debug_from_native; | |
+ jstring java_string; | |
+ JNIEnv *java_environment; | |
+ | |
+ jobject java_object = Jni_.java_object(); | |
+ | |
+ java_environment = Jni_.java_environment(); | |
+ | |
+ // getting the class that | |
+ // represents the java object | |
+ jclass main_class = java_environment->GetObjectClass(java_object); | |
+ // if the pointer is NULL set the error and return | |
+ if (main_class == NULL) | |
+ { | |
+ Jni_.set_jni_custom_error("GetObjectClass error"); | |
+ return; | |
+ } | |
+ // getting the id of method | |
+ // debugFromNative which has | |
+ // parameter String | |
+ // and returns void | |
+ debug_from_native = | |
+ java_environment->GetMethodID(main_class, | |
+ "debugFromNative", | |
+ "(Ljava/lang/String;)V"); | |
+ // if the pointer is null set the error and return | |
+ if (debug_from_native == NULL) | |
+ { | |
+ Jni_.set_jni_custom_error("GetMethodID error"); | |
+ return; | |
+ } | |
+ java_string = | |
+ java_environment->NewStringUTF((const char *) buffer); | |
+ // calling the method debugFromNative | |
+ java_environment->CallVoidMethod(java_object, | |
+ debug_from_native, java_string); | |
+ Jni_.set_jni_custom_error("OK"); | |
+ } | |
+ private: | |
+ JniEssentials Jni_; | |
+ }; | |
+} | |
+#endif | |
diff --git a/wiselib.testing/external_interface/android/android_os_model.h b/wiselib.testing/external_interface/android/android_os_model.h | |
new file mode 100644 | |
index 0000000..8e647d4 | |
--- /dev/null | |
+++ b/wiselib.testing/external_interface/android/android_os_model.h | |
@@ -0,0 +1,47 @@ | |
+/*************************************************************************** | |
+ ** This file is part of the generic algorithm library Wiselib. ** | |
+ ** Copyright (C) 2008,2012 by the Wisebed (www.wisebed.eu) project. ** | |
+ ** ** | |
+ ** The Wiselib is free software: you can redistribute it and/or modify ** | |
+ ** it under the terms of the GNU Lesser General Public License as ** | |
+ ** published by the Free Software Foundation, either version 3 of the ** | |
+ ** License, or (at your option) any later version. ** | |
+ ** ** | |
+ ** The Wiselib is distributed in the hope that it will be useful, ** | |
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** | |
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** | |
+ ** GNU Lesser General Public License for more details. ** | |
+ ** ** | |
+ ** You should have received a copy of the GNU Lesser General Public ** | |
+ ** License along with the Wiselib. ** | |
+ ** If not, see <http://www.gnu.org/licenses/>. ** | |
+ ***************************************************************************/ | |
+ | |
+// vim: set noexpandtab ts=4 sw=4: | |
+ | |
+#ifndef ANDROID_OS_MODEL_H | |
+#define ANDROID_OS_MODEL_H | |
+#define path | |
+ | |
+#include <stdint.h> | |
+#include "jni_essentials.h" | |
+#include "android_debug.h" | |
+#include "external_interface/default_return_values.h" | |
+ | |
+namespace wiselib | |
+{ | |
+/** | |
+* \brief AndroidOs implementation of \ref os_concept "Os Concept". | |
+* \ingroup os_concept | |
+* \ingroup basic_return_values_concept | |
+*/ | |
+ class AndroidOsModel:public DefaultReturnValues < AndroidOsModel > | |
+ { | |
+ public: | |
+ int argc; | |
+ const char **argv; | |
+ typedef AndroidDebug < AndroidOsModel > Debug; | |
+ }; | |
+} // ns wiselib | |
+ | |
+#endif // ANDROID_OS_MODEL_H | |
diff --git a/wiselib.testing/external_interface/android/jni_essentials.cpp b/wiselib.testing/external_interface/android/jni_essentials.cpp | |
new file mode 100644 | |
index 0000000..45f3081 | |
--- /dev/null | |
+++ b/wiselib.testing/external_interface/android/jni_essentials.cpp | |
@@ -0,0 +1,31 @@ | |
+/*************************************************************************** | |
+ ** This file is part of the generic algorithm library Wiselib. ** | |
+ ** Copyright (C) 2008,2012 by the Wisebed (www.wisebed.eu) project. ** | |
+ ** ** | |
+ ** The Wiselib is free software: you can redistribute it and/or modify ** | |
+ ** it under the terms of the GNU Lesser General Public License as ** | |
+ ** published by the Free Software Foundation, either version 3 of the ** | |
+ ** License, or (at your option) any later version. ** | |
+ ** ** | |
+ ** The Wiselib is distributed in the hope that it will be useful, ** | |
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** | |
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** | |
+ ** GNU Lesser General Public License for more details. ** | |
+ ** ** | |
+ ** You should have received a copy of the GNU Lesser General Public ** | |
+ ** License along with the Wiselib. ** | |
+ ** If not, see <http://www.gnu.org/licenses/>. ** | |
+ ***************************************************************************/ | |
+ | |
+#include <jni.h> | |
+#include "jni_essentials.h" | |
+ | |
+namespace wiselib | |
+{ | |
+ // string that holds the error(not used yet) | |
+ string JniEssentials::jni_custom_error_; | |
+ // global variable that holds the Java environment | |
+ JNIEnv *JniEssentials::java_environment_; | |
+ // global variable that holds the Java object | |
+ jobject JniEssentials::java_object_; | |
+} | |
diff --git a/wiselib.testing/external_interface/android/jni_essentials.h b/wiselib.testing/external_interface/android/jni_essentials.h | |
new file mode 100644 | |
index 0000000..c969de6 | |
--- /dev/null | |
+++ b/wiselib.testing/external_interface/android/jni_essentials.h | |
@@ -0,0 +1,74 @@ | |
+/*************************************************************************** | |
+ ** This file is part of the generic algorithm library Wiselib. ** | |
+ ** Copyright (C) 2008,2012 by the Wisebed (www.wisebed.eu) project. ** | |
+ ** ** | |
+ ** The Wiselib is free software: you can redistribute it and/or modify ** | |
+ ** it under the terms of the GNU Lesser General Public License as ** | |
+ ** published by the Free Software Foundation, either version 3 of the ** | |
+ ** License, or (at your option) any later version. ** | |
+ ** ** | |
+ ** The Wiselib is distributed in the hope that it will be useful, ** | |
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** | |
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** | |
+ ** GNU Lesser General Public License for more details. ** | |
+ ** ** | |
+ ** You should have received a copy of the GNU Lesser General Public ** | |
+ ** License along with the Wiselib. ** | |
+ ** If not, see <http://www.gnu.org/licenses/>. ** | |
+ ***************************************************************************/ | |
+ | |
+#ifndef JNI_ESSENTIALS_H | |
+#define JNI_ESSENTIALS_H | |
+ | |
+#include <jni.h> | |
+#include <string> | |
+using namespace std; | |
+ | |
+namespace wiselib | |
+{ | |
+/** \brief JniEssentials types and variables needed by of \ref os_concept | |
+* "Os Concept". | |
+*/ | |
+ class JniEssentials | |
+ { | |
+ public: | |
+ // method that sets the Java object to a global variable | |
+ jobject java_object(void) | |
+ { | |
+ return java_object_; | |
+ } | |
+ // method that returns the Java environment | |
+ void set_java_object(jobject j_object) | |
+ { | |
+ java_object_ = j_object; | |
+ } | |
+ // method that returns the Java environment | |
+ JNIEnv *java_environment(void) | |
+ { | |
+ return java_environment_; | |
+ } | |
+ // method that sets the Java environment to a global variable | |
+ void set_java_environment(JNIEnv * envir) | |
+ { | |
+ java_environment_ = envir; | |
+ } | |
+ // method that returns the JNI error (if any) | |
+ string jni_custom_error(void) | |
+ { | |
+ return jni_custom_error_; | |
+ } | |
+ // method that sets the JNI error | |
+ void set_jni_custom_error(string error) | |
+ { | |
+ jni_custom_error_ = error; | |
+ } | |
+ private: | |
+ // string that holds the error(custom error) | |
+ static string jni_custom_error_; | |
+ // global variable that holds the Java environment | |
+ static JNIEnv *java_environment_; | |
+ // global variable that holds the Java object | |
+ static jobject java_object_; | |
+ }; | |
+} | |
+#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment