Renamed project files
This commit is contained in:
parent
da891d4223
commit
034aaa46d9
11
pom.xml
11
pom.xml
@ -1,9 +1,9 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>it.ernytech</groupId>
|
<groupId>it.tdlight</groupId>
|
||||||
<artifactId>tdlib</artifactId>
|
<artifactId>tdlight-java</artifactId>
|
||||||
<version>2.168.0</version>
|
<version>2.168.0</version>
|
||||||
<name>JTDLib</name>
|
<name>TDLight Java Wrapper</name>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
@ -57,6 +57,11 @@
|
|||||||
<artifactId>common-utils</artifactId>
|
<artifactId>common-utils</artifactId>
|
||||||
<version>1.0.3</version>
|
<version>1.0.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>it.tdlight</groupId>
|
||||||
|
<artifactId>tdlight-natives-linux-amd64</artifactId>
|
||||||
|
<version>1.0.3</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
|
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package it.ernytech.tdlib.utils;
|
package it.tdlight.tdlight.utils;
|
||||||
public final class LibraryVersion {
|
public final class LibraryVersion {
|
||||||
public static final String VERSION = "${project.version}";
|
public static final String VERSION = "${project.version}";
|
||||||
}
|
}
|
@ -1,21 +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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* it.ernytech.tdbot is a group of class for to simplify the creation of bots or userbots.
|
|
||||||
*/
|
|
||||||
package it.ernytech.tdbot;
|
|
@ -1,172 +0,0 @@
|
|||||||
package it.ernytech.tdlib;
|
|
||||||
/*
|
|
||||||
* 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.ernytech.tdlib.utils.Init;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
|
||||||
import java.util.concurrent.locks.StampedLock;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface for interaction with TDLib.
|
|
||||||
*/
|
|
||||||
public class Client implements TelegramClient {
|
|
||||||
private long clientId;
|
|
||||||
private final ReentrantLock receiveLock = new ReentrantLock();
|
|
||||||
private final StampedLock executionLock = new StampedLock();
|
|
||||||
private volatile Long stampedLockValue = 1L;
|
|
||||||
private static native long createNativeClient();
|
|
||||||
private static native void nativeClientSend(long nativeClientId, long eventId, TdApi.Function function);
|
|
||||||
private static native int nativeClientReceive(long nativeClientId, long[] eventIds, TdApi.Object[] events, double timeout);
|
|
||||||
private static native TdApi.Object nativeClientExecute(TdApi.Function function);
|
|
||||||
private static native void destroyNativeClient(long nativeClientId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new TDLib client.
|
|
||||||
*/
|
|
||||||
public Client() {
|
|
||||||
try {
|
|
||||||
Init.start();
|
|
||||||
} catch (Throwable throwable) {
|
|
||||||
throwable.printStackTrace();
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
this.clientId = createNativeClient();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends request to TDLib. May be called from any thread.
|
|
||||||
* @param request Request to TDLib.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void send(Request request) {
|
|
||||||
if (this.executionLock.isWriteLocked()) {
|
|
||||||
throw new IllegalStateException("ClientActor is destroyed");
|
|
||||||
}
|
|
||||||
|
|
||||||
nativeClientSend(this.clientId, request.getId(), request.getFunction());
|
|
||||||
}
|
|
||||||
|
|
||||||
private long[] eventIds;
|
|
||||||
private TdApi.Object[] events;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Receives incoming updates and request responses from TDLib. May be called from any thread, but shouldn't be called simultaneously from two different threads.
|
|
||||||
* @param timeout Maximum number of seconds allowed for this function to wait for new records.
|
|
||||||
* @param eventSize Maximum number of events allowed in list.
|
|
||||||
* @return An incoming update or request response list. The object returned in the response may be an empty list if the timeout expires.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public List<Response> receive(double timeout, int eventSize) {
|
|
||||||
if (this.executionLock.isWriteLocked()) {
|
|
||||||
throw new IllegalStateException("ClientActor is destroyed");
|
|
||||||
}
|
|
||||||
|
|
||||||
var responseList = new ArrayList<Response>();
|
|
||||||
if (eventIds == null) {
|
|
||||||
eventIds = new long[eventSize];
|
|
||||||
events = new TdApi.Object[eventSize];
|
|
||||||
} else if (eventIds.length != eventSize) {
|
|
||||||
throw new IllegalArgumentException("EventSize can't change! Previous value = " + eventIds.length + " New value = " + eventSize);
|
|
||||||
} else {
|
|
||||||
Arrays.fill(eventIds, 0);
|
|
||||||
Arrays.fill(events, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.receiveLock.isLocked()) {
|
|
||||||
throw new IllegalThreadStateException("Thread: " + Thread.currentThread().getName() + " trying receive incoming updates but shouldn't be called simultaneously from two different threads!");
|
|
||||||
}
|
|
||||||
|
|
||||||
int resultSize;
|
|
||||||
this.receiveLock.lock();
|
|
||||||
try {
|
|
||||||
resultSize = nativeClientReceive(this.clientId, eventIds, events, timeout);
|
|
||||||
} finally {
|
|
||||||
this.receiveLock.unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < resultSize; i++) {
|
|
||||||
responseList.add(new Response(eventIds[i], events[i]));
|
|
||||||
}
|
|
||||||
|
|
||||||
return responseList;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Receives incoming updates and request responses from TDLib. May be called from any thread, but shouldn't be called simultaneously from two different threads.
|
|
||||||
* @param timeout Maximum number of seconds allowed for this function to wait for new records.
|
|
||||||
* @return An incoming update or request response. The object returned in the response may be a nullptr if the timeout expires.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Response receive(double timeout) {
|
|
||||||
if (this.executionLock.isWriteLocked()) {
|
|
||||||
throw new IllegalStateException("ClientActor is destroyed");
|
|
||||||
}
|
|
||||||
|
|
||||||
var responseList = receive(timeout, 1);
|
|
||||||
|
|
||||||
if (responseList.size() < 1) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return responseList.get(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Synchronously executes TDLib requests. Only a few requests can be executed synchronously. May be called from any thread.
|
|
||||||
* @param request Request to the TDLib.
|
|
||||||
* @return The request response.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Response execute(Request request) {
|
|
||||||
if (this.executionLock.isWriteLocked()) {
|
|
||||||
throw new IllegalStateException("ClientActor is destroyed");
|
|
||||||
}
|
|
||||||
|
|
||||||
TdApi.Object object = nativeClientExecute(request.getFunction());
|
|
||||||
return new Response(0, object);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Destroys the client and TDLib instance.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void destroyClient() {
|
|
||||||
stampedLockValue = this.executionLock.tryWriteLock();
|
|
||||||
destroyNativeClient(this.clientId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Destroys the client and TDLib instance.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void initializeClient() {
|
|
||||||
this.executionLock.tryUnlockWrite();
|
|
||||||
stampedLockValue = null;
|
|
||||||
this.clientId = createNativeClient();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isDestroyed() {
|
|
||||||
return this.executionLock.isWriteLocked();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* it.ernytech.tdlib.utils is a group of utils necessary to complete the essential operation of tdlib.
|
|
||||||
*/
|
|
||||||
package it.ernytech.tdlib.utils;
|
|
150
src/main/java/it/tdlight/tdlight/Client.java
Normal file
150
src/main/java/it/tdlight/tdlight/Client.java
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
package it.tdlight.tdlight;
|
||||||
|
|
||||||
|
import it.tdlight.tdnatives.TdApi.Object;
|
||||||
|
import it.tdlight.tdlight.natives.NativeClient;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
import java.util.concurrent.locks.StampedLock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for interaction with TDLib.
|
||||||
|
*/
|
||||||
|
public class Client extends NativeClient implements TelegramClient {
|
||||||
|
private long clientId;
|
||||||
|
private final ReentrantLock receiveLock = new ReentrantLock();
|
||||||
|
private final StampedLock executionLock = new StampedLock();
|
||||||
|
private volatile Long stampedLockValue = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new TDLib client.
|
||||||
|
*/
|
||||||
|
public Client() {
|
||||||
|
super();
|
||||||
|
try {
|
||||||
|
Init.start();
|
||||||
|
} catch (Throwable throwable) {
|
||||||
|
throwable.printStackTrace();
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
this.clientId = createNativeClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends request to TDLib. May be called from any thread.
|
||||||
|
* @param request Request to TDLib.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void send(Request request) {
|
||||||
|
if (this.executionLock.isWriteLocked()) {
|
||||||
|
throw new IllegalStateException("ClientActor is destroyed");
|
||||||
|
}
|
||||||
|
|
||||||
|
nativeClientSend(this.clientId, request.getId(), request.getFunction());
|
||||||
|
}
|
||||||
|
|
||||||
|
private long[] eventIds;
|
||||||
|
private Object[] events;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Receives incoming updates and request responses from TDLib. May be called from any thread, but shouldn't be called simultaneously from two different threads.
|
||||||
|
* @param timeout Maximum number of seconds allowed for this function to wait for new records.
|
||||||
|
* @param eventSize Maximum number of events allowed in list.
|
||||||
|
* @return An incoming update or request response list. The object returned in the response may be an empty list if the timeout expires.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<Response> receive(double timeout, int eventSize) {
|
||||||
|
if (this.executionLock.isWriteLocked()) {
|
||||||
|
throw new IllegalStateException("ClientActor is destroyed");
|
||||||
|
}
|
||||||
|
|
||||||
|
var responseList = new ArrayList<Response>();
|
||||||
|
if (eventIds == null) {
|
||||||
|
eventIds = new long[eventSize];
|
||||||
|
events = new Object[eventSize];
|
||||||
|
} else if (eventIds.length != eventSize) {
|
||||||
|
throw new IllegalArgumentException("EventSize can't change! Previous value = " + eventIds.length + " New value = " + eventSize);
|
||||||
|
} else {
|
||||||
|
Arrays.fill(eventIds, 0);
|
||||||
|
Arrays.fill(events, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.receiveLock.isLocked()) {
|
||||||
|
throw new IllegalThreadStateException("Thread: " + Thread.currentThread().getName() + " trying receive incoming updates but shouldn't be called simultaneously from two different threads!");
|
||||||
|
}
|
||||||
|
|
||||||
|
int resultSize;
|
||||||
|
this.receiveLock.lock();
|
||||||
|
try {
|
||||||
|
resultSize = nativeClientReceive(this.clientId, eventIds, events, timeout);
|
||||||
|
} finally {
|
||||||
|
this.receiveLock.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < resultSize; i++) {
|
||||||
|
responseList.add(new Response(eventIds[i], events[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
return responseList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Receives incoming updates and request responses from TDLib. May be called from any thread, but shouldn't be called simultaneously from two different threads.
|
||||||
|
* @param timeout Maximum number of seconds allowed for this function to wait for new records.
|
||||||
|
* @return An incoming update or request response. The object returned in the response may be a nullptr if the timeout expires.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Response receive(double timeout) {
|
||||||
|
if (this.executionLock.isWriteLocked()) {
|
||||||
|
throw new IllegalStateException("ClientActor is destroyed");
|
||||||
|
}
|
||||||
|
|
||||||
|
var responseList = receive(timeout, 1);
|
||||||
|
|
||||||
|
if (responseList.size() < 1) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return responseList.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Synchronously executes TDLib requests. Only a few requests can be executed synchronously. May be called from any thread.
|
||||||
|
* @param request Request to the TDLib.
|
||||||
|
* @return The request response.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Response execute(Request request) {
|
||||||
|
if (this.executionLock.isWriteLocked()) {
|
||||||
|
throw new IllegalStateException("ClientActor is destroyed");
|
||||||
|
}
|
||||||
|
|
||||||
|
Object object = nativeClientExecute(request.getFunction());
|
||||||
|
return new Response(0, object);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroys the client and TDLib instance.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void destroyClient() {
|
||||||
|
stampedLockValue = this.executionLock.tryWriteLock();
|
||||||
|
destroyNativeClient(this.clientId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroys the client and TDLib instance.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void initializeClient() {
|
||||||
|
this.executionLock.tryUnlockWrite();
|
||||||
|
stampedLockValue = null;
|
||||||
|
this.clientId = createNativeClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDestroyed() {
|
||||||
|
return this.executionLock.isWriteLocked();
|
||||||
|
}
|
||||||
|
}
|
@ -15,10 +15,9 @@
|
|||||||
* along with JTdlib. If not, see <http://www.gnu.org/licenses/>.
|
* along with JTdlib. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package it.ernytech.tdbot;
|
package it.tdlight.tdlight;
|
||||||
|
|
||||||
import it.ernytech.tdlib.TdApi;
|
|
||||||
|
|
||||||
|
import it.tdlight.tdnatives.TdApi;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
@ -30,7 +29,7 @@ public class ConstructorDetector {
|
|||||||
static {
|
static {
|
||||||
// Call this to load static methods and prevent errors during startup!
|
// Call this to load static methods and prevent errors during startup!
|
||||||
try {
|
try {
|
||||||
it.ernytech.tdlib.utils.Init.start();
|
Init.start();
|
||||||
} catch (Throwable throwable) {
|
} catch (Throwable throwable) {
|
||||||
throwable.printStackTrace();
|
throwable.printStackTrace();
|
||||||
}
|
}
|
@ -15,7 +15,7 @@
|
|||||||
* along with JTdlib. If not, see <http://www.gnu.org/licenses/>.
|
* along with JTdlib. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package it.ernytech.tdlib;
|
package it.tdlight.tdlight;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A type of callback function that will be called when a fatal error happens.
|
* A type of callback function that will be called when a fatal error happens.
|
@ -15,9 +15,11 @@
|
|||||||
* along with JTdlib. If not, see <http://www.gnu.org/licenses/>.
|
* along with JTdlib. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package it.ernytech.tdlib.utils;
|
package it.tdlight.tdlight;
|
||||||
|
|
||||||
import it.ernytech.tdbot.ConstructorDetector;
|
import it.tdlight.tdlight.utils.CantLoadLibrary;
|
||||||
|
import it.tdlight.tdlight.utils.LoadLibrary;
|
||||||
|
import it.tdlight.tdlight.utils.Os;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init class to successfully initialize Tdlib
|
* Init class to successfully initialize Tdlib
|
31
src/main/java/it/tdlight/tdlight/Log.java
Normal file
31
src/main/java/it/tdlight/tdlight/Log.java
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package it.tdlight.tdlight;
|
||||||
|
|
||||||
|
import it.tdlight.tdlight.natives.NativeLog;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class Log extends NativeLog {
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
Init.start();
|
||||||
|
} catch (Throwable throwable) {
|
||||||
|
throwable.printStackTrace();
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final FatalErrorCallbackPtr defaultFatalErrorCallbackPtr = System.err::println;
|
||||||
|
private static FatalErrorCallbackPtr fatalErrorCallback = defaultFatalErrorCallbackPtr;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 void setFatalErrorCallback(FatalErrorCallbackPtr fatalErrorCallback) {
|
||||||
|
Log.fatalErrorCallback = Objects.requireNonNullElse(fatalErrorCallback, defaultFatalErrorCallbackPtr);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void onFatalError(String errorMessage) {
|
||||||
|
new Thread(() -> Log.fatalErrorCallback.onFatalError(errorMessage)).start();
|
||||||
|
}
|
||||||
|
}
|
@ -15,21 +15,23 @@
|
|||||||
* along with JTdlib. If not, see <http://www.gnu.org/licenses/>.
|
* along with JTdlib. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package it.ernytech.tdlib;
|
package it.tdlight.tdlight;
|
||||||
|
|
||||||
|
import it.tdlight.tdnatives.TdApi.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A request to the TDLib.
|
* A request to the TDLib.
|
||||||
*/
|
*/
|
||||||
public class Request {
|
public class Request {
|
||||||
private long id;
|
private long id;
|
||||||
private TdApi.Function function;
|
private Function function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a request with eventId and function.
|
* Creates a request with eventId and function.
|
||||||
* @param id Request identifier. Responses to TDLib requests will have the same id as the corresponding request. Updates from TDLib will have id == 0, incoming requests are thus disallowed to have id == 0.
|
* @param id Request identifier. Responses to TDLib requests will have the same id as the corresponding request. Updates from TDLib will have id == 0, incoming requests are thus disallowed to have id == 0.
|
||||||
* @param function TDLib API function representing a request to TDLib.
|
* @param function TDLib API function representing a request to TDLib.
|
||||||
*/
|
*/
|
||||||
public Request(long id, TdApi.Function function) {
|
public Request(long id, Function function) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.function = function;
|
this.function = function;
|
||||||
}
|
}
|
||||||
@ -46,7 +48,7 @@ public class Request {
|
|||||||
* Get TDLib API function.
|
* Get TDLib API function.
|
||||||
* @return TDLib API function representing a request to TDLib.
|
* @return TDLib API function representing a request to TDLib.
|
||||||
*/
|
*/
|
||||||
public TdApi.Function getFunction() {
|
public Function getFunction() {
|
||||||
return this.function;
|
return this.function;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -15,21 +15,23 @@
|
|||||||
* along with JTdlib. If not, see <http://www.gnu.org/licenses/>.
|
* along with JTdlib. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package it.ernytech.tdlib;
|
package it.tdlight.tdlight;
|
||||||
|
|
||||||
|
import it.tdlight.tdnatives.TdApi.Object;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A response to a request, or an incoming update from TDLib.
|
* A response to a request, or an incoming update from TDLib.
|
||||||
*/
|
*/
|
||||||
public class Response {
|
public class Response {
|
||||||
private long id;
|
private long id;
|
||||||
private TdApi.Object object;
|
private Object object;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a response with eventId and object, do not create answers explicitly! you must receive the reply through a client.
|
* Creates a response with eventId and object, do not create answers explicitly! you must receive the reply through a client.
|
||||||
* @param id TDLib request identifier, which corresponds to the response or 0 for incoming updates from TDLib.
|
* @param id TDLib request identifier, which corresponds to the response or 0 for incoming updates from TDLib.
|
||||||
* @param object TDLib API object representing a response to a TDLib request or an incoming update.
|
* @param object TDLib API object representing a response to a TDLib request or an incoming update.
|
||||||
*/
|
*/
|
||||||
public Response(long id, TdApi.Object object) {
|
public Response(long id, Object object) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.object = object;
|
this.object = object;
|
||||||
}
|
}
|
||||||
@ -46,7 +48,7 @@ public class Response {
|
|||||||
* Get TDLib API object.
|
* Get TDLib API object.
|
||||||
* @return TDLib API object representing a response to a TDLib request or an incoming update.
|
* @return TDLib API object representing a response to a TDLib request or an incoming update.
|
||||||
*/
|
*/
|
||||||
public TdApi.Object getObject() {
|
public Object getObject() {
|
||||||
return this.object;
|
return this.object;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -15,7 +15,7 @@
|
|||||||
* along with JTdlib. If not, see <http://www.gnu.org/licenses/>.
|
* along with JTdlib. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package it.ernytech.tdlib;
|
package it.tdlight.tdlight;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An array of incoming updates from TDLib.
|
* An array of incoming updates from TDLib.
|
@ -15,11 +15,11 @@
|
|||||||
* along with JTdlib. If not, see <http://www.gnu.org/licenses/>.
|
* along with JTdlib. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package it.ernytech.tdlib;
|
package it.tdlight.tdlight;
|
||||||
|
|
||||||
import it.ernytech.tdlib.utils.CloseCallback;
|
import it.tdlight.tdlight.utils.CloseCallback;
|
||||||
import it.ernytech.tdlib.utils.ErrorCallback;
|
import it.tdlight.tdlight.utils.ErrorCallback;
|
||||||
import it.ernytech.tdlib.utils.ReceiveCallback;
|
import it.tdlight.tdlight.utils.ReceiveCallback;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface of callback for interaction with TDLib.
|
* Interface of callback for interaction with TDLib.
|
@ -1,4 +1,4 @@
|
|||||||
package it.ernytech.tdlib;
|
package it.tdlight.tdlight;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
@ -15,7 +15,7 @@
|
|||||||
* along with JTdlib. If not, see <http://www.gnu.org/licenses/>.
|
* along with JTdlib. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package it.ernytech.tdlib.utils;
|
package it.tdlight.tdlight.utils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enumeration with all architectures recognized by this library.
|
* Enumeration with all architectures recognized by this library.
|
@ -15,7 +15,7 @@
|
|||||||
* along with JTdlib. If not, see <http://www.gnu.org/licenses/>.
|
* along with JTdlib. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package it.ernytech.tdlib.utils;
|
package it.tdlight.tdlight.utils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An exception that is thrown when the LoadLibrary class fails to load the library.
|
* An exception that is thrown when the LoadLibrary class fails to load the library.
|
@ -15,7 +15,7 @@
|
|||||||
* along with JTdlib. If not, see <http://www.gnu.org/licenses/>.
|
* along with JTdlib. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package it.ernytech.tdlib.utils;
|
package it.tdlight.tdlight.utils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface of callback for receive notification of closing Tdlib.
|
* Interface of callback for receive notification of closing Tdlib.
|
@ -15,9 +15,9 @@
|
|||||||
* along with JTdlib. If not, see <http://www.gnu.org/licenses/>.
|
* along with JTdlib. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package it.ernytech.tdlib.utils;
|
package it.tdlight.tdlight.utils;
|
||||||
|
|
||||||
import it.ernytech.tdlib.Response;
|
import it.tdlight.tdlight.Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface of callback for receive incoming error response.
|
* Interface of callback for receive incoming error response.
|
@ -15,7 +15,7 @@
|
|||||||
* along with JTdlib. If not, see <http://www.gnu.org/licenses/>.
|
* along with JTdlib. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package it.ernytech.tdlib.utils;
|
package it.tdlight.tdlight.utils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
@ -15,9 +15,9 @@
|
|||||||
* along with JTdlib. If not, see <http://www.gnu.org/licenses/>.
|
* along with JTdlib. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package it.ernytech.tdlib.utils;
|
package it.tdlight.tdlight.utils;
|
||||||
|
|
||||||
import it.ernytech.tdlib.Response;
|
import it.tdlight.tdlight.Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface of callback for receive incoming error response.
|
* Interface of callback for receive incoming error response.
|
@ -15,7 +15,7 @@
|
|||||||
* along with JTdlib. If not, see <http://www.gnu.org/licenses/>.
|
* along with JTdlib. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package it.ernytech.tdlib.utils;
|
package it.tdlight.tdlight.utils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enumeration with all operating systems recognized by this library.
|
* Enumeration with all operating systems recognized by this library.
|
@ -15,9 +15,9 @@
|
|||||||
* along with JTdlib. If not, see <http://www.gnu.org/licenses/>.
|
* along with JTdlib. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package it.ernytech.tdlib.utils;
|
package it.tdlight.tdlight.utils;
|
||||||
|
|
||||||
import it.ernytech.tdlib.Response;
|
import it.tdlight.tdlight.Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface of callback for receive incoming update or request response.
|
* Interface of callback for receive incoming update or request response.
|
@ -1,4 +1,4 @@
|
|||||||
package it.ernytech.tdlib.utils;
|
package it.tdlight.tdlight.utils;
|
||||||
|
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
@ -1,3 +1,4 @@
|
|||||||
|
package it.tdlight.tdlight.natives;
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018. Ernesto Castellotti <erny.castell@gmail.com>
|
* Copyright (c) 2018. Ernesto Castellotti <erny.castell@gmail.com>
|
||||||
* This file is part of JTdlib.
|
* This file is part of JTdlib.
|
||||||
@ -15,7 +16,15 @@
|
|||||||
* along with JTdlib. If not, see <http://www.gnu.org/licenses/>.
|
* along with JTdlib. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* it.ernytech.tdlib is a group of inspired by the classic native C ++ classes of Tdlib Client and Log to interact with the Tdlib API.
|
|
||||||
*/
|
import it.tdlight.tdnatives.TdApi.Function;
|
||||||
package it.ernytech.tdlib;
|
import it.tdlight.tdnatives.TdApi.Object;
|
||||||
|
|
||||||
|
public class NativeClient {
|
||||||
|
protected static native long createNativeClient();
|
||||||
|
protected static native void nativeClientSend(long nativeClientId, long eventId, Function function);
|
||||||
|
protected static native int nativeClientReceive(long nativeClientId, long[] eventIds, Object[] events, double timeout);
|
||||||
|
protected static native Object nativeClientExecute(Function function);
|
||||||
|
protected static native void destroyNativeClient(long nativeClientId);
|
||||||
|
}
|
@ -15,27 +15,12 @@
|
|||||||
* along with JTdlib. If not, see <http://www.gnu.org/licenses/>.
|
* along with JTdlib. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package it.ernytech.tdlib;
|
package it.tdlight.tdlight.natives;
|
||||||
|
|
||||||
import it.ernytech.tdlib.utils.Init;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for managing the internal logging of TDLib. By default TDLib writes logs to stderr or an OS specific log and uses a verbosity level of 5.
|
* Interface for managing the internal logging of TDLib. By default TDLib writes logs to stderr or an OS specific log and uses a verbosity level of 5.
|
||||||
*/
|
*/
|
||||||
public class Log {
|
public class NativeLog {
|
||||||
static {
|
|
||||||
try {
|
|
||||||
Init.start();
|
|
||||||
} catch (Throwable throwable) {
|
|
||||||
throwable.printStackTrace();
|
|
||||||
System.exit(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final FatalErrorCallbackPtr defaultFatalErrorCallbackPtr = System.err::println;
|
|
||||||
private static FatalErrorCallbackPtr fatalErrorCallback = defaultFatalErrorCallbackPtr;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the path to the file to where the internal TDLib log will be written. By default TDLib writes logs to stderr or an OS specific log. Use this method to write the log to a file instead.
|
* Sets the path to the file to where the internal TDLib log will be written. By default TDLib writes logs to stderr or an OS specific log. Use this method to write the log to a file instead.
|
||||||
@ -55,16 +40,4 @@ public class Log {
|
|||||||
* @param verbosityLevel New value of the verbosity level for logging. Value 0 corresponds to fatal errors, value 1 corresponds to errors, value 2 corresponds to warnings and debug warnings, value 3 corresponds to informational, value 4 corresponds to debug, value 5 corresponds to verbose debug, value greater than 5 and up to 1024 can be used to enable even more logging.
|
* @param verbosityLevel New value of the verbosity level for logging. Value 0 corresponds to fatal errors, value 1 corresponds to errors, value 2 corresponds to warnings and debug warnings, value 3 corresponds to informational, value 4 corresponds to debug, value 5 corresponds to verbose debug, value greater than 5 and up to 1024 can be used to enable even more logging.
|
||||||
*/
|
*/
|
||||||
public static native void setVerbosityLevel(int verbosityLevel);
|
public static native void setVerbosityLevel(int verbosityLevel);
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 void setFatalErrorCallback(FatalErrorCallbackPtr fatalErrorCallback) {
|
|
||||||
Log.fatalErrorCallback = Objects.requireNonNullElse(fatalErrorCallback, defaultFatalErrorCallbackPtr);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void onFatalError(String errorMessage) {
|
|
||||||
new Thread(() -> Log.fatalErrorCallback.onFatalError(errorMessage)).start();
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package it.ernytech.tdlib;
|
package it.tdlight.tdnatives;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
@ -2,8 +2,8 @@
|
|||||||
#rm -r jtdlib/jnibuild
|
#rm -r jtdlib/jnibuild
|
||||||
#rm -r jtdlib/build
|
#rm -r jtdlib/build
|
||||||
|
|
||||||
rm ../java/it/ernytech/tdlib/TdApi.java || true
|
rm ../java/it/tdlight/tdlight/natives/TdApi.java || true
|
||||||
rm ../java/it/ernytech/tdlib/new_TdApi.java || true
|
rm ../java/it/tdlight/tdlight/natives/new_TdApi.java || true
|
||||||
|
|
||||||
export TD_SRC_DIR=${PWD}/td
|
export TD_SRC_DIR=${PWD}/td
|
||||||
export TD_BIN_DIR=${PWD}/jtdlib/td
|
export TD_BIN_DIR=${PWD}/jtdlib/td
|
||||||
|
@ -12,6 +12,8 @@ endif()
|
|||||||
find_package(Td REQUIRED)
|
find_package(Td REQUIRED)
|
||||||
|
|
||||||
if (NOT JNI_FOUND)
|
if (NOT JNI_FOUND)
|
||||||
|
set(JAVA_AWT_LIBRARY NotNeeded)
|
||||||
|
set(JAVA_AWT_INCLUDE_PATH NotNeeded)
|
||||||
find_package(JNI REQUIRED)
|
find_package(JNI REQUIRED)
|
||||||
endif()
|
endif()
|
||||||
message(STATUS "Found JNI: ${JNI_INCLUDE_DIRS} ${JNI_LIBRARIES}")
|
message(STATUS "Found JNI: ${JNI_INCLUDE_DIRS} ${JNI_LIBRARIES}")
|
||||||
@ -26,7 +28,7 @@ message(STATUS "Java Source Directory: ${JAVA_SRC_DIR}")
|
|||||||
# Generating TdApi.java
|
# Generating TdApi.java
|
||||||
find_program(PHP_EXECUTABLE php)
|
find_program(PHP_EXECUTABLE php)
|
||||||
|
|
||||||
set(TD_API_JAVA_PACKAGE "it/ernytech/tdlib")
|
set(TD_API_JAVA_PACKAGE "it/tdlight/tdnatives")
|
||||||
set(TD_API_JAVA_PATH ${JAVA_SRC_DIR})
|
set(TD_API_JAVA_PATH ${JAVA_SRC_DIR})
|
||||||
set(TD_API_TLO_PATH ${CMAKE_CURRENT_SOURCE_DIR}/td/bin/td/generate/scheme/td_api.tlo)
|
set(TD_API_TLO_PATH ${CMAKE_CURRENT_SOURCE_DIR}/td/bin/td/generate/scheme/td_api.tlo)
|
||||||
set(TD_API_TL_PATH ${CMAKE_CURRENT_SOURCE_DIR}/td/bin/td/generate/scheme/td_api.tl)
|
set(TD_API_TL_PATH ${CMAKE_CURRENT_SOURCE_DIR}/td/bin/td/generate/scheme/td_api.tl)
|
||||||
@ -51,7 +53,7 @@ add_custom_target(build_java
|
|||||||
)
|
)
|
||||||
|
|
||||||
add_custom_target(generate_javadoc
|
add_custom_target(generate_javadoc
|
||||||
COMMAND ${Java_JAVADOC_EXECUTABLE} -d ${JAVA_OUTPUT_DIRECTORY}/../docs it.ernytech.tdlib
|
COMMAND ${Java_JAVADOC_EXECUTABLE} -d ${JAVA_OUTPUT_DIRECTORY}/../docs it.tdlight.tdnatives
|
||||||
WORKING_DIRECTORY ${TD_API_JAVA_PATH}
|
WORKING_DIRECTORY ${TD_API_JAVA_PATH}
|
||||||
COMMENT "Generating Javadoc documentation"
|
COMMENT "Generating Javadoc documentation"
|
||||||
DEPENDS td_generate_java_api
|
DEPENDS td_generate_java_api
|
||||||
|
@ -1,15 +1,3 @@
|
|||||||
../../../java/it/ernytech/tdlib/Client.java
|
../../../java/it/tdlight/tdnatives/NativeClient.java
|
||||||
../../../java/it/ernytech/tdlib/TelegramClient.java
|
../../../java/it/tdlight/tdnatives/NativeLog.java
|
||||||
../../../java/it/ernytech/tdlib/utils/Init.java
|
../../../java/it/tdlight/tdnatives/TdApi.java
|
||||||
../../../java/it/ernytech/tdlib/utils/LoadLibrary.java
|
|
||||||
../../../java/it/ernytech/tdlib/utils/Os.java
|
|
||||||
../../../java/it/ernytech/tdlib/Log.java
|
|
||||||
../../../java/it/ernytech/tdlib/Request.java
|
|
||||||
../../../java/it/ernytech/tdlib/Response.java
|
|
||||||
../../../java/it/ernytech/tdlib/utils/Arch.java
|
|
||||||
../../../java/it/ernytech/tdlib/utils/CantLoadLibrary.java
|
|
||||||
../../../java/it/ernytech/tdlib/FatalErrorCallbackPtr.java
|
|
||||||
../../../java/it/ernytech/tdbot/ConstructorDetector.java
|
|
||||||
../../../java/it/ernytech/tdlib/TdApi.java
|
|
||||||
../../../java-templates/it/ernytech/tdlib/utils/LibraryVersion.java
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user