diff options
author | Angelo Mantellini (manangel) <angelo.mantellini@irt-systemx.fr> | 2017-03-29 18:00:06 +0200 |
---|---|---|
committer | Angelo Mantellini (manangel) <angelo.mantellini@irt-systemx.fr> | 2017-03-30 18:58:33 +0200 |
commit | 3137acdd5a45285dab9903f9d41560c63eca8523 (patch) | |
tree | 38bd8525a9e214d848a73fc40e81ddb182cf91b6 /ccnxandroidmetis/ccnxsupportlibrary | |
parent | 9b30fc10fb1cbebe651e5a107e8ca5b24de54675 (diff) |
first commit
Change-Id: I8412b8e7d966c2fbc508b537fd9a9bbcfc628ca8
Signed-off-by: Angelo Mantellini (manangel) <angelo.mantellini@irt-systemx.fr>
Diffstat (limited to 'ccnxandroidmetis/ccnxsupportlibrary')
10 files changed, 473 insertions, 0 deletions
diff --git a/ccnxandroidmetis/ccnxsupportlibrary/build.gradle b/ccnxandroidmetis/ccnxsupportlibrary/build.gradle new file mode 100644 index 00000000..3ec07d19 --- /dev/null +++ b/ccnxandroidmetis/ccnxsupportlibrary/build.gradle @@ -0,0 +1,66 @@ + +apply plugin: 'com.android.library' + +android { + compileSdkVersion 23 + buildToolsVersion '25.0.0' + + defaultConfig { + minSdkVersion 15 + targetSdkVersion 23 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + debug { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + + sourceSets { + main { + jni.srcDirs = [] + java.srcDirs = ['src/main/java'] + resources.srcDirs = ['src/main/res'] + res.srcDirs = ['src/main/res'] + jniLibs.srcDirs = ['src/main/libs'] + assets.srcDirs = ['src/main/assets'] + } + } + + task buildNative(type: Exec, description: 'Compile JNI source via NDK') { + def ndkDir = android.ndkDirectory + commandLine "$ndkDir/ndk-build", + '-C', file('src/main/jni').absolutePath, // Change src/main/jni the relative path to your jni source + '-j', Runtime.runtime.availableProcessors(), + 'all', + 'NDK_DEBUG=1' + } + + task cleanNative(type: Exec, description: 'Clean JNI object files') { + def ndkDir = android.ndkDirectory + commandLine "$ndkDir/ndk-build", + '-C', file('src/main/jni').absolutePath, // Change src/main/jni the relative path to your jni source + 'clean' + } + + tasks.withType(JavaCompile) { + compileTask -> compileTask.dependsOn(buildNative) + } + + clean.dependsOn 'cleanNative' +} + +dependencies { + compile fileTree(include: ['*.jar'], dir: 'libs') + testCompile 'junit:junit:4.12' + compile 'com.android.support:appcompat-v7:23.4.0' +} + +configurations.maybeCreate("default") +artifacts.add("default", file('build/outputs/aar/ccnxsupportlibrary-release.aar')) diff --git a/ccnxandroidmetis/ccnxsupportlibrary/proguard-rules.pro b/ccnxandroidmetis/ccnxsupportlibrary/proguard-rules.pro new file mode 100644 index 00000000..c51dd9b5 --- /dev/null +++ b/ccnxandroidmetis/ccnxsupportlibrary/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /Users/walendo/Library/Android/sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/ccnxandroidmetis/ccnxsupportlibrary/src/main/AndroidManifest.xml b/ccnxandroidmetis/ccnxsupportlibrary/src/main/AndroidManifest.xml new file mode 100644 index 00000000..8ac2d0c6 --- /dev/null +++ b/ccnxandroidmetis/ccnxsupportlibrary/src/main/AndroidManifest.xml @@ -0,0 +1,32 @@ +<!-- + ~ Copyright (c) 2017 Cisco and/or its affiliates. + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at: + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. +--> + +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.metis.ccnx.ccnxsupportlibrary"> + + <application + android:allowBackup="true" + android:label="@string/app_name" + android:supportsRtl="true"> + + </application> + <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> + <uses-permission + android:name="android.permission.READ_EXTERNAL_STORAGE" + android:maxSdkVersion="21" /> + <uses-permission android:name="android.permission.INTERNET" /> + <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> + +</manifest> diff --git a/ccnxandroidmetis/ccnxsupportlibrary/src/main/java/com/metis/ccnx/ccnxsupportlibrary/Metis.java b/ccnxandroidmetis/ccnxsupportlibrary/src/main/java/com/metis/ccnx/ccnxsupportlibrary/Metis.java new file mode 100644 index 00000000..5be6af9a --- /dev/null +++ b/ccnxandroidmetis/ccnxsupportlibrary/src/main/java/com/metis/ccnx/ccnxsupportlibrary/Metis.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.metis.ccnx.ccnxsupportlibrary; + +public class Metis { + + private static Metis sInstance = null; + + static { + System.loadLibrary("ccnxsupportlibrary"); + } + + public static Metis getInstance() { + if (sInstance == null) { + sInstance = new Metis(); + } + return sInstance; + } + + private Metis() { + + } + + public native boolean isRunning(); + public native void start(String path); + public native void stop(); +} diff --git a/ccnxandroidmetis/ccnxsupportlibrary/src/main/jni/Android.mk b/ccnxandroidmetis/ccnxsupportlibrary/src/main/jni/Android.mk new file mode 100644 index 00000000..6613742d --- /dev/null +++ b/ccnxandroidmetis/ccnxsupportlibrary/src/main/jni/Android.mk @@ -0,0 +1,19 @@ +############################################################################## +# Copyright (c) 2017 Cisco and/or its affiliates. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################## +LOCAL_PATH := $(call my-dir) + +subdirs := $(call all-subdir-makefiles) + +include $(subdirs) diff --git a/ccnxandroidmetis/ccnxsupportlibrary/src/main/jni/Application.mk b/ccnxandroidmetis/ccnxsupportlibrary/src/main/jni/Application.mk new file mode 100644 index 00000000..bd11e2d6 --- /dev/null +++ b/ccnxandroidmetis/ccnxsupportlibrary/src/main/jni/Application.mk @@ -0,0 +1,20 @@ +############################################################################## +# Copyright (c) 2017 Cisco and/or its affiliates. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################## + +APP_PLATFORM := android-23 + +APP_ABI := armeabi-v7a + +APP_MODULES += ccnxsupportlibrary diff --git a/ccnxandroidmetis/ccnxsupportlibrary/src/main/jni/ccnxsupportlibrary/Android.mk b/ccnxandroidmetis/ccnxsupportlibrary/src/main/jni/ccnxsupportlibrary/Android.mk new file mode 100644 index 00000000..2d2ab65c --- /dev/null +++ b/ccnxandroidmetis/ccnxsupportlibrary/src/main/jni/ccnxsupportlibrary/Android.mk @@ -0,0 +1,121 @@ +############################################################################## +# Copyright (c) 2017 Cisco and/or its affiliates. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################## + +LOCAL_PATH := $(call my-dir) + +ARMDIST_ROOT := $(DISTILLERY_ROOT_DIR) + +ARMDIST := $(ARMDIST_ROOT)/usr +ARMDEPS := $(ARMDIST_ROOT)/usr +METIS_INC := $(ARMDIST_ROOT)/usr/include + +include $(CLEAR_VARS) +LOCAL_MODULE := liblongbow-ansiterm +LOCAL_SRC_FILES := $(ARMDIST)/lib/liblongbow-ansiterm.a +include $(PREBUILT_STATIC_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := liblongbow-textplain +LOCAL_SRC_FILES := $(ARMDIST)/lib/liblongbow-textplain.a +include $(PREBUILT_STATIC_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := libparc +LOCAL_SRC_FILES := $(ARMDIST)/lib/libparc.a +include $(PREBUILT_STATIC_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := libmetis +LOCAL_SRC_FILES := $(ARMDIST)/lib/libmetis.a +include $(PREBUILT_STATIC_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := libccnx_api_control +LOCAL_SRC_FILES := $(ARMDIST)/lib/libccnx_api_control.a +include $(PREBUILT_STATIC_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := libccnx_api_notify +LOCAL_SRC_FILES := $(ARMDIST)/lib/libccnx_api_notify.a +include $(PREBUILT_STATIC_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := libccnx_api_portal +LOCAL_SRC_FILES := $(ARMDIST)/lib/libccnx_api_portal.a +include $(PREBUILT_STATIC_LIBRARY) +include $(CLEAR_VARS) + +include $(CLEAR_VARS) +LOCAL_MODULE := libccnx_transport_rta +LOCAL_SRC_FILES := $(ARMDIST)/lib/libccnx_transport_rta.a +include $(PREBUILT_STATIC_LIBRARY) +include $(CLEAR_VARS) + +include $(CLEAR_VARS) +LOCAL_MODULE := libccnx_common +LOCAL_SRC_FILES := $(ARMDIST)/lib/libccnx_common.a +include $(PREBUILT_STATIC_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := libevent +LOCAL_SRC_FILES := $(ARMDEPS)/lib/libevent.a +include $(PREBUILT_STATIC_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := libssl +LOCAL_SRC_FILES := $(ARMDEPS)/lib/libssl.a +include $(PREBUILT_STATIC_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := libcrypto +LOCAL_SRC_FILES := $(ARMDEPS)/lib/libcrypto.a +include $(PREBUILT_STATIC_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := liblongbow +LOCAL_SRC_FILES := $(ARMDIST)/lib/liblongbow.a +include $(PREBUILT_STATIC_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := ccnxsupportlibrary + + +LOCAL_SRC_FILES := \ + Metis_wrap.c + +LOCAL_CFLAGS := $(M_CFLAGS) $(OS_CFLAGS) -I$(ARMDIST)/include -I$(METIS_INC) + +LOCAL_CFLAGS += -I$(ARMDIST)/include -I$(METIS_INC) +LOCAL_CFLAGS += -std=c99 -g + + +LOCAL_LDLIBS := -ldl -llog $(OS_LDFLAGS) + +LOCAL_STATIC_LIBRARIES := \ + libmetis \ + libccnx_api_portal \ + libccnx_api_control \ + libccnx_api_notify \ + libccnx_transport_rta \ + libccnx_common \ + libparc \ + liblongbow \ + liblongbow-textplain \ + liblongbow-ansiterm \ + libssl \ + libevent \ + libcrypto + +include $(BUILD_SHARED_LIBRARY)
\ No newline at end of file diff --git a/ccnxandroidmetis/ccnxsupportlibrary/src/main/jni/ccnxsupportlibrary/Metis_wrap.c b/ccnxandroidmetis/ccnxsupportlibrary/src/main/jni/ccnxsupportlibrary/Metis_wrap.c new file mode 100644 index 00000000..2febb40f --- /dev/null +++ b/ccnxandroidmetis/ccnxsupportlibrary/src/main/jni/ccnxsupportlibrary/Metis_wrap.c @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <string.h> +#include <stdio.h> +#include <getopt.h> +#include <sys/param.h> +#include <sys/utsname.h> +#include <pthread.h> +#include <dirent.h> +#include <android/log.h> +#include "Metis_wrap.h" +#include <ccnx/forwarder/metis/core/metis_Forwarder.h> +#include <ccnx/forwarder/metis/core/metis_System.h> +#include <ccnx/forwarder/metis/content_store/metis_ContentStoreInterface.h> +#include <ccnx/api/control/cpi_Listener.h> +#include <ccnx/api/control/cpi_InterfaceSet.h> + + +static bool _isRunning = false; + + +static MetisForwarder *metis; + +static void +_setLogLevelToLevel(int logLevelArray[MetisLoggerFacility_END], MetisLoggerFacility facility, const char *levelString) +{ + PARCLogLevel level = parcLogLevel_FromString(levelString); + + if (level < PARCLogLevel_All) { + // we have a good facility and level + logLevelArray[facility] = level; + } else { + printf("Invalid log level string %s\n", levelString); + __android_log_print(ANDROID_LOG_DEBUG, "Metis Wrap", "Invalid log level stringa %s", levelString); + } +} + + +static void +_setLogLevel(int logLevelArray[MetisLoggerFacility_END], const char *string) +{ + char *tofree = parcMemory_StringDuplicate(string, strlen(string)); + char *p = tofree; + + char *facilityString = strsep(&p, "="); + if (facilityString) { + char *levelString = p; + + if (strcasecmp(facilityString, "all") == 0) { + for (MetisLoggerFacility facility = 0; facility < MetisLoggerFacility_END; facility++) { + _setLogLevelToLevel(logLevelArray, facility, levelString); + } + } else { + MetisLoggerFacility facility; + for (facility = 0; facility < MetisLoggerFacility_END; facility++) { + if (strcasecmp(facilityString, metisLogger_FacilityString(facility)) == 0) { + break; + } + } + + if (facility < MetisLoggerFacility_END) { + _setLogLevelToLevel(logLevelArray, facility, levelString); + } else { + __android_log_print(ANDROID_LOG_DEBUG, "Metis Wrap", "Invalid facility string %s", facilityString); + } + } + } + parcMemory_Deallocate((void **) &tofree); +} + + + +JNIEXPORT void JNICALL Java_com_metis_ccnx_ccnxsupportlibrary_Metis_start + (JNIEnv *env, jobject obj, jstring path) +{ + if (!_isRunning) { + metis = metisForwarder_Create(NULL); + MetisConfiguration *configuration = metisForwarder_GetConfiguration(metis); + metisConfiguration_SetObjectStoreSize(configuration, 0); + metisConfiguration_StartCLI(configuration, 2001); + if (path != NULL) { + __android_log_print(ANDROID_LOG_DEBUG, "Metis Wrap","qui"); + const char *configFileName = (*env)->GetStringUTFChars(env, path, 0); + __android_log_print(ANDROID_LOG_DEBUG, "Metis Wrap", "configuration file %s", configFileName); + metisForwarder_SetupFromConfigFile(metis, configFileName); + __android_log_print(ANDROID_LOG_DEBUG, "Metis Wrap","config from file"); + } else { + __android_log_print(ANDROID_LOG_DEBUG, "Metis Wrap","qua"); + metisForwarder_SetupAllListeners(metis, PORT_NUMBER, NULL); + } + MetisDispatcher *dispatcher = metisForwarder_GetDispatcher(metis); + __android_log_print(ANDROID_LOG_DEBUG, "Metis Wrap","dispatcher"); + _isRunning = true; + __android_log_print(ANDROID_LOG_DEBUG, "Metis Wrap","true"); + metisDispatcher_Run(dispatcher); + __android_log_print(ANDROID_LOG_DEBUG, "Metis Wrap","run"); + } + + } + +JNIEXPORT void JNICALL Java_com_metis_ccnx_ccnxsupportlibrary_Metis_stop + (JNIEnv *env, jobject obj) +{ + if(_isRunning) { + __android_log_print(ANDROID_LOG_DEBUG, "Metis Wrap", "%s", "stopping metis..."); + metisForwarder_Destroy(&metis); + _isRunning = false; + } +} + + +JNIEXPORT jboolean JNICALL Java_com_metis_ccnx_ccnxsupportlibrary_Metis_isRunning + (JNIEnv *env, jobject obj) { + __android_log_print(ANDROID_LOG_DEBUG, "Metis Wrap", "%s %d", " metis is running", _isRunning); + return _isRunning; +} + + diff --git a/ccnxandroidmetis/ccnxsupportlibrary/src/main/jni/ccnxsupportlibrary/Metis_wrap.h b/ccnxandroidmetis/ccnxsupportlibrary/src/main/jni/ccnxsupportlibrary/Metis_wrap.h new file mode 100644 index 00000000..ad4bceb2 --- /dev/null +++ b/ccnxandroidmetis/ccnxsupportlibrary/src/main/jni/ccnxsupportlibrary/Metis_wrap.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <jni.h> +#include <android/log.h> + +#define LOG_TAG "CCNxSDK" +#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__) +#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__) +#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__) + + diff --git a/ccnxandroidmetis/ccnxsupportlibrary/src/main/res/values/strings.xml b/ccnxandroidmetis/ccnxsupportlibrary/src/main/res/values/strings.xml new file mode 100644 index 00000000..843d2b5b --- /dev/null +++ b/ccnxandroidmetis/ccnxsupportlibrary/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ +<resources> + <string name="app_name">CCNxSupportLibrary</string> +</resources> |