Skip to content

Commit

Permalink
removed interface IppExchange
Browse files Browse the repository at this point in the history
  • Loading branch information
gmuth committed Sep 23, 2024
1 parent 666426b commit 87d368a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/main/kotlin/de/gmuth/ipp/client/IppClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import javax.net.ssl.HttpsURLConnection

typealias IppResponseInterceptor = (request: IppRequest, response: IppResponse) -> Unit

open class IppClient(val config: IppConfig = IppConfig()) : IppExchange {
open class IppClient(val config: IppConfig = IppConfig()) {
protected val logger: Logger = getLogger(javaClass.name)

var responseInterceptor: IppResponseInterceptor? = null
Expand Down Expand Up @@ -72,7 +72,7 @@ open class IppClient(val config: IppConfig = IppConfig()) : IppExchange {
// Exchange IppRequest for IppResponse
//------------------------------------

override fun exchange(request: IppRequest) = with(request) {
fun exchange(request: IppRequest) = with(request) {
logger.fine { "Send '$operation' request to $printerOrJobUri" }
httpPost(toHttpUri(printerOrJobUri), request).also {
logger.finer { "Req #${request.requestId} @${printerOrJobUri.host}: $request => $it" }
Expand Down
14 changes: 0 additions & 14 deletions src/main/kotlin/de/gmuth/ipp/client/IppExchange.kt

This file was deleted.

4 changes: 3 additions & 1 deletion src/main/kotlin/de/gmuth/ipp/client/IppJob.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import java.util.logging.Logger.getLogger
class IppJob(
val printer: IppPrinter,
val attributes: IppAttributesGroup,
) : IppExchange by printer {
) {

private val logger = getLogger(javaClass.name)
var subscription: IppSubscription? = null
Expand Down Expand Up @@ -362,6 +362,8 @@ class IppJob(
}
}

private fun exchange(request: IppRequest) = printer.exchange(request)

// -------
// Logging
// -------
Expand Down
7 changes: 4 additions & 3 deletions src/main/kotlin/de/gmuth/ipp/client/IppPrinter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class IppPrinter(
internal val ippClient: IppClient = IppClient(ippConfig),
getPrinterAttributesOnInit: Boolean = true,
requestedAttributesOnInit: List<String>? = null
) : IppExchange {
) {

private val logger = getLogger(javaClass.name)
var workDirectory: File = createTempDirectory().toFile()
Expand Down Expand Up @@ -534,11 +534,12 @@ class IppPrinter(
) = ippClient
.ippRequest(operation, printerUri, requestedAttributes, userName)

override fun exchange(request: IppRequest) = ippClient.exchange(request.apply {
fun exchange(request: IppRequest): IppResponse = request.run {
checkIfValueIsSupported("ipp-versions", version!!, true)
checkIfValueIsSupported("operations", code!!.toInt(), true)
checkIfValueIsSupported("charset", attributesCharset, true)
})
ippClient.exchange(this)
}

private fun exchangeForIppJob(request: IppRequest) =
IppJob(this, exchange(request)).apply {
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/de/gmuth/ipp/client/IppSubscription.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ package de.gmuth.ipp.client
*/

import de.gmuth.ipp.client.IppOperationException.ClientErrorNotFoundException
import de.gmuth.ipp.core.IppAttributesGroup
import de.gmuth.ipp.core.IppOperation
import de.gmuth.ipp.core.*
import de.gmuth.ipp.core.IppOperation.*
import de.gmuth.ipp.core.IppString
import de.gmuth.ipp.core.IppTag.EventNotification
import de.gmuth.ipp.core.IppTag.Integer
import java.time.Duration
Expand All @@ -24,7 +22,7 @@ class IppSubscription(
val printer: IppPrinter,
val attributes: IppAttributesGroup,
startLease: Boolean = true
) : IppExchange by printer {
) {

private val logger = getLogger(javaClass.name)
private var lastSequenceNumber: Int = 0
Expand Down Expand Up @@ -122,6 +120,8 @@ class IppSubscription(
printer.ippRequest(operation, requestedAttributes = requestedAttributes)
.apply { operationGroup.attribute("notify-subscription-id", Integer, id) }

private fun exchange(request: IppRequest) = printer.exchange(request)

//------------------------------------
// Poll and handle event notifications
//------------------------------------
Expand Down

0 comments on commit 87d368a

Please sign in to comment.