Update native classes

This commit is contained in:
Andrea Cavalli 2020-10-12 18:46:42 +02:00
parent c310fb7643
commit 74ce9b996f
4 changed files with 11 additions and 77 deletions

View File

@ -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

View File

@ -1,29 +0,0 @@
/*
* Copyright (c) 2018. Ernesto Castellotti <erny.castell@gmail.com>
* 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 <http://www.gnu.org/licenses/>.
*/
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);
}

View File

@ -1,35 +1,14 @@
package it.tdlight.jni;
/*
* Copyright (c) 2018. Ernesto Castellotti <erny.castell@gmail.com>
* 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 <http://www.gnu.org/licenses/>.
*/
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);
}

View File

@ -1,30 +1,15 @@
/*
* Copyright (c) 2018. Ernesto Castellotti <erny.castell@gmail.com>
* 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 <http://www.gnu.org/licenses/>.
*/
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<String> defaultFatalErrorCallbackPtr = System.err::println;
private static Consumer<String> 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<String> fatalErrorCallback) {
NativeLog.fatalErrorCallback = ObjectsUtils.requireNonNullElse(fatalErrorCallback, defaultFatalErrorCallbackPtr);
}
}