diff --git a/jni-wrappers/.gitignore b/jni-wrappers/.gitignore new file mode 100644 index 00000000..3a708ac0 --- /dev/null +++ b/jni-wrappers/.gitignore @@ -0,0 +1,5 @@ +scripts +**/build +!privmx-libs/**/.gitkeep +!privmx-libs/**/.gitignore +privmx-libs \ No newline at end of file diff --git a/jni-wrappers/CMakeLists.txt b/jni-wrappers/CMakeLists.txt new file mode 100644 index 00000000..9689dedf --- /dev/null +++ b/jni-wrappers/CMakeLists.txt @@ -0,0 +1,51 @@ +# Set the minimum required version of CMake +cmake_minimum_required(VERSION 3.10) + +# Set the project name +project("jni-wrappers") + +set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -s") +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s") + +if (NOT DEFINED CMAKE_DESTINATION_OS) + set(CMAKE_DESTINATION_OS ${CMAKE_SYSTEM_NAME}) +endif () + +if (NOT DEFINED CMAKE_DESTINATION_ARCHITECTURE) + if (CMAKE_DESTINATION_OS STREQUAL "Android" AND DEFINED CMAKE_ANDROID_ARCH_ABI) + set(CMAKE_DESTINATION_ARCHITECTURE ${CMAKE_ANDROID_ARCH_ABI}) + else () + set(CMAKE_DESTINATION_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR}) + endif () +endif () + +if ("${CMAKE_DESTINATION_OS}" STREQUAL "Darwin") + set(file_extension "dylib") + set(CMAKE_MACOSX_RPATH 1) + set(CMAKE_INSTALL_RPATH "@loader_path") +elseif ("${CMAKE_DESTINATION_OS}" STREQUAL "Windows") + set(file_extension "dll") +else () + set(file_extension "so") +endif () + +set(PRIVMX_INCLUDES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/privmx-libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/include") +set(PRIVMX_LIBS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/privmx-libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib") + +message(DEBUG "CMAKE DEST OS ${CMAKE_DESTINATION_OS}") +message(DEBUG "CMAKE DEST PROCESSOR ${CMAKE_DESTINATION_ARCHITECTURE}") + +include_directories(${JAVA_HOME}/include ${JAVA_HOME}/include/darwin) + +# Add the subdirectories that contain the libraries +if(BUILD_ANDROID_STREAM STREQUAL "ON") + add_subdirectory(privmx-endpoint-streams/android) +endif () + +if(BUILD_JVM_STREAM STREQUAL "ON") + add_subdirectory(privmx-endpoint-streams/jvm) +endif () + +if(BUILD_ENDPOINT STREQUAL "ON") + add_subdirectory(privmx-endpoint) +endif () \ No newline at end of file diff --git a/jni-wrappers/build.gradle.kts b/jni-wrappers/build.gradle.kts new file mode 100755 index 00000000..1a49dc9a --- /dev/null +++ b/jni-wrappers/build.gradle.kts @@ -0,0 +1,208 @@ +// +// PrivMX Endpoint Java. +// Copyright © 2025 Simplito sp. z o.o. +// +// This file is part of the PrivMX Platform (https://privmx.dev). +// This software is Licensed under the MIT License. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import org.gradle.internal.jvm.Jvm +import org.gradle.kotlin.dsl.register +import java.util.Properties + +import javax.inject.Inject + +//This task add native libraries to Android Studio IDE to enable cxx code writing features +plugins { + alias(libs.plugins.androidLibrary) +} + +android { + namespace = "com.simplito.privmx_endpoint_jni" + compileSdk = 36 + ndkVersion = "29.0.13599879" + defaultConfig { + minSdk = 24 + externalNativeBuild { + cmake { + cppFlags("-std=c++17") + } + } + } + + externalNativeBuild { + cmake { + path = file("CMakeLists.txt") + version = "3.22.1" + } + } +} + +abstract class NativeBuild @Inject constructor( + @Input + val exec: ExecOperations +) : DefaultTask() { + + private val archs = mutableSetOf() + private lateinit var target: NativePrivMXTarget + + @get:Input + abstract val androidNdkPath: Property + + @get:Input + abstract val androidToolChainPath: Property + + @get:Input + abstract val androidAPILevel: Property + + @get:Input + abstract val privmxEndpointJavaVersion: Property + + private val compileDir = project.layout.buildDirectory.dir("native/compile").get() + private val installDir = project.layout.buildDirectory.dir("native/install").get() + + @TaskAction + fun execute() { + println(Jvm.current().javaHome) + for (arch in archs) { + println("Build ${arch.getSystemName()} - ${arch.getArchName()}") + val platformCompileDir = + compileDir.dir("${arch.getSystemName()}/${privmxEndpointJavaVersion.get()}/${arch.getArchName()}").asFile + val platformInstallDir = + installDir.dir("${arch.getSystemName()}/${privmxEndpointJavaVersion.get()}/${arch.getArchName()}").asFile + + exec.exec { + workingDir = project.layout.projectDirectory.asFile + commandLine = buildList { + add("sh") + add("-c") + add(buildCommand(arch,platformCompileDir,platformInstallDir)) + } + } + exec.exec { + workingDir = platformCompileDir + commandLine("sh", "-c", "make -s -j8") + } + exec.exec { + workingDir = platformCompileDir + commandLine("sh", "-c", "make -s install") + } + } + } + + fun buildCommand( + arch: Arch, + platformCompileDir: File, + platformInstallDir: File + + ): String = buildString { + append("cmake") + append(" -B${platformCompileDir.absolutePath}") + append(" -DCMAKE_INSTALL_PREFIX=\"${platformInstallDir.absolutePath}\"") + append(" -DCMAKE_BUILD_TYPE=Release") + append(" -DCMAKE_CXX_FLAGS=-std=c++17") + append(" -DCMAKE_DESTINATION_OS=${arch.getSystemName()}") + append(" -DCMAKE_DESTINATION_ARCHITECTURE=\"${arch.getArchName()}\"") + append(" -DJAVA_HOME=\"${Jvm.current().javaHome}\"") + append(" -D${target.buildOption}=ON") + if (arch is Arch.AndroidArch) { + append(" -DANDROID_NDK=\"${androidNdkPath.get()}\"") + append(" -DCMAKE_TOOLCHAIN_FILE=\"${androidToolChainPath.get()}\"") + append(" -DANDROID_PLATFORM=\"android-${androidAPILevel.get()}\"") + append(" -DANDROID_ABI=\"${arch.getArchName()}\"") + } + } + + + fun setArchs( + vararg archs: Arch + ) { + this.archs.addAll(archs) + } + + fun setTarget(target: NativePrivMXTarget) { + this.target = target + } + + fun validateInput() { +// if(!::target.isInitialized) throw IncompleteArgumentException("Target is not specified (select one value from NativePrivMXTarget enum)") + } + + + sealed interface Arch { + fun getArchName(): String + fun getSystemName(): String + + enum class AndroidArch : Arch { + `arm64-v8a`, `armeabi-v7a`, x86, x86_64; + + override fun getArchName() = name + + override fun getSystemName(): String = "Android" + } + + enum class DarwinArch : Arch { + arm64; + + override fun getArchName(): String = name + + override fun getSystemName(): String = "Darwin" + } + } + + enum class NativePrivMXTarget { + ENDPOINT, JVM_STREAM, ANDROID_STREAM; + + val buildOption get() = "BUILD_${this.name}" + } + +} + +val Project.privmxEndpointJavaVersion get() = project(":privmx-endpoint").version.toString() + +fun allPlatforms(): Array { + return arrayOf(*NativeBuild.Arch.AndroidArch.values(), *NativeBuild.Arch.DarwinArch.values()) +} + +class PropertiesConfig { + private val properties = Properties().apply { + load(File(rootDir, "local.properties").inputStream()) + } + val sdkPath get() = properties["sdk.dir"] + val ndkVersion get() = properties["ndk.version"] + val ndkPath get() = "$sdkPath/ndk/$ndkVersion" + val androidToolChainPath get() = "$ndkPath/build/cmake/android.toolchain.cmake" +} + +val PropertiesConfig = PropertiesConfig() + + +tasks.register("buildJNIEndpoint") { + setArchs(*allPlatforms()) + setTarget(NativeBuild.NativePrivMXTarget.ENDPOINT) + androidAPILevel.set("24") + androidNdkPath.set(PropertiesConfig.ndkPath) + androidToolChainPath.set(PropertiesConfig.androidToolChainPath) + privmxEndpointJavaVersion.set(project.privmxEndpointJavaVersion) +} + +tasks.register("buildJNIStreamsJVM") { + setArchs(*NativeBuild.Arch.DarwinArch.values()) + setTarget(NativeBuild.NativePrivMXTarget.JVM_STREAM) + androidAPILevel.set("24") + androidNdkPath.set(PropertiesConfig.ndkPath) + androidToolChainPath.set(PropertiesConfig.androidToolChainPath) + privmxEndpointJavaVersion.set(project.privmxEndpointJavaVersion) +} + +tasks.register("buildJNIStreamsAndroid") { + setArchs(*NativeBuild.Arch.AndroidArch.values()) + setTarget(NativeBuild.NativePrivMXTarget.ANDROID_STREAM) + androidAPILevel.set("24") + androidNdkPath.set(PropertiesConfig.ndkPath) + androidToolChainPath.set(PropertiesConfig.androidToolChainPath) + privmxEndpointJavaVersion.set(project.privmxEndpointJavaVersion) +} diff --git a/jni-wrappers/privmx-endpoint-streams/android/CMakeLists.txt b/jni-wrappers/privmx-endpoint-streams/android/CMakeLists.txt new file mode 100644 index 00000000..370f9cf4 --- /dev/null +++ b/jni-wrappers/privmx-endpoint-streams/android/CMakeLists.txt @@ -0,0 +1,28 @@ +# For more information about using CMake with Android Studio, read the +# documentation: https://d.android.com/studio/projects/add-native-code.html. +# For more examples on how to use CMake, see https://github.com/android/ndk-samples. + +# Sets the minimum CMake version required for this project. +cmake_minimum_required(VERSION 3.22.1) + +# Declares the project name. The project name can be accessed via ${ PROJECT_NAME}, +# Since this is the top level CMakeLists.txt, the project name is also accessible +# with ${CMAKE_PROJECT_NAME} (both CMake variables are in-sync within the top level +# build script scope). +project("privmx-endpoint-streams-android") +set(CMAKE_PROJECT_NAME "privmx-endpoint-streams-android") + +add_library(${CMAKE_PROJECT_NAME} SHARED + src/cpp/privmx/endpoint/wrapper/streams/StreamApiLow.cpp +) +target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/includes) + +add_library(privmxendpointstream SHARED IMPORTED GLOBAL) +set_target_properties(privmxendpointstream PROPERTIES IMPORTED_LOCATION ${PRIVMX_LIBS_DIR}/libprivmxendpointstream.${file_extension}) + +include_directories(${PRIVMX_INCLUDES_DIR}) +target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE privmx-endpoint-java privmxendpointstream) + +install(TARGETS ${CMAKE_PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/privmx-endpoint-streams/android/lib) +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/includes DESTINATION ${CMAKE_INSTALL_PREFIX}/privmx-endpoint-streams/android/include) +install(IMPORTED_RUNTIME_ARTIFACTS privmxendpointstream DESTINATION ${CMAKE_INSTALL_PREFIX}/privmx-endpoint-streams/android/lib) \ No newline at end of file diff --git a/jni-wrappers/privmx-endpoint-streams/android/includes/privmx/endpoint/wrapper/streams/StreamApiLow.hpp b/jni-wrappers/privmx-endpoint-streams/android/includes/privmx/endpoint/wrapper/streams/StreamApiLow.hpp new file mode 100644 index 00000000..e69de29b diff --git a/jni-wrappers/privmx-endpoint-streams/android/src/cpp/privmx/endpoint/wrapper/streams/StreamApiLow.cpp b/jni-wrappers/privmx-endpoint-streams/android/src/cpp/privmx/endpoint/wrapper/streams/StreamApiLow.cpp new file mode 100644 index 00000000..e69de29b diff --git a/jni-wrappers/privmx-endpoint-streams/jvm/CMakeLists.txt b/jni-wrappers/privmx-endpoint-streams/jvm/CMakeLists.txt new file mode 100644 index 00000000..24ca814c --- /dev/null +++ b/jni-wrappers/privmx-endpoint-streams/jvm/CMakeLists.txt @@ -0,0 +1,28 @@ +# For more information about using CMake with Android Studio, read the +# documentation: https://d.android.com/studio/projects/add-native-code.html. +# For more examples on how to use CMake, see https://github.com/android/ndk-samples. + +# Sets the minimum CMake version required for this project. +cmake_minimum_required(VERSION 3.22.1) + +# Declares the project name. The project name can be accessed via ${ PROJECT_NAME}, +# Since this is the top level CMakeLists.txt, the project name is also accessible +# with ${CMAKE_PROJECT_NAME} (both CMake variables are in-sync within the top level +# build script scope). +project("privmx-endpoint-streams-jvm") +set(CMAKE_PROJECT_NAME "privmx-endpoint-streams-jvm") + +add_library(${CMAKE_PROJECT_NAME} SHARED + src/cpp/privmx/endpoint/wrapper/streams/StreamApi.cpp +) +target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/includes) + +add_library(privmxendpointstream SHARED IMPORTED GLOBAL) +set_target_properties(privmxendpointstream PROPERTIES IMPORTED_LOCATION ${PRIVMX_LIBS_DIR}/libprivmxendpointstream.${file_extension}) + +include_directories(${PRIVMX_INCLUDES_DIR}) +target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE privmx-endpoint-java privmxendpointstream) + +install(TARGETS ${CMAKE_PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/privmx-endpoint-streams/jvm/lib) +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/includes DESTINATION ${CMAKE_INSTALL_PREFIX}/privmx-endpoint-streams/jvm/include) +install(IMPORTED_RUNTIME_ARTIFACTS privmxendpointstream DESTINATION ${CMAKE_INSTALL_PREFIX}/privmx-endpoint-streams/jvm/lib) \ No newline at end of file diff --git a/jni-wrappers/privmx-endpoint/CMakeLists.txt b/jni-wrappers/privmx-endpoint/CMakeLists.txt new file mode 100644 index 00000000..0584f2ca --- /dev/null +++ b/jni-wrappers/privmx-endpoint/CMakeLists.txt @@ -0,0 +1,102 @@ +# For more information about using CMake with Android Studio, read the +# documentation: https://d.android.com/studio/projects/add-native-code.html. +# For more examples on how to use CMake, see https://github.com/android/ndk-samples. + +# Sets the minimum CMake version required for this project. +cmake_minimum_required(VERSION 3.22.1) + +# Declares the project name. The project name can be accessed via ${ PROJECT_NAME}, +# Since this is the top level CMakeLists.txt, the project name is also accessible +# with ${CMAKE_PROJECT_NAME} (both CMake variables are in-sync within the top level +# build script scope). +project("privmx-endpoint-java") +set(CMAKE_PROJECT_NAME "privmx-endpoint-java") +add_library(${CMAKE_PROJECT_NAME} SHARED + ${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/parsers/parser.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/parsers/model_native_initializers.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/utils/exceptions.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/utils/jniUtils.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/utils/utils.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/modules/Connection.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/modules/CryptoApi.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/modules/ThreadApi.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/modules/StoreApi.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/modules/InboxApi.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/modules/EventQueue.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/modules/BackendRequester.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/modules/EventApi.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/modules/UserVerifierInterfaceJNI.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/modules/ExtKey.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/modules/Utils.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/modules/KvdbApi.cpp +) +target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/includes) + +add_library(ssl SHARED IMPORTED GLOBAL) +set_target_properties(ssl PROPERTIES IMPORTED_LOCATION ${PRIVMX_LIBS_DIR}/libssl.${file_extension}) + +add_library(crypto SHARED IMPORTED GLOBAL) +set_target_properties(crypto PROPERTIES IMPORTED_LOCATION ${PRIVMX_LIBS_DIR}/libcrypto.${file_extension}) + +add_library(gmp SHARED IMPORTED GLOBAL) +set_target_properties(gmp PROPERTIES IMPORTED_LOCATION ${PRIVMX_LIBS_DIR}/libgmp.${file_extension}) + +add_library(PocoFoundation SHARED IMPORTED GLOBAL) +set_target_properties(PocoFoundation PROPERTIES IMPORTED_LOCATION ${PRIVMX_LIBS_DIR}/libPocoFoundation.${file_extension}) + +add_library(PocoJSON SHARED IMPORTED GLOBAL) +set_target_properties(PocoJSON PROPERTIES IMPORTED_LOCATION ${PRIVMX_LIBS_DIR}/libPocoJSON.${file_extension}) + +add_library(PocoNet SHARED IMPORTED GLOBAL) +set_target_properties(PocoNet PROPERTIES IMPORTED_LOCATION ${PRIVMX_LIBS_DIR}/libPocoNet.${file_extension}) + +add_library(PocoCrypto SHARED IMPORTED GLOBAL) +set_target_properties(PocoCrypto PROPERTIES IMPORTED_LOCATION ${PRIVMX_LIBS_DIR}/libPocoCrypto.${file_extension}) + +add_library(PocoXML SHARED IMPORTED GLOBAL) +set_target_properties(PocoXML PROPERTIES IMPORTED_LOCATION ${PRIVMX_LIBS_DIR}/libPocoXML.${file_extension}) + +add_library(PocoNetSSL SHARED IMPORTED GLOBAL) +set_target_properties(PocoNetSSL PROPERTIES IMPORTED_LOCATION ${PRIVMX_LIBS_DIR}/libPocoNetSSL.${file_extension}) + +add_library(PocoUtil SHARED IMPORTED GLOBAL) +set_target_properties(PocoUtil PROPERTIES IMPORTED_LOCATION ${PRIVMX_LIBS_DIR}/libPocoUtil.${file_extension}) + +add_library(Pson SHARED IMPORTED GLOBAL) +set_target_properties(Pson PROPERTIES IMPORTED_LOCATION ${PRIVMX_LIBS_DIR}/libPson.${file_extension}) + +add_library(libprivmx SHARED IMPORTED GLOBAL) +set_target_properties(libprivmx PROPERTIES IMPORTED_LOCATION ${PRIVMX_LIBS_DIR}/libprivmx.${file_extension}) + +add_library(privmxendpointcore SHARED IMPORTED GLOBAL) +set_target_properties(privmxendpointcore PROPERTIES IMPORTED_LOCATION ${PRIVMX_LIBS_DIR}/libprivmxendpointcore.${file_extension}) + +add_library(privmxendpointcrypto SHARED IMPORTED GLOBAL) +set_target_properties(privmxendpointcrypto PROPERTIES IMPORTED_LOCATION ${PRIVMX_LIBS_DIR}/libprivmxendpointcrypto.${file_extension}) + +add_library(privmxendpointstore SHARED IMPORTED GLOBAL) +set_target_properties(privmxendpointstore PROPERTIES IMPORTED_LOCATION ${PRIVMX_LIBS_DIR}/libprivmxendpointstore.${file_extension}) + +add_library(privmxendpointthread SHARED IMPORTED GLOBAL) +set_target_properties(privmxendpointthread PROPERTIES IMPORTED_LOCATION ${PRIVMX_LIBS_DIR}/libprivmxendpointthread.${file_extension}) + +add_library(privmxendpointinbox SHARED IMPORTED GLOBAL) +set_target_properties(privmxendpointinbox PROPERTIES IMPORTED_LOCATION ${PRIVMX_LIBS_DIR}/libprivmxendpointinbox.${file_extension}) + +add_library(privmxendpointevent SHARED IMPORTED GLOBAL) +set_target_properties(privmxendpointevent PROPERTIES IMPORTED_LOCATION ${PRIVMX_LIBS_DIR}/libprivmxendpointevent.${file_extension}) + +add_library(privmxendpointkvdb SHARED IMPORTED GLOBAL) +set_target_properties(privmxendpointkvdb PROPERTIES IMPORTED_LOCATION ${PRIVMX_LIBS_DIR}/libprivmxendpointkvdb.${file_extension}) + + +include_directories(${PRIVMX_INCLUDES_DIR}) + +target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE ssl crypto) +target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE gmp) +target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE PocoFoundation PocoXML PocoJSON PocoNet PocoNetSSL PocoUtil PocoCrypto) +target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE Pson libprivmx privmxendpointcrypto privmxendpointcore privmxendpointstore privmxendpointthread privmxendpointinbox privmxendpointevent privmxendpointkvdb) + +install(TARGETS ${CMAKE_PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/privmx-endpoint-java/lib) +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/includes DESTINATION ${CMAKE_INSTALL_PREFIX}/privmx-endpoint-java/include) +install(IMPORTED_RUNTIME_ARTIFACTS crypto ssl gmp PocoFoundation PocoXML PocoJSON PocoNet PocoNetSSL PocoUtil PocoCrypto Pson libprivmx privmxendpointcore privmxendpointcrypto privmxendpointstore privmxendpointthread privmxendpointinbox privmxendpointevent privmxendpointkvdb DESTINATION ${CMAKE_INSTALL_PREFIX}/privmx-endpoint-java/lib) \ No newline at end of file diff --git a/privmx-endpoint/src/main/cpp/modules/Connection.h b/jni-wrappers/privmx-endpoint/includes/privmx/endpoint/wrapper/modules/Connection.h similarity index 91% rename from privmx-endpoint/src/main/cpp/modules/Connection.h rename to jni-wrappers/privmx-endpoint/includes/privmx/endpoint/wrapper/modules/Connection.h index fb6a7898..ea05415a 100644 --- a/privmx-endpoint/src/main/cpp/modules/Connection.h +++ b/jni-wrappers/privmx-endpoint/includes/privmx/endpoint/wrapper/modules/Connection.h @@ -8,7 +8,7 @@ // See the License for the specific language governing permissions and // limitations under the License. // -#include +#include "privmx/endpoint/core/Connection.hpp" #include #ifndef PRIVMXENDPOINTWRAPPER_CONNECTION_H diff --git a/jni-wrappers/privmx-endpoint/includes/privmx/endpoint/wrapper/modules/EventApi.h b/jni-wrappers/privmx-endpoint/includes/privmx/endpoint/wrapper/modules/EventApi.h new file mode 100644 index 00000000..7bcfb221 --- /dev/null +++ b/jni-wrappers/privmx-endpoint/includes/privmx/endpoint/wrapper/modules/EventApi.h @@ -0,0 +1,14 @@ +#include +#include "../utils/utils.hpp" +#include "Connection.h" +#include "../parsers/parser.h" +#include "privmx/endpoint/event/EventApi.hpp" + +using namespace privmx::endpoint; + +#ifndef PRIVMXENDPOINT_EVENTAPI_H +#define PRIVMXENDPOINT_EVENTAPI_H + +privmx::endpoint::event::EventApi *getEventApi(JniContextUtils &ctx, jobject eventApiInstance); + +#endif //PRIVMXENDPOINT_EVENTAPI_H \ No newline at end of file diff --git a/privmx-endpoint/src/main/cpp/modules/StoreApi.h b/jni-wrappers/privmx-endpoint/includes/privmx/endpoint/wrapper/modules/StoreApi.h similarity index 84% rename from privmx-endpoint/src/main/cpp/modules/StoreApi.h rename to jni-wrappers/privmx-endpoint/includes/privmx/endpoint/wrapper/modules/StoreApi.h index 3399a5fa..cc763398 100644 --- a/privmx-endpoint/src/main/cpp/modules/StoreApi.h +++ b/jni-wrappers/privmx-endpoint/includes/privmx/endpoint/wrapper/modules/StoreApi.h @@ -10,8 +10,8 @@ // #include -#include -#include "../utils.hpp" +#include "privmx/endpoint/store/StoreApi.hpp" +#include "privmx/endpoint/wrapper/utils/utils.hpp" #ifndef PRIVMXENDPOINT_STOREAPI_H #define PRIVMXENDPOINT_STOREAPI_H diff --git a/privmx-endpoint/src/main/cpp/modules/ThreadApi.h b/jni-wrappers/privmx-endpoint/includes/privmx/endpoint/wrapper/modules/ThreadApi.h similarity index 84% rename from privmx-endpoint/src/main/cpp/modules/ThreadApi.h rename to jni-wrappers/privmx-endpoint/includes/privmx/endpoint/wrapper/modules/ThreadApi.h index 68c8848f..bb2337f2 100644 --- a/privmx-endpoint/src/main/cpp/modules/ThreadApi.h +++ b/jni-wrappers/privmx-endpoint/includes/privmx/endpoint/wrapper/modules/ThreadApi.h @@ -10,8 +10,8 @@ // #include -#include -#include "../utils.hpp" +#include "privmx/endpoint/thread/ThreadApi.hpp" +#include "privmx/endpoint/wrapper/utils/utils.hpp" #ifndef PRIVMXENDPOINT_THREADAPI_H #define PRIVMXENDPOINT_THREADAPI_H diff --git a/privmx-endpoint/src/main/cpp/modules/UserVerifierInterfaceJNI.h b/jni-wrappers/privmx-endpoint/includes/privmx/endpoint/wrapper/modules/UserVerifierInterfaceJNI.h similarity index 100% rename from privmx-endpoint/src/main/cpp/modules/UserVerifierInterfaceJNI.h rename to jni-wrappers/privmx-endpoint/includes/privmx/endpoint/wrapper/modules/UserVerifierInterfaceJNI.h diff --git a/privmx-endpoint/src/main/cpp/model_native_initializers.h b/jni-wrappers/privmx-endpoint/includes/privmx/endpoint/wrapper/parsers/model_native_initializers.h similarity index 90% rename from privmx-endpoint/src/main/cpp/model_native_initializers.h rename to jni-wrappers/privmx-endpoint/includes/privmx/endpoint/wrapper/parsers/model_native_initializers.h index f83c7959..4119af93 100644 --- a/privmx-endpoint/src/main/cpp/model_native_initializers.h +++ b/jni-wrappers/privmx-endpoint/includes/privmx/endpoint/wrapper/parsers/model_native_initializers.h @@ -13,7 +13,7 @@ #define PRIVMXENDPOINTWRAPPER_MODEL_NATIVE_INITIALIZERS_H #include -#include "utils.hpp" +#include "../utils/utils.hpp" #include "privmx/endpoint/core/Connection.hpp" #include "privmx/endpoint/core/UserVerifierInterface.hpp" #include "privmx/endpoint/core/Types.hpp" @@ -34,6 +34,7 @@ #include "privmx/endpoint/crypto/ExtKey.hpp" #include "privmx/endpoint/kvdb/KvdbApi.hpp" #include "privmx/endpoint/kvdb/Types.hpp" +#include "privmx/endpoint/kvdb/Events.hpp" namespace privmx { namespace wrapper { @@ -115,8 +116,10 @@ namespace privmx { jobject fileChange2Java(JniContextUtils &ctx, privmx::endpoint::store::FileChange file_change_c); //Event - jobject contextUsersStatusChangeData2Java(JniContextUtils &ctx, - privmx::endpoint::core::ContextUsersStatusChangeData contextUsersStatusChangeData_c); + jobject contextUsersStatusChangedEventData2Java( + JniContextUtils &ctx, + privmx::endpoint::core::ContextUsersStatusChangedEventData contextUsersStatusChangedEventData_c + ); jobject contextUserEventData2Java(JniContextUtils &ctx, privmx::endpoint::core::ContextUserEventData contextUserEventData_c); @@ -153,6 +156,18 @@ namespace privmx { privmx::endpoint::event::ContextCustomEventData contextCustomEventData_c ); + jobject kvdbDeletedEventData2Java(JniContextUtils &ctx, + privmx::endpoint::kvdb::KvdbDeletedEventData kvdbDeletedEventData_c + ); + + jobject kvdbStatsEventData2Java(JniContextUtils &ctx, + privmx::endpoint::kvdb::KvdbStatsEventData kvdbStatsEventData_c + ); + + jobject kvdbDeletedEntryEventData2Java(JniContextUtils &ctx, + privmx::endpoint::kvdb::KvdbDeletedEntryEventData kvdbDeletedEntryEventData_c + ); + //Kvdb jobject kvdb2Java(JniContextUtils &ctx, privmx::endpoint::kvdb::Kvdb kvdb_c); diff --git a/privmx-endpoint/src/main/cpp/parser.h b/jni-wrappers/privmx-endpoint/includes/privmx/endpoint/wrapper/parsers/parser.h similarity index 97% rename from privmx-endpoint/src/main/cpp/parser.h rename to jni-wrappers/privmx-endpoint/includes/privmx/endpoint/wrapper/parsers/parser.h index 17391741..62edae03 100644 --- a/privmx-endpoint/src/main/cpp/parser.h +++ b/jni-wrappers/privmx-endpoint/includes/privmx/endpoint/wrapper/parsers/parser.h @@ -12,7 +12,7 @@ #ifndef PRIVMX_POCKET_LIB_PARSER_H #define PRIVMX_POCKET_LIB_PARSER_H -#include "utils.hpp" +#include "../utils/utils.hpp" #include #include "model_native_initializers.h" diff --git a/privmx-endpoint/src/main/cpp/exceptions.h b/jni-wrappers/privmx-endpoint/includes/privmx/endpoint/wrapper/utils/exceptions.h similarity index 100% rename from privmx-endpoint/src/main/cpp/exceptions.h rename to jni-wrappers/privmx-endpoint/includes/privmx/endpoint/wrapper/utils/exceptions.h diff --git a/privmx-endpoint/src/main/cpp/jniUtils.h b/jni-wrappers/privmx-endpoint/includes/privmx/endpoint/wrapper/utils/jniUtils.h similarity index 100% rename from privmx-endpoint/src/main/cpp/jniUtils.h rename to jni-wrappers/privmx-endpoint/includes/privmx/endpoint/wrapper/utils/jniUtils.h diff --git a/privmx-endpoint/src/main/cpp/utils.hpp b/jni-wrappers/privmx-endpoint/includes/privmx/endpoint/wrapper/utils/utils.hpp similarity index 98% rename from privmx-endpoint/src/main/cpp/utils.hpp rename to jni-wrappers/privmx-endpoint/includes/privmx/endpoint/wrapper/utils/utils.hpp index bfada2b7..fca5d1c6 100644 --- a/privmx-endpoint/src/main/cpp/utils.hpp +++ b/jni-wrappers/privmx-endpoint/includes/privmx/endpoint/wrapper/utils/utils.hpp @@ -15,7 +15,6 @@ #include #include #include -#include #include "privmx/endpoint/core/Exception.hpp" #include "exceptions.h" diff --git a/privmx-endpoint/src/main/cpp/modules/BackendRequester.cpp b/jni-wrappers/privmx-endpoint/src/cpp/modules/BackendRequester.cpp similarity index 97% rename from privmx-endpoint/src/main/cpp/modules/BackendRequester.cpp rename to jni-wrappers/privmx-endpoint/src/cpp/modules/BackendRequester.cpp index e0d1f9ed..33023b28 100644 --- a/privmx-endpoint/src/main/cpp/modules/BackendRequester.cpp +++ b/jni-wrappers/privmx-endpoint/src/cpp/modules/BackendRequester.cpp @@ -10,8 +10,8 @@ // #include -#include "../exceptions.h" -#include "../utils.hpp" +#include "privmx/endpoint/wrapper/utils/exceptions.h" +#include "privmx/endpoint/wrapper/utils/utils.hpp" #include #include diff --git a/privmx-endpoint/src/main/cpp/modules/Connection.cpp b/jni-wrappers/privmx-endpoint/src/cpp/modules/Connection.cpp similarity index 97% rename from privmx-endpoint/src/main/cpp/modules/Connection.cpp rename to jni-wrappers/privmx-endpoint/src/cpp/modules/Connection.cpp index bdc4b946..624f37a7 100644 --- a/privmx-endpoint/src/main/cpp/modules/Connection.cpp +++ b/jni-wrappers/privmx-endpoint/src/cpp/modules/Connection.cpp @@ -13,11 +13,11 @@ #include #include "privmx/endpoint/core/Config.hpp" #include -#include "UserVerifierInterfaceJNI.h" -#include "Connection.h" -#include "../utils.hpp" -#include "../parser.h" -#include "../exceptions.h" +#include "privmx/endpoint/wrapper/modules/UserVerifierInterfaceJNI.h" +#include "privmx/endpoint/wrapper/modules/Connection.h" +#include "privmx/endpoint/wrapper/utils/utils.hpp" +#include "privmx/endpoint/wrapper/parsers/parser.h" +#include "privmx/endpoint/wrapper/utils/exceptions.h" using namespace privmx::endpoint; @@ -361,7 +361,7 @@ Java_com_simplito_java_privmx_1endpoint_modules_core_Connection_subscribeFor( jobject result; ctx.callResultEndpointApi( &result, - [&ctx, &env, &thiz, &subscription_queries]() { + [&ctx, &env, &thiz, &subscription_queries]() -> jobject { jclass arrayListCls = env->FindClass("java/util/ArrayList"); jmethodID initMID = env->GetMethodID(arrayListCls, "", "()V"); jmethodID addToListMID = env->GetMethodID(arrayListCls, "add", @@ -372,8 +372,8 @@ Java_com_simplito_java_privmx_1endpoint_modules_core_Connection_subscribeFor( for (int i = 0; i < ctx->GetArrayLength(subscription_queries_arr); i++) { jobject arrayElement = ctx->GetObjectArrayElement(subscription_queries_arr, i); - if (ctx.nullCheck(arrayElement, "Subscription queries array elements")) { - return nullptr; + if (ctx.nullCheck(arrayElement, "Subscription queries list elements")) { + return (jobject) nullptr; } subscription_queries_c.push_back(ctx.jString2string((jstring) arrayElement)); } @@ -418,7 +418,7 @@ Java_com_simplito_java_privmx_1endpoint_modules_core_Connection_unsubscribeFrom( for (int i = 0; i < ctx->GetArrayLength(subscription_ids_arr); i++) { jobject arrayElement = ctx->GetObjectArrayElement(subscription_ids_arr, i); if (ctx.nullCheck(arrayElement, "Subscription ids array elements")) { - return nullptr; + return; } subscription_ids_c.push_back(ctx.jString2string((jstring) arrayElement)); } diff --git a/privmx-endpoint/src/main/cpp/modules/CryptoApi.cpp b/jni-wrappers/privmx-endpoint/src/cpp/modules/CryptoApi.cpp similarity index 99% rename from privmx-endpoint/src/main/cpp/modules/CryptoApi.cpp rename to jni-wrappers/privmx-endpoint/src/cpp/modules/CryptoApi.cpp index f1058feb..eaa10cc2 100644 --- a/privmx-endpoint/src/main/cpp/modules/CryptoApi.cpp +++ b/jni-wrappers/privmx-endpoint/src/cpp/modules/CryptoApi.cpp @@ -12,9 +12,9 @@ #include #include #include -#include "../utils.hpp" -#include "../parser.h" -#include "../exceptions.h" +#include "privmx/endpoint/wrapper/utils/utils.hpp" +#include "privmx/endpoint/wrapper/parsers/parser.h" +#include "privmx/endpoint/wrapper/utils/exceptions.h" using namespace privmx::endpoint; diff --git a/privmx-endpoint/src/main/cpp/modules/EventApi.cpp b/jni-wrappers/privmx-endpoint/src/cpp/modules/EventApi.cpp similarity index 95% rename from privmx-endpoint/src/main/cpp/modules/EventApi.cpp rename to jni-wrappers/privmx-endpoint/src/cpp/modules/EventApi.cpp index 5591cce5..dc0da851 100644 --- a/privmx-endpoint/src/main/cpp/modules/EventApi.cpp +++ b/jni-wrappers/privmx-endpoint/src/cpp/modules/EventApi.cpp @@ -11,9 +11,9 @@ #include #include -#include "../utils.hpp" -#include "Connection.h" -#include "../parser.h" +#include "privmx/endpoint/wrapper/utils/utils.hpp" +#include "privmx/endpoint/wrapper/modules/Connection.h" +#include "privmx/endpoint/wrapper/parsers/parser.h" using namespace privmx::endpoint; @@ -131,6 +131,9 @@ Java_com_simplito_java_privmx_1endpoint_modules_event_EventApi_subscribeFor( int length = ctx->GetArrayLength(subscription_queries_arr); for (int i = 0; i < length; i++) { jobject arrayElement = ctx->GetObjectArrayElement(subscription_queries_arr, i); + if (ctx.nullCheck(arrayElement, "Subscription queries list elements")) { + return (jobject) nullptr; + } subscription_queries_c.push_back(ctx.jString2string((jstring) arrayElement)); } diff --git a/privmx-endpoint/src/main/cpp/modules/EventQueue.cpp b/jni-wrappers/privmx-endpoint/src/cpp/modules/EventQueue.cpp similarity index 94% rename from privmx-endpoint/src/main/cpp/modules/EventQueue.cpp rename to jni-wrappers/privmx-endpoint/src/cpp/modules/EventQueue.cpp index 29bcca7a..22af8d15 100644 --- a/privmx-endpoint/src/main/cpp/modules/EventQueue.cpp +++ b/jni-wrappers/privmx-endpoint/src/cpp/modules/EventQueue.cpp @@ -11,8 +11,8 @@ #include #include -#include "../utils.hpp" -#include "../parser.h" +#include "privmx/endpoint/wrapper/utils/utils.hpp" +#include "privmx/endpoint/wrapper/parsers/parser.h" using namespace privmx::endpoint::core; diff --git a/privmx-endpoint/src/main/cpp/modules/ExtKey.cpp b/jni-wrappers/privmx-endpoint/src/cpp/modules/ExtKey.cpp similarity index 99% rename from privmx-endpoint/src/main/cpp/modules/ExtKey.cpp rename to jni-wrappers/privmx-endpoint/src/cpp/modules/ExtKey.cpp index 76d720f7..40d3229f 100644 --- a/privmx-endpoint/src/main/cpp/modules/ExtKey.cpp +++ b/jni-wrappers/privmx-endpoint/src/cpp/modules/ExtKey.cpp @@ -10,7 +10,7 @@ // #include "privmx/endpoint/crypto/ExtKey.hpp" -#include "../utils.hpp" +#include "privmx/endpoint/wrapper/utils/utils.hpp" #include using namespace privmx::endpoint; diff --git a/privmx-endpoint/src/main/cpp/modules/InboxApi.cpp b/jni-wrappers/privmx-endpoint/src/cpp/modules/InboxApi.cpp similarity index 97% rename from privmx-endpoint/src/main/cpp/modules/InboxApi.cpp rename to jni-wrappers/privmx-endpoint/src/cpp/modules/InboxApi.cpp index 959e8c4b..04625a0f 100644 --- a/privmx-endpoint/src/main/cpp/modules/InboxApi.cpp +++ b/jni-wrappers/privmx-endpoint/src/cpp/modules/InboxApi.cpp @@ -12,13 +12,13 @@ #include #include #include -#include "Connection.h" -#include "ThreadApi.h" -#include "StoreApi.h" -#include "../utils.hpp" -#include "../parser.h" -#include "../model_native_initializers.h" -#include "../exceptions.h" +#include "privmx/endpoint/wrapper/modules/Connection.h" +#include "privmx/endpoint/wrapper/modules/ThreadApi.h" +#include "privmx/endpoint/wrapper/modules/StoreApi.h" +#include "privmx/endpoint/wrapper/utils/utils.hpp" +#include "privmx/endpoint/wrapper/parsers/parser.h" +#include "privmx/endpoint/wrapper/parsers/model_native_initializers.h" +#include "privmx/endpoint/wrapper/utils/exceptions.h" #include "privmx/endpoint/core/Exception.hpp" using namespace privmx::endpoint; @@ -688,6 +688,9 @@ Java_com_simplito_java_privmx_1endpoint_modules_inbox_InboxApi_subscribeFor( int length = ctx->GetArrayLength(subscription_queries_arr); for (int i = 0; i < length; i++) { jobject arrayElement = ctx->GetObjectArrayElement(subscription_queries_arr, i); + if (ctx.nullCheck(arrayElement, "Subscription queries list elements")) { + return (jobject) nullptr; + } subscription_queries_c.push_back(ctx.jString2string((jstring) arrayElement)); } diff --git a/privmx-endpoint/src/main/cpp/modules/KvdbApi.cpp b/jni-wrappers/privmx-endpoint/src/cpp/modules/KvdbApi.cpp similarity index 98% rename from privmx-endpoint/src/main/cpp/modules/KvdbApi.cpp rename to jni-wrappers/privmx-endpoint/src/cpp/modules/KvdbApi.cpp index b3e7683c..ed61ed07 100644 --- a/privmx-endpoint/src/main/cpp/modules/KvdbApi.cpp +++ b/jni-wrappers/privmx-endpoint/src/cpp/modules/KvdbApi.cpp @@ -9,14 +9,14 @@ // limitations under the License. // -#include "../utils.hpp" -#include "../parser.h" -#include "Connection.h" +#include "privmx/endpoint/wrapper/utils/utils.hpp" +#include "privmx/endpoint/wrapper/parsers/parser.h" +#include "privmx/endpoint/wrapper/modules/Connection.h" #include #include -#include "../model_native_initializers.h" +#include "privmx/endpoint/wrapper/parsers/model_native_initializers.h" -using namespace privmx::endpoint; +using namespace privmx::endpoint;s kvdb::KvdbApi *getKvdbApi(JniContextUtils &ctx, jobject kvdbApiInstance) { jclass cls = ctx->GetObjectClass(kvdbApiInstance); @@ -641,6 +641,9 @@ Java_com_simplito_java_privmx_1endpoint_modules_kvdb_KvdbApi_subscribeFor( int length = ctx->GetArrayLength(subscription_queries_arr); for (int i = 0; i < length; i++) { jobject arrayElement = ctx->GetObjectArrayElement(subscription_queries_arr, i); + if (ctx.nullCheck(arrayElement, "Subscription queries list elements")) { + return (jobject) nullptr; + } subscription_queries_c.push_back(ctx.jString2string((jstring) arrayElement)); } diff --git a/privmx-endpoint/src/main/cpp/modules/StoreApi.cpp b/jni-wrappers/privmx-endpoint/src/cpp/modules/StoreApi.cpp similarity index 98% rename from privmx-endpoint/src/main/cpp/modules/StoreApi.cpp rename to jni-wrappers/privmx-endpoint/src/cpp/modules/StoreApi.cpp index 05c7f99b..3364ad8b 100644 --- a/privmx-endpoint/src/main/cpp/modules/StoreApi.cpp +++ b/jni-wrappers/privmx-endpoint/src/cpp/modules/StoreApi.cpp @@ -12,11 +12,11 @@ #include #include #include -#include "Connection.h" -#include "StoreApi.h" -#include "../utils.hpp" -#include "../parser.h" -#include "../exceptions.h" +#include "privmx/endpoint/wrapper/modules/Connection.h" +#include "privmx/endpoint/wrapper/modules/StoreApi.h" +#include "privmx/endpoint/wrapper/utils/utils.hpp" +#include "privmx/endpoint/wrapper/parsers/parser.h" +#include "privmx/endpoint/wrapper/utils/exceptions.h" using namespace privmx::endpoint; @@ -645,6 +645,9 @@ Java_com_simplito_java_privmx_1endpoint_modules_store_StoreApi_subscribeFor( for (int i = 0; i < ctx->GetArrayLength(subscription_queries_arr); i++) { jobject arrayElement = ctx->GetObjectArrayElement(subscription_queries_arr, i); + if (ctx.nullCheck(arrayElement, "Subscription queries list elements")) { + return (jobject) nullptr; + } subscription_queries_c.push_back(ctx.jString2string((jstring) arrayElement)); } diff --git a/jni-wrappers/privmx-endpoint/src/cpp/modules/StreamApi.cpp b/jni-wrappers/privmx-endpoint/src/cpp/modules/StreamApi.cpp new file mode 100644 index 00000000..6cc1fbce --- /dev/null +++ b/jni-wrappers/privmx-endpoint/src/cpp/modules/StreamApi.cpp @@ -0,0 +1,59 @@ +#include "StreamApi.h" + +stream::StreamApi *getStreamApi(JniContextUtils &ctx, jobject streamApiInstance) { + jclass cls = ctx->GetObjectClass(streamApiInstance); + jfieldID apiFID = ctx->GetFieldID(cls, "api", "Ljava/lang/Long;"); + jobject apiLong = ctx->GetObjectField(streamApiInstance, apiFID); + if (apiLong == nullptr) { + throw IllegalStateException("StreamApi cannot be used"); + } + return (stream::StreamApi *) ctx.getObject(apiLong).getLongValue(); +} + +extern "C" +JNIEXPORT jobject JNICALL +Java_com_simplito_java_privmx_1endpoint_modules_stream_StreamApi_init( + JNIEnv *env, + jobject thiz, + jobject connection, + jobject event_api +) { + JniContextUtils ctx(env); + jobject result; + ctx.callResultEndpointApi( + &result, + [&ctx, &env, &connection, &event_api]() { + auto connection_c = getConnection(env, connection); + auto event_api_c = getEventApi(ctx, event_api); + auto streamApi = stream::StreamApi::create(*connection_c, *event_api_c); + auto streamApi_ptr = new stream::StreamApi(); + *streamApi_ptr = streamApi; + return ctx.long2jLong((jlong) streamApi_ptr); + }); + if (ctx->ExceptionCheck()) { + return nullptr; + } + return result; +} + +extern "C" +JNIEXPORT void JNICALL +Java_com_simplito_java_privmx_1endpoint_modules_stream_StreamApi_deinit( + JNIEnv *env, + jobject thiz +) { + try { + JniContextUtils ctx(env); + //if null go to catch + auto api = getStreamApi(ctx, thiz); + delete api; + jclass cls = env->GetObjectClass(thiz); + jfieldID apiFID = env->GetFieldID(cls, "api", "Ljava/lang/Long;"); + env->SetObjectField(thiz, apiFID, (jobject) nullptr); + } catch (const IllegalStateException &e) { + env->ThrowNew( + env->FindClass("java/lang/IllegalStateException"), + e.what() + ); + } +} \ No newline at end of file diff --git a/jni-wrappers/privmx-endpoint/src/cpp/modules/StreamApi.h b/jni-wrappers/privmx-endpoint/src/cpp/modules/StreamApi.h new file mode 100644 index 00000000..cdded5cd --- /dev/null +++ b/jni-wrappers/privmx-endpoint/src/cpp/modules/StreamApi.h @@ -0,0 +1,14 @@ +#include +#include +#include "privmx/endpoint/wrapper/utils/utils.hpp" +#include "privmx/endpoint/wrapper/modules/Connection.h" +#include "privmx/endpoint/wrapper/modules/EventApi.h" + +using namespace privmx::endpoint; + +#ifndef PRIVMXENDPOINT_STREAMAPI_H +#define PRIVMXENDPOINT_STREAMAPI_H + +privmx::endpoint::stream::StreamApi *getStreamApi(JniContextUtils &ctx, jobject streamApiInstance); + +#endif //PRIVMXENDPOINT_STREAMAPI_H diff --git a/privmx-endpoint/src/main/cpp/modules/ThreadApi.cpp b/jni-wrappers/privmx-endpoint/src/cpp/modules/ThreadApi.cpp similarity index 97% rename from privmx-endpoint/src/main/cpp/modules/ThreadApi.cpp rename to jni-wrappers/privmx-endpoint/src/cpp/modules/ThreadApi.cpp index cb997690..fc3f5e1f 100644 --- a/privmx-endpoint/src/main/cpp/modules/ThreadApi.cpp +++ b/jni-wrappers/privmx-endpoint/src/cpp/modules/ThreadApi.cpp @@ -12,12 +12,12 @@ #include #include #include -#include "Connection.h" -#include "ThreadApi.h" -#include "../utils.hpp" -#include "../parser.h" -#include "../exceptions.h" -#include "Connection.h" +#include "privmx/endpoint/wrapper/modules/Connection.h" +#include "privmx/endpoint/wrapper/modules/ThreadApi.h" +#include "privmx/endpoint/wrapper/utils/utils.hpp" +#include "privmx/endpoint/wrapper/parsers/parser.h" +#include "privmx/endpoint/wrapper/utils/exceptions.h" +#include "privmx/endpoint/wrapper/modules/Connection.h" using namespace privmx::endpoint; @@ -499,6 +499,9 @@ Java_com_simplito_java_privmx_1endpoint_modules_thread_ThreadApi_subscribeFor( int length = ctx->GetArrayLength(subscription_queries_arr); for (int i = 0; i < length; i++) { jobject arrayElement = ctx->GetObjectArrayElement(subscription_queries_arr, i); + if (ctx.nullCheck(arrayElement, "Subscription queries list elements")) { + return (jobject) nullptr; + } subscription_queries_c.push_back(ctx.jString2string((jstring) arrayElement)); } diff --git a/privmx-endpoint/src/main/cpp/modules/UserVerifierInterfaceJNI.cpp b/jni-wrappers/privmx-endpoint/src/cpp/modules/UserVerifierInterfaceJNI.cpp similarity index 94% rename from privmx-endpoint/src/main/cpp/modules/UserVerifierInterfaceJNI.cpp rename to jni-wrappers/privmx-endpoint/src/cpp/modules/UserVerifierInterfaceJNI.cpp index f7d0a2c2..fd5746fe 100644 --- a/privmx-endpoint/src/main/cpp/modules/UserVerifierInterfaceJNI.cpp +++ b/jni-wrappers/privmx-endpoint/src/cpp/modules/UserVerifierInterfaceJNI.cpp @@ -9,10 +9,10 @@ // limitations under the License. // -#include "UserVerifierInterfaceJNI.h" -#include "../model_native_initializers.h" -#include "../utils.hpp" -#include "../jniUtils.h" +#include "privmx/endpoint/wrapper/modules/UserVerifierInterfaceJNI.h" +#include "privmx/endpoint/wrapper/parsers/model_native_initializers.h" +#include "privmx/endpoint/wrapper/utils/utils.hpp" +#include "privmx/endpoint/wrapper/utils/jniUtils.h" #include #include #include diff --git a/privmx-endpoint/src/main/cpp/modules/Utils.cpp b/jni-wrappers/privmx-endpoint/src/cpp/modules/Utils.cpp similarity index 99% rename from privmx-endpoint/src/main/cpp/modules/Utils.cpp rename to jni-wrappers/privmx-endpoint/src/cpp/modules/Utils.cpp index a0863ed2..85c64ad0 100644 --- a/privmx-endpoint/src/main/cpp/modules/Utils.cpp +++ b/jni-wrappers/privmx-endpoint/src/cpp/modules/Utils.cpp @@ -9,7 +9,7 @@ // limitations under the License. // -#include "../utils.hpp" +#include "privmx/endpoint/wrapper/utils/utils.hpp" #include #include diff --git a/privmx-endpoint/src/main/cpp/model_native_initializers.cpp b/jni-wrappers/privmx-endpoint/src/cpp/parsers/model_native_initializers.cpp similarity index 88% rename from privmx-endpoint/src/main/cpp/model_native_initializers.cpp rename to jni-wrappers/privmx-endpoint/src/cpp/parsers/model_native_initializers.cpp index 2577819f..ca9b762d 100644 --- a/privmx-endpoint/src/main/cpp/model_native_initializers.cpp +++ b/jni-wrappers/privmx-endpoint/src/cpp/parsers/model_native_initializers.cpp @@ -9,7 +9,7 @@ // limitations under the License. // -#include "model_native_initializers.h" +#include "privmx/endpoint/wrapper/parsers/model_native_initializers.h" namespace privmx { namespace wrapper { @@ -194,8 +194,8 @@ namespace privmx { collectionItemChangeCls, "", "(" - "Ljava/lang/String;Ljava/lang/String;" // itemId - "Ljava/lang/String;Ljava/lang/String;" // action + "Ljava/lang/String;" // itemId + "Ljava/lang/String;" // action ")V" ); return ctx->NewObject( @@ -374,7 +374,7 @@ namespace privmx { jobject bridgeIdentity = nullptr; if (verificationRequest_c.bridgeIdentity.has_value()) { bridgeIdentity = bridgeIdentity2Java(ctx, - verificationRequest_c.bridgeIdentity.value()); + verificationRequest_c.bridgeIdentity.value()); } return ctx->NewObject( @@ -416,7 +416,7 @@ namespace privmx { ); jbyteArray entropy = ctx->NewByteArray(BIP39_c.entropy.size()); ctx->SetByteArrayRegion(entropy, 0, BIP39_c.entropy.size(), - (jbyte *) BIP39_c.entropy.data()); + (jbyte *) BIP39_c.entropy.data()); return ctx->NewObject( BIP39Cls, @@ -472,18 +472,18 @@ namespace privmx { jbyteArray publicMeta = ctx->NewByteArray(thread_c.publicMeta.size()); jbyteArray privateMeta = ctx->NewByteArray(thread_c.privateMeta.size()); ctx->SetByteArrayRegion(publicMeta, 0, thread_c.publicMeta.size(), - (jbyte *) thread_c.publicMeta.data()); + (jbyte *) thread_c.publicMeta.data()); ctx->SetByteArrayRegion(privateMeta, 0, thread_c.privateMeta.size(), - (jbyte *) thread_c.privateMeta.data()); + (jbyte *) thread_c.privateMeta.data()); for (auto &user: thread_c.users) { ctx->CallBooleanMethod(users, - addToArrayMID, - ctx->NewStringUTF(user.c_str())); + addToArrayMID, + ctx->NewStringUTF(user.c_str())); } for (auto &manager: thread_c.managers) { ctx->CallBooleanMethod(managers, - addToArrayMID, - ctx->NewStringUTF(manager.c_str())); + addToArrayMID, + ctx->NewStringUTF(manager.c_str())); } return ctx->NewObject( threadCls, @@ -509,7 +509,7 @@ namespace privmx { //Messages jobject serverMessageInfo2Java(JniContextUtils &ctx, - privmx::endpoint::thread::ServerMessageInfo serverMessageInfo_c) { + privmx::endpoint::thread::ServerMessageInfo serverMessageInfo_c) { jclass messageCls = ctx->FindClass( "com/simplito/java/privmx_endpoint/model/ServerMessageInfo"); jmethodID initMessageMID = ctx->GetMethodID( @@ -547,13 +547,13 @@ namespace privmx { jbyteArray privateMeta = ctx->NewByteArray(message_c.privateMeta.size()); jbyteArray data = ctx->NewByteArray(message_c.data.size()); ctx->SetByteArrayRegion(publicMeta, 0, message_c.publicMeta.size(), - (jbyte *) message_c.publicMeta.data()); + (jbyte *) message_c.publicMeta.data()); ctx->SetByteArrayRegion(privateMeta, 0, message_c.privateMeta.size(), - (jbyte *) message_c.privateMeta.data()); + (jbyte *) message_c.privateMeta.data()); ctx->SetByteArrayRegion(data, 0, message_c.data.size(), - (jbyte *) message_c.data.data()); + (jbyte *) message_c.data.data()); return ctx->NewObject( messageCls, @@ -611,18 +611,18 @@ namespace privmx { jbyteArray publicMeta = ctx->NewByteArray(store_c.publicMeta.size()); jbyteArray privateMeta = ctx->NewByteArray(store_c.privateMeta.size()); ctx->SetByteArrayRegion(publicMeta, 0, store_c.publicMeta.size(), - (jbyte *) store_c.publicMeta.data()); + (jbyte *) store_c.publicMeta.data()); ctx->SetByteArrayRegion(privateMeta, 0, store_c.privateMeta.size(), - (jbyte *) store_c.privateMeta.data()); + (jbyte *) store_c.privateMeta.data()); for (auto &user: store_c.users) { ctx->CallBooleanMethod(users, - addToArrayMID, - ctx->NewStringUTF(user.c_str())); + addToArrayMID, + ctx->NewStringUTF(user.c_str())); } for (auto &manager: store_c.managers) { ctx->CallBooleanMethod(managers, - addToArrayMID, - ctx->NewStringUTF(manager.c_str())); + addToArrayMID, + ctx->NewStringUTF(manager.c_str())); } return ctx->NewObject( @@ -687,18 +687,18 @@ namespace privmx { jbyteArray publicMeta = ctx->NewByteArray(inbox_c.publicMeta.size()); jbyteArray privateMeta = ctx->NewByteArray(inbox_c.privateMeta.size()); ctx->SetByteArrayRegion(publicMeta, 0, inbox_c.publicMeta.size(), - (jbyte *) inbox_c.publicMeta.data()); + (jbyte *) inbox_c.publicMeta.data()); ctx->SetByteArrayRegion(privateMeta, 0, inbox_c.privateMeta.size(), - (jbyte *) inbox_c.privateMeta.data()); + (jbyte *) inbox_c.privateMeta.data()); for (auto &user: inbox_c.users) { ctx->CallBooleanMethod(users, - addToArrayMID, - ctx->NewStringUTF(user.c_str())); + addToArrayMID, + ctx->NewStringUTF(user.c_str())); } for (auto &manager: inbox_c.managers) { ctx->CallBooleanMethod(managers, - addToArrayMID, - ctx->NewStringUTF(manager.c_str())); + addToArrayMID, + ctx->NewStringUTF(manager.c_str())); } jobject filesConfig = nullptr; @@ -757,12 +757,12 @@ namespace privmx { ); jbyteArray data = ctx->NewByteArray(inboxEntry_c.data.size()); ctx->SetByteArrayRegion(data, 0, inboxEntry_c.data.size(), - (jbyte *) inboxEntry_c.data.data()); + (jbyte *) inboxEntry_c.data.data()); jobject files = ctx->NewObject(arrayCls, initArrayMID); for (auto &file: inboxEntry_c.files) { ctx->CallBooleanMethod(files, - addToArrayMID, - file2Java(ctx, file)); + addToArrayMID, + file2Java(ctx, file)); } return ctx->NewObject( inboxEntryCls, @@ -779,7 +779,7 @@ namespace privmx { } jobject inboxPublicView2Java(JniContextUtils &ctx, - privmx::endpoint::inbox::InboxPublicView inboxPublicView_c) { + privmx::endpoint::inbox::InboxPublicView inboxPublicView_c) { jclass inboxPublicViewCls = ctx->FindClass( "com/simplito/java/privmx_endpoint/model/InboxPublicView"); jmethodID initInboxPublicViewMID = ctx->GetMethodID( @@ -793,7 +793,7 @@ namespace privmx { ); jbyteArray publicMeta = ctx->NewByteArray(inboxPublicView_c.publicMeta.size()); ctx->SetByteArrayRegion(publicMeta, 0, inboxPublicView_c.publicMeta.size(), - (jbyte *) inboxPublicView_c.publicMeta.data()); + (jbyte *) inboxPublicView_c.publicMeta.data()); return ctx->NewObject( inboxPublicViewCls, initInboxPublicViewMID, @@ -829,7 +829,7 @@ namespace privmx { //Files jobject serverFileInfo2Java(JniContextUtils &ctx, - privmx::endpoint::store::ServerFileInfo serverFileInfo_c) { + privmx::endpoint::store::ServerFileInfo serverFileInfo_c) { jclass serverFileInfoCls = ctx->FindClass( "com/simplito/java/privmx_endpoint/model/ServerFileInfo"); jmethodID initServerFileInfoMID = ctx->GetMethodID( @@ -868,10 +868,10 @@ namespace privmx { jbyteArray publicMeta = ctx->NewByteArray(file_c.publicMeta.size()); jbyteArray privateMeta = ctx->NewByteArray(file_c.privateMeta.size()); ctx->SetByteArrayRegion(publicMeta, 0, file_c.publicMeta.size(), - (jbyte *) file_c.publicMeta.data()); + (jbyte *) file_c.publicMeta.data()); ctx->SetByteArrayRegion(privateMeta, 0, file_c.privateMeta.size(), - (jbyte *) file_c.privateMeta.data()); + (jbyte *) file_c.privateMeta.data()); return ctx->NewObject( fileCls, @@ -918,9 +918,9 @@ namespace privmx { } //Event - jobject contextUsersStatusChangeData2Java( + jobject contextUsersStatusChangedEventData2Java( JniContextUtils &ctx, - privmx::endpoint::core::ContextUsersStatusChangeData contextUsersStatusChangeData_c + privmx::endpoint::core::ContextUsersStatusChangedEventData contextUsersStatusChangedEventData_c ) { jclass arrayCls = ctx->FindClass("java/util/ArrayList"); jmethodID initArrayMID = ctx->GetMethodID( @@ -932,10 +932,10 @@ namespace privmx { "add", "(Ljava/lang/Object;)Z" ); - jclass contextUsersStatusChangeDataCls = ctx->FindClass( + jclass ContextUsersStatusChangedEventDataCls = ctx->FindClass( "com/simplito/java/privmx_endpoint/model/events/ContextUsersStatusChangedEventData"); - jmethodID initContextUsersStatusChangeDataMID = ctx->GetMethodID( - contextUsersStatusChangeDataCls, + jmethodID initContextUsersStatusChangedEventDataMID = ctx->GetMethodID( + ContextUsersStatusChangedEventDataCls, "", "(" "Ljava/lang/String;" // contextId @@ -945,7 +945,7 @@ namespace privmx { jobject users = ctx->NewObject(arrayCls, initArrayMID); - for (auto &user: contextUsersStatusChangeData_c.users) { + for (auto &user: contextUsersStatusChangedEventData_c.users) { ctx->CallBooleanMethod(users, addToArrayMID, userWithAction2Java(ctx, user) @@ -953,9 +953,9 @@ namespace privmx { } return ctx->NewObject( - contextUsersStatusChangeDataCls, - initContextUsersStatusChangeDataMID, - ctx->NewStringUTF(contextUsersStatusChangeData_c.contextId.c_str()), + ContextUsersStatusChangedEventDataCls, + initContextUsersStatusChangedEventDataMID, + ctx->NewStringUTF(contextUsersStatusChangedEventData_c.contextId.c_str()), users ); } @@ -1031,7 +1031,7 @@ namespace privmx { } jobject storeFileDeletedEventData2Java(JniContextUtils &ctx, - privmx::endpoint::store::StoreFileDeletedEventData storeFileDeletedEventData_c) { + privmx::endpoint::store::StoreFileDeletedEventData storeFileDeletedEventData_c) { jclass storeFileDeletedEventDataCls = ctx->FindClass( "com/simplito/java/privmx_endpoint/model/events/StoreFileDeletedEventData"); jmethodID initStoreFileDeletedEventDataMID = ctx->GetMethodID( @@ -1049,7 +1049,7 @@ namespace privmx { } jobject storeStatsChangedEventData2Java(JniContextUtils &ctx, - privmx::endpoint::store::StoreStatsChangedEventData storeStatsChangedEventData_c) { + privmx::endpoint::store::StoreStatsChangedEventData storeStatsChangedEventData_c) { jclass storeStatsChangedEventDataCls = ctx->FindClass( "com/simplito/java/privmx_endpoint/model/events/StoreStatsChangedEventData"); jmethodID initStoreStatsChangedEventDataMID = ctx->GetMethodID( @@ -1068,7 +1068,7 @@ namespace privmx { } jobject threadDeletedEventData2Java(JniContextUtils &ctx, - privmx::endpoint::thread::ThreadDeletedEventData threadDeletedEventData_c) { + privmx::endpoint::thread::ThreadDeletedEventData threadDeletedEventData_c) { jclass threadDeletedEventDataCls = ctx->FindClass( "com/simplito/java/privmx_endpoint/model/events/ThreadDeletedEventData"); jmethodID initThreadDeletedEventDataMID = ctx->GetMethodID( @@ -1084,7 +1084,7 @@ namespace privmx { } jobject threadDeletedMessageEventData2Java(JniContextUtils &ctx, - privmx::endpoint::thread::ThreadDeletedMessageEventData threadDeletedMessageEventData) { + privmx::endpoint::thread::ThreadDeletedMessageEventData threadDeletedMessageEventData) { jclass threadDeletedMessageEventDataCls = ctx->FindClass( "com/simplito/java/privmx_endpoint/model/events/ThreadDeletedMessageEventData"); jmethodID initThreadDeletedMessageEventDataMID = ctx->GetMethodID( @@ -1101,7 +1101,7 @@ namespace privmx { } jobject storeDeletedEventData2Java(JniContextUtils &ctx, - privmx::endpoint::store::StoreDeletedEventData storeDeletedEventData_c) { + privmx::endpoint::store::StoreDeletedEventData storeDeletedEventData_c) { jclass storeDeletedEventDataCls = ctx->FindClass( "com/simplito/java/privmx_endpoint/model/events/StoreDeletedEventData"); jmethodID initStoreDeletedEventDataMID = ctx->GetMethodID( @@ -1228,21 +1228,90 @@ namespace privmx { "Ljava/lang/Long;" // schemaVersion ")V" ); - jbyteArray payload = ctx->NewByteArray(contextCustomEvent_c.payload.size()); - ctx->SetByteArrayRegion(payload, 0, contextCustomEvent_c.payload.size(), - (jbyte *) contextCustomEvent_c.payload.data()); + jbyteArray payload = ctx->NewByteArray(contextCustomEventData_c.payload.size()); + ctx->SetByteArrayRegion(payload, 0, contextCustomEventData_c.payload.size(), + (jbyte *) contextCustomEventData_c.payload.data()); return ctx->NewObject( contextCustomEventDataCls, initContextCustomEventDataMID, - ctx->NewStringUTF(contextCustomEvent_c.contextId.c_str()), - ctx->NewStringUTF(contextCustomEvent_c.userId.c_str()), + ctx->NewStringUTF(contextCustomEventData_c.contextId.c_str()), + ctx->NewStringUTF(contextCustomEventData_c.userId.c_str()), payload, - ctx.long2jLong(contextCustomEvent_c.statusCode), - ctx.long2jLong(contextCustomEvent_c.schemaVersion) + ctx.long2jLong(contextCustomEventData_c.statusCode), + ctx.long2jLong(contextCustomEventData_c.schemaVersion) ); } + jobject kvdbDeletedEventData2Java( + JniContextUtils &ctx, + privmx::endpoint::kvdb::KvdbDeletedEventData kvdbDeletedEventData_c + ) { + jclass kvdbDeletedEventDataCls = ctx->FindClass( + "com/simplito/java/privmx_endpoint/model/events/KvdbDeletedEventData"); + jmethodID initKvdbDeletedEventDataMID = ctx->GetMethodID( + kvdbDeletedEventDataCls, + "", + "(" + "Ljava/lang/String;" // kvdbId + ")V" + ); + + return ctx->NewObject( + kvdbDeletedEventDataCls, + initKvdbDeletedEventDataMID, + ctx->NewStringUTF(kvdbDeletedEventData_c.kvdbId.c_str()) + ); + } + + jobject kvdbStatsEventData2Java( + JniContextUtils &ctx, + privmx::endpoint::kvdb::KvdbStatsEventData kvdbStatsEventData_c + ) { + jclass kvdbStatsEventDataCls = ctx->FindClass( + "com/simplito/java/privmx_endpoint/model/events/KvdbStatsEventData"); + jmethodID initKvdbStatsEventDataMID = ctx->GetMethodID( + kvdbStatsEventDataCls, + "", + "(" + "Ljava/lang/String;" // kvdbId + "Ljava/lang/Long;" // lastEntryDate + "Ljava/lang/Long;" // entries + ")V" + ); + + return ctx->NewObject( + kvdbStatsEventDataCls, + initKvdbStatsEventDataMID, + ctx->NewStringUTF(kvdbStatsEventData_c.kvdbId.c_str()), + ctx.long2jLong(kvdbStatsEventData_c.lastEntryDate), + ctx.long2jLong(kvdbStatsEventData_c.entries) + ); + } + + jobject kvdbDeletedEntryEventData2Java( + JniContextUtils &ctx, + privmx::endpoint::kvdb::KvdbDeletedEntryEventData kvdbDeletedEntryEventData_c + ) { + jclass kvdbDeletedEntryEventDataCls = ctx->FindClass( + "com/simplito/java/privmx_endpoint/model/events/KvdbDeletedEntryEventData"); + jmethodID initKvdbDeletedEntryEventDataMID = ctx->GetMethodID( + kvdbDeletedEntryEventDataCls, + "", + "(" + "Ljava/lang/String;" // kvdbId + "Ljava/lang/String;" // kvdbEntryKey + ")V" + ); + + return ctx->NewObject( + kvdbDeletedEntryEventDataCls, + initKvdbDeletedEntryEventDataMID, + ctx->NewStringUTF(kvdbDeletedEntryEventData_c.kvdbId.c_str()), + ctx->NewStringUTF(kvdbDeletedEntryEventData_c.kvdbEntryKey.c_str()) + ); + } + //Kvdb jobject kvdb2Java( JniContextUtils &ctx, @@ -1287,18 +1356,18 @@ namespace privmx { jbyteArray publicMeta = ctx->NewByteArray(kvdb_c.publicMeta.size()); jbyteArray privateMeta = ctx->NewByteArray(kvdb_c.privateMeta.size()); ctx->SetByteArrayRegion(publicMeta, 0, kvdb_c.publicMeta.size(), - (jbyte *) kvdb_c.publicMeta.data()); + (jbyte *) kvdb_c.publicMeta.data()); ctx->SetByteArrayRegion(privateMeta, 0, kvdb_c.privateMeta.size(), - (jbyte *) kvdb_c.privateMeta.data()); + (jbyte *) kvdb_c.privateMeta.data()); for (auto &user: kvdb_c.users) { ctx->CallBooleanMethod(users, - addToArrayMID, - ctx->NewStringUTF(user.c_str())); + addToArrayMID, + ctx->NewStringUTF(user.c_str())); } for (auto &manager: kvdb_c.managers) { ctx->CallBooleanMethod(managers, - addToArrayMID, - ctx->NewStringUTF(manager.c_str())); + addToArrayMID, + ctx->NewStringUTF(manager.c_str())); } return ctx->NewObject( @@ -1374,11 +1443,11 @@ namespace privmx { jbyteArray data = ctx->NewByteArray(kvdbEntry_c.data.size()); ctx->SetByteArrayRegion(publicMeta, 0, kvdbEntry_c.publicMeta.size(), - (jbyte *) kvdbEntry_c.publicMeta.data()); + (jbyte *) kvdbEntry_c.publicMeta.data()); ctx->SetByteArrayRegion(privateMeta, 0, kvdbEntry_c.privateMeta.size(), - (jbyte *) kvdbEntry_c.privateMeta.data()); + (jbyte *) kvdbEntry_c.privateMeta.data()); ctx->SetByteArrayRegion(data, 0, kvdbEntry_c.data.size(), - (jbyte *) kvdbEntry_c.data.data()); + (jbyte *) kvdbEntry_c.data.data()); return ctx->NewObject( itemCls, diff --git a/privmx-endpoint/src/main/cpp/parser.cpp b/jni-wrappers/privmx-endpoint/src/cpp/parsers/parser.cpp similarity index 81% rename from privmx-endpoint/src/main/cpp/parser.cpp rename to jni-wrappers/privmx-endpoint/src/cpp/parsers/parser.cpp index 94075eac..d9820766 100644 --- a/privmx-endpoint/src/main/cpp/parser.cpp +++ b/jni-wrappers/privmx-endpoint/src/cpp/parsers/parser.cpp @@ -9,7 +9,7 @@ // limitations under the License. // -#include "parser.h" +#include "privmx/endpoint/wrapper/parsers/parser.h" using namespace privmx::endpoint; @@ -197,7 +197,7 @@ privmx::endpoint::inbox::FilesConfig parseFilesConfig(JniContextUtils &ctx, jobj } jobject initEvent(JniContextUtils &ctx, std::string type, std::string channel, int64_t connectionId, - std::vector &subscriptions, jobject data_j) { + std::vector &subscriptions, int64_t timestamp, jobject data_j) { if (type.empty()) return nullptr; jclass eventCls = ctx->FindClass("com/simplito/java/privmx_endpoint/model/Event"); jmethodID eventInitMID = ctx->GetMethodID(eventCls, "", "()V"); @@ -209,6 +209,8 @@ jobject initEvent(JniContextUtils &ctx, std::string type, std::string channel, i jfieldID eventSubscriptionsFieldID = ctx->GetFieldID(eventCls, "subscriptions", "Ljava/util/List;"); + jfieldID eventTimestampFieldID = ctx->GetFieldID(eventCls, "timestamp", + "Ljava/lang/Long;"); jclass arrayListCls = ctx->FindClass("java/util/ArrayList"); jmethodID arrayListInit = ctx->GetMethodID(arrayListCls, "", "()V"); @@ -247,6 +249,11 @@ jobject initEvent(JniContextUtils &ctx, std::string type, std::string channel, i eventSubscriptionsFieldID, subscriptionsList ); + ctx->SetObjectField( + event_j, + eventTimestampFieldID, + ctx.long2jLong(timestamp) + ); return event_j; } @@ -263,6 +270,7 @@ parseEvent(JniContextUtils &ctx, std::shared_ptr event_cast.channel, event_cast.connectionId, event_cast.subscriptions, + event_cast.timestamp, privmx::wrapper::contextCustomEventData2Java(ctx, event_cast.data) ); } else if (core::Events::isCollectionChangedEvent(event)) { @@ -273,6 +281,8 @@ parseEvent(JniContextUtils &ctx, std::shared_ptr event_cast.type, event_cast.channel, event_cast.connectionId, + event_cast.subscriptions, + event_cast.timestamp, privmx::wrapper::collectionChangedEventData2Java(ctx, event_cast.data) ); } else if (core::Events::isContextUserAddedEvent(event)) { @@ -283,6 +293,8 @@ parseEvent(JniContextUtils &ctx, std::shared_ptr event_cast.type, event_cast.channel, event_cast.connectionId, + event_cast.subscriptions, + event_cast.timestamp, privmx::wrapper::contextUserEventData2Java(ctx, event_cast.data) ); } else if (core::Events::isContextUserRemovedEvent(event)) { @@ -293,17 +305,21 @@ parseEvent(JniContextUtils &ctx, std::shared_ptr event_cast.type, event_cast.channel, event_cast.connectionId, + event_cast.subscriptions, + event_cast.timestamp, privmx::wrapper::contextUserEventData2Java(ctx, event_cast.data) ); - } else if (core::Events::isContextUsersStatusChangeEvent(event)) { - privmx::endpoint::core::ContextUsersStatusChangeEvent event_cast = core::Events::extractContextUsersStatusChangeEvent( + } else if (core::Events::isContextUsersStatusChangedEvent(event)) { + privmx::endpoint::core::ContextUsersStatusChangedEvent event_cast = core::Events::extractContextUsersStatusChangedEvent( event); return initEvent( ctx, event_cast.type, event_cast.channel, event_cast.connectionId, - privmx::wrapper::contextUsersStatusChangeData2Java(ctx, event_cast.data) + event_cast.subscriptions, + event_cast.timestamp, + privmx::wrapper::contextUsersStatusChangedEventData2Java(ctx, event_cast.data) ); } else if (thread::Events::isThreadCreatedEvent(event)) { privmx::endpoint::thread::ThreadCreatedEvent event_cast = thread::Events::extractThreadCreatedEvent( @@ -314,6 +330,7 @@ parseEvent(JniContextUtils &ctx, std::shared_ptr event_cast.channel, event_cast.connectionId, event_cast.subscriptions, + event_cast.timestamp, privmx::wrapper::thread2Java(ctx, event_cast.data) ); } else if (thread::Events::isThreadUpdatedEvent(event)) { @@ -325,6 +342,7 @@ parseEvent(JniContextUtils &ctx, std::shared_ptr event_cast.channel, event_cast.connectionId, event_cast.subscriptions, + event_cast.timestamp, privmx::wrapper::thread2Java(ctx, event_cast.data) ); } else if (thread::Events::isThreadStatsEvent(event)) { @@ -336,6 +354,7 @@ parseEvent(JniContextUtils &ctx, std::shared_ptr event_cast.channel, event_cast.connectionId, event_cast.subscriptions, + event_cast.timestamp, privmx::wrapper::threadStatsEventData2Java(ctx, event_cast.data) ); } else if (thread::Events::isThreadDeletedEvent(event)) { @@ -347,6 +366,7 @@ parseEvent(JniContextUtils &ctx, std::shared_ptr event_cast.channel, event_cast.connectionId, event_cast.subscriptions, + event_cast.timestamp, privmx::wrapper::threadDeletedEventData2Java(ctx, event_cast.data) ); } else if (thread::Events::isThreadNewMessageEvent(event)) { @@ -358,6 +378,7 @@ parseEvent(JniContextUtils &ctx, std::shared_ptr event_cast.channel, event_cast.connectionId, event_cast.subscriptions, + event_cast.timestamp, privmx::wrapper::message2Java(ctx, event_cast.data) ); return nullptr; @@ -370,6 +391,7 @@ parseEvent(JniContextUtils &ctx, std::shared_ptr event_cast.channel, event_cast.connectionId, event_cast.subscriptions, + event_cast.timestamp, privmx::wrapper::message2Java(ctx, event_cast.data) ); return nullptr; @@ -382,6 +404,7 @@ parseEvent(JniContextUtils &ctx, std::shared_ptr event_cast.channel, event_cast.connectionId, event_cast.subscriptions, + event_cast.timestamp, privmx::wrapper::threadDeletedMessageEventData2Java(ctx, event_cast.data) ); } else if (store::Events::isStoreCreatedEvent(event)) { @@ -393,6 +416,7 @@ parseEvent(JniContextUtils &ctx, std::shared_ptr event_cast.channel, event_cast.connectionId, event_cast.subscriptions, + event_cast.timestamp, privmx::wrapper::store2Java(ctx, event_cast.data) ); } else if (store::Events::isStoreUpdatedEvent(event)) { @@ -404,6 +428,7 @@ parseEvent(JniContextUtils &ctx, std::shared_ptr event_cast.channel, event_cast.connectionId, event_cast.subscriptions, + event_cast.timestamp, privmx::wrapper::store2Java(ctx, event_cast.data) ); } else if (store::Events::isStoreStatsChangedEvent(event)) { @@ -415,6 +440,7 @@ parseEvent(JniContextUtils &ctx, std::shared_ptr event_cast.channel, event_cast.connectionId, event_cast.subscriptions, + event_cast.timestamp, privmx::wrapper::storeStatsChangedEventData2Java(ctx, event_cast.data) ); } else if (store::Events::isStoreUpdatedEvent(event)) { @@ -426,6 +452,7 @@ parseEvent(JniContextUtils &ctx, std::shared_ptr event_cast.channel, event_cast.connectionId, event_cast.subscriptions, + event_cast.timestamp, privmx::wrapper::store2Java(ctx, event_cast.data) ); } else if (store::Events::isStoreDeletedEvent(event)) { @@ -437,6 +464,7 @@ parseEvent(JniContextUtils &ctx, std::shared_ptr event_cast.channel, event_cast.connectionId, event_cast.subscriptions, + event_cast.timestamp, privmx::wrapper::storeDeletedEventData2Java(ctx, event_cast.data) ); } else if (store::Events::isStoreFileCreatedEvent(event)) { @@ -448,6 +476,7 @@ parseEvent(JniContextUtils &ctx, std::shared_ptr event_cast.channel, event_cast.connectionId, event_cast.subscriptions, + event_cast.timestamp, privmx::wrapper::file2Java(ctx, event_cast.data) ); } else if (store::Events::isStoreFileUpdatedEvent(event)) { @@ -459,6 +488,7 @@ parseEvent(JniContextUtils &ctx, std::shared_ptr event_cast.channel, event_cast.connectionId, event_cast.subscriptions, + event_cast.timestamp, privmx::wrapper::storeFileUpdatedEventData2Java(ctx, event_cast.data) ); } else if (store::Events::isStoreFileDeletedEvent(event)) { @@ -470,6 +500,7 @@ parseEvent(JniContextUtils &ctx, std::shared_ptr event_cast.channel, event_cast.connectionId, event_cast.subscriptions, + event_cast.timestamp, privmx::wrapper::storeFileDeletedEventData2Java(ctx, event_cast.data) ); } else if (inbox::Events::isInboxCreatedEvent(event)) { @@ -481,6 +512,7 @@ parseEvent(JniContextUtils &ctx, std::shared_ptr event_cast.channel, event_cast.connectionId, event_cast.subscriptions, + event_cast.timestamp, privmx::wrapper::inbox2Java(ctx, event_cast.data) ); } else if (inbox::Events::isInboxUpdatedEvent(event)) { @@ -492,6 +524,7 @@ parseEvent(JniContextUtils &ctx, std::shared_ptr event_cast.channel, event_cast.connectionId, event_cast.subscriptions, + event_cast.timestamp, privmx::wrapper::inbox2Java(ctx, event_cast.data) ); } else if (inbox::Events::isInboxDeletedEvent(event)) { @@ -503,6 +536,7 @@ parseEvent(JniContextUtils &ctx, std::shared_ptr event_cast.channel, event_cast.connectionId, event_cast.subscriptions, + event_cast.timestamp, privmx::wrapper::inboxDeletedEventData2Java(ctx, event_cast.data) ); } else if (inbox::Events::isInboxEntryCreatedEvent(event)) { @@ -514,6 +548,7 @@ parseEvent(JniContextUtils &ctx, std::shared_ptr event_cast.channel, event_cast.connectionId, event_cast.subscriptions, + event_cast.timestamp, privmx::wrapper::inboxEntry2Java(ctx, event_cast.data) ); } else if (inbox::Events::isInboxEntryDeletedEvent(event)) { @@ -525,8 +560,93 @@ parseEvent(JniContextUtils &ctx, std::shared_ptr event_cast.channel, event_cast.connectionId, event_cast.subscriptions, + event_cast.timestamp, privmx::wrapper::inboxEntryDeletedEventData2Java(ctx, event_cast.data) ); + } else if (kvdb::Events::isKvdbCreatedEvent(event)) { + privmx::endpoint::kvdb::KvdbCreatedEvent event_cast = kvdb::Events::extractKvdbCreatedEvent( + event); + return initEvent( + ctx, + event_cast.type, + event_cast.channel, + event_cast.connectionId, + event_cast.subscriptions, + event_cast.timestamp, + privmx::wrapper::kvdb2Java(ctx, event_cast.data) + ); + } else if (kvdb::Events::isKvdbDeletedEvent(event)) { + privmx::endpoint::kvdb::KvdbDeletedEvent event_cast = kvdb::Events::extractKvdbDeletedEvent( + event); + return initEvent( + ctx, + event_cast.type, + event_cast.channel, + event_cast.connectionId, + event_cast.subscriptions, + event_cast.timestamp, + privmx::wrapper::kvdbDeletedEventData2Java(ctx, event_cast.data) + ); + } else if (kvdb::Events::isKvdbUpdatedEvent(event)) { + privmx::endpoint::kvdb::KvdbUpdatedEvent event_cast = kvdb::Events::extractKvdbUpdatedEvent( + event); + return initEvent( + ctx, + event_cast.type, + event_cast.channel, + event_cast.connectionId, + event_cast.subscriptions, + event_cast.timestamp, + privmx::wrapper::kvdb2Java(ctx, event_cast.data) + ); + } else if (kvdb::Events::isKvdbStatsEvent(event)) { + privmx::endpoint::kvdb::KvdbStatsChangedEvent event_cast = kvdb::Events::extractKvdbStatsEvent( + event); + return initEvent( + ctx, + event_cast.type, + event_cast.channel, + event_cast.connectionId, + event_cast.subscriptions, + event_cast.timestamp, + privmx::wrapper::kvdbStatsEventData2Java(ctx, event_cast.data) + ); + }else if (kvdb::Events::isKvdbNewEntryEvent(event)) { + privmx::endpoint::kvdb::KvdbNewEntryEvent event_cast = kvdb::Events::extractKvdbNewEntryEvent( + event); + return initEvent( + ctx, + event_cast.type, + event_cast.channel, + event_cast.connectionId, + event_cast.subscriptions, + event_cast.timestamp, + privmx::wrapper::kvdbEntry2Java(ctx, event_cast.data) + ); + } else if (kvdb::Events::isKvdbEntryUpdatedEvent(event)) { + privmx::endpoint::kvdb::KvdbEntryUpdatedEvent event_cast = kvdb::Events::extractKvdbEntryUpdatedEvent( + event); + return initEvent( + ctx, + event_cast.type, + event_cast.channel, + event_cast.connectionId, + event_cast.subscriptions, + event_cast.timestamp, + privmx::wrapper::kvdbEntry2Java(ctx, event_cast.data) + ); + } else if (kvdb::Events::isKvdbEntryDeletedEvent(event)) { + privmx::endpoint::kvdb::KvdbEntryDeletedEvent event_cast = kvdb::Events::extractKvdbEntryDeletedEvent( + event); + return initEvent( + ctx, + event_cast.type, + event_cast.channel, + event_cast.connectionId, + event_cast.subscriptions, + event_cast.timestamp, + privmx::wrapper::kvdbDeletedEntryEventData2Java(ctx, event_cast.data) + ); } else { return initEvent( ctx, @@ -534,6 +654,7 @@ parseEvent(JniContextUtils &ctx, std::shared_ptr event->channel, event->connectionId, event->subscriptions, + event->timestamp, nullptr ); } diff --git a/privmx-endpoint/src/main/cpp/exceptions.cpp b/jni-wrappers/privmx-endpoint/src/cpp/utils/exceptions.cpp similarity index 90% rename from privmx-endpoint/src/main/cpp/exceptions.cpp rename to jni-wrappers/privmx-endpoint/src/cpp/utils/exceptions.cpp index ad75e411..d47a4d83 100644 --- a/privmx-endpoint/src/main/cpp/exceptions.cpp +++ b/jni-wrappers/privmx-endpoint/src/cpp/utils/exceptions.cpp @@ -9,7 +9,7 @@ // limitations under the License. // -#include "exceptions.h" +#include "privmx/endpoint/wrapper/utils/exceptions.h" IllegalStateException::IllegalStateException(const char *message) { this->message = message; diff --git a/privmx-endpoint/src/main/cpp/jniUtils.cpp b/jni-wrappers/privmx-endpoint/src/cpp/utils/jniUtils.cpp similarity index 97% rename from privmx-endpoint/src/main/cpp/jniUtils.cpp rename to jni-wrappers/privmx-endpoint/src/cpp/utils/jniUtils.cpp index f42aea0d..0b9c0227 100644 --- a/privmx-endpoint/src/main/cpp/jniUtils.cpp +++ b/jni-wrappers/privmx-endpoint/src/cpp/utils/jniUtils.cpp @@ -9,7 +9,7 @@ // limitations under the License. // -#include "jniUtils.h" +#include "privmx/endpoint/wrapper/utils/jniUtils.h" namespace privmx { namespace wrapper { diff --git a/privmx-endpoint/src/main/cpp/utils.cpp b/jni-wrappers/privmx-endpoint/src/cpp/utils/utils.cpp similarity index 99% rename from privmx-endpoint/src/main/cpp/utils.cpp rename to jni-wrappers/privmx-endpoint/src/cpp/utils/utils.cpp index 166ecdf3..bdb10097 100644 --- a/privmx-endpoint/src/main/cpp/utils.cpp +++ b/jni-wrappers/privmx-endpoint/src/cpp/utils/utils.cpp @@ -9,7 +9,7 @@ // limitations under the License. // -#include "utils.hpp" +#include "privmx/endpoint/wrapper/utils/utils.hpp" void replace_all(std::string &input, const std::string &from, const std::string &to); diff --git a/jni-wrappers/privmx-libs/Android/arm64-v8a/include/.gitkeep b/jni-wrappers/privmx-libs/Android/arm64-v8a/include/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/jni-wrappers/privmx-libs/Android/arm64-v8a/lib/.gitkeep b/jni-wrappers/privmx-libs/Android/arm64-v8a/lib/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/jni-wrappers/privmx-libs/Android/armeabi-v7a/include/.gitkeep b/jni-wrappers/privmx-libs/Android/armeabi-v7a/include/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/jni-wrappers/privmx-libs/Android/armeabi-v7a/lib/.gitkeep b/jni-wrappers/privmx-libs/Android/armeabi-v7a/lib/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/jni-wrappers/privmx-libs/Android/x86/include/.gitkeep b/jni-wrappers/privmx-libs/Android/x86/include/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/jni-wrappers/privmx-libs/Android/x86/lib/.gitkeep b/jni-wrappers/privmx-libs/Android/x86/lib/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/jni-wrappers/privmx-libs/Android/x86_64/include/.gitkeep b/jni-wrappers/privmx-libs/Android/x86_64/include/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/jni-wrappers/privmx-libs/Android/x86_64/lib/.gitkeep b/jni-wrappers/privmx-libs/Android/x86_64/lib/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/jni-wrappers/privmx-libs/Darwin/arm64/include/.gitkeep b/jni-wrappers/privmx-libs/Darwin/arm64/include/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/jni-wrappers/privmx-libs/Darwin/arm64/lib/.gitkeep b/jni-wrappers/privmx-libs/Darwin/arm64/lib/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/privmx-endpoint-streams/android/build.gradle b/privmx-endpoint-streams/android/build.gradle new file mode 100644 index 00000000..8ef560df --- /dev/null +++ b/privmx-endpoint-streams/android/build.gradle @@ -0,0 +1,81 @@ +plugins { + alias(libs.plugins.androidLibrary) + id 'maven-publish' + id 'signing' +} + +//Apply script for generating official documentation +if (file("build-documentation.gradle").exists()) { + apply from: "build-documentation.gradle" +} + +//Apply script for publishing maven dependency +if (file("build-publish-maven.gradle").exists()) { + apply from: "build-publish-maven.gradle" +} + +version = '2.6.0-rc2' + +android { + namespace 'com.simplito.android.privmx_endpoint_streams' + compileSdk 34 + + defaultConfig { + minSdk 24 + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles "consumer-rules.pro" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + publishing { + singleVariant('release') { + withSourcesJar() + withJavadocJar() + } + } +} + +dependencies { + testImplementation libs.junit + androidTestImplementation libs.ext.junit + androidTestImplementation libs.espresso.core + implementation(project(":privmx-endpoint")) + implementation("com.simplito.webrtc:webrtc-android:1.0.0") +} + +sourceSets { + main { + java { + srcDirs = ["src/main/java"] + } + } +} +afterEvaluate { + sourceReleaseJar { + System.out.println("hello world") + filter(new Transformer() { + @Override + String transform(String s) { + if ( + s.trim().matches("\\* *@group.*") || + s.trim().matches("\\* *@folder.*") || + s.trim().matches("\\* *@category.*") + ) { + return null + } + return s + } + }) + } +} \ No newline at end of file diff --git a/privmx-endpoint-streams/build.gradle b/privmx-endpoint-streams/build.gradle new file mode 100644 index 00000000..e69de29b diff --git a/privmx-endpoint-streams/jvm/build.gradle b/privmx-endpoint-streams/jvm/build.gradle new file mode 100644 index 00000000..6e3a1711 --- /dev/null +++ b/privmx-endpoint-streams/jvm/build.gradle @@ -0,0 +1,10 @@ +plugins { + id 'java-library' + id 'signing' + id 'maven-publish' +} + + +dependencies { + implementation(project(":privmx-endpoint")) +} \ No newline at end of file diff --git a/privmx-endpoint/src/main/cpp/.gitignore b/privmx-endpoint/src/main/cpp/.gitignore deleted file mode 100644 index 19f2c158..00000000 --- a/privmx-endpoint/src/main/cpp/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -build -deployer/ -libs/ -.cxx -buildScript.sh -build.gradle \ No newline at end of file diff --git a/privmx-endpoint/src/main/cpp/CMakeLists.txt b/privmx-endpoint/src/main/cpp/CMakeLists.txt deleted file mode 100644 index fb8dc2e8..00000000 --- a/privmx-endpoint/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,130 +0,0 @@ -# For more information about using CMake with Android Studio, read the -# documentation: https://d.android.com/studio/projects/add-native-code.html. -# For more examples on how to use CMake, see https://github.com/android/ndk-samples. - -# Sets the minimum CMake version required for this project. -cmake_minimum_required(VERSION 3.22.1) - -# Declares the project name. The project name can be accessed via ${ PROJECT_NAME}, -# Since this is the top level CMakeLists.txt, the project name is also accessible -# with ${CMAKE_PROJECT_NAME} (both CMake variables are in-sync within the top level -# build script scope). -project("privmx-endpoint-java") - -set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -s") -set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s") - -if (NOT DEFINED CMAKE_DESTINATION_OS) - set(CMAKE_DESTINATION_OS ${CMAKE_SYSTEM_NAME}) -endif () - -if (NOT DEFINED CMAKE_DESTINATION_ARCHITECTURE) - if (CMAKE_DESTINATION_OS STREQUAL "Android" AND DEFINED CMAKE_ANDROID_ARCH_ABI) - set(CMAKE_DESTINATION_ARCHITECTURE ${CMAKE_ANDROID_ARCH_ABI}) - else () - set(CMAKE_DESTINATION_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR}) - endif () -endif () - -if ("${CMAKE_DESTINATION_OS}" STREQUAL "Darwin") - set(file_extension "dylib") - set(CMAKE_MACOSX_RPATH 1) - set(CMAKE_INSTALL_RPATH "@loader_path") -elseif ("${CMAKE_DESTINATION_OS}" STREQUAL "Windows") - set(file_extension "dll") -else () - set(file_extension "so") -endif () - -message(DEBUG "CMAKE DEST OS ${CMAKE_DESTINATION_OS}") -message(DEBUG "CMAKE DEST PROCESSOR ${CMAKE_DESTINATION_ARCHITECTURE}") - -add_library(ssl SHARED IMPORTED GLOBAL) -set_target_properties(ssl PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libssl.${file_extension}) - -add_library(crypto SHARED IMPORTED GLOBAL) -set_target_properties(crypto PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libcrypto.${file_extension}) - -add_library(gmp SHARED IMPORTED GLOBAL) -set_target_properties(gmp PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libgmp.${file_extension}) - -add_library(PocoFoundation SHARED IMPORTED GLOBAL) -set_target_properties(PocoFoundation PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libPocoFoundation.${file_extension}) - -add_library(PocoJSON SHARED IMPORTED GLOBAL) -set_target_properties(PocoJSON PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libPocoJSON.${file_extension}) - -add_library(PocoNet SHARED IMPORTED GLOBAL) -set_target_properties(PocoNet PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libPocoNet.${file_extension}) - -add_library(PocoCrypto SHARED IMPORTED GLOBAL) -set_target_properties(PocoCrypto PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libPocoCrypto.${file_extension}) - -add_library(PocoXML SHARED IMPORTED GLOBAL) -set_target_properties(PocoXML PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libPocoXML.${file_extension}) - -add_library(PocoNetSSL SHARED IMPORTED GLOBAL) -set_target_properties(PocoNetSSL PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libPocoNetSSL.${file_extension}) - -add_library(PocoUtil SHARED IMPORTED GLOBAL) -set_target_properties(PocoUtil PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libPocoUtil.${file_extension}) - -add_library(Pson SHARED IMPORTED GLOBAL) -set_target_properties(Pson PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libPson.${file_extension}) - -add_library(libprivmx SHARED IMPORTED GLOBAL) -set_target_properties(libprivmx PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libprivmx.${file_extension}) - -add_library(privmxendpointcore SHARED IMPORTED GLOBAL) -set_target_properties(privmxendpointcore PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libprivmxendpointcore.${file_extension}) - -add_library(privmxendpointcrypto SHARED IMPORTED GLOBAL) -set_target_properties(privmxendpointcrypto PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libprivmxendpointcrypto.${file_extension}) - -add_library(privmxendpointstore SHARED IMPORTED GLOBAL) -set_target_properties(privmxendpointstore PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libprivmxendpointstore.${file_extension}) - -add_library(privmxendpointthread SHARED IMPORTED GLOBAL) -set_target_properties(privmxendpointthread PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libprivmxendpointthread.${file_extension}) - -add_library(privmxendpointinbox SHARED IMPORTED GLOBAL) -set_target_properties(privmxendpointinbox PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libprivmxendpointinbox.${file_extension}) - -add_library(privmxendpointevent SHARED IMPORTED GLOBAL) -set_target_properties(privmxendpointevent PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libprivmxendpointevent.${file_extension}) - -add_library(privmxendpointkvdb SHARED IMPORTED GLOBAL) -set_target_properties(privmxendpointkvdb PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/${CMAKE_DESTINATION_OS}/${CMAKE_DESTINATION_ARCHITECTURE}/lib/libprivmxendpointkvdb.${file_extension}) - -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/libs/include ${JAVA_HOME}/include ${JAVA_HOME}/include/darwin) - -add_library(${CMAKE_PROJECT_NAME} SHARED - ${CMAKE_CURRENT_SOURCE_DIR}/parser.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/utils.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/jniUtils.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/model_native_initializers.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/modules/Connection.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/modules/CryptoApi.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/modules/ThreadApi.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/modules/StoreApi.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/modules/InboxApi.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/modules/EventQueue.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/exceptions.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/modules/BackendRequester.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/modules/EventApi.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/modules/UserVerifierInterfaceJNI.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/modules/ExtKey.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/modules/Utils.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/modules/KvdbApi.cpp -) - -# Android Debugging -#find_library( log-lib log ) -#target_link_libraries(${CMAKE_PROJECT_NAME} ${log-lib} ${log}) -target_link_libraries(${CMAKE_PROJECT_NAME} ssl crypto) -target_link_libraries(${CMAKE_PROJECT_NAME} gmp) -target_link_libraries(${CMAKE_PROJECT_NAME} PocoFoundation PocoXML PocoJSON PocoNet PocoNetSSL PocoUtil PocoCrypto) -target_link_libraries(${CMAKE_PROJECT_NAME} Pson libprivmx privmxendpointcore privmxendpointcrypto privmxendpointstore privmxendpointthread privmxendpointinbox privmxendpointevent privmxendpointkvdb) -message(DEBUG "Install to ${CMAKE_INSTALL_PREFIX}") -install(TARGETS ${CMAKE_PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}) -install(IMPORTED_RUNTIME_ARTIFACTS crypto ssl gmp PocoFoundation PocoXML PocoJSON PocoNet PocoNetSSL PocoUtil PocoCrypto Pson libprivmx privmxendpointcore privmxendpointcrypto privmxendpointstore privmxendpointthread privmxendpointinbox privmxendpointevent privmxendpointkvdb DESTINATION ${CMAKE_INSTALL_PREFIX}) \ No newline at end of file diff --git a/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/modules/stream/StreamApi.java b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/modules/stream/StreamApi.java new file mode 100644 index 00000000..6f7b512f --- /dev/null +++ b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/modules/stream/StreamApi.java @@ -0,0 +1,30 @@ +package com.simplito.java.privmx_endpoint.modules.stream; + +import com.simplito.java.privmx_endpoint.LibLoader; +import com.simplito.java.privmx_endpoint.modules.core.Connection; +import com.simplito.java.privmx_endpoint.modules.event.EventApi; + +import java.util.Objects; + +public class StreamApi implements AutoCloseable { + static { + LibLoader.loadPrivmxLibraries(); + } + @SuppressWarnings("FieldCanBeLocal") + private final Long api; + + private native Long init(Connection connection, EventApi eventApi) throws IllegalStateException; + + private native void deinit() throws IllegalStateException; + + public StreamApi(Connection connection, EventApi eventApi) throws IllegalStateException { + Objects.requireNonNull(connection); + Objects.requireNonNull(eventApi); + this.api = init(connection, eventApi); + } + + @Override + public void close() throws Exception { + deinit(); + } +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 92e34452..f1b6b225 100644 --- a/settings.gradle +++ b/settings.gradle @@ -27,6 +27,14 @@ rootProject.name = "PrivmxEndpoint" include ':privmx-endpoint' include ':privmx-endpoint-extra' include ':privmx-endpoint-android' -include ':privmx-endpoint-jni' + +//Jni implementation of modules +include ':jni-wrappers' + +//Streams modules +include ':privmx-endpoint-streams:jvm' +include ':privmx-endpoint-streams:android' + + +include ':examples:privmx-snippets' include ':examples:privmx-snippets' -project(':privmx-endpoint-jni').projectDir = file("privmx-endpoint/src/main/cpp") \ No newline at end of file