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

Implement RPC stubs for quassel

parent 5a67f989
No related branches found
No related tags found
No related merge requests found
/*
* libquassel
* Copyright (c) 2021 Janne Mareike Koschinski
* Copyright (c) 2021 The Quassel Project
*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at https://mozilla.org/MPL/2.0/.
*/
package de.justjanne.libquassel.state.protocol
import de.justjanne.libquassel.annotations.ProtocolSide
import de.justjanne.libquassel.annotations.SyncedCall
import de.justjanne.libquassel.annotations.SyncedObject
import de.justjanne.libquassel.protocol.models.BufferInfo
import de.justjanne.libquassel.protocol.models.Message
import de.justjanne.libquassel.protocol.models.NetworkInfo
import de.justjanne.libquassel.protocol.models.ids.IdentityId
import de.justjanne.libquassel.protocol.models.ids.NetworkId
import de.justjanne.libquassel.protocol.models.types.QtType
import de.justjanne.libquassel.protocol.models.types.QuasselType
import de.justjanne.libquassel.protocol.variant.QVariantMap
import de.justjanne.libquassel.protocol.variant.qVariant
import java.nio.ByteBuffer
@SyncedObject(name = "RpcHandler")
interface RpcHandlerProtocol : SyncableProtocol {
@SyncedCall(name = "__objectRenamed__", target = ProtocolSide.CLIENT)
fun objectRenamed(classname: ByteBuffer, newName: String?, oldName: String?) {
rpc(
target = ProtocolSide.CLIENT,
"__objectRenamed__",
qVariant(classname, QtType.QByteArray),
qVariant(newName, QtType.QString),
qVariant(oldName, QtType.QString)
)
}
@SyncedCall(name = "2displayMsg(Message)", target = ProtocolSide.CLIENT)
fun displayMsg(message: Message) {
rpc(
target = ProtocolSide.CLIENT,
"2displayMsg(Message)",
qVariant(message, QuasselType.Message)
)
}
@SyncedCall(name = "2displayStatusMsg(QString,QString)", target = ProtocolSide.CLIENT)
fun displayStatusMsg(net: String?, msg: String?) {
rpc(
target = ProtocolSide.CLIENT,
"2displayStatusMsg(QString,QString)",
qVariant(net, QtType.QString),
qVariant(msg, QtType.QString)
)
}
@SyncedCall(name = "2bufferInfoUpdated(BufferInfo)", target = ProtocolSide.CLIENT)
fun bufferInfoUpdated(bufferInfo: BufferInfo) {
rpc(
target = ProtocolSide.CLIENT,
"2bufferInfoUpdated(BufferInfo)",
qVariant(bufferInfo, QuasselType.BufferInfo)
)
}
@SyncedCall(name = "2identityCreated(Identity)", target = ProtocolSide.CLIENT)
fun identityCreated(identity: IdentityProtocol) {
rpc(
target = ProtocolSide.CLIENT,
"2identityCreated(Identity)",
qVariant(identity, QuasselType.Identity)
)
}
@SyncedCall(name = "2identityRemoved(IdentityId)", target = ProtocolSide.CLIENT)
fun identityRemoved(identityId: IdentityId) {
rpc(
target = ProtocolSide.CLIENT,
"2identityRemoved(IdentityId)",
qVariant(identityId, QuasselType.IdentityId)
)
}
@SyncedCall(name = "2networkCreated(NetworkId)", target = ProtocolSide.CLIENT)
fun networkCreated(networkId: NetworkId) {
rpc(
target = ProtocolSide.CLIENT,
"2networkCreated(NetworkId)",
qVariant(networkId, QuasselType.NetworkId)
)
}
@SyncedCall(name = "2networkRemoved(NetworkId)", target = ProtocolSide.CLIENT)
fun networkRemoved(networkId: NetworkId) {
rpc(
target = ProtocolSide.CLIENT,
"2networkRemoved(NetworkId)",
qVariant(networkId, QuasselType.NetworkId)
)
}
@SyncedCall(name = "2passwordChanged(PeerPtr,bool)", target = ProtocolSide.CLIENT)
fun passwordChanged(peer: ULong, success: Boolean) {
rpc(
target = ProtocolSide.CLIENT,
"2passwordChanged(PeerPtr,bool)",
qVariant(peer, QuasselType.PeerPtr),
qVariant(success, QtType.Bool)
)
}
@SyncedCall(name = "2disconnectFromCore()", target = ProtocolSide.CLIENT)
fun disconnectFromCore() {
rpc(
target = ProtocolSide.CLIENT,
"2disconnectFromCore()",
)
}
@SyncedCall(name = "2createIdentity(Identity,QVariantMap)", target = ProtocolSide.CORE)
fun createIdentity(identity: IdentityProtocol, additional: QVariantMap) {
rpc(
target = ProtocolSide.CORE,
"2createIdentity(Identity,QVariantMap)",
qVariant(identity, QuasselType.Identity),
qVariant(additional, QtType.QVariantMap),
)
}
@SyncedCall(name = "2removeIdentity(IdentityId)", target = ProtocolSide.CORE)
fun removeIdentity(identityId: IdentityId) {
rpc(
target = ProtocolSide.CORE,
"2removeIdentity(IdentityId)",
qVariant(identityId, QuasselType.IdentityId),
)
}
@SyncedCall(name = "2createNetwork(NetworkInfo,QStringList)", target = ProtocolSide.CORE)
fun createNetwork(networkInfo: NetworkInfo, channels: List<String>) {
rpc(
target = ProtocolSide.CORE,
"2createNetwork(NetworkInfo,QStringList)",
qVariant(networkInfo, QuasselType.NetworkInfo),
qVariant(channels, QtType.QStringList),
)
}
@SyncedCall(name = "2removeNetwork(NetworkId)", target = ProtocolSide.CORE)
fun removeNetwork(networkId: NetworkId) {
rpc(
target = ProtocolSide.CORE,
"2removeNetwork(NetworkId)",
qVariant(networkId, QuasselType.NetworkId),
)
}
@SyncedCall(name = "2changePassword(PeerPtr,QString,QString,QString)", target = ProtocolSide.CORE)
fun changePassword(peerPtr: ULong, user: String?, old: String?, new: String?) {
rpc(
target = ProtocolSide.CORE,
"2changePassword(PeerPtr,QString,QString,QString)",
qVariant(peerPtr, QuasselType.PeerPtr),
qVariant(user, QtType.QString),
qVariant(old, QtType.QString),
qVariant(new, QtType.QString)
)
}
@SyncedCall(name = "2kickClient(int)", target = ProtocolSide.CORE)
fun requestKickClient(id: Int) {
rpc(
target = ProtocolSide.CORE,
"2kickClient(int)",
qVariant(id, QtType.Int)
)
}
@SyncedCall(name = "2sendInput(BufferInfo,QString)", target = ProtocolSide.CORE)
fun sendInput(bufferInfo: BufferInfo, message: String?) {
rpc(
target = ProtocolSide.CORE,
"2sendInput(BufferInfo,QString)",
qVariant(bufferInfo, QuasselType.BufferInfo),
qVariant(message, QtType.QString)
)
}
}
/*
* libquassel
* Copyright (c) 2021 Janne Mareike Koschinski
* Copyright (c) 2021 The Quassel Project
*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at https://mozilla.org/MPL/2.0/.
*/
package de.justjanne.libquassel.state.protocol
import de.justjanne.libquassel.annotations.ProtocolSide
import de.justjanne.libquassel.protocol.models.SignalProxyMessage
import de.justjanne.libquassel.protocol.variant.QVariantList
interface SignalProxy {
val protocolSide: ProtocolSide
fun sync(
target: ProtocolSide,
className: String,
objectName: String,
function: String,
arguments: QVariantList
) {
if (target != protocolSide) {
emit(
SignalProxyMessage.Sync(
className,
objectName,
function,
arguments
)
)
}
}
fun rpc(
target: ProtocolSide,
function: String,
arguments: QVariantList
) {
if (target != protocolSide) {
emit(
SignalProxyMessage.Rpc(
function,
arguments
)
)
}
}
fun emit(message: SignalProxyMessage)
}
/*
* libquassel
* Copyright (c) 2021 Janne Mareike Koschinski
* Copyright (c) 2021 The Quassel Project
*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at https://mozilla.org/MPL/2.0/.
*/
package de.justjanne.libquassel.state.protocol
import de.justjanne.libquassel.annotations.ProtocolSide
import de.justjanne.libquassel.protocol.models.types.QtType
import de.justjanne.libquassel.protocol.variant.QVariantMap
import de.justjanne.libquassel.protocol.variant.QVariant_
import de.justjanne.libquassel.protocol.variant.qVariant
interface SyncableProtocol {
val className: String
val objectName: String
val initialized: Boolean
val proxy: SignalProxy
fun fromVariantMap(properties: QVariantMap)
fun toVariantMap(): QVariantMap
fun sync(target: ProtocolSide, function: String, vararg arg: QVariant_) {
if (initialized) {
proxy.sync(target, className, objectName, function, arg.toList())
}
}
fun rpc(target: ProtocolSide, function: String, vararg arg: QVariant_) {
if (initialized) {
proxy.rpc(target, function, arg.toList())
}
}
fun update(properties: QVariantMap) {
fromVariantMap(properties)
sync(
target = ProtocolSide.CLIENT,
"update",
/**
* Construct a QVariant from a QVariantMap
*/
qVariant(properties, QtType.QVariantMap)
)
}
fun requestUpdate(properties: QVariantMap = toVariantMap()) {
sync(
target = ProtocolSide.CORE,
"requestUpdate",
/**
* Construct a QVariant from a QVariantMap
*/
qVariant(properties, QtType.QVariantMap)
)
}
}
/*
* libquassel
* Copyright (c) 2021 Janne Mareike Koschinski
* Copyright (c) 2021 The Quassel Project
*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at https://mozilla.org/MPL/2.0/.
*/
package de.justjanne.libquassel.state.protocol
import de.justjanne.libquassel.annotations.ProtocolSide
import de.justjanne.libquassel.annotations.SyncedCall
import de.justjanne.libquassel.protocol.models.TransferIdList
import de.justjanne.libquassel.protocol.models.types.QtType
import de.justjanne.libquassel.protocol.models.types.QuasselType
import de.justjanne.libquassel.protocol.variant.QVariantMap
import de.justjanne.libquassel.protocol.variant.qVariant
import java.util.UUID
interface TransferManagerProtocol : SyncableProtocol {
@SyncedCall(target = ProtocolSide.CLIENT)
fun setTransferIds(transferIds: TransferIdList) {
sync(
target = ProtocolSide.CLIENT,
"setTransferIds",
qVariant(transferIds, QuasselType.TransferIdList)
)
}
@SyncedCall(target = ProtocolSide.CLIENT)
fun onCoreTransferAdded(transferId: UUID) {
sync(
target = ProtocolSide.CLIENT,
"onCoreTransferAdded",
qVariant(transferId, QtType.Uuid)
)
}
@SyncedCall(target = ProtocolSide.CLIENT)
override fun update(properties: QVariantMap) = super.update(properties)
@SyncedCall(target = ProtocolSide.CORE)
override fun requestUpdate(properties: QVariantMap) = super.requestUpdate(properties)
}
/*
* libquassel
* Copyright (c) 2021 Janne Mareike Koschinski
* Copyright (c) 2021 The Quassel Project
*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at https://mozilla.org/MPL/2.0/.
*/
package de.justjanne.libquassel.state.protocol
import de.justjanne.libquassel.annotations.ProtocolSide
import de.justjanne.libquassel.annotations.SyncedCall
import de.justjanne.libquassel.protocol.models.TransferDirection
import de.justjanne.libquassel.protocol.models.TransferStatus
import de.justjanne.libquassel.protocol.models.types.QtType
import de.justjanne.libquassel.protocol.models.types.QuasselType
import de.justjanne.libquassel.protocol.variant.QVariantMap
import de.justjanne.libquassel.protocol.variant.qVariant
import java.net.InetAddress
import java.nio.ByteBuffer
interface TransferProtocol : SyncableProtocol {
@SyncedCall(target = ProtocolSide.CLIENT)
fun accept(savePath: String) {
sync(
target = ProtocolSide.CLIENT,
"accept",
/**
* Construct a QVariant from a String
*/
qVariant(savePath, QtType.QString)
)
}
@SyncedCall(target = ProtocolSide.CORE)
fun requestAccepted(peer: ULong = 0uL) {
sync(
target = ProtocolSide.CORE,
"requestAccepted",
/**
* Construct a QVariant from a ULong
*/
qVariant(peer, QtType.ULong)
)
}
@SyncedCall(target = ProtocolSide.CLIENT)
fun reject() {
sync(
target = ProtocolSide.CLIENT,
"reject"
)
}
@SyncedCall(target = ProtocolSide.CORE)
fun requestRejected(peer: ULong = 0uL) {
sync(
target = ProtocolSide.CORE,
"requestRejected",
/**
* Construct a QVariant from a ULong
*/
qVariant(peer, QtType.ULong)
)
}
@SyncedCall(target = ProtocolSide.CLIENT)
fun setStatus(status: TransferStatus) {
sync(
target = ProtocolSide.CLIENT,
"setStatus",
qVariant(status, QuasselType.TransferStatus)
)
}
@SyncedCall(target = ProtocolSide.CLIENT)
fun setDirection(direction: TransferDirection) {
sync(
target = ProtocolSide.CLIENT,
"setDirection",
qVariant(direction, QuasselType.TransferDirection)
)
}
@SyncedCall(target = ProtocolSide.CLIENT)
fun setAddress(address: InetAddress) {
sync(
target = ProtocolSide.CLIENT,
"setAddress",
/**
* Construct a QVariant from a InetAddress
*/
qVariant(address, QuasselType.QHostAddress)
)
}
@SyncedCall(target = ProtocolSide.CLIENT)
fun setPort(port: UShort) {
sync(
target = ProtocolSide.CLIENT,
"setPort",
/**
* Construct a QVariant from a UShort
*/
qVariant(port, QtType.UShort)
)
}
@SyncedCall(target = ProtocolSide.CLIENT)
fun setFileName(fileName: String) {
sync(
target = ProtocolSide.CLIENT,
"setFileName",
/**
* Construct a QVariant from a String
*/
qVariant(fileName, QtType.QString)
)
}
@SyncedCall(target = ProtocolSide.CLIENT)
fun setFileSize(fileSize: ULong) {
sync(
target = ProtocolSide.CLIENT,
"setFileSize",
/**
* Construct a QVariant from a ULong
*/
qVariant(fileSize, QtType.ULong)
)
}
@SyncedCall(target = ProtocolSide.CLIENT)
fun setNick(nick: String) {
sync(
target = ProtocolSide.CLIENT,
"setNick",
/**
* Construct a QVariant from a String
*/
qVariant(nick, QtType.QString)
)
}
@SyncedCall(target = ProtocolSide.CLIENT)
fun setError(errorString: String) {
sync(
target = ProtocolSide.CLIENT,
"setError",
/**
* Construct a QVariant from a String
*/
qVariant(errorString, QtType.QString)
)
}
@SyncedCall(target = ProtocolSide.CLIENT)
fun dataReceived(peer: ULong, data: ByteBuffer) {
sync(
target = ProtocolSide.CLIENT,
"dataReceived",
qVariant(peer, QuasselType.PeerPtr),
/**
* Construct a QVariant from a ByteBuffer
*/
qVariant(data, QtType.QByteArray)
)
}
@SyncedCall(target = ProtocolSide.CLIENT)
fun cleanUp() {
sync(
target = ProtocolSide.CLIENT,
"cleanUp",
)
}
@SyncedCall(target = ProtocolSide.CLIENT)
override fun update(properties: QVariantMap) = super.update(properties)
@SyncedCall(target = ProtocolSide.CORE)
override fun requestUpdate(properties: QVariantMap) = super.requestUpdate(properties)
}
...@@ -13,5 +13,6 @@ rootProject.name = "libquassel" ...@@ -13,5 +13,6 @@ rootProject.name = "libquassel"
include( include(
":libquassel-annotations", ":libquassel-annotations",
":libquassel-protocol", ":libquassel-protocol",
":libquassel-state",
":libquassel-client" ":libquassel-client"
) )
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment