diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 80585669f..b75fa20cb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,16 +14,19 @@ jobs: common: uses: TokTok/ci-tools/.github/workflows/common-ci.yml@master - docker-jvm: + docker: + strategy: + matrix: + target: [jvm, native] runs-on: ubuntu-latest steps: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Build toxchat/jvm-toxcore-c:jvm + - name: Build toxchat/jvm-toxcore-c:${{ matrix.target }} uses: docker/build-push-action@v5 with: - file: docker/jvm.Dockerfile - tags: toxchat/jvm-toxcore-c:jvm + file: docker/${{ matrix.target }}.Dockerfile + tags: toxchat/jvm-toxcore-c:${{ matrix.target }} ktlint: runs-on: ubuntu-22.04 diff --git a/BUILD.bazel b/BUILD.bazel index 7edd11fd7..ab3b04ac7 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -14,22 +14,22 @@ genrule( "//tools/config:osx": ["@bazel_tools//tools/jdk:jni_md_header-darwin"], "//tools/config:windows": ["@bazel_tools//tools/jdk:jni_md_header-windows"], }), - outs = ["lib/src/main/cpp/jni_md.h"], + outs = ["lib/src/jvmMain/cpp/jni_md.h"], cmd = "cp -f $< $@", ) genrule( name = "copy_link_jni_header", srcs = ["@bazel_tools//tools/jdk:jni_header"], - outs = ["lib/src/main/cpp/jni.h"], + outs = ["lib/src/jvmMain/cpp/jni.h"], cmd = "cp -f $< $@", ) proto_library( name = "jni_proto", srcs = [ - "lib/src/main/proto/Av.proto", - "lib/src/main/proto/Core.proto", + "lib/src/jvmMain/proto/Av.proto", + "lib/src/jvmMain/proto/Core.proto", ], ) @@ -46,28 +46,28 @@ java_proto_library( cc_binary( name = "libtox4j-c.so", srcs = glob([ - "lib/src/main/cpp/**/*.cpp", - "lib/src/main/cpp/**/*.h", + "lib/src/jvmMain/cpp/**/*.cpp", + "lib/src/jvmMain/cpp/**/*.h", ]) + [ - ":lib/src/main/cpp/jni.h", - ":lib/src/main/cpp/jni_md.h", + ":lib/src/jvmMain/cpp/jni.h", + ":lib/src/jvmMain/cpp/jni_md.h", ], copts = [ "-DHAVE_TO_STRING", ], includes = [ - "lib/src/main/cpp", - "lib/src/main/proto", + "lib/src/jvmMain/cpp", + "lib/src/jvmMain/proto", ], linkopts = select({ - "//tools/config:freebsd": ["-Wl,--version-script,$(location lib/src/main/cpp/libtox4j-c.ld)"], - "//tools/config:linux": ["-Wl,--version-script,$(location lib/src/main/cpp/libtox4j-c.ld)"], + "//tools/config:freebsd": ["-Wl,--version-script,$(location lib/src/jvmMain/cpp/libtox4j-c.ld)"], + "//tools/config:linux": ["-Wl,--version-script,$(location lib/src/jvmMain/cpp/libtox4j-c.ld)"], "//tools/config:osx": [], "//tools/config:windows": [], }), linkshared = True, deps = [ - "lib/src/main/cpp/libtox4j-c.ld", + "lib/src/jvmMain/cpp/libtox4j-c.ld", ":jni_cc_proto", "//c-toxcore", ], @@ -76,8 +76,8 @@ cc_binary( kt_jvm_library( name = "jvm-toxcore-c", srcs = glob([ - "lib/src/main/java/**/*.java", - "lib/src/main/java/**/*.kt", + "lib/src/*Main/**/*.java", + "lib/src/*Main/**/*.kt", ]), data = ["libtox4j-c.so"], deps = [":jni_java_proto"], @@ -86,7 +86,7 @@ kt_jvm_library( kt_jvm_test( name = "ToxCoreTest", size = "small", - srcs = ["lib/src/test/java/im/tox/tox4j/core/ToxCoreTest.kt"], + srcs = ["lib/src/jvmTest/java/im/tox/tox4j/core/ToxCoreTest.kt"], jvm_flags = ["-Djava.library.path=jvm-toxcore-c"], test_class = "im.tox.tox4j.core.ToxCoreTest", deps = [ diff --git a/docker/build-native b/docker/build-native new file mode 100755 index 000000000..0e850164d --- /dev/null +++ b/docker/build-native @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +set -eux + +cat <native.txt +-p +library +EOF + +find lib/src/commonMain -name '*.kt' -exec printf '{}\n-Xcommon-sources={}\n' ';' >>native.txt + +kotlinc-native @native.txt +ls diff --git a/docker/jvm.Dockerfile b/docker/jvm.Dockerfile index f8ee7a066..1dadf917d 100644 --- a/docker/jvm.Dockerfile +++ b/docker/jvm.Dockerfile @@ -7,6 +7,7 @@ RUN apt-get update \ build-essential \ ca-certificates \ cmake \ + curl \ default-jdk \ git \ libtool \ @@ -23,8 +24,8 @@ RUN scripts/build-host "$PWD/_install/host/protobuf.stamp" "-j$(nproc)" RUN scripts/build-host "$PWD/_install/host/toxcore.stamp" "-j$(nproc)" # Native code, changes less frequently. -COPY lib/src/main/cpp/ /work/jvm-toxcore-c/lib/src/main/cpp/ -COPY lib/src/main/proto/ /work/jvm-toxcore-c/lib/src/main/proto/ +COPY lib/src/jvmMain/cpp/ /work/jvm-toxcore-c/lib/src/jvmMain/cpp/ +COPY lib/src/jvmMain/proto/ /work/jvm-toxcore-c/lib/src/jvmMain/proto/ RUN touch "$PWD/_install/host/.stamp" \ && touch "$PWD/_install/host/libsodium.stamp" \ && touch "$PWD/_install/host/libvpx.stamp" \ @@ -42,10 +43,10 @@ ENV LD_LIBRARY_PATH=/work/jvm-toxcore-c/_install/host/lib ENV PATH=/work/jvm-toxcore-c/_install/host/bin:$PATH RUN ./gradlew build -RUN javac -h . -cp /work/jvm-toxcore-c/lib/build/classes/kotlin/main:/work/jvm-toxcore-c/lib/build/classes/java/main \ - lib/src/main/java/im/tox/tox4j/impl/jni/ToxAvJni.java \ - lib/src/main/java/im/tox/tox4j/impl/jni/ToxCoreJni.java \ - lib/src/main/java/im/tox/tox4j/impl/jni/ToxCryptoJni.java -RUN diff -u lib/src/main/cpp/ToxCore/generated/im_tox_tox4j_impl_jni_ToxCoreJni.h im_tox_tox4j_impl_jni_ToxCoreJni.h \ - && diff -u lib/src/main/cpp/ToxAv/generated/im_tox_tox4j_impl_jni_ToxAvJni.h im_tox_tox4j_impl_jni_ToxAvJni.h \ - && diff -u lib/src/main/cpp/ToxCrypto/generated/im_tox_tox4j_impl_jni_ToxCryptoJni.h im_tox_tox4j_impl_jni_ToxCryptoJni.h +RUN javac -h . -cp /work/jvm-toxcore-c/lib/build/classes/kotlin/jvm/main:/work/jvm-toxcore-c/lib/build/classes/java/jvm/main \ + lib/src/jvmMain/java/im/tox/tox4j/impl/jni/ToxAvJni.java \ + lib/src/jvmMain/java/im/tox/tox4j/impl/jni/ToxCoreJni.java \ + lib/src/jvmMain/java/im/tox/tox4j/impl/jni/ToxCryptoJni.java +RUN diff -u lib/src/jvmMain/cpp/ToxCore/generated/im_tox_tox4j_impl_jni_ToxCoreJni.h im_tox_tox4j_impl_jni_ToxCoreJni.h \ + && diff -u lib/src/jvmMain/cpp/ToxAv/generated/im_tox_tox4j_impl_jni_ToxAvJni.h im_tox_tox4j_impl_jni_ToxAvJni.h \ + && diff -u lib/src/jvmMain/cpp/ToxCrypto/generated/im_tox_tox4j_impl_jni_ToxCryptoJni.h im_tox_tox4j_impl_jni_ToxCryptoJni.h diff --git a/docker/native.Dockerfile b/docker/native.Dockerfile new file mode 100644 index 000000000..e64a28876 --- /dev/null +++ b/docker/native.Dockerfile @@ -0,0 +1,33 @@ +FROM ubuntu:22.04 + +RUN apt-get update \ + && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + autoconf \ + automake \ + build-essential \ + ca-certificates \ + cmake \ + curl \ + default-jdk \ + git \ + libtool \ + make \ + pkg-config \ + yasm \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /opt +RUN curl -L -o kotlin-native.tar.gz https://github.com/JetBrains/kotlin/releases/download/v1.9.22/kotlin-native-linux-x86_64-1.9.22.tar.gz \ + && tar zxf kotlin-native.tar.gz \ + && mv kotlin-native-linux-x86_64-1.9.22 kotlin \ + && rm kotlin-native.tar.gz +ENV PATH=$PATH:/opt/kotlin/bin + +RUN ["touch", "Boot.kt"] +RUN ["kotlinc-native", "-p", "library", "Boot.kt"] + +WORKDIR /work/jvm-toxcore-c +COPY lib/ /work/jvm-toxcore-c/lib/ +COPY docker/build-native /work/jvm-toxcore-c/docker/ +RUN ["docker/build-native"] diff --git a/lib/build.gradle.kts b/lib/build.gradle.kts index de800d8ea..95087fa38 100644 --- a/lib/build.gradle.kts +++ b/lib/build.gradle.kts @@ -1,14 +1,5 @@ -/* - * This file was generated by the Gradle 'init' task. - * - * This generated file contains a sample Kotlin library project to get you started. - * For more details on building Java & JVM projects, please refer to https://docs.gradle.org/8.4/userguide/building_java_projects.html in the Gradle documentation. - * This project uses @Incubating APIs which are subject to change. - */ - plugins { - // Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin. - id("org.jetbrains.kotlin.jvm") version "1.9.22" + kotlin("multiplatform") version "1.9.22" id("com.google.protobuf") version "0.9.4" // Apply the java-library plugin for API and implementation separation. @@ -21,10 +12,21 @@ repositories { } dependencies { - implementation("com.google.protobuf:protobuf-java:3.24.4") testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0") } +kotlin { + jvm() + + sourceSets { + val jvmMain by getting { + dependencies { + implementation("com.google.protobuf:protobuf-java:3.24.4") + } + } + } +} + testing { suites { // Configure the built-in test suite diff --git a/lib/src/main/java/im/tox/tox4j/ToxEventListener.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/ToxEventListener.kt similarity index 100% rename from lib/src/main/java/im/tox/tox4j/ToxEventListener.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/ToxEventListener.kt diff --git a/lib/src/main/java/im/tox/tox4j/av/ToxAv.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/av/ToxAv.kt similarity index 99% rename from lib/src/main/java/im/tox/tox4j/av/ToxAv.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/av/ToxAv.kt index 1a1c5a8e1..bdfa93525 100644 --- a/lib/src/main/java/im/tox/tox4j/av/ToxAv.kt +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/av/ToxAv.kt @@ -8,7 +8,6 @@ import im.tox.tox4j.av.data.SamplingRate import im.tox.tox4j.av.enums.ToxavCallControl import im.tox.tox4j.core.ToxCore import im.tox.tox4j.core.data.ToxFriendNumber -import java.io.Closeable /** * Public audio/video API for Tox clients. @@ -28,7 +27,8 @@ import java.io.Closeable * otherwise undefined behaviour occurs. Upon closing of ToxAv instance, all active calls will be * forcibly terminated without notifying peers. */ -interface ToxAv : Closeable { +@kotlin.ExperimentalStdlibApi +interface ToxAv : AutoCloseable { /** * Start new A/V session. There can only be only one session per Tox instance. * diff --git a/lib/src/main/java/im/tox/tox4j/av/callbacks/AudioBitRateCallback.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/av/callbacks/AudioBitRateCallback.kt similarity index 100% rename from lib/src/main/java/im/tox/tox4j/av/callbacks/AudioBitRateCallback.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/av/callbacks/AudioBitRateCallback.kt diff --git a/lib/src/main/java/im/tox/tox4j/av/callbacks/AudioReceiveFrameCallback.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/av/callbacks/AudioReceiveFrameCallback.kt similarity index 100% rename from lib/src/main/java/im/tox/tox4j/av/callbacks/AudioReceiveFrameCallback.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/av/callbacks/AudioReceiveFrameCallback.kt diff --git a/lib/src/main/java/im/tox/tox4j/av/callbacks/CallCallback.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/av/callbacks/CallCallback.kt similarity index 100% rename from lib/src/main/java/im/tox/tox4j/av/callbacks/CallCallback.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/av/callbacks/CallCallback.kt diff --git a/lib/src/main/java/im/tox/tox4j/av/callbacks/CallStateCallback.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/av/callbacks/CallStateCallback.kt similarity index 90% rename from lib/src/main/java/im/tox/tox4j/av/callbacks/CallStateCallback.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/av/callbacks/CallStateCallback.kt index 09a747fff..aef2019d3 100644 --- a/lib/src/main/java/im/tox/tox4j/av/callbacks/CallStateCallback.kt +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/av/callbacks/CallStateCallback.kt @@ -2,7 +2,6 @@ package im.tox.tox4j.av.callbacks import im.tox.tox4j.av.enums.ToxavFriendCallState import im.tox.tox4j.core.data.ToxFriendNumber -import java.util.EnumSet /** Called when the call state changes. */ interface CallStateCallback { @@ -14,7 +13,7 @@ interface CallStateCallback { */ fun callState( friendNumber: ToxFriendNumber, - callState: EnumSet, + callState: Set, state: ToxCoreState, ): ToxCoreState = state } diff --git a/lib/src/main/java/im/tox/tox4j/av/callbacks/ToxAvEventListener.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/av/callbacks/ToxAvEventListener.kt similarity index 100% rename from lib/src/main/java/im/tox/tox4j/av/callbacks/ToxAvEventListener.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/av/callbacks/ToxAvEventListener.kt diff --git a/lib/src/main/java/im/tox/tox4j/av/callbacks/VideoBitRateCallback.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/av/callbacks/VideoBitRateCallback.kt similarity index 100% rename from lib/src/main/java/im/tox/tox4j/av/callbacks/VideoBitRateCallback.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/av/callbacks/VideoBitRateCallback.kt diff --git a/lib/src/main/java/im/tox/tox4j/av/callbacks/VideoReceiveFrameCallback.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/av/callbacks/VideoReceiveFrameCallback.kt similarity index 100% rename from lib/src/main/java/im/tox/tox4j/av/callbacks/VideoReceiveFrameCallback.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/av/callbacks/VideoReceiveFrameCallback.kt diff --git a/lib/src/main/java/im/tox/tox4j/av/data/AudioChannels.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/av/data/AudioChannels.kt similarity index 100% rename from lib/src/main/java/im/tox/tox4j/av/data/AudioChannels.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/av/data/AudioChannels.kt diff --git a/lib/src/main/java/im/tox/tox4j/av/data/AudioLength.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/av/data/AudioLength.kt similarity index 100% rename from lib/src/main/java/im/tox/tox4j/av/data/AudioLength.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/av/data/AudioLength.kt diff --git a/lib/src/main/java/im/tox/tox4j/av/data/BitRate.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/av/data/BitRate.kt similarity index 87% rename from lib/src/main/java/im/tox/tox4j/av/data/BitRate.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/av/data/BitRate.kt index a78f31d09..59991d43b 100644 --- a/lib/src/main/java/im/tox/tox4j/av/data/BitRate.kt +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/av/data/BitRate.kt @@ -1,5 +1,7 @@ package im.tox.tox4j.av.data +import kotlin.jvm.JvmInline + @JvmInline value class BitRate(val value: Int) { companion object { diff --git a/lib/src/main/java/im/tox/tox4j/av/data/Height.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/av/data/Height.kt similarity index 72% rename from lib/src/main/java/im/tox/tox4j/av/data/Height.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/av/data/Height.kt index 722018e15..4b66c21e4 100644 --- a/lib/src/main/java/im/tox/tox4j/av/data/Height.kt +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/av/data/Height.kt @@ -1,3 +1,5 @@ package im.tox.tox4j.av.data +import kotlin.jvm.JvmInline + @JvmInline value class Height(val value: Int) diff --git a/lib/src/main/java/im/tox/tox4j/av/data/SampleCount.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/av/data/SampleCount.kt similarity index 89% rename from lib/src/main/java/im/tox/tox4j/av/data/SampleCount.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/av/data/SampleCount.kt index 8c92801f8..e21e40b22 100644 --- a/lib/src/main/java/im/tox/tox4j/av/data/SampleCount.kt +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/av/data/SampleCount.kt @@ -1,5 +1,7 @@ package im.tox.tox4j.av.data +import kotlin.jvm.JvmInline + @JvmInline value class SampleCount(val value: Int) { constructor( diff --git a/lib/src/main/java/im/tox/tox4j/av/data/SamplingRate.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/av/data/SamplingRate.kt similarity index 100% rename from lib/src/main/java/im/tox/tox4j/av/data/SamplingRate.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/av/data/SamplingRate.kt diff --git a/lib/src/main/java/im/tox/tox4j/av/data/Width.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/av/data/Width.kt similarity index 72% rename from lib/src/main/java/im/tox/tox4j/av/data/Width.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/av/data/Width.kt index b52b16d8a..05ff9d880 100644 --- a/lib/src/main/java/im/tox/tox4j/av/data/Width.kt +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/av/data/Width.kt @@ -1,3 +1,5 @@ package im.tox.tox4j.av.data +import kotlin.jvm.JvmInline + @JvmInline value class Width(val value: Int) diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/av/enums/ToxavCallControl.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/av/enums/ToxavCallControl.kt new file mode 100644 index 000000000..b52cee2aa --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/av/enums/ToxavCallControl.kt @@ -0,0 +1,50 @@ +package im.tox.tox4j.av.enums + +/** + * Call control. + */ +enum class ToxavCallControl { + /** + * Resume a previously paused call. Only valid if the pause was caused by this + * client, if not, this control is ignored. Not valid before the call is + * accepted. + */ + RESUME, + + /** + * Put a call on hold. Not valid before the call is accepted. + */ + PAUSE, + + /** + * Reject a call if it was not answered, yet. Cancel a call after it was + * answered. + */ + CANCEL, + + /** + * Request that the friend stops sending audio. Regardless of the friend's + * compliance, this will cause the {@link + * im.tox.tox4j.av.callbacks.AudioReceiveFrameCallback} event to stop being + * triggered on receiving an audio frame from the friend. + */ + MUTE_AUDIO, + + /** + * Calling this control will notify client to start sending audio again. + */ + UNMUTE_AUDIO, + + /** + * Request that the friend stops sending video. Regardless of the friend's + * compliance, this will cause the {@link + * im.tox.tox4j.av.callbacks.VideoReceiveFrameCallback} event to stop being + * triggered on receiving an video frame from the friend. + */ + HIDE_VIDEO, + + /** + * Calling this control will notify client to start sending video again. + */ + SHOW_VIDEO, +} diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/av/enums/ToxavFriendCallState.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/av/enums/ToxavFriendCallState.kt new file mode 100644 index 000000000..fe5fdd982 --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/av/enums/ToxavFriendCallState.kt @@ -0,0 +1,41 @@ +package im.tox.tox4j.av.enums + +/** + * Call state graph. + */ +enum class ToxavFriendCallState { + /** + * Set by the AV core if an error occurred on the remote end or if friend + * timed out. This is the final state after which no more state + * transitions can occur for the call. This call state will never be triggered + * in combination with other call states. + */ + ERROR, + + /** + * The call has finished. This is the final state after which no more state + * transitions can occur for the call. This call state will never be + * triggered in combination with other call states. + */ + FINISHED, + + /** + * The flag that marks that friend is sending audio. + */ + SENDING_A, + + /** + * The flag that marks that friend is sending video. + */ + SENDING_V, + + /** + * The flag that marks that friend is receiving audio. + */ + ACCEPTING_A, + + /** + * The flag that marks that friend is receiving video. + */ + ACCEPTING_V, +} diff --git a/lib/src/main/java/im/tox/tox4j/av/exceptions/Makefile b/lib/src/commonMain/kotlin/im/tox/tox4j/av/exceptions/Makefile similarity index 100% rename from lib/src/main/java/im/tox/tox4j/av/exceptions/Makefile rename to lib/src/commonMain/kotlin/im/tox/tox4j/av/exceptions/Makefile diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/av/exceptions/ToxavAnswerException.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/av/exceptions/ToxavAnswerException.kt new file mode 100644 index 000000000..48860e383 --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/av/exceptions/ToxavAnswerException.kt @@ -0,0 +1,35 @@ +package im.tox.tox4j.av.exceptions + +import im.tox.tox4j.exceptions.ToxException + +class ToxavAnswerException : ToxException { + enum class Code { + /** + * Failed to initialise codecs for call session. + */ + CODEC_INITIALIZATION, + + /** + * The friend was valid, but they are not currently trying to initiate a call. + * This is also returned if this client is already in a call with the friend. + */ + FRIEND_NOT_CALLING, + + /** + * The friend number did not designate a valid friend. + */ + FRIEND_NOT_FOUND, + + /** + * Audio or video bit rate is invalid. + */ + INVALID_BIT_RATE, + + /** + * Synchronization error occurred. + */ + SYNC, + } + + constructor(code: Code, message: String = "") : super(code, message) +} diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/av/exceptions/ToxavBitRateSetException.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/av/exceptions/ToxavBitRateSetException.kt new file mode 100644 index 000000000..b1c20d544 --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/av/exceptions/ToxavBitRateSetException.kt @@ -0,0 +1,29 @@ +package im.tox.tox4j.av.exceptions + +import im.tox.tox4j.exceptions.ToxException + +class ToxavBitRateSetException : ToxException { + enum class Code { + /** + * The friend_number passed did not designate a valid friend. + */ + FRIEND_NOT_FOUND, + + /** + * This client is currently not in a call with the friend. + */ + FRIEND_NOT_IN_CALL, + + /** + * The bit rate passed was not one of the supported values. + */ + INVALID_BIT_RATE, + + /** + * Synchronization error occurred. + */ + SYNC, + } + + constructor(code: Code, message: String = "") : super(code, message) +} diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/av/exceptions/ToxavCallControlException.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/av/exceptions/ToxavCallControlException.kt new file mode 100644 index 000000000..d0235a8da --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/av/exceptions/ToxavCallControlException.kt @@ -0,0 +1,31 @@ +package im.tox.tox4j.av.exceptions + +import im.tox.tox4j.exceptions.ToxException + +class ToxavCallControlException : ToxException { + enum class Code { + /** + * The friend number did not designate a valid friend. + */ + FRIEND_NOT_FOUND, + + /** + * This client is currently not in a call with the friend. Before the call is + * answered, only CANCEL is a valid control + */ + FRIEND_NOT_IN_CALL, + + /** + * Happens if user tried to pause an already paused call or if trying to + * resume a call that is not paused. + */ + INVALID_TRANSITION, + + /** + * Synchronization error occurred. + */ + SYNC, + } + + constructor(code: Code, message: String = "") : super(code, message) +} diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/av/exceptions/ToxavCallException.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/av/exceptions/ToxavCallException.kt new file mode 100644 index 000000000..2c4f54623 --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/av/exceptions/ToxavCallException.kt @@ -0,0 +1,39 @@ +package im.tox.tox4j.av.exceptions + +import im.tox.tox4j.exceptions.ToxException + +class ToxavCallException : ToxException { + enum class Code { + /** + * Attempted to call a friend while already in an audio or video call with them. + */ + FRIEND_ALREADY_IN_CALL, + + /** + * The friend was valid, but not currently connected. + */ + FRIEND_NOT_CONNECTED, + + /** + * The friend number did not designate a valid friend. + */ + FRIEND_NOT_FOUND, + + /** + * Audio or video bit rate is invalid. + */ + INVALID_BIT_RATE, + + /** + * A memory allocation error occurred. + */ + MALLOC, + + /** + * Synchronization error occurred. + */ + SYNC, + } + + constructor(code: Code, message: String = "") : super(code, message) +} diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/av/exceptions/ToxavNewException.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/av/exceptions/ToxavNewException.kt new file mode 100644 index 000000000..732bc189e --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/av/exceptions/ToxavNewException.kt @@ -0,0 +1,31 @@ +package im.tox.tox4j.av.exceptions + +import im.tox.tox4j.exceptions.JavaOnly +import im.tox.tox4j.exceptions.ToxException + +class ToxavNewException : ToxException { + enum class Code { + /** + * The ToxCore implementation passed was not compatible with this ToxAv implementation. + */ + @JavaOnly INCOMPATIBLE, + + /** + * Memory allocation failure while trying to allocate structures required for + * the A/V session. + */ + MALLOC, + + /** + * Attempted to create a second session for the same Tox instance. + */ + MULTIPLE, + + /** + * One of the arguments to the function was NULL when it was not expected. + */ + NULL, + } + + constructor(code: Code, message: String = "") : super(code, message) +} diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/av/exceptions/ToxavSendFrameException.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/av/exceptions/ToxavSendFrameException.kt new file mode 100644 index 000000000..b88615d73 --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/av/exceptions/ToxavSendFrameException.kt @@ -0,0 +1,47 @@ +package im.tox.tox4j.av.exceptions + +import im.tox.tox4j.exceptions.ToxException + +class ToxavSendFrameException : ToxException { + enum class Code { + /** + * The friend number did not designate a valid friend. + */ + FRIEND_NOT_FOUND, + + /** + * This client is currently not in a call with the friend. + */ + FRIEND_NOT_IN_CALL, + + /** + * One or more of the frame parameters was invalid. E.g. the resolution may be too + * small or too large, or the audio sampling rate may be unsupported. + */ + INVALID, + + /** + * In case of video, one of Y, U, or V was NULL. In case of audio, the samples + * data pointer was NULL. + */ + NULL, + + /** + * Either friend turned off audio or video receiving or we turned off sending + * for the said payload. + */ + PAYLOAD_TYPE_DISABLED, + + /** + * Failed to push frame through rtp interface. + */ + RTP_FAILED, + + /** + * Synchronization error occurred. + */ + SYNC, + } + + constructor(code: Code, message: String = "") : super(code, message) +} diff --git a/lib/src/main/java/im/tox/tox4j/av/exceptions/exceptions.json b/lib/src/commonMain/kotlin/im/tox/tox4j/av/exceptions/exceptions.json similarity index 100% rename from lib/src/main/java/im/tox/tox4j/av/exceptions/exceptions.json rename to lib/src/commonMain/kotlin/im/tox/tox4j/av/exceptions/exceptions.json diff --git a/lib/src/main/java/im/tox/tox4j/core/ToxCore.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/ToxCore.kt similarity index 99% rename from lib/src/main/java/im/tox/tox4j/core/ToxCore.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/ToxCore.kt index b0ddb61aa..e2b823441 100644 --- a/lib/src/main/java/im/tox/tox4j/core/ToxCore.kt +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/ToxCore.kt @@ -1,7 +1,7 @@ package im.tox.tox4j.core -import im.tox.core.network.Port import im.tox.tox4j.core.callbacks.ToxCoreEventListener +import im.tox.tox4j.core.data.Port import im.tox.tox4j.core.data.ToxFileId import im.tox.tox4j.core.data.ToxFilename import im.tox.tox4j.core.data.ToxFriendAddress @@ -18,7 +18,6 @@ import im.tox.tox4j.core.enums.ToxFileControl import im.tox.tox4j.core.enums.ToxMessageType import im.tox.tox4j.core.enums.ToxUserStatus import im.tox.tox4j.core.options.ToxOptions -import java.io.Closeable /** * Interface for a basic wrapper of tox chat functionality. @@ -31,7 +30,8 @@ import java.io.Closeable * the instance before one thread invokes [[ToxCore.close]] on it, or appropriate exception handlers * should be installed in all threads. */ -interface ToxCore : Closeable { +@kotlin.ExperimentalStdlibApi +interface ToxCore : AutoCloseable { /** * Store all information associated with the tox instance to a byte array. * diff --git a/lib/src/main/java/im/tox/tox4j/core/ToxCoreConstants.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/ToxCoreConstants.kt similarity index 100% rename from lib/src/main/java/im/tox/tox4j/core/ToxCoreConstants.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/ToxCoreConstants.kt diff --git a/lib/src/main/java/im/tox/tox4j/core/callbacks/FileChunkRequestCallback.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/callbacks/FileChunkRequestCallback.kt similarity index 100% rename from lib/src/main/java/im/tox/tox4j/core/callbacks/FileChunkRequestCallback.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/callbacks/FileChunkRequestCallback.kt diff --git a/lib/src/main/java/im/tox/tox4j/core/callbacks/FileRecvCallback.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/callbacks/FileRecvCallback.kt similarity index 100% rename from lib/src/main/java/im/tox/tox4j/core/callbacks/FileRecvCallback.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/callbacks/FileRecvCallback.kt diff --git a/lib/src/main/java/im/tox/tox4j/core/callbacks/FileRecvChunkCallback.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/callbacks/FileRecvChunkCallback.kt similarity index 100% rename from lib/src/main/java/im/tox/tox4j/core/callbacks/FileRecvChunkCallback.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/callbacks/FileRecvChunkCallback.kt diff --git a/lib/src/main/java/im/tox/tox4j/core/callbacks/FileRecvControlCallback.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/callbacks/FileRecvControlCallback.kt similarity index 100% rename from lib/src/main/java/im/tox/tox4j/core/callbacks/FileRecvControlCallback.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/callbacks/FileRecvControlCallback.kt diff --git a/lib/src/main/java/im/tox/tox4j/core/callbacks/FriendConnectionStatusCallback.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/callbacks/FriendConnectionStatusCallback.kt similarity index 100% rename from lib/src/main/java/im/tox/tox4j/core/callbacks/FriendConnectionStatusCallback.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/callbacks/FriendConnectionStatusCallback.kt diff --git a/lib/src/main/java/im/tox/tox4j/core/callbacks/FriendLosslessPacketCallback.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/callbacks/FriendLosslessPacketCallback.kt similarity index 100% rename from lib/src/main/java/im/tox/tox4j/core/callbacks/FriendLosslessPacketCallback.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/callbacks/FriendLosslessPacketCallback.kt diff --git a/lib/src/main/java/im/tox/tox4j/core/callbacks/FriendLossyPacketCallback.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/callbacks/FriendLossyPacketCallback.kt similarity index 100% rename from lib/src/main/java/im/tox/tox4j/core/callbacks/FriendLossyPacketCallback.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/callbacks/FriendLossyPacketCallback.kt diff --git a/lib/src/main/java/im/tox/tox4j/core/callbacks/FriendMessageCallback.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/callbacks/FriendMessageCallback.kt similarity index 100% rename from lib/src/main/java/im/tox/tox4j/core/callbacks/FriendMessageCallback.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/callbacks/FriendMessageCallback.kt diff --git a/lib/src/main/java/im/tox/tox4j/core/callbacks/FriendNameCallback.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/callbacks/FriendNameCallback.kt similarity index 100% rename from lib/src/main/java/im/tox/tox4j/core/callbacks/FriendNameCallback.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/callbacks/FriendNameCallback.kt diff --git a/lib/src/main/java/im/tox/tox4j/core/callbacks/FriendReadReceiptCallback.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/callbacks/FriendReadReceiptCallback.kt similarity index 100% rename from lib/src/main/java/im/tox/tox4j/core/callbacks/FriendReadReceiptCallback.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/callbacks/FriendReadReceiptCallback.kt diff --git a/lib/src/main/java/im/tox/tox4j/core/callbacks/FriendRequestCallback.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/callbacks/FriendRequestCallback.kt similarity index 100% rename from lib/src/main/java/im/tox/tox4j/core/callbacks/FriendRequestCallback.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/callbacks/FriendRequestCallback.kt diff --git a/lib/src/main/java/im/tox/tox4j/core/callbacks/FriendStatusCallback.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/callbacks/FriendStatusCallback.kt similarity index 100% rename from lib/src/main/java/im/tox/tox4j/core/callbacks/FriendStatusCallback.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/callbacks/FriendStatusCallback.kt diff --git a/lib/src/main/java/im/tox/tox4j/core/callbacks/FriendStatusMessageCallback.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/callbacks/FriendStatusMessageCallback.kt similarity index 100% rename from lib/src/main/java/im/tox/tox4j/core/callbacks/FriendStatusMessageCallback.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/callbacks/FriendStatusMessageCallback.kt diff --git a/lib/src/main/java/im/tox/tox4j/core/callbacks/FriendTypingCallback.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/callbacks/FriendTypingCallback.kt similarity index 100% rename from lib/src/main/java/im/tox/tox4j/core/callbacks/FriendTypingCallback.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/callbacks/FriendTypingCallback.kt diff --git a/lib/src/main/java/im/tox/tox4j/core/callbacks/SelfConnectionStatusCallback.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/callbacks/SelfConnectionStatusCallback.kt similarity index 100% rename from lib/src/main/java/im/tox/tox4j/core/callbacks/SelfConnectionStatusCallback.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/callbacks/SelfConnectionStatusCallback.kt diff --git a/lib/src/main/java/im/tox/tox4j/core/callbacks/ToxCoreEventAdapter.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/callbacks/ToxCoreEventAdapter.kt similarity index 100% rename from lib/src/main/java/im/tox/tox4j/core/callbacks/ToxCoreEventAdapter.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/callbacks/ToxCoreEventAdapter.kt diff --git a/lib/src/main/java/im/tox/tox4j/core/callbacks/ToxCoreEventListener.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/callbacks/ToxCoreEventListener.kt similarity index 100% rename from lib/src/main/java/im/tox/tox4j/core/callbacks/ToxCoreEventListener.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/callbacks/ToxCoreEventListener.kt diff --git a/lib/src/main/java/im/tox/core/network/Port.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/data/Port.kt similarity index 65% rename from lib/src/main/java/im/tox/core/network/Port.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/data/Port.kt index 0f9120b6f..e45a8f904 100644 --- a/lib/src/main/java/im/tox/core/network/Port.kt +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/data/Port.kt @@ -1,4 +1,6 @@ -package im.tox.core.network +package im.tox.tox4j.core.data + +import kotlin.jvm.JvmInline /** IP_Port stores an IP datastructure with a port. */ @JvmInline value class Port constructor(val value: UShort) diff --git a/lib/src/main/java/im/tox/tox4j/core/data/ToxFileId.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxFileId.kt similarity index 75% rename from lib/src/main/java/im/tox/tox4j/core/data/ToxFileId.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxFileId.kt index db160f09a..906100795 100644 --- a/lib/src/main/java/im/tox/tox4j/core/data/ToxFileId.kt +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxFileId.kt @@ -1,3 +1,5 @@ package im.tox.tox4j.core.data +import kotlin.jvm.JvmInline + @JvmInline value class ToxFileId(val value: ByteArray) diff --git a/lib/src/main/java/im/tox/tox4j/core/data/ToxFilename.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxFilename.kt similarity index 75% rename from lib/src/main/java/im/tox/tox4j/core/data/ToxFilename.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxFilename.kt index 2eb5634df..04260ce9d 100644 --- a/lib/src/main/java/im/tox/tox4j/core/data/ToxFilename.kt +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxFilename.kt @@ -1,3 +1,5 @@ package im.tox.tox4j.core.data +import kotlin.jvm.JvmInline + @JvmInline value class ToxFilename(val value: ByteArray) diff --git a/lib/src/main/java/im/tox/tox4j/core/data/ToxFriendAddress.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxFriendAddress.kt similarity index 76% rename from lib/src/main/java/im/tox/tox4j/core/data/ToxFriendAddress.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxFriendAddress.kt index eb3b0d2f6..1a6b273f0 100644 --- a/lib/src/main/java/im/tox/tox4j/core/data/ToxFriendAddress.kt +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxFriendAddress.kt @@ -1,3 +1,5 @@ package im.tox.tox4j.core.data +import kotlin.jvm.JvmInline + @JvmInline value class ToxFriendAddress(val value: ByteArray) diff --git a/lib/src/main/java/im/tox/tox4j/core/data/ToxFriendMessage.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxFriendMessage.kt similarity index 76% rename from lib/src/main/java/im/tox/tox4j/core/data/ToxFriendMessage.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxFriendMessage.kt index 26549ab73..001fcf6b5 100644 --- a/lib/src/main/java/im/tox/tox4j/core/data/ToxFriendMessage.kt +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxFriendMessage.kt @@ -1,3 +1,5 @@ package im.tox.tox4j.core.data +import kotlin.jvm.JvmInline + @JvmInline value class ToxFriendMessage(val value: ByteArray) diff --git a/lib/src/main/java/im/tox/tox4j/core/data/ToxFriendNumber.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxFriendNumber.kt similarity index 75% rename from lib/src/main/java/im/tox/tox4j/core/data/ToxFriendNumber.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxFriendNumber.kt index fdad58e2e..a095227b0 100644 --- a/lib/src/main/java/im/tox/tox4j/core/data/ToxFriendNumber.kt +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxFriendNumber.kt @@ -1,3 +1,5 @@ package im.tox.tox4j.core.data +import kotlin.jvm.JvmInline + @JvmInline value class ToxFriendNumber(val value: Int) diff --git a/lib/src/main/java/im/tox/tox4j/core/data/ToxFriendRequestMessage.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxFriendRequestMessage.kt similarity index 77% rename from lib/src/main/java/im/tox/tox4j/core/data/ToxFriendRequestMessage.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxFriendRequestMessage.kt index a6256e186..b3a2cd88e 100644 --- a/lib/src/main/java/im/tox/tox4j/core/data/ToxFriendRequestMessage.kt +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxFriendRequestMessage.kt @@ -1,3 +1,5 @@ package im.tox.tox4j.core.data +import kotlin.jvm.JvmInline + @JvmInline value class ToxFriendRequestMessage(val value: ByteArray) diff --git a/lib/src/main/java/im/tox/tox4j/core/data/ToxLosslessPacket.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxLosslessPacket.kt similarity index 76% rename from lib/src/main/java/im/tox/tox4j/core/data/ToxLosslessPacket.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxLosslessPacket.kt index bb5632849..2aa3dcd4c 100644 --- a/lib/src/main/java/im/tox/tox4j/core/data/ToxLosslessPacket.kt +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxLosslessPacket.kt @@ -1,3 +1,5 @@ package im.tox.tox4j.core.data +import kotlin.jvm.JvmInline + @JvmInline value class ToxLosslessPacket(val value: ByteArray) diff --git a/lib/src/main/java/im/tox/tox4j/core/data/ToxLossyPacket.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxLossyPacket.kt similarity index 76% rename from lib/src/main/java/im/tox/tox4j/core/data/ToxLossyPacket.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxLossyPacket.kt index 18527eed9..dbbed5ff5 100644 --- a/lib/src/main/java/im/tox/tox4j/core/data/ToxLossyPacket.kt +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxLossyPacket.kt @@ -1,3 +1,5 @@ package im.tox.tox4j.core.data +import kotlin.jvm.JvmInline + @JvmInline value class ToxLossyPacket(val value: ByteArray) diff --git a/lib/src/main/java/im/tox/tox4j/core/data/ToxNickname.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxNickname.kt similarity index 75% rename from lib/src/main/java/im/tox/tox4j/core/data/ToxNickname.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxNickname.kt index 9ef022474..9190d5454 100644 --- a/lib/src/main/java/im/tox/tox4j/core/data/ToxNickname.kt +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxNickname.kt @@ -1,3 +1,5 @@ package im.tox.tox4j.core.data +import kotlin.jvm.JvmInline + @JvmInline value class ToxNickname(val value: ByteArray) diff --git a/lib/src/main/java/im/tox/tox4j/core/data/ToxPublicKey.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxPublicKey.kt similarity index 75% rename from lib/src/main/java/im/tox/tox4j/core/data/ToxPublicKey.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxPublicKey.kt index 405d27426..25e5bf78b 100644 --- a/lib/src/main/java/im/tox/tox4j/core/data/ToxPublicKey.kt +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxPublicKey.kt @@ -1,3 +1,5 @@ package im.tox.tox4j.core.data +import kotlin.jvm.JvmInline + @JvmInline value class ToxPublicKey(val value: ByteArray) diff --git a/lib/src/main/java/im/tox/tox4j/core/data/ToxSecretKey.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxSecretKey.kt similarity index 75% rename from lib/src/main/java/im/tox/tox4j/core/data/ToxSecretKey.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxSecretKey.kt index 7744d4e26..8954d2a44 100644 --- a/lib/src/main/java/im/tox/tox4j/core/data/ToxSecretKey.kt +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxSecretKey.kt @@ -1,3 +1,5 @@ package im.tox.tox4j.core.data +import kotlin.jvm.JvmInline + @JvmInline value class ToxSecretKey(val value: ByteArray) diff --git a/lib/src/main/java/im/tox/tox4j/core/data/ToxStatusMessage.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxStatusMessage.kt similarity index 76% rename from lib/src/main/java/im/tox/tox4j/core/data/ToxStatusMessage.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxStatusMessage.kt index 64c4e5d38..41dc9e79b 100644 --- a/lib/src/main/java/im/tox/tox4j/core/data/ToxStatusMessage.kt +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/data/ToxStatusMessage.kt @@ -1,3 +1,5 @@ package im.tox.tox4j.core.data +import kotlin.jvm.JvmInline + @JvmInline value class ToxStatusMessage(val value: ByteArray) diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/core/enums/ToxConnection.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/enums/ToxConnection.kt new file mode 100644 index 000000000..6ad324cf3 --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/enums/ToxConnection.kt @@ -0,0 +1,27 @@ +package im.tox.tox4j.core.enums + +/** + * Protocols that can be used to connect to the network or friends. + */ +enum class ToxConnection { + /** + * There is no connection. This instance, or the friend the state change is + * about, is now offline. + */ + NONE, + + /** + * A TCP connection has been established. For the own instance, this means it + * is connected through a TCP relay, only. For a friend, this means that the + * connection to that particular friend goes through a TCP relay. + */ + TCP, + + /** + * A UDP connection has been established. For the own instance, this means it + * is able to send UDP packets to DHT nodes, but may still be connected to + * a TCP relay. For a friend, this means that the connection to that + * particular friend was built using direct UDP packets. + */ + UDP, +} diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/core/enums/ToxFileControl.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/enums/ToxFileControl.kt new file mode 100644 index 000000000..42c8bffa5 --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/enums/ToxFileControl.kt @@ -0,0 +1,23 @@ +package im.tox.tox4j.core.enums + +enum class ToxFileControl { + /** + * Sent by the receiving side to accept a file send request. Also sent after a + * {@link #PAUSE} command to continue sending or receiving. + */ + RESUME, + + /** + * Sent by clients to pause the file transfer. The initial state of a file + * transfer is always paused on the receiving side and running on the sending + * side. If both the sending and receiving side pause the transfer, then both + * need to send {@link #RESUME} for the transfer to resume. + */ + PAUSE, + + /** + * Sent by the receiving side to reject a file send request before any other + * commands are sent. Also sent by either side to terminate a file transfer. + */ + CANCEL, +} diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/core/enums/ToxFileKind.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/enums/ToxFileKind.kt new file mode 100644 index 000000000..d59fc8a74 --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/enums/ToxFileKind.kt @@ -0,0 +1,34 @@ +package im.tox.tox4j.core.enums + +object ToxFileKind { + /** + * Arbitrary file data. Clients can choose to handle it based on the file name + * or magic or any other way they choose. + */ + const val DATA = 0 + + /** + * Avatar image data. + * + *

+ * Avatars can be sent at any time the client wishes. Generally, a client will + * send the avatar to a friend when that friend comes online, and to all + * friends when the avatar changed. A client can save some traffic by + * remembering which friend received the updated avatar already and only send + * it if the friend has an out of date avatar. + * + *

+ * Clients who receive avatar send requests can reject it (by sending + * {@link FileControl#CANCEL} before any other controls), or accept it + * (by sending {@link FileControl#RESUME}). + * The file_id of length {@link ToxCryptoConstants#HASH_LENGTH} bytes (same + * length as {@link ToxCoreConstants#FILE_ID_LENGTH}) will contain the hash. + * A client can compare this hash with a saved hash and send + * {@link FileControl#CANCEL} to terminate the avatar transfer if it matches. + * + *

+ * When fileSize is set to 0 in the transfer request it means that the client + * has no avatar. + */ + const val AVATAR = 1 +} diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/core/enums/ToxMessageType.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/enums/ToxMessageType.kt new file mode 100644 index 000000000..ab0c0876e --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/enums/ToxMessageType.kt @@ -0,0 +1,18 @@ +package im.tox.tox4j.core.enums + +/** + * Represents message types for {@link + * im.tox.tox4j.core.ToxCore#friendSendMessage} and group chat messages. + */ +enum class ToxMessageType { + /** + * Normal text message. Similar to PRIVMSG on IRC. + */ + NORMAL, + + /** + * A message describing an user action. This is similar to /me (CTCP ACTION) + * on IRC. + */ + ACTION, +} diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/core/enums/ToxProxyType.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/enums/ToxProxyType.kt new file mode 100644 index 000000000..36aa176ab --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/enums/ToxProxyType.kt @@ -0,0 +1,21 @@ +package im.tox.tox4j.core.enums + +/** + * Type of proxy used to connect to TCP relays. + */ +enum class ToxProxyType { + /** + * Don't use a proxy. + */ + NONE, + + /** + * HTTP proxy using CONNECT. + */ + HTTP, + + /** + * SOCKS proxy for simple socket pipes. + */ + SOCKS5, +} diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/core/enums/ToxSavedataType.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/enums/ToxSavedataType.kt new file mode 100644 index 000000000..11d437ef2 --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/enums/ToxSavedataType.kt @@ -0,0 +1,22 @@ +package im.tox.tox4j.core.enums + +/** + * Type of savedata to create the Tox instance from. + */ +enum class ToxSavedataType { + /** + * No savedata. + */ + NONE, + + /** + * Savedata is one that was obtained from {@link + * im.tox.tox4j.core.ToxCore#getSavedata}. + */ + TOX_SAVE, + + /** + * Savedata is a secret key of length {@link ToxCoreConstants#SecretKeySize}. + */ + SECRET_KEY, +} diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/core/enums/ToxUserStatus.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/enums/ToxUserStatus.kt new file mode 100644 index 000000000..516b35524 --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/enums/ToxUserStatus.kt @@ -0,0 +1,23 @@ +package im.tox.tox4j.core.enums + +/** + * Represents the possible statuses a client can have. + */ +enum class ToxUserStatus { + /** + * User is online and available. + */ + NONE, + + /** + * User is away. Clients can set this e.g. after a user defined + * inactivity time. + */ + AWAY, + + /** + * User is busy. Signals to other clients that this client does not + * currently wish to communicate. + */ + BUSY, +} diff --git a/lib/src/main/java/im/tox/tox4j/core/exceptions/Makefile b/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/Makefile similarity index 100% rename from lib/src/main/java/im/tox/tox4j/core/exceptions/Makefile rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/Makefile diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxBootstrapException.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxBootstrapException.kt new file mode 100644 index 000000000..5c10bc802 --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxBootstrapException.kt @@ -0,0 +1,31 @@ +package im.tox.tox4j.core.exceptions + +import im.tox.tox4j.exceptions.JavaOnly +import im.tox.tox4j.exceptions.ToxException + +class ToxBootstrapException : ToxException { + enum class Code { + /** + * The public key was of invalid length. + */ + @JavaOnly BAD_KEY, + + /** + * The address could not be resolved to an IP address, or the IP address + * passed was invalid. + */ + BAD_HOST, + + /** + * The port passed was invalid. The valid port range is (1, 65535). + */ + BAD_PORT, + + /** + * An argument was null. + */ + NULL, + } + + constructor(code: Code, message: String = "") : super(code, message) +} diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxFileControlException.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxFileControlException.kt new file mode 100644 index 000000000..5d7706708 --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxFileControlException.kt @@ -0,0 +1,45 @@ +package im.tox.tox4j.core.exceptions + +import im.tox.tox4j.exceptions.ToxException + +class ToxFileControlException : ToxException { + enum class Code { + /** + * A {@link ToxFileControl#PAUSE} control was sent, but the file transfer was already paused. + */ + ALREADY_PAUSED, + + /** + * A {@link ToxFileControl#RESUME} control was sent, but the file transfer was paused by the other + * party. Only the party that paused the transfer can resume it. + */ + DENIED, + + /** + * This client is currently not connected to the friend. + */ + FRIEND_NOT_CONNECTED, + + /** + * The friendNumber passed did not designate a valid friend. + */ + FRIEND_NOT_FOUND, + + /** + * No file transfer with the given file number was found for the given friend. + */ + NOT_FOUND, + + /** + * A {@link ToxFileControl#RESUME} control was sent, but the file transfer is running normally. + */ + NOT_PAUSED, + + /** + * An allocation error occurred while increasing the send queue size. + */ + SENDQ, + } + + constructor(code: Code, message: String = "") : super(code, message) +} diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxFileGetException.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxFileGetException.kt new file mode 100644 index 000000000..c15a055ed --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxFileGetException.kt @@ -0,0 +1,24 @@ +package im.tox.tox4j.core.exceptions + +import im.tox.tox4j.exceptions.ToxException + +class ToxFileGetException : ToxException { + enum class Code { + /** + * The friendNumber passed did not designate a valid friend. + */ + FRIEND_NOT_FOUND, + + /** + * No file transfer with the given file number was found for the given friend. + */ + NOT_FOUND, + + /** + * An argument was null. + */ + NULL, + } + + constructor(code: Code, message: String = "") : super(code, message) +} diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxFileSeekException.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxFileSeekException.kt new file mode 100644 index 000000000..e92be391a --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxFileSeekException.kt @@ -0,0 +1,39 @@ +package im.tox.tox4j.core.exceptions + +import im.tox.tox4j.exceptions.ToxException + +class ToxFileSeekException : ToxException { + enum class Code { + /** + * File was not in a state where it could be seeked. + */ + DENIED, + + /** + * This client is currently not connected to the friend. + */ + FRIEND_NOT_CONNECTED, + + /** + * The friendNumber passed did not designate a valid friend. + */ + FRIEND_NOT_FOUND, + + /** + * Seek position was invalid. + */ + INVALID_POSITION, + + /** + * No file transfer with the given file number was found for the given friend. + */ + NOT_FOUND, + + /** + * An allocation error occurred while increasing the send queue size. + */ + SENDQ, + } + + constructor(code: Code, message: String = "") : super(code, message) +} diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxFileSendChunkException.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxFileSendChunkException.kt new file mode 100644 index 000000000..1f1500660 --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxFileSendChunkException.kt @@ -0,0 +1,52 @@ +package im.tox.tox4j.core.exceptions + +import im.tox.tox4j.exceptions.ToxException + +class ToxFileSendChunkException : ToxException { + enum class Code { + /** + * This client is currently not connected to the friend. + */ + FRIEND_NOT_CONNECTED, + + /** + * The friendNumber passed did not designate a valid friend. + */ + FRIEND_NOT_FOUND, + + /** + * Attempted to send more or less data than requested. The requested data size is + * adjusted according to maximum transmission unit and the expected end of + * the file. Trying to send less or more than requested will return this error. + */ + INVALID_LENGTH, + + /** + * No file transfer with the given file number was found for the given friend. + */ + NOT_FOUND, + + /** + * File transfer was found but isn't in a transferring state: (paused, done, + * broken, etc...) (happens only when not called from the request chunk callback). + */ + NOT_TRANSFERRING, + + /** + * An argument was null. + */ + NULL, + + /** + * An allocation error occurred while increasing the send queue size. + */ + SENDQ, + + /** + * Position parameter was wrong. + */ + WRONG_POSITION, + } + + constructor(code: Code, message: String = "") : super(code, message) +} diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxFileSendException.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxFileSendException.kt new file mode 100644 index 000000000..27a21a46b --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxFileSendException.kt @@ -0,0 +1,35 @@ +package im.tox.tox4j.core.exceptions + +import im.tox.tox4j.exceptions.ToxException + +class ToxFileSendException : ToxException { + enum class Code { + /** + * This client is currently not connected to the friend. + */ + FRIEND_NOT_CONNECTED, + + /** + * The friendNumber passed did not designate a valid friend. + */ + FRIEND_NOT_FOUND, + + /** + * Filename length exceeded {@link ToxCoreConstants#MAX_FILENAME_LENGTH} bytes. + */ + NAME_TOO_LONG, + + /** + * An argument was null. + */ + NULL, + + /** + * Too many ongoing transfers. The maximum number of concurrent file transfers + * is 256 per friend per direction (sending and receiving, so 512 total). + */ + TOO_MANY, + } + + constructor(code: Code, message: String = "") : super(code, message) +} diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxFriendAddException.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxFriendAddException.kt new file mode 100644 index 000000000..b65bb9e00 --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxFriendAddException.kt @@ -0,0 +1,52 @@ +package im.tox.tox4j.core.exceptions + +import im.tox.tox4j.exceptions.ToxException + +class ToxFriendAddException : ToxException { + enum class Code { + /** + * A friend request has already been sent, or the address belongs to a friend + * that is already on the friend list. To resend a friend request, first remove + * the friend, and then call addFriend again. + */ + ALREADY_SENT, + + /** + * The friend address checksum failed. + */ + BAD_CHECKSUM, + + /** + * A memory allocation failed when trying to increase the friend list size. + */ + MALLOC, + + /** + * The friend request message was empty. This, and the TOO_LONG code will + * never be returned from {@link ToxCore#addFriendNoRequest}. + */ + NO_MESSAGE, + + /** + * An argument was null. + */ + NULL, + + /** + * The friend address belongs to the sending client. + */ + OWN_KEY, + + /** + * The friend was already on the friend list, but the noSpam value was different. + */ + SET_NEW_NOSPAM, + + /** + * The length of the friend request message exceeded {@link ToxCoreConstants#MAX_FRIEND_REQUEST_LENGTH}. + */ + TOO_LONG, + } + + constructor(code: Code, message: String = "") : super(code, message) +} diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxFriendByPublicKeyException.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxFriendByPublicKeyException.kt new file mode 100644 index 000000000..d211e4391 --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxFriendByPublicKeyException.kt @@ -0,0 +1,19 @@ +package im.tox.tox4j.core.exceptions + +import im.tox.tox4j.exceptions.ToxException + +class ToxFriendByPublicKeyException : ToxException { + enum class Code { + /** + * No friend with the given Public Key exists on the friend list. + */ + NOT_FOUND, + + /** + * An argument was null. + */ + NULL, + } + + constructor(code: Code, message: String = "") : super(code, message) +} diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxFriendCustomPacketException.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxFriendCustomPacketException.kt new file mode 100644 index 000000000..ac6630d0d --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxFriendCustomPacketException.kt @@ -0,0 +1,45 @@ +package im.tox.tox4j.core.exceptions + +import im.tox.tox4j.exceptions.ToxException + +class ToxFriendCustomPacketException : ToxException { + enum class Code { + /** + * Attempted to send an empty packet. + */ + EMPTY, + + /** + * This client is currently not connected to the friend. + */ + FRIEND_NOT_CONNECTED, + + /** + * The friendNumber passed did not designate a valid friend. + */ + FRIEND_NOT_FOUND, + + /** + * The first byte of data was not in the specified range for the packet type. + * This range is 200-254 for lossy, and 160-191 for lossless packets. + */ + INVALID, + + /** + * An argument was null. + */ + NULL, + + /** + * An allocation error occurred while increasing the send queue size. + */ + SENDQ, + + /** + * Packet data length exceeded {@link ToxCoreConstants#MAX_CUSTOM_PACKET_SIZE}. + */ + TOO_LONG, + } + + constructor(code: Code, message: String = "") : super(code, message) +} diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxFriendDeleteException.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxFriendDeleteException.kt new file mode 100644 index 000000000..a0acd5d46 --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxFriendDeleteException.kt @@ -0,0 +1,14 @@ +package im.tox.tox4j.core.exceptions + +import im.tox.tox4j.exceptions.ToxException + +class ToxFriendDeleteException : ToxException { + enum class Code { + /** + * There was no friend with the given friend number. No friends were deleted. + */ + FRIEND_NOT_FOUND, + } + + constructor(code: Code, message: String = "") : super(code, message) +} diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxFriendGetPublicKeyException.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxFriendGetPublicKeyException.kt new file mode 100644 index 000000000..c88a7d42a --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxFriendGetPublicKeyException.kt @@ -0,0 +1,14 @@ +package im.tox.tox4j.core.exceptions + +import im.tox.tox4j.exceptions.ToxException + +class ToxFriendGetPublicKeyException : ToxException { + enum class Code { + /** + * The friendNumber passed did not designate a valid friend. + */ + FRIEND_NOT_FOUND, + } + + constructor(code: Code, message: String = "") : super(code, message) +} diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxFriendSendMessageException.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxFriendSendMessageException.kt new file mode 100644 index 000000000..55847d1f0 --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxFriendSendMessageException.kt @@ -0,0 +1,39 @@ +package im.tox.tox4j.core.exceptions + +import im.tox.tox4j.exceptions.ToxException + +class ToxFriendSendMessageException : ToxException { + enum class Code { + /** + * Attempted to send a zero-length message. + */ + EMPTY, + + /** + * This client is currently not connected to the friend. + */ + FRIEND_NOT_CONNECTED, + + /** + * The friend number did not designate a valid friend. + */ + FRIEND_NOT_FOUND, + + /** + * An argument was null. + */ + NULL, + + /** + * An allocation error occurred while increasing the send queue size. + */ + SENDQ, + + /** + * Message length exceeded {@link ToxCoreConstants#MAX_MESSAGE_LENGTH}. + */ + TOO_LONG, + } + + constructor(code: Code, message: String = "") : super(code, message) +} diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxGetPortException.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxGetPortException.kt new file mode 100644 index 000000000..74dfc7763 --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxGetPortException.kt @@ -0,0 +1,14 @@ +package im.tox.tox4j.core.exceptions + +import im.tox.tox4j.exceptions.ToxException + +class ToxGetPortException : ToxException { + enum class Code { + /** + * The instance was not bound to any port. + */ + NOT_BOUND, + } + + constructor(code: Code, message: String = "") : super(code, message) +} diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxNewException.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxNewException.kt new file mode 100644 index 000000000..d372d34ad --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxNewException.kt @@ -0,0 +1,63 @@ +package im.tox.tox4j.core.exceptions + +import im.tox.tox4j.exceptions.ToxException + +class ToxNewException : ToxException { + enum class Code { + /** + * The data format was invalid. This can happen when loading data that was + * saved by an older version of Tox, or when the data has been corrupted. + * When loading from badly formatted data, some data may have been loaded, + * and the rest is discarded. Passing an invalid length parameter also + * causes this error. + */ + LOAD_BAD_FORMAT, + + /** + * The byte array to be loaded contained an encrypted save. + */ + LOAD_ENCRYPTED, + + /** + * The function was unable to allocate enough memory to store the internal + * structures for the Tox object. + */ + MALLOC, + + /** + * An argument was null. + */ + NULL, + + /** + * The function was unable to bind to a port. This may mean that all ports + * have already been bound, e.g. by other Tox instances, or it may mean + * a permission error. You may be able to gather more information from errno. + */ + PORT_ALLOC, + + /** + * {@link im.tox.tox4j.core.ToxOptions#proxyType} was valid, + * but the {@link im.tox.tox4j.core.ToxOptions#proxyAddress} passed had an invalid format. + */ + PROXY_BAD_HOST, + + /** + * {@link im.tox.tox4j.core.ToxOptions#proxyType} was valid, + * but the {@link im.tox.tox4j.core.ToxOptions#proxyPort} was invalid. + */ + PROXY_BAD_PORT, + + /** + * {@link im.tox.tox4j.core.ToxOptions#proxyType} was invalid. + */ + PROXY_BAD_TYPE, + + /** + * The proxy address passed could not be resolved. + */ + PROXY_NOT_FOUND, + } + + constructor(code: Code, message: String = "") : super(code, message) +} diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxSetInfoException.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxSetInfoException.kt new file mode 100644 index 000000000..f64f8a08d --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxSetInfoException.kt @@ -0,0 +1,19 @@ +package im.tox.tox4j.core.exceptions + +import im.tox.tox4j.exceptions.ToxException + +class ToxSetInfoException : ToxException { + enum class Code { + /** + * An argument was null. + */ + NULL, + + /** + * Information length exceeded maximum permissible size. + */ + TOO_LONG, + } + + constructor(code: Code, message: String = "") : super(code, message) +} diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxSetTypingException.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxSetTypingException.kt new file mode 100644 index 000000000..636977fdc --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/ToxSetTypingException.kt @@ -0,0 +1,14 @@ +package im.tox.tox4j.core.exceptions + +import im.tox.tox4j.exceptions.ToxException + +class ToxSetTypingException : ToxException { + enum class Code { + /** + * The friendNumber passed did not designate a valid friend. + */ + FRIEND_NOT_FOUND, + } + + constructor(code: Code, message: String = "") : super(code, message) +} diff --git a/lib/src/main/java/im/tox/tox4j/core/exceptions/exceptions.json b/lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/exceptions.json similarity index 100% rename from lib/src/main/java/im/tox/tox4j/core/exceptions/exceptions.json rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/exceptions/exceptions.json diff --git a/lib/src/main/java/im/tox/tox4j/core/options/ProxyOptions.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/options/ProxyOptions.kt similarity index 100% rename from lib/src/main/java/im/tox/tox4j/core/options/ProxyOptions.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/options/ProxyOptions.kt diff --git a/lib/src/main/java/im/tox/tox4j/core/options/SaveDataOptions.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/options/SaveDataOptions.kt similarity index 100% rename from lib/src/main/java/im/tox/tox4j/core/options/SaveDataOptions.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/options/SaveDataOptions.kt diff --git a/lib/src/main/java/im/tox/tox4j/core/options/ToxOptions.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/core/options/ToxOptions.kt similarity index 100% rename from lib/src/main/java/im/tox/tox4j/core/options/ToxOptions.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/core/options/ToxOptions.kt diff --git a/lib/src/main/java/im/tox/tox4j/crypto/ToxCrypto.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/crypto/ToxCrypto.kt similarity index 100% rename from lib/src/main/java/im/tox/tox4j/crypto/ToxCrypto.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/crypto/ToxCrypto.kt diff --git a/lib/src/main/java/im/tox/tox4j/crypto/ToxCryptoConstants.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/crypto/ToxCryptoConstants.kt similarity index 100% rename from lib/src/main/java/im/tox/tox4j/crypto/ToxCryptoConstants.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/crypto/ToxCryptoConstants.kt diff --git a/lib/src/main/java/im/tox/tox4j/crypto/exceptions/Makefile b/lib/src/commonMain/kotlin/im/tox/tox4j/crypto/exceptions/Makefile similarity index 100% rename from lib/src/main/java/im/tox/tox4j/crypto/exceptions/Makefile rename to lib/src/commonMain/kotlin/im/tox/tox4j/crypto/exceptions/Makefile diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/crypto/exceptions/ToxDecryptionException.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/crypto/exceptions/ToxDecryptionException.kt new file mode 100644 index 000000000..62609879f --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/crypto/exceptions/ToxDecryptionException.kt @@ -0,0 +1,39 @@ +package im.tox.tox4j.crypto.exceptions + +import im.tox.tox4j.exceptions.ToxException + +class ToxDecryptionException : ToxException { + enum class Code { + /** + * The input data is missing the magic number (i.e. wasn't created by this + * module, or is corrupted) + */ + BAD_FORMAT, + + /** + * The encrypted byte array could not be decrypted. Either the data was + * corrupt or the password/key was incorrect. + */ + FAILED, + + /** + * The input data was shorter than {@link + * ToxCryptoConstants.ENCRYPTION_EXTRA_LENGTH} bytes. + */ + INVALID_LENGTH, + + /** + * The crypto lib was unable to derive a key from the given passphrase, + * which is usually a lack of memory issue. The functions accepting keys + * do not produce this error. + */ + KEY_DERIVATION_FAILED, + + /** + * The key or input data was null or empty. + */ + NULL, + } + + constructor(code: Code, message: String = "") : super(code, message) +} diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/crypto/exceptions/ToxEncryptionException.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/crypto/exceptions/ToxEncryptionException.kt new file mode 100644 index 000000000..e18255ed2 --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/crypto/exceptions/ToxEncryptionException.kt @@ -0,0 +1,26 @@ +package im.tox.tox4j.crypto.exceptions + +import im.tox.tox4j.exceptions.ToxException + +class ToxEncryptionException : ToxException { + enum class Code { + /** + * The encryption itself failed. + */ + FAILED, + + /** + * The crypto lib was unable to derive a key from the given passphrase, + * which is usually a lack of memory issue. The functions accepting keys + * do not produce this error. + */ + KEY_DERIVATION_FAILED, + + /** + * The key or input data was null or empty. + */ + NULL, + } + + constructor(code: Code, message: String = "") : super(code, message) +} diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/crypto/exceptions/ToxGetSaltException.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/crypto/exceptions/ToxGetSaltException.kt new file mode 100644 index 000000000..7f9e8005e --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/crypto/exceptions/ToxGetSaltException.kt @@ -0,0 +1,20 @@ +package im.tox.tox4j.crypto.exceptions + +import im.tox.tox4j.exceptions.ToxException + +class ToxGetSaltException : ToxException { + enum class Code { + /** + * The input data is missing the magic number (i.e. wasn't created by this + * module, or is corrupted) + */ + BAD_FORMAT, + + /** + * The data or salt were null. + */ + NULL, + } + + constructor(code: Code, message: String = "") : super(code, message) +} diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/crypto/exceptions/ToxKeyDerivationException.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/crypto/exceptions/ToxKeyDerivationException.kt new file mode 100644 index 000000000..de5ee7c01 --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/crypto/exceptions/ToxKeyDerivationException.kt @@ -0,0 +1,27 @@ +package im.tox.tox4j.crypto.exceptions + +import im.tox.tox4j.exceptions.JavaOnly +import im.tox.tox4j.exceptions.ToxException + +class ToxKeyDerivationException : ToxException { + enum class Code { + /** + * The salt was of incorrect length. + */ + @JavaOnly INVALID_LENGTH, + + /** + * The crypto lib was unable to derive a key from the given passphrase, + * which is usually a lack of memory issue. The functions accepting keys + * do not produce this error. + */ + FAILED, + + /** + * The passphrase was null or empty. + */ + NULL, + } + + constructor(code: Code, message: String = "") : super(code, message) +} diff --git a/lib/src/main/java/im/tox/tox4j/crypto/exceptions/exceptions.json b/lib/src/commonMain/kotlin/im/tox/tox4j/crypto/exceptions/exceptions.json similarity index 93% rename from lib/src/main/java/im/tox/tox4j/crypto/exceptions/exceptions.json rename to lib/src/commonMain/kotlin/im/tox/tox4j/crypto/exceptions/exceptions.json index e9cb37cc8..ad68d74e7 100644 --- a/lib/src/main/java/im/tox/tox4j/crypto/exceptions/exceptions.json +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/crypto/exceptions/exceptions.json @@ -23,7 +23,8 @@ "Decryption": { "NULL": ["The key or input data was null or empty."], "INVALID_LENGTH": [ - "The input data was shorter than {@link ToxCryptoConstants.ENCRYPTION_EXTRA_LENGTH} bytes." + "The input data was shorter than {@link", + "ToxCryptoConstants.ENCRYPTION_EXTRA_LENGTH} bytes." ], "BAD_FORMAT": [ "The input data is missing the magic number (i.e. wasn't created by this", diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/exceptions/JavaOnly.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/exceptions/JavaOnly.kt new file mode 100644 index 000000000..a67f2f75b --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/exceptions/JavaOnly.kt @@ -0,0 +1,10 @@ +package im.tox.tox4j.exceptions + +/** + * Annotation to mark error codes in Java exception enums as Java-only, so they + * are not emitted as part of the error code conversion fragments in C++ (see + * {@link im.tox.tox4j.impl.jni.codegen.JniErrorCodes}). + */ +@Retention(AnnotationRetention.RUNTIME) +@Target(AnnotationTarget.FIELD) +annotation class JavaOnly diff --git a/lib/src/main/java/im/tox/tox4j/exceptions/ToxException.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/exceptions/ToxException.kt similarity index 100% rename from lib/src/main/java/im/tox/tox4j/exceptions/ToxException.kt rename to lib/src/commonMain/kotlin/im/tox/tox4j/exceptions/ToxException.kt diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/exceptions/ToxKilledException.kt b/lib/src/commonMain/kotlin/im/tox/tox4j/exceptions/ToxKilledException.kt new file mode 100644 index 000000000..620fbbcc4 --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/exceptions/ToxKilledException.kt @@ -0,0 +1,11 @@ +package im.tox.tox4j.exceptions + +/** + * Exception to be thrown when a method is invoked on a tox instance that has + * been closed. + * + * @author Simon Levermann (sonOfRa) + */ +class ToxKilledException : RuntimeException { + constructor(message: String) : super(message) +} diff --git a/lib/src/commonMain/kotlin/im/tox/tox4j/mkexceptions b/lib/src/commonMain/kotlin/im/tox/tox4j/mkexceptions new file mode 100755 index 000000000..1cdf8b6e1 --- /dev/null +++ b/lib/src/commonMain/kotlin/im/tox/tox4j/mkexceptions @@ -0,0 +1,51 @@ +#!/usr/bin/env perl + +use strict; +use warnings FATAL => 'all'; +use utf8; + +use JSON::PP; + +my $data = do { local $/; open my $fh, '<', 'exceptions.json' or die $!; decode_json <$fh> }; + +my $package = $data->[0]; +my $prefix = $data->[1]; +my $exns = $data->[2]; + +for my $type (keys %$exns) { + for (keys %{ $exns->{$type} }) { + my @lines = @{ $exns->{$type}{$_} }; + s/^/ * / for @lines; + $exns->{$type}{$_} = join "\n", @lines; + } +} + +for my $type (keys %$exns) { + open my $fh, '>', "Tox${prefix}${type}Exception.kt" + or die $!; + + my $codes = + join ",\n\n", + map { " /**\n$exns->{$type}{$_}\n */\n $_" } + (sort keys %{ $exns->{$type} }); + + my $JavaOnly = + $codes =~ /\@JavaOnly/ + ? "import im.tox.tox4j.exceptions.JavaOnly\n" + : ""; + + print $fh < = mutableListOf() diff --git a/lib/src/main/java/im/tox/tox4j/av/enums/ToxavCallControl.java b/lib/src/main/java/im/tox/tox4j/av/enums/ToxavCallControl.java deleted file mode 100644 index 5c37d5732..000000000 --- a/lib/src/main/java/im/tox/tox4j/av/enums/ToxavCallControl.java +++ /dev/null @@ -1,50 +0,0 @@ -package im.tox.tox4j.av.enums; - -/** - * Call control. - */ -public enum ToxavCallControl { - /** - * Resume a previously paused call. Only valid if the pause was caused by this - * client, if not, this control is ignored. Not valid before the call is - * accepted. - */ - RESUME, - - /** - * Put a call on hold. Not valid before the call is accepted. - */ - PAUSE, - - /** - * Reject a call if it was not answered, yet. Cancel a call after it was - * answered. - */ - CANCEL, - - /** - * Request that the friend stops sending audio. Regardless of the friend's - * compliance, this will cause the {@link - * im.tox.tox4j.av.callbacks.AudioReceiveFrameCallback} event to stop being - * triggered on receiving an audio frame from the friend. - */ - MUTE_AUDIO, - - /** - * Calling this control will notify client to start sending audio again. - */ - UNMUTE_AUDIO, - - /** - * Request that the friend stops sending video. Regardless of the friend's - * compliance, this will cause the {@link - * im.tox.tox4j.av.callbacks.VideoReceiveFrameCallback} event to stop being - * triggered on receiving an video frame from the friend. - */ - HIDE_VIDEO, - - /** - * Calling this control will notify client to start sending video again. - */ - SHOW_VIDEO, -} diff --git a/lib/src/main/java/im/tox/tox4j/av/enums/ToxavFriendCallState.java b/lib/src/main/java/im/tox/tox4j/av/enums/ToxavFriendCallState.java deleted file mode 100644 index cf5de6e99..000000000 --- a/lib/src/main/java/im/tox/tox4j/av/enums/ToxavFriendCallState.java +++ /dev/null @@ -1,41 +0,0 @@ -package im.tox.tox4j.av.enums; - -/** - * Call state graph. - */ -public enum ToxavFriendCallState { - /** - * Set by the AV core if an error occurred on the remote end or if friend - * timed out. This is the final state after which no more state - * transitions can occur for the call. This call state will never be triggered - * in combination with other call states. - */ - ERROR, - - /** - * The call has finished. This is the final state after which no more state - * transitions can occur for the call. This call state will never be - * triggered in combination with other call states. - */ - FINISHED, - - /** - * The flag that marks that friend is sending audio. - */ - SENDING_A, - - /** - * The flag that marks that friend is sending video. - */ - SENDING_V, - - /** - * The flag that marks that friend is receiving audio. - */ - ACCEPTING_A, - - /** - * The flag that marks that friend is receiving video. - */ - ACCEPTING_V, -} diff --git a/lib/src/main/java/im/tox/tox4j/av/exceptions/ToxavAnswerException.java b/lib/src/main/java/im/tox/tox4j/av/exceptions/ToxavAnswerException.java deleted file mode 100644 index 7fb0669dc..000000000 --- a/lib/src/main/java/im/tox/tox4j/av/exceptions/ToxavAnswerException.java +++ /dev/null @@ -1,38 +0,0 @@ -package im.tox.tox4j.av.exceptions; - -import im.tox.tox4j.exceptions.ToxException; - -public final class ToxavAnswerException extends ToxException { - public enum Code { - /** - * Failed to initialise codecs for call session. - */ - CODEC_INITIALIZATION, - /** - * The friend was valid, but they are not currently trying to initiate a - * call. This is also returned if this client is already in a call with the - * friend. - */ - FRIEND_NOT_CALLING, - /** - * The friend number did not designate a valid friend. - */ - FRIEND_NOT_FOUND, - /** - * Audio or video bit rate is invalid. - */ - INVALID_BIT_RATE, - /** - * Synchronization error occurred. - */ - SYNC, - } - - public ToxavAnswerException(Code code) { - this(code, ""); - } - - public ToxavAnswerException(Code code, String message) { - super(code, message); - } -} diff --git a/lib/src/main/java/im/tox/tox4j/av/exceptions/ToxavBitRateSetException.java b/lib/src/main/java/im/tox/tox4j/av/exceptions/ToxavBitRateSetException.java deleted file mode 100644 index 36b93da6c..000000000 --- a/lib/src/main/java/im/tox/tox4j/av/exceptions/ToxavBitRateSetException.java +++ /dev/null @@ -1,32 +0,0 @@ -package im.tox.tox4j.av.exceptions; - -import im.tox.tox4j.exceptions.ToxException; - -public final class ToxavBitRateSetException extends ToxException { - public enum Code { - /** - * The friend_number passed did not designate a valid friend. - */ - FRIEND_NOT_FOUND, - /** - * This client is currently not in a call with the friend. - */ - FRIEND_NOT_IN_CALL, - /** - * The bit rate passed was not one of the supported values. - */ - INVALID_BIT_RATE, - /** - * Synchronization error occurred. - */ - SYNC, - } - - public ToxavBitRateSetException(Code code) { - this(code, ""); - } - - public ToxavBitRateSetException(Code code, String message) { - super(code, message); - } -} diff --git a/lib/src/main/java/im/tox/tox4j/av/exceptions/ToxavCallControlException.java b/lib/src/main/java/im/tox/tox4j/av/exceptions/ToxavCallControlException.java deleted file mode 100644 index 25adbdc60..000000000 --- a/lib/src/main/java/im/tox/tox4j/av/exceptions/ToxavCallControlException.java +++ /dev/null @@ -1,34 +0,0 @@ -package im.tox.tox4j.av.exceptions; - -import im.tox.tox4j.exceptions.ToxException; - -public final class ToxavCallControlException extends ToxException { - public enum Code { - /** - * The friend number did not designate a valid friend. - */ - FRIEND_NOT_FOUND, - /** - * This client is currently not in a call with the friend. Before the call - * is answered, only CANCEL is a valid control - */ - FRIEND_NOT_IN_CALL, - /** - * Happens if user tried to pause an already paused call or if trying to - * resume a call that is not paused. - */ - INVALID_TRANSITION, - /** - * Synchronization error occurred. - */ - SYNC, - } - - public ToxavCallControlException(Code code) { - this(code, ""); - } - - public ToxavCallControlException(Code code, String message) { - super(code, message); - } -} diff --git a/lib/src/main/java/im/tox/tox4j/av/exceptions/ToxavCallException.java b/lib/src/main/java/im/tox/tox4j/av/exceptions/ToxavCallException.java deleted file mode 100644 index 8671e33ca..000000000 --- a/lib/src/main/java/im/tox/tox4j/av/exceptions/ToxavCallException.java +++ /dev/null @@ -1,41 +0,0 @@ -package im.tox.tox4j.av.exceptions; - -import im.tox.tox4j.exceptions.ToxException; - -public final class ToxavCallException extends ToxException { - public enum Code { - /** - * Attempted to call a friend while already in an audio or video call with - * them. - */ - FRIEND_ALREADY_IN_CALL, - /** - * The friend was valid, but not currently connected. - */ - FRIEND_NOT_CONNECTED, - /** - * The friend number did not designate a valid friend. - */ - FRIEND_NOT_FOUND, - /** - * Audio or video bit rate is invalid. - */ - INVALID_BIT_RATE, - /** - * A memory allocation error occurred. - */ - MALLOC, - /** - * Synchronization error occurred. - */ - SYNC, - } - - public ToxavCallException(Code code) { - this(code, ""); - } - - public ToxavCallException(Code code, String message) { - super(code, message); - } -} diff --git a/lib/src/main/java/im/tox/tox4j/av/exceptions/ToxavNewException.java b/lib/src/main/java/im/tox/tox4j/av/exceptions/ToxavNewException.java deleted file mode 100644 index 2debd0284..000000000 --- a/lib/src/main/java/im/tox/tox4j/av/exceptions/ToxavNewException.java +++ /dev/null @@ -1,35 +0,0 @@ -package im.tox.tox4j.av.exceptions; - -import im.tox.tox4j.exceptions.JavaOnly; -import im.tox.tox4j.exceptions.ToxException; - -public final class ToxavNewException extends ToxException { - public enum Code { - /** - * The ToxCore implementation passed was not compatible with this ToxAv - * implementation. - */ - @JavaOnly INCOMPATIBLE, - /** - * Memory allocation failure while trying to allocate structures required - * for the A/V session. - */ - MALLOC, - /** - * Attempted to create a second session for the same Tox instance. - */ - MULTIPLE, - /** - * One of the arguments to the function was NULL when it was not expected. - */ - NULL, - } - - public ToxavNewException(Code code) { - this(code, ""); - } - - public ToxavNewException(Code code, String message) { - super(code, message); - } -} diff --git a/lib/src/main/java/im/tox/tox4j/av/exceptions/ToxavSendFrameException.java b/lib/src/main/java/im/tox/tox4j/av/exceptions/ToxavSendFrameException.java deleted file mode 100644 index 8f83b78d6..000000000 --- a/lib/src/main/java/im/tox/tox4j/av/exceptions/ToxavSendFrameException.java +++ /dev/null @@ -1,47 +0,0 @@ -package im.tox.tox4j.av.exceptions; - -import im.tox.tox4j.exceptions.ToxException; - -public final class ToxavSendFrameException extends ToxException { - public enum Code { - /** - * The friend number did not designate a valid friend. - */ - FRIEND_NOT_FOUND, - /** - * This client is currently not in a call with the friend. - */ - FRIEND_NOT_IN_CALL, - /** - * One or more of the frame parameters was invalid. E.g. the resolution may - * be too small or too large, or the audio sampling rate may be unsupported. - */ - INVALID, - /** - * In case of video, one of Y, U, or V was NULL. In case of audio, the - * samples data pointer was NULL. - */ - NULL, - /** - * Either friend turned off audio or video receiving or we turned off - * sending for the said payload. - */ - PAYLOAD_TYPE_DISABLED, - /** - * Failed to push frame through rtp interface. - */ - RTP_FAILED, - /** - * Synchronization error occurred. - */ - SYNC, - } - - public ToxavSendFrameException(Code code) { - this(code, ""); - } - - public ToxavSendFrameException(Code code, String message) { - super(code, message); - } -} diff --git a/lib/src/main/java/im/tox/tox4j/core/enums/ToxConnection.java b/lib/src/main/java/im/tox/tox4j/core/enums/ToxConnection.java deleted file mode 100644 index 76668b12c..000000000 --- a/lib/src/main/java/im/tox/tox4j/core/enums/ToxConnection.java +++ /dev/null @@ -1,25 +0,0 @@ -package im.tox.tox4j.core.enums; - -/** - * Protocols that can be used to connect to the network or friends. - */ -public enum ToxConnection { - /** - * There is no connection. This instance, or the friend the state change is - * about, is now offline. - */ - NONE, - /** - * A TCP connection has been established. For the own instance, this means it - * is connected through a TCP relay, only. For a friend, this means that the - * connection to that particular friend goes through a TCP relay. - */ - TCP, - /** - * A UDP connection has been established. For the own instance, this means it - * is able to send UDP packets to DHT nodes, but may still be connected to - * a TCP relay. For a friend, this means that the connection to that - * particular friend was built using direct UDP packets. - */ - UDP, -} diff --git a/lib/src/main/java/im/tox/tox4j/core/enums/ToxFileControl.java b/lib/src/main/java/im/tox/tox4j/core/enums/ToxFileControl.java deleted file mode 100644 index 37e82197f..000000000 --- a/lib/src/main/java/im/tox/tox4j/core/enums/ToxFileControl.java +++ /dev/null @@ -1,21 +0,0 @@ -package im.tox.tox4j.core.enums; - -public enum ToxFileControl { - /** - * Sent by the receiving side to accept a file send request. Also sent after a - * {@link #PAUSE} command to continue sending or receiving. - */ - RESUME, - /** - * Sent by clients to pause the file transfer. The initial state of a file - * transfer is always paused on the receiving side and running on the sending - * side. If both the sending and receiving side pause the transfer, then both - * need to send {@link #RESUME} for the transfer to resume. - */ - PAUSE, - /** - * Sent by the receiving side to reject a file send request before any other - * commands are sent. Also sent by either side to terminate a file transfer. - */ - CANCEL, -} diff --git a/lib/src/main/java/im/tox/tox4j/core/enums/ToxFileKind.java b/lib/src/main/java/im/tox/tox4j/core/enums/ToxFileKind.java deleted file mode 100644 index ce68e81cd..000000000 --- a/lib/src/main/java/im/tox/tox4j/core/enums/ToxFileKind.java +++ /dev/null @@ -1,33 +0,0 @@ -package im.tox.tox4j.core.enums; - -public final class ToxFileKind { - /** - * Arbitrary file data. Clients can choose to handle it based on the file name - * or magic or any other way they choose. - */ - public static final int DATA = 0; - /** - * Avatar image data. - * - *

- * Avatars can be sent at any time the client wishes. Generally, a client will - * send the avatar to a friend when that friend comes online, and to all - * friends when the avatar changed. A client can save some traffic by - * remembering which friend received the updated avatar already and only send - * it if the friend has an out of date avatar. - * - *

- * Clients who receive avatar send requests can reject it (by sending - * {@link FileControl#CANCEL} before any other controls), or accept it - * (by sending {@link FileControl#RESUME}). - * The file_id of length {@link ToxCryptoConstants#HASH_LENGTH} bytes (same - * length as {@link ToxCoreConstants#FILE_ID_LENGTH}) will contain the hash. - * A client can compare this hash with a saved hash and send - * {@link FileControl#CANCEL} to terminate the avatar transfer if it matches. - * - *

- * When fileSize is set to 0 in the transfer request it means that the client - * has no avatar. - */ - public static final int AVATAR = 1; -} diff --git a/lib/src/main/java/im/tox/tox4j/core/enums/ToxMessageType.java b/lib/src/main/java/im/tox/tox4j/core/enums/ToxMessageType.java deleted file mode 100644 index ab401229f..000000000 --- a/lib/src/main/java/im/tox/tox4j/core/enums/ToxMessageType.java +++ /dev/null @@ -1,17 +0,0 @@ -package im.tox.tox4j.core.enums; - -/** - * Represents message types for {@link - * im.tox.tox4j.core.ToxCore#friendSendMessage} and group chat messages. - */ -public enum ToxMessageType { - /** - * Normal text message. Similar to PRIVMSG on IRC. - */ - NORMAL, - /** - * A message describing an user action. This is similar to /me (CTCP ACTION) - * on IRC. - */ - ACTION, -} diff --git a/lib/src/main/java/im/tox/tox4j/core/enums/ToxProxyType.java b/lib/src/main/java/im/tox/tox4j/core/enums/ToxProxyType.java deleted file mode 100644 index cadfa4786..000000000 --- a/lib/src/main/java/im/tox/tox4j/core/enums/ToxProxyType.java +++ /dev/null @@ -1,19 +0,0 @@ -package im.tox.tox4j.core.enums; - -/** - * Type of proxy used to connect to TCP relays. - */ -public enum ToxProxyType { - /** - * Don't use a proxy. - */ - NONE, - /** - * HTTP proxy using CONNECT. - */ - HTTP, - /** - * SOCKS proxy for simple socket pipes. - */ - SOCKS5, -} diff --git a/lib/src/main/java/im/tox/tox4j/core/enums/ToxSavedataType.java b/lib/src/main/java/im/tox/tox4j/core/enums/ToxSavedataType.java deleted file mode 100644 index 1a3a4d789..000000000 --- a/lib/src/main/java/im/tox/tox4j/core/enums/ToxSavedataType.java +++ /dev/null @@ -1,20 +0,0 @@ -package im.tox.tox4j.core.enums; - -/** - * Type of savedata to create the Tox instance from. - */ -public enum ToxSavedataType { - /** - * No savedata. - */ - NONE, - /** - * Savedata is one that was obtained from {@link - * im.tox.tox4j.core.ToxCore#getSavedata}. - */ - TOX_SAVE, - /** - * Savedata is a secret key of length {@link ToxCoreConstants#SecretKeySize}. - */ - SECRET_KEY, -} diff --git a/lib/src/main/java/im/tox/tox4j/core/enums/ToxUserStatus.java b/lib/src/main/java/im/tox/tox4j/core/enums/ToxUserStatus.java deleted file mode 100644 index c6464dc82..000000000 --- a/lib/src/main/java/im/tox/tox4j/core/enums/ToxUserStatus.java +++ /dev/null @@ -1,21 +0,0 @@ -package im.tox.tox4j.core.enums; - -/** - * Represents the possible statuses a client can have. - */ -public enum ToxUserStatus { - /** - * User is online and available. - */ - NONE, - /** - * User is away. Clients can set this e.g. after a user defined - * inactivity time. - */ - AWAY, - /** - * User is busy. Signals to other clients that this client does not - * currently wish to communicate. - */ - BUSY, -} diff --git a/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxBootstrapException.java b/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxBootstrapException.java deleted file mode 100644 index 4f96907c6..000000000 --- a/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxBootstrapException.java +++ /dev/null @@ -1,34 +0,0 @@ -package im.tox.tox4j.core.exceptions; - -import im.tox.tox4j.exceptions.JavaOnly; -import im.tox.tox4j.exceptions.ToxException; - -public final class ToxBootstrapException extends ToxException { - public enum Code { - /** - * The public key was of invalid length. - */ - @JavaOnly BAD_KEY, - /** - * The address could not be resolved to an IP address, or the IP address - * passed was invalid. - */ - BAD_HOST, - /** - * The port passed was invalid. The valid port range is (1, 65535). - */ - BAD_PORT, - /** - * An argument was null. - */ - NULL, - } - - public ToxBootstrapException(Code code) { - this(code, ""); - } - - public ToxBootstrapException(Code code, String message) { - super(code, message); - } -} diff --git a/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxFileControlException.java b/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxFileControlException.java deleted file mode 100644 index a43134218..000000000 --- a/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxFileControlException.java +++ /dev/null @@ -1,49 +0,0 @@ -package im.tox.tox4j.core.exceptions; - -import im.tox.tox4j.exceptions.ToxException; - -public final class ToxFileControlException extends ToxException { - public enum Code { - /** - * A {@link ToxFileControl#PAUSE} control was sent, but the file transfer - * was already paused. - */ - ALREADY_PAUSED, - /** - * A {@link ToxFileControl#RESUME} control was sent, but the file transfer - * was paused by the other party. Only the party that paused the transfer - * can resume it. - */ - DENIED, - /** - * This client is currently not connected to the friend. - */ - FRIEND_NOT_CONNECTED, - /** - * The friendNumber passed did not designate a valid friend. - */ - FRIEND_NOT_FOUND, - /** - * No file transfer with the given file number was found for the given - * friend. - */ - NOT_FOUND, - /** - * A {@link ToxFileControl#RESUME} control was sent, but the file transfer - * is running normally. - */ - NOT_PAUSED, - /** - * An allocation error occurred while increasing the send queue size. - */ - SENDQ, - } - - public ToxFileControlException(Code code) { - this(code, ""); - } - - public ToxFileControlException(Code code, String message) { - super(code, message); - } -} diff --git a/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxFileGetException.java b/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxFileGetException.java deleted file mode 100644 index 35f199224..000000000 --- a/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxFileGetException.java +++ /dev/null @@ -1,29 +0,0 @@ -package im.tox.tox4j.core.exceptions; - -import im.tox.tox4j.exceptions.ToxException; - -public final class ToxFileGetException extends ToxException { - public enum Code { - /** - * The friendNumber passed did not designate a valid friend. - */ - FRIEND_NOT_FOUND, - /** - * No file transfer with the given file number was found for the given - * friend. - */ - NOT_FOUND, - /** - * An argument was null. - */ - NULL, - } - - public ToxFileGetException(Code code) { - this(code, ""); - } - - public ToxFileGetException(Code code, String message) { - super(code, message); - } -} diff --git a/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxFileSeekException.java b/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxFileSeekException.java deleted file mode 100644 index 9950c8c6b..000000000 --- a/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxFileSeekException.java +++ /dev/null @@ -1,41 +0,0 @@ -package im.tox.tox4j.core.exceptions; - -import im.tox.tox4j.exceptions.ToxException; - -public final class ToxFileSeekException extends ToxException { - public enum Code { - /** - * File was not in a state where it could be seeked. - */ - DENIED, - /** - * This client is currently not connected to the friend. - */ - FRIEND_NOT_CONNECTED, - /** - * The friendNumber passed did not designate a valid friend. - */ - FRIEND_NOT_FOUND, - /** - * Seek position was invalid. - */ - INVALID_POSITION, - /** - * No file transfer with the given file number was found for the given - * friend. - */ - NOT_FOUND, - /** - * An allocation error occurred while increasing the send queue size. - */ - SENDQ, - } - - public ToxFileSeekException(Code code) { - this(code, ""); - } - - public ToxFileSeekException(Code code, String message) { - super(code, message); - } -} diff --git a/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxFileSendChunkException.java b/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxFileSendChunkException.java deleted file mode 100644 index 43f90aea1..000000000 --- a/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxFileSendChunkException.java +++ /dev/null @@ -1,54 +0,0 @@ -package im.tox.tox4j.core.exceptions; - -import im.tox.tox4j.exceptions.ToxException; - -public final class ToxFileSendChunkException extends ToxException { - public enum Code { - /** - * This client is currently not connected to the friend. - */ - FRIEND_NOT_CONNECTED, - /** - * The friendNumber passed did not designate a valid friend. - */ - FRIEND_NOT_FOUND, - /** - * Attempted to send more or less data than requested. The requested data - * size is adjusted according to maximum transmission unit and the expected - * end of the file. Trying to send less or more than requested will return - * this error. - */ - INVALID_LENGTH, - /** - * No file transfer with the given file number was found for the given - * friend. - */ - NOT_FOUND, - /** - * File transfer was found but isn't in a transferring state: (paused, done, - * broken, etc...) (happens only when not called from the request chunk - * callback). - */ - NOT_TRANSFERRING, - /** - * An argument was null. - */ - NULL, - /** - * An allocation error occurred while increasing the send queue size. - */ - SENDQ, - /** - * Position parameter was wrong. - */ - WRONG_POSITION, - } - - public ToxFileSendChunkException(Code code) { - this(code, ""); - } - - public ToxFileSendChunkException(Code code, String message) { - super(code, message); - } -} diff --git a/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxFileSendException.java b/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxFileSendException.java deleted file mode 100644 index 23b54fcc1..000000000 --- a/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxFileSendException.java +++ /dev/null @@ -1,39 +0,0 @@ -package im.tox.tox4j.core.exceptions; - -import im.tox.tox4j.exceptions.ToxException; - -public final class ToxFileSendException extends ToxException { - public enum Code { - /** - * This client is currently not connected to the friend. - */ - FRIEND_NOT_CONNECTED, - /** - * The friendNumber passed did not designate a valid friend. - */ - FRIEND_NOT_FOUND, - /** - * Filename length exceeded {@link ToxCoreConstants#MAX_FILENAME_LENGTH} - * bytes. - */ - NAME_TOO_LONG, - /** - * An argument was null. - */ - NULL, - /** - * Too many ongoing transfers. The maximum number of concurrent file - * transfers is 256 per friend per direction (sending and receiving, so 512 - * total). - */ - TOO_MANY, - } - - public ToxFileSendException(Code code) { - this(code, ""); - } - - public ToxFileSendException(Code code, String message) { - super(code, message); - } -} diff --git a/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxFriendAddException.java b/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxFriendAddException.java deleted file mode 100644 index 17e350471..000000000 --- a/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxFriendAddException.java +++ /dev/null @@ -1,53 +0,0 @@ -package im.tox.tox4j.core.exceptions; - -import im.tox.tox4j.exceptions.ToxException; - -public final class ToxFriendAddException extends ToxException { - public enum Code { - /** - * A friend request has already been sent, or the address belongs to a - * friend that is already on the friend list. To resend a friend request, - * first remove the friend, and then call addFriend again. - */ - ALREADY_SENT, - /** - * The friend address checksum failed. - */ - BAD_CHECKSUM, - /** - * A memory allocation failed when trying to increase the friend list size. - */ - MALLOC, - /** - * The friend request message was empty. This, and the TOO_LONG code will - * never be returned from {@link ToxCore#addFriendNoRequest}. - */ - NO_MESSAGE, - /** - * An argument was null. - */ - NULL, - /** - * The friend address belongs to the sending client. - */ - OWN_KEY, - /** - * The friend was already on the friend list, but the noSpam value was - * different. - */ - SET_NEW_NOSPAM, - /** - * The length of the friend request message exceeded {@link - * ToxCoreConstants#MAX_FRIEND_REQUEST_LENGTH}. - */ - TOO_LONG, - } - - public ToxFriendAddException(Code code) { - this(code, ""); - } - - public ToxFriendAddException(Code code, String message) { - super(code, message); - } -} diff --git a/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxFriendByPublicKeyException.java b/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxFriendByPublicKeyException.java deleted file mode 100644 index e9ea80716..000000000 --- a/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxFriendByPublicKeyException.java +++ /dev/null @@ -1,24 +0,0 @@ -package im.tox.tox4j.core.exceptions; - -import im.tox.tox4j.exceptions.ToxException; - -public final class ToxFriendByPublicKeyException extends ToxException { - public enum Code { - /** - * No friend with the given Public Key exists on the friend list. - */ - NOT_FOUND, - /** - * An argument was null. - */ - NULL, - } - - public ToxFriendByPublicKeyException(Code code) { - this(code, ""); - } - - public ToxFriendByPublicKeyException(Code code, String message) { - super(code, message); - } -} diff --git a/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxFriendCustomPacketException.java b/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxFriendCustomPacketException.java deleted file mode 100644 index 68b72cffc..000000000 --- a/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxFriendCustomPacketException.java +++ /dev/null @@ -1,46 +0,0 @@ -package im.tox.tox4j.core.exceptions; - -import im.tox.tox4j.exceptions.ToxException; - -public final class ToxFriendCustomPacketException extends ToxException { - public enum Code { - /** - * Attempted to send an empty packet. - */ - EMPTY, - /** - * This client is currently not connected to the friend. - */ - FRIEND_NOT_CONNECTED, - /** - * The friendNumber passed did not designate a valid friend. - */ - FRIEND_NOT_FOUND, - /** - * The first byte of data was not in the specified range for the packet - * type. This range is 200-254 for lossy, and 160-191 for lossless packets. - */ - INVALID, - /** - * An argument was null. - */ - NULL, - /** - * An allocation error occurred while increasing the send queue size. - */ - SENDQ, - /** - * Packet data length exceeded {@link - * ToxCoreConstants#MAX_CUSTOM_PACKET_SIZE}. - */ - TOO_LONG, - } - - public ToxFriendCustomPacketException(Code code) { - this(code, ""); - } - - public ToxFriendCustomPacketException(Code code, String message) { - super(code, message); - } -} diff --git a/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxFriendDeleteException.java b/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxFriendDeleteException.java deleted file mode 100644 index 0d1af68b8..000000000 --- a/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxFriendDeleteException.java +++ /dev/null @@ -1,21 +0,0 @@ -package im.tox.tox4j.core.exceptions; - -import im.tox.tox4j.exceptions.ToxException; - -public final class ToxFriendDeleteException extends ToxException { - public enum Code { - /** - * There was no friend with the given friend number. No friends were - * deleted. - */ - FRIEND_NOT_FOUND, - } - - public ToxFriendDeleteException(Code code) { - this(code, ""); - } - - public ToxFriendDeleteException(Code code, String message) { - super(code, message); - } -} diff --git a/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxFriendGetPublicKeyException.java b/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxFriendGetPublicKeyException.java deleted file mode 100644 index ec808864d..000000000 --- a/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxFriendGetPublicKeyException.java +++ /dev/null @@ -1,20 +0,0 @@ -package im.tox.tox4j.core.exceptions; - -import im.tox.tox4j.exceptions.ToxException; - -public final class ToxFriendGetPublicKeyException extends ToxException { - public enum Code { - /** - * The friendNumber passed did not designate a valid friend. - */ - FRIEND_NOT_FOUND, - } - - public ToxFriendGetPublicKeyException(Code code) { - this(code, ""); - } - - public ToxFriendGetPublicKeyException(Code code, String message) { - super(code, message); - } -} diff --git a/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxFriendSendMessageException.java b/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxFriendSendMessageException.java deleted file mode 100644 index 4fdcfe3b9..000000000 --- a/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxFriendSendMessageException.java +++ /dev/null @@ -1,40 +0,0 @@ -package im.tox.tox4j.core.exceptions; - -import im.tox.tox4j.exceptions.ToxException; - -public final class ToxFriendSendMessageException extends ToxException { - public enum Code { - /** - * Attempted to send a zero-length message. - */ - EMPTY, - /** - * This client is currently not connected to the friend. - */ - FRIEND_NOT_CONNECTED, - /** - * The friend number did not designate a valid friend. - */ - FRIEND_NOT_FOUND, - /** - * An argument was null. - */ - NULL, - /** - * An allocation error occurred while increasing the send queue size. - */ - SENDQ, - /** - * Message length exceeded {@link ToxCoreConstants#MAX_MESSAGE_LENGTH}. - */ - TOO_LONG, - } - - public ToxFriendSendMessageException(Code code) { - this(code, ""); - } - - public ToxFriendSendMessageException(Code code, String message) { - super(code, message); - } -} diff --git a/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxGetPortException.java b/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxGetPortException.java deleted file mode 100644 index 256f472fb..000000000 --- a/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxGetPortException.java +++ /dev/null @@ -1,20 +0,0 @@ -package im.tox.tox4j.core.exceptions; - -import im.tox.tox4j.exceptions.ToxException; - -public final class ToxGetPortException extends ToxException { - public enum Code { - /** - * The instance was not bound to any port. - */ - NOT_BOUND, - } - - public ToxGetPortException(Code code) { - this(code, ""); - } - - public ToxGetPortException(Code code, String message) { - super(code, message); - } -} diff --git a/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxNewException.java b/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxNewException.java deleted file mode 100644 index 2c23b11c0..000000000 --- a/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxNewException.java +++ /dev/null @@ -1,63 +0,0 @@ -package im.tox.tox4j.core.exceptions; - -import im.tox.tox4j.exceptions.ToxException; - -public final class ToxNewException extends ToxException { - public enum Code { - /** - * The data format was invalid. This can happen when loading data that was - * saved by an older version of Tox, or when the data has been corrupted. - * When loading from badly formatted data, some data may have been loaded, - * and the rest is discarded. Passing an invalid length parameter also - * causes this error. - */ - LOAD_BAD_FORMAT, - /** - * The byte array to be loaded contained an encrypted save. - */ - LOAD_ENCRYPTED, - /** - * The function was unable to allocate enough memory to store the internal - * structures for the Tox object. - */ - MALLOC, - /** - * An argument was null. - */ - NULL, - /** - * The function was unable to bind to a port. This may mean that all ports - * have already been bound, e.g. by other Tox instances, or it may mean - * a permission error. You may be able to gather more information from - * errno. - */ - PORT_ALLOC, - /** - * {@link im.tox.tox4j.core.ToxOptions#proxyType} was valid, - * but the {@link im.tox.tox4j.core.ToxOptions#proxyAddress} passed had an - * invalid format. - */ - PROXY_BAD_HOST, - /** - * {@link im.tox.tox4j.core.ToxOptions#proxyType} was valid, - * but the {@link im.tox.tox4j.core.ToxOptions#proxyPort} was invalid. - */ - PROXY_BAD_PORT, - /** - * {@link im.tox.tox4j.core.ToxOptions#proxyType} was invalid. - */ - PROXY_BAD_TYPE, - /** - * The proxy address passed could not be resolved. - */ - PROXY_NOT_FOUND, - } - - public ToxNewException(Code code) { - this(code, ""); - } - - public ToxNewException(Code code, String message) { - super(code, message); - } -} diff --git a/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxSetInfoException.java b/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxSetInfoException.java deleted file mode 100644 index 89845271b..000000000 --- a/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxSetInfoException.java +++ /dev/null @@ -1,24 +0,0 @@ -package im.tox.tox4j.core.exceptions; - -import im.tox.tox4j.exceptions.ToxException; - -public final class ToxSetInfoException extends ToxException { - public enum Code { - /** - * An argument was null. - */ - NULL, - /** - * Information length exceeded maximum permissible size. - */ - TOO_LONG, - } - - public ToxSetInfoException(Code code) { - this(code, ""); - } - - public ToxSetInfoException(Code code, String message) { - super(code, message); - } -} diff --git a/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxSetTypingException.java b/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxSetTypingException.java deleted file mode 100644 index 6328ba198..000000000 --- a/lib/src/main/java/im/tox/tox4j/core/exceptions/ToxSetTypingException.java +++ /dev/null @@ -1,20 +0,0 @@ -package im.tox.tox4j.core.exceptions; - -import im.tox.tox4j.exceptions.ToxException; - -public final class ToxSetTypingException extends ToxException { - public enum Code { - /** - * The friendNumber passed did not designate a valid friend. - */ - FRIEND_NOT_FOUND, - } - - public ToxSetTypingException(Code code) { - this(code, ""); - } - - public ToxSetTypingException(Code code, String message) { - super(code, message); - } -} diff --git a/lib/src/main/java/im/tox/tox4j/crypto/exceptions/ToxDecryptionException.java b/lib/src/main/java/im/tox/tox4j/crypto/exceptions/ToxDecryptionException.java deleted file mode 100644 index a3304b3bb..000000000 --- a/lib/src/main/java/im/tox/tox4j/crypto/exceptions/ToxDecryptionException.java +++ /dev/null @@ -1,41 +0,0 @@ -package im.tox.tox4j.crypto.exceptions; - -import im.tox.tox4j.exceptions.ToxException; - -public final class ToxDecryptionException extends ToxException { - public enum Code { - /** - * The input data is missing the magic number (i.e. wasn't created by this - * module, or is corrupted) - */ - BAD_FORMAT, - /** - * The encrypted byte array could not be decrypted. Either the data was - * corrupt or the password/key was incorrect. - */ - FAILED, - /** - * The input data was shorter than {@link - * ToxCryptoConstants.ENCRYPTION_EXTRA_LENGTH} bytes. - */ - INVALID_LENGTH, - /** - * The crypto lib was unable to derive a key from the given passphrase, - * which is usually a lack of memory issue. The functions accepting keys - * do not produce this error. - */ - KEY_DERIVATION_FAILED, - /** - * The key or input data was null or empty. - */ - NULL, - } - - public ToxDecryptionException(Code code) { - this(code, ""); - } - - public ToxDecryptionException(Code code, String message) { - super(code, message); - } -} diff --git a/lib/src/main/java/im/tox/tox4j/crypto/exceptions/ToxEncryptionException.java b/lib/src/main/java/im/tox/tox4j/crypto/exceptions/ToxEncryptionException.java deleted file mode 100644 index bf0ff894e..000000000 --- a/lib/src/main/java/im/tox/tox4j/crypto/exceptions/ToxEncryptionException.java +++ /dev/null @@ -1,30 +0,0 @@ -package im.tox.tox4j.crypto.exceptions; - -import im.tox.tox4j.exceptions.ToxException; - -public final class ToxEncryptionException extends ToxException { - public enum Code { - /** - * The encryption itself failed. - */ - FAILED, - /** - * The crypto lib was unable to derive a key from the given passphrase, - * which is usually a lack of memory issue. The functions accepting keys - * do not produce this error. - */ - KEY_DERIVATION_FAILED, - /** - * The key or input data was null or empty. - */ - NULL, - } - - public ToxEncryptionException(Code code) { - this(code, ""); - } - - public ToxEncryptionException(Code code, String message) { - super(code, message); - } -} diff --git a/lib/src/main/java/im/tox/tox4j/crypto/exceptions/ToxGetSaltException.java b/lib/src/main/java/im/tox/tox4j/crypto/exceptions/ToxGetSaltException.java deleted file mode 100644 index 7e631b47d..000000000 --- a/lib/src/main/java/im/tox/tox4j/crypto/exceptions/ToxGetSaltException.java +++ /dev/null @@ -1,25 +0,0 @@ -package im.tox.tox4j.crypto.exceptions; - -import im.tox.tox4j.exceptions.ToxException; - -public final class ToxGetSaltException extends ToxException { - public enum Code { - /** - * The input data is missing the magic number (i.e. wasn't created by this - * module, or is corrupted) - */ - BAD_FORMAT, - /** - * The data or salt were null. - */ - NULL, - } - - public ToxGetSaltException(Code code) { - this(code, ""); - } - - public ToxGetSaltException(Code code, String message) { - super(code, message); - } -} diff --git a/lib/src/main/java/im/tox/tox4j/crypto/exceptions/ToxKeyDerivationException.java b/lib/src/main/java/im/tox/tox4j/crypto/exceptions/ToxKeyDerivationException.java deleted file mode 100644 index 00e03d1b6..000000000 --- a/lib/src/main/java/im/tox/tox4j/crypto/exceptions/ToxKeyDerivationException.java +++ /dev/null @@ -1,31 +0,0 @@ -package im.tox.tox4j.crypto.exceptions; - -import im.tox.tox4j.exceptions.JavaOnly; -import im.tox.tox4j.exceptions.ToxException; - -public final class ToxKeyDerivationException extends ToxException { - public enum Code { - /** - * The salt was of incorrect length. - */ - @JavaOnly INVALID_LENGTH, - /** - * The crypto lib was unable to derive a key from the given passphrase, - * which is usually a lack of memory issue. The functions accepting keys - * do not produce this error. - */ - FAILED, - /** - * The passphrase was null or empty. - */ - NULL, - } - - public ToxKeyDerivationException(Code code) { - this(code, ""); - } - - public ToxKeyDerivationException(Code code, String message) { - super(code, message); - } -} diff --git a/lib/src/main/java/im/tox/tox4j/exceptions/JavaOnly.java b/lib/src/main/java/im/tox/tox4j/exceptions/JavaOnly.java deleted file mode 100644 index 1da5c3670..000000000 --- a/lib/src/main/java/im/tox/tox4j/exceptions/JavaOnly.java +++ /dev/null @@ -1,20 +0,0 @@ -package im.tox.tox4j.exceptions; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotation to mark error codes in Java exception enums as Java-only, so they - * are not emitted as part of the error code conversion fragments in C++ (see - * {@link im.tox.tox4j.impl.jni.codegen.JniErrorCodes}). - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface JavaOnly { - /** - * This is just here so the annotation is retained at runtime. - */ - String value() default ""; -} diff --git a/lib/src/main/java/im/tox/tox4j/exceptions/ToxKilledException.java b/lib/src/main/java/im/tox/tox4j/exceptions/ToxKilledException.java deleted file mode 100644 index 3212a9ce6..000000000 --- a/lib/src/main/java/im/tox/tox4j/exceptions/ToxKilledException.java +++ /dev/null @@ -1,15 +0,0 @@ -package im.tox.tox4j.exceptions; - -import org.jetbrains.annotations.NotNull; - -/** - * Exception to be thrown when a method is invoked on a tox instance that has - * been closed. - * - * @author Simon Levermann (sonOfRa) - */ -public final class ToxKilledException extends RuntimeException { - public ToxKilledException(@NotNull String message) { - super(message); - } -} diff --git a/lib/src/main/java/im/tox/tox4j/mkexceptions b/lib/src/main/java/im/tox/tox4j/mkexceptions deleted file mode 100755 index d2a49bdfe..000000000 --- a/lib/src/main/java/im/tox/tox4j/mkexceptions +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env perl - -use strict; -use warnings FATAL => 'all'; -use utf8; - -use JSON::PP; - -my $data = do { local $/; open my $fh, '<', 'exceptions.json' or die $!; decode_json <$fh> }; - -my $package = $data->[0]; -my $prefix = $data->[1]; -my $exns = $data->[2]; - -for my $type (keys %$exns) { - for (keys %{ $exns->{$type} }) { - my @lines = @{ $exns->{$type}{$_} }; - s/^/ * / for @lines; - $exns->{$type}{$_} = join "\n", @lines; - } -} - -for my $type (keys %$exns) { - open my $fh, '>', "Tox${prefix}${type}Exception.java" - or die $!; - - my $codes = - join ",\n", - map { " /**\n$exns->{$type}{$_}\n */\n $_" } - (sort keys %{ $exns->{$type} }); - - my $JavaOnly = - $codes =~ /\@JavaOnly/ - ? "import im.tox.tox4j.exceptions.JavaOnly;\n" - : ""; - - print $fh <