Code cleanup
This commit is contained in:
parent
4de5f47b95
commit
c313cb8fa2
@ -33,7 +33,7 @@ public class Init {
|
|||||||
*
|
*
|
||||||
* @throws CantLoadLibrary An exception that is thrown when the LoadLibrary class fails to load the library.
|
* @throws CantLoadLibrary An exception that is thrown when the LoadLibrary class fails to load the library.
|
||||||
*/
|
*/
|
||||||
public synchronized static void start() throws Throwable {
|
public synchronized static void start() throws CantLoadLibrary {
|
||||||
if (!started) {
|
if (!started) {
|
||||||
Os os = LoadLibrary.getOs();
|
Os os = LoadLibrary.getOs();
|
||||||
|
|
||||||
|
@ -1,146 +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.tdlight;
|
|
||||||
|
|
||||||
import it.tdlight.tdlight.utils.CloseCallback;
|
|
||||||
import it.tdlight.tdlight.utils.ErrorCallback;
|
|
||||||
import it.tdlight.tdlight.utils.ReceiveCallback;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface of callback for interaction with TDLib.
|
|
||||||
*/
|
|
||||||
public class TdCallback {
|
|
||||||
private ReceiveCallback receiveCallback;
|
|
||||||
private ErrorCallback errorCallback;
|
|
||||||
private CloseCallback closeCallback;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new TdCallback.
|
|
||||||
*
|
|
||||||
* @param receiveCallback Interface of callback for receive incoming update or request response.
|
|
||||||
* @param errorCallback Interface of callback for receive incoming error response.
|
|
||||||
* @param closeCallback Interface of callback for receive notification of closing Tdlib.
|
|
||||||
*/
|
|
||||||
public TdCallback(ReceiveCallback receiveCallback, ErrorCallback errorCallback, CloseCallback closeCallback) {
|
|
||||||
this.receiveCallback = receiveCallback;
|
|
||||||
this.errorCallback = errorCallback;
|
|
||||||
this.closeCallback = closeCallback;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new TdCallback.
|
|
||||||
*
|
|
||||||
* @param receiveCallback Interface of callback for receive incoming update or request response.
|
|
||||||
*/
|
|
||||||
public TdCallback(ReceiveCallback receiveCallback) {
|
|
||||||
this.receiveCallback = receiveCallback;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new TdCallback.
|
|
||||||
*
|
|
||||||
* @param errorCallback Interface of callback for receive incoming error response.
|
|
||||||
*/
|
|
||||||
public TdCallback(ErrorCallback errorCallback) {
|
|
||||||
this.errorCallback = errorCallback;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new TdCallback.
|
|
||||||
*
|
|
||||||
* @param closeCallback Interface of callback for receive notification of closing Tdlib.
|
|
||||||
*/
|
|
||||||
public TdCallback(CloseCallback closeCallback) {
|
|
||||||
this.closeCallback = closeCallback;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new TdCallback.
|
|
||||||
*
|
|
||||||
* @param receiveCallback Interface of callback for receive incoming update or request response.
|
|
||||||
* @param errorCallback Interface of callback for receive incoming error response.
|
|
||||||
*/
|
|
||||||
public TdCallback(ReceiveCallback receiveCallback, ErrorCallback errorCallback) {
|
|
||||||
this.receiveCallback = receiveCallback;
|
|
||||||
this.errorCallback = errorCallback;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new TdCallback.
|
|
||||||
*
|
|
||||||
* @param errorCallback Interface of callback for receive incoming error response.
|
|
||||||
* @param closeCallback Interface of callback for receive notification of closing Tdlib.
|
|
||||||
*/
|
|
||||||
public TdCallback(ErrorCallback errorCallback, CloseCallback closeCallback) {
|
|
||||||
this.errorCallback = errorCallback;
|
|
||||||
this.closeCallback = closeCallback;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new TdCallback.
|
|
||||||
*
|
|
||||||
* @param receiveCallback Interface of callback for receive incoming update or request response.
|
|
||||||
* @param closeCallback Interface of callback for receive notification of closing Tdlib.
|
|
||||||
*/
|
|
||||||
public TdCallback(ReceiveCallback receiveCallback, CloseCallback closeCallback) {
|
|
||||||
this.receiveCallback = receiveCallback;
|
|
||||||
this.closeCallback = closeCallback;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get ReceiveCallback.
|
|
||||||
*
|
|
||||||
* @return This method return ReceiveCallback or "null callback" (a callback that receives records from tdlib but does not perform any operation) if is null.
|
|
||||||
*/
|
|
||||||
public ReceiveCallback getReceiveCallback() {
|
|
||||||
if (this.receiveCallback == null) {
|
|
||||||
return response -> {
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.receiveCallback;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get ErrorCallback.
|
|
||||||
*
|
|
||||||
* @return This method return ErrorCallback or "null callback" (a callback that receives records from tdlib but does not perform any operation) if is null.
|
|
||||||
*/
|
|
||||||
public ErrorCallback getErrorCallback() {
|
|
||||||
if (this.errorCallback == null) {
|
|
||||||
return error -> {
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.errorCallback;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get CloseCallback.
|
|
||||||
*
|
|
||||||
* @return This method return CloseCallback or "null callback" (a callback that receives records from tdlib but does not perform any operation) if is null.
|
|
||||||
*/
|
|
||||||
public CloseCallback getCloseCallback() {
|
|
||||||
if (this.closeCallback == null) {
|
|
||||||
return () -> {
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.closeCallback;
|
|
||||||
}
|
|
||||||
}
|
|
@ -20,7 +20,7 @@ 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.
|
||||||
*/
|
*/
|
||||||
public class CantLoadLibrary extends RuntimeException {
|
public class CantLoadLibrary extends Exception {
|
||||||
/**
|
/**
|
||||||
* Creates a new CantLoadLibrary exception.
|
* Creates a new CantLoadLibrary exception.
|
||||||
*/
|
*/
|
||||||
|
@ -49,7 +49,7 @@ public class LoadLibrary {
|
|||||||
* @param libname The name of the library.
|
* @param libname The name of the library.
|
||||||
* @throws CantLoadLibrary An exception that is thrown when the LoadLibrary class fails to load the library.
|
* @throws CantLoadLibrary An exception that is thrown when the LoadLibrary class fails to load the library.
|
||||||
*/
|
*/
|
||||||
public static void load(String libname) throws Throwable {
|
public static void load(String libname) throws CantLoadLibrary {
|
||||||
if (libname == null || libname.trim().isEmpty()) {
|
if (libname == null || libname.trim().isEmpty()) {
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
@ -64,16 +64,16 @@ public class LoadLibrary {
|
|||||||
libraryLoaded.put(libname, true);
|
libraryLoaded.put(libname, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void loadLibrary(String libname) throws Throwable {
|
private static void loadLibrary(String libname) throws CantLoadLibrary {
|
||||||
Arch arch = getCpuArch();
|
Arch arch = getCpuArch();
|
||||||
Os os = getOs();
|
Os os = getOs();
|
||||||
|
|
||||||
if (arch == Arch.unknown) {
|
if (arch == Arch.unknown) {
|
||||||
throw new CantLoadLibrary().initCause(new IllegalStateException("Arch: \"" + System.getProperty("os.arch") + "\" is unknown"));
|
throw (CantLoadLibrary) new CantLoadLibrary().initCause(new IllegalStateException("Arch: \"" + System.getProperty("os.arch") + "\" is unknown"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (os == Os.unknown) {
|
if (os == Os.unknown) {
|
||||||
throw new CantLoadLibrary().initCause(new IllegalStateException("Os: \"" + System.getProperty("os.name") + "\" is unknown"));
|
throw (CantLoadLibrary) new CantLoadLibrary().initCause(new IllegalStateException("Os: \"" + System.getProperty("os.name") + "\" is unknown"));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -82,7 +82,7 @@ public class LoadLibrary {
|
|||||||
if (loadSysLibrary(libname)) {
|
if (loadSysLibrary(libname)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw new CantLoadLibrary().initCause(e);
|
throw (CantLoadLibrary) new CantLoadLibrary().initCause(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user