From 74ce9b996f8520d04214d3bd0f842935e5f2ae04 Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Mon, 12 Oct 2020 18:46:42 +0200 Subject: [PATCH] Update native classes --- src/main/jni-cpp-src/common/sources.txt | 1 - .../it/tdlight/jni/FatalErrorCallbackPtr.java | 29 ----------------- .../it/tdlight/jni/NativeClient.java | 31 +++---------------- .../it/tdlight/jni/NativeLog.java | 27 ++++------------ 4 files changed, 11 insertions(+), 77 deletions(-) delete mode 100644 src/main/jni-java-src/it/tdlight/jni/FatalErrorCallbackPtr.java diff --git a/src/main/jni-cpp-src/common/sources.txt b/src/main/jni-cpp-src/common/sources.txt index da4eadc..81417d6 100644 --- a/src/main/jni-cpp-src/common/sources.txt +++ b/src/main/jni-cpp-src/common/sources.txt @@ -1,5 +1,4 @@ ../src/main/jni-java-src/it/tdlight/jni/NativeClient.java ../src/main/jni-java-src/it/tdlight/jni/NativeLog.java ../src/main/jni-java-src/it/tdlight/jni/TdApi.java -../src/main/jni-java-src/it/tdlight/jni/FatalErrorCallbackPtr.java ../src/main/jni-java-src/it/tdlight/jni/ObjectsUtils.java diff --git a/src/main/jni-java-src/it/tdlight/jni/FatalErrorCallbackPtr.java b/src/main/jni-java-src/it/tdlight/jni/FatalErrorCallbackPtr.java deleted file mode 100644 index 5bf1e43..0000000 --- a/src/main/jni-java-src/it/tdlight/jni/FatalErrorCallbackPtr.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2018. Ernesto Castellotti - * This file is part of JTdlib. - * - * JTdlib is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License. - * - * JTdlib is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JTdlib. If not, see . - */ - -package it.tdlight.jni; - -/** - * A type of callback function that will be called when a fatal error happens. - */ -public interface FatalErrorCallbackPtr { - /** - * Send error message to callback. - * @param error_message String with a description of a happened fatal error. - */ - void onFatalError(String error_message); -} diff --git a/src/main/jni-java-src/it/tdlight/jni/NativeClient.java b/src/main/jni-java-src/it/tdlight/jni/NativeClient.java index cfee09b..e9b5ec8 100644 --- a/src/main/jni-java-src/it/tdlight/jni/NativeClient.java +++ b/src/main/jni-java-src/it/tdlight/jni/NativeClient.java @@ -1,35 +1,14 @@ package it.tdlight.jni; -/* - * Copyright (c) 2018. Ernesto Castellotti - * This file is part of JTdlib. - * - * JTdlib is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License. - * - * JTdlib is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JTdlib. If not, see . - */ - - - -import it.tdlight.jni.TdApi.Function; -import it.tdlight.jni.TdApi.Object; public class NativeClient { - private static native int createNativeClient(); + protected static native int createNativeClient(); - private static native void nativeClientSend(int nativeClientId, long eventId, TdApi.Function function); + protected static native void nativeClientSend(int nativeClientId, long eventId, TdApi.Function function); - private static native int nativeClientReceive(int[] clientIds, long[] eventIds, TdApi.Object[] events, double timeout); + protected static native int nativeClientReceive(int[] clientIds, long[] eventIds, TdApi.Object[] events, double timeout); - private static native int nativeClientReceive(int[] clientIds, long[] eventIds, TdApi.Object[] events, double timeout, boolean include_responses, boolean include_updates); + protected static native int nativeClientReceive(int[] clientIds, long[] eventIds, TdApi.Object[] events, double timeout, boolean include_responses, boolean include_updates); - private static native TdApi.Object nativeClientExecute(TdApi.Function function); + protected static native TdApi.Object nativeClientExecute(TdApi.Function function); } diff --git a/src/main/jni-java-src/it/tdlight/jni/NativeLog.java b/src/main/jni-java-src/it/tdlight/jni/NativeLog.java index 2a8b36f..eac5854 100644 --- a/src/main/jni-java-src/it/tdlight/jni/NativeLog.java +++ b/src/main/jni-java-src/it/tdlight/jni/NativeLog.java @@ -1,30 +1,15 @@ -/* - * Copyright (c) 2018. Ernesto Castellotti - * This file is part of JTdlib. - * - * JTdlib is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License. - * - * JTdlib is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JTdlib. If not, see . - */ - package it.tdlight.jni; +import java.util.function.Consumer; + /** * Class used for managing internal TDLib logging. * Use TdApi.*Log* methods instead. */ public class NativeLog { - private static final FatalErrorCallbackPtr defaultFatalErrorCallbackPtr = System.err::println; - private static FatalErrorCallbackPtr fatalErrorCallback = defaultFatalErrorCallbackPtr; + private static final Consumer defaultFatalErrorCallbackPtr = System.err::println; + private static Consumer fatalErrorCallback = defaultFatalErrorCallbackPtr; /** * Sets file path for writing TDLib internal log. By default TDLib writes logs to the System.err. @@ -72,14 +57,14 @@ public class NativeLog { * @param errorMessage Error message. */ private static synchronized void onFatalError(String errorMessage) { - new Thread(() -> NativeLog.fatalErrorCallback.onFatalError(errorMessage)).start(); + new Thread(() -> NativeLog.fatalErrorCallback.accept(errorMessage)).start(); } /** * Sets the callback that will be called when a fatal error happens. None of the TDLib methods can be called from the callback. The TDLib will crash as soon as callback returns. By default the callback set to print in stderr. * @param fatalErrorCallback Callback that will be called when a fatal error happens. Pass null to restore default callback. */ - public static synchronized void setFatalErrorCallback(FatalErrorCallbackPtr fatalErrorCallback) { + public static synchronized void setFatalErrorCallback(Consumer fatalErrorCallback) { NativeLog.fatalErrorCallback = ObjectsUtils.requireNonNullElse(fatalErrorCallback, defaultFatalErrorCallbackPtr); } }