Skip to content
Snippets Groups Projects
Verified Commit e6e10d12 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Split code into modules, implement early parts for later module usage

parent cb0a2970
Branches
No related tags found
1 merge request!2Draft: Jetpack compose rewrite
Pipeline #570 failed
Showing
with 212 additions and 41 deletions
......@@ -60,6 +60,8 @@ dependencies {
implementation("org.threeten", "threetenbp", "1.4.0")
implementation(project(":protocol"))
implementation("io.coil-kt", "coil", "1.1.1")
implementation("dev.chrisbanes.accompanist", "accompanist-coil", "0.5.0")
......
......@@ -17,7 +17,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.quasseldroid.protocol.io
package de.kuschku.libquassel.protocol.io
import de.kuschku.quasseldroid.util.TlsInfo
import kotlinx.coroutines.Dispatchers
......@@ -68,7 +68,7 @@ class CoroutineChannel {
this.channel.write(buffer)
}
suspend fun write(chainedBuffer: ChainedByteBuffer) {
suspend fun write(chainedBuffer: de.kuschku.libquassel.protocol.io.ChainedByteBuffer) {
for (buffer in chainedBuffer.buffers()) {
write(buffer)
}
......
......@@ -17,7 +17,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.quasseldroid.protocol.io
package de.kuschku.libquassel.protocol.io
import java.io.OutputStream
import java.util.zip.DeflaterOutputStream
......
......@@ -17,7 +17,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.quasseldroid.protocol.io
package de.kuschku.libquassel.protocol.io
import android.util.Log
import java.io.InputStream
......
......@@ -17,7 +17,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.quasseldroid.protocol.io
package de.kuschku.libquassel.protocol.io
import de.kuschku.quasseldroid.util.TlsInfo
import java.io.Flushable
......
......@@ -17,7 +17,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.quasseldroid.protocol.io
package de.kuschku.libquassel.protocol.io
import java.io.OutputStream
import java.nio.ByteBuffer
......
package de.kuschku.quasseldroid
import de.kuschku.quasseldroid.protocol.io.ChainedByteBuffer
import de.kuschku.quasseldroid.protocol.serializers.primitive.IntSerializer
import de.kuschku.quasseldroid.protocol.serializers.primitive.ProtocolInfoSerializer
import de.kuschku.quasseldroid.protocol.serializers.primitive.UIntSerializer
import de.kuschku.quasseldroid.protocol.io.CoroutineChannel
import de.kuschku.libquassel.protocol.io.ChainedByteBuffer
import de.kuschku.libquassel.protocol.serializers.primitive.IntSerializer
import de.kuschku.libquassel.protocol.serializers.primitive.ProtocolInfoSerializer
import de.kuschku.libquassel.protocol.serializers.primitive.UIntSerializer
import de.kuschku.libquassel.protocol.io.CoroutineChannel
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Test
......@@ -45,7 +45,7 @@ class ExampleUnitTest {
runBlocking {
val sizeBuffer = ByteBuffer.allocateDirect(4)
val sendBuffer = ChainedByteBuffer(direct = true)
val sendBuffer = de.kuschku.libquassel.protocol.io.ChainedByteBuffer(direct = true)
val channel = CoroutineChannel()
channel.connect(InetSocketAddress("kuschku.de", 4242))
val readBuffer = ByteBuffer.allocateDirect(4)
......
plugins {
kotlin("jvm")
}
dependencies {
implementation(kotlin("stdlib"))
testImplementation("junit", "junit", "4.13.1")
}
/*
* Quasseldroid - Quassel client for Android
*
* Copyright (c) 2021 Janne Mareike Koschinski
* Copyright (c) 2021 The Quassel Project
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.bitflags
interface Flag<T> {
val value: T
}
/*
* Quasseldroid - Quassel client for Android
*
* Copyright (c) 2021 Janne Mareike Koschinski
* Copyright (c) 2021 The Quassel Project
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.bitflags
interface Flags<T, U : Flag<T>> {
operator fun get(value: T): U?
fun all(): Collection<U>
}
......@@ -17,51 +17,46 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.quasseldroid.protocol
package de.kuschku.bitflags
import kotlin.experimental.or
interface Flag<T> {
val value: T
}
@JvmName("toByteFlag")
fun Set<Flag<Byte>>.toFlag(): Byte = fold(0.toByte()) { acc, el ->
fun Set<Flag<Byte>>?.toBits(): Byte = this?.fold(0.toByte()) { acc, el ->
acc or el.value
}
} ?: 0.toByte()
@JvmName("toUByteFlag")
fun Set<Flag<UByte>>.toFlag(): UByte = fold(0.toUByte()) { acc, el ->
fun Set<Flag<UByte>>?.toBits(): UByte = this?.fold(0.toUByte()) { acc, el ->
acc or el.value
}
} ?: 0.toUByte()
@JvmName("toShortFlag")
fun Set<Flag<Short>>.toFlag(): Short = fold(0.toShort()) { acc, el ->
fun Set<Flag<Short>>?.toBits(): Short = this?.fold(0.toShort()) { acc, el ->
acc or el.value
}
} ?: 0.toShort()
@JvmName("toUShortFlag")
fun Set<Flag<UShort>>.toFlag(): UShort = fold(0.toUShort()) { acc, el ->
fun Set<Flag<UShort>>?.toBits(): UShort = this?.fold(0.toUShort()) { acc, el ->
acc or el.value
}
} ?: 0.toUShort()
@JvmName("toIntFlag")
fun Set<Flag<Int>>.toFlag(): Int = fold(0) { acc, el ->
fun Set<Flag<Int>>?.toBits(): Int = this?.fold(0) { acc, el ->
acc or el.value
}
} ?: 0
@JvmName("toUIntFlag")
fun Set<Flag<UInt>>.toFlag(): UInt = fold(0.toUInt()) { acc, el ->
fun Set<Flag<UInt>>?.toBits(): UInt = this?.fold(0.toUInt()) { acc, el ->
acc or el.value
}
} ?: 0u
@JvmName("toLongFlag")
fun Set<Flag<Long>>.toFlag(): Long = fold(0.toLong()) { acc, el ->
fun Set<Flag<Long>>?.toBits(): Long = this?.fold(0.toLong()) { acc, el ->
acc or el.value
}
} ?: 0L
@JvmName("toULongFlag")
fun Set<Flag<ULong>>.toFlag(): ULong = fold(0.toULong()) { acc, el ->
fun Set<Flag<ULong>>?.toBits(): ULong = this?.fold(0.toULong()) { acc, el ->
acc or el.value
}
} ?: 0uL
/*
* Quasseldroid - Quassel client for Android
*
* Copyright (c) 2021 Janne Mareike Koschinski
* Copyright (c) 2021 The Quassel Project
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.bitflags
import java.util.*
inline fun <reified T : Enum<T>> List<T>.toEnumSet(): EnumSet<T> =
if (this.isEmpty()) EnumSet.noneOf(T::class.java)
else EnumSet.of(this.first(), *this.subList(1, this.size).toTypedArray())
/*
* Quasseldroid - Quassel client for Android
*
* Copyright (c) 2021 Janne Mareike Koschinski
* Copyright (c) 2021 The Quassel Project
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.bitflags
import java.util.*
import kotlin.experimental.and
inline fun <reified T> Flags<Byte, T>.toFlag(value: Byte?): EnumSet<T> where T: Flag<Byte>, T: Enum<T> {
if (value == null) return emptyList<T>().toEnumSet()
return this.all().filter { (value and it.value) != 0.toByte() }.toEnumSet()
}
inline fun <reified T> Flags<UByte, T>.toFlag(value: UByte?): EnumSet<T> where T: Flag<UByte>, T: Enum<T> {
if (value == null) return emptyList<T>().toEnumSet()
return this.all().filter { (value and it.value) != 0.toUByte() }.toEnumSet()
}
inline fun <reified T> Flags<Short, T>.toFlag(value: Short?): EnumSet<T> where T: Flag<Short>, T: Enum<T> {
if (value == null) return emptyList<T>().toEnumSet()
return this.all().filter { (value and it.value) != 0.toShort() }.toEnumSet()
}
inline fun <reified T> Flags<UShort, T>.toFlag(value: UShort?): EnumSet<T> where T: Flag<UShort>, T: Enum<T> {
if (value == null) return emptyList<T>().toEnumSet()
return this.all().filter { (value and it.value) != 0.toUShort() }.toEnumSet()
}
inline fun <reified T> Flags<Int, T>.toFlag(value: Int?): EnumSet<T> where T: Flag<Int>, T: Enum<T> {
if (value == null) return emptyList<T>().toEnumSet()
return this.all().filter { (value and it.value) != 0 }.toEnumSet()
}
inline fun <reified T> Flags<UInt, T>.toFlag(value: UInt?): EnumSet<T> where T: Flag<UInt>, T: Enum<T> {
if (value == null) return emptyList<T>().toEnumSet()
return this.all().filter { (value and it.value) != 0u }.toEnumSet()
}
inline fun <reified T> Flags<Long, T>.toFlag(value: Long?): EnumSet<T> where T: Flag<Long>, T: Enum<T> {
if (value == null) return emptyList<T>().toEnumSet()
return this.all().filter { (value and it.value) != 0L }.toEnumSet()
}
inline fun <reified T> Flags<ULong, T>.toFlag(value: ULong?): EnumSet<T> where T: Flag<ULong>, T: Enum<T> {
if (value == null) return emptyList<T>().toEnumSet()
return this.all().filter { (value and it.value) != 0uL }.toEnumSet()
}
......@@ -16,3 +16,9 @@
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
buildscript {
dependencies {
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.21'
}
}
plugins {
kotlin("jvm")
}
dependencies {
implementation(kotlin("stdlib"))
api(project(":bitflags"))
testImplementation("junit", "junit", "4.13.1")
}
......@@ -17,7 +17,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.quasseldroid
package de.kuschku.libquassel.protocol.connection
data class ProtocolInfo(
val flags: UByte,
......
......@@ -17,7 +17,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.quasseldroid.protocol
package de.kuschku.libquassel.protocol.features
inline class ExtendedFeatureName(
val name: String,
......@@ -64,5 +64,5 @@ enum class ExtendedFeature {
/** CoreInfo dynamically updated using signals */
SyncedCoreInfo;
fun name(): ExtendedFeatureName = ExtendedFeatureName(name)
fun feature(): ExtendedFeatureName = ExtendedFeatureName(name)
}
......@@ -17,7 +17,10 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.quasseldroid.protocol
package de.kuschku.libquassel.protocol.features
import de.kuschku.bitflags.Flag
import de.kuschku.bitflags.Flags
/**
* A list of features that are optional in core and/or client, but need runtime checking
......@@ -55,4 +58,12 @@ enum class LegacyFeature(override val value: UInt): Flag<UInt> {
RemoteDisconnect(0x4000u),
/** Transmit features as list of strings */
ExtendedFeatures(0x8000u);
companion object : Flags<UInt, LegacyFeature> {
private val values = values().associateBy(LegacyFeature::value)
override fun get(value: UInt) = values[value]
override fun all() = values.values
}
}
typealias LegacyFeatures = Set<LegacyFeature>
......@@ -17,7 +17,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.quasseldroid.protocol.io
package de.kuschku.libquassel.protocol.io
import java.nio.ByteBuffer
import java.util.*
......
/*
* Quasseldroid 1 Quassel client for Android
* Quasseldroid - Quassel client for Android
*
* Copyright (c) 2021 Janne Mareike Koschinski
* Copyright (c) 2021 The Quassel Project
......@@ -17,7 +17,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.quasseldroid.protocol.io
package de.kuschku.libquassel.protocol.io
import java.nio.ByteBuffer
import java.nio.CharBuffer
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment