diff options
Diffstat (limited to 'ccnxandroidmetis/ccnxsupportlibrary/src')
8 files changed, 390 insertions, 0 deletions
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> |