riku
2019-08-26 e074a057b0a9c11022c57185d6e559e45cea1b3a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.flightfeather.obd.socket
 
import io.netty.channel.ChannelHandlerContext
import io.netty.channel.ChannelInboundHandlerAdapter
import io.netty.util.AttributeKey
 
class ServerHandler : ChannelInboundHandlerAdapter() {
 
    val attributeKey = AttributeKey.valueOf<String>("deviceCode")
 
    override fun channelRegistered(ctx: ChannelHandlerContext?) {
        super.channelRegistered(ctx)
    }
 
    override fun channelActive(ctx: ChannelHandlerContext?) {
        super.channelActive(ctx)
    }
 
    override fun channelRead(ctx: ChannelHandlerContext?, msg: Any?) {
        super.channelRead(ctx, msg)
        val attribute = ctx?.channel()?.attr(attributeKey)?.apply {
            if (get() == null) {
//                set()
            }
        }
    }
 
    override fun channelReadComplete(ctx: ChannelHandlerContext?) {
        super.channelReadComplete(ctx)
    }
 
    override fun channelInactive(ctx: ChannelHandlerContext?) {
        super.channelInactive(ctx)
    }
 
    override fun exceptionCaught(ctx: ChannelHandlerContext?, cause: Throwable?) {
        super.exceptionCaught(ctx, cause)
    }
}