package Ġio . re bble . lib pe bble common . services . app Ċ Ċ import Ġio . re bble . lib pe bble common . Protocol Handler Ċ import Ġio . re bble . lib pe bble common . packets . App Run State Message Ċ import Ġio . re bble . lib pe bble common . protocol helpers . P eb ble Packet Ċ import Ġio . re bble . lib pe bble common . protocol helpers . Protocol Endpoint Ċ import Ġio . re bble . lib pe bble common . services . Protocol Service Ċ import Ġkotlinx . coroutines . channels . Channel Ċ Ċ class ĠApp Run State Service ( private Ġval Ġprotocol Handler : ĠProtocol Handler ) Ġ: ĠProtocol Service Ġ{ ĊĠĠĠ Ġval Ġreceived Messages Ġ= ĠChannel < App Run State Message >( Channel . BUFFER ED ) ĊĊĠĠĠ Ġinit Ġ{ ĊĠĠĠĠĠĠĠ Ġprotocol Handler . register Receive Callback ( Protocol Endpoint . APP _ RUN _ STATE , Ġthis :: receive ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġsuspend Ġfun Ġsend ( packet : ĠApp Run State Message ) Ġ{ ĊĠĠĠĠĠĠĠ Ġprotocol Handler . send ( packet ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġreceive ( packet : ĠP eb ble Packet ) Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( packet Ġ! is ĠApp Run State Message ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġthrow ĠIllegalStateException (" Received Ġinvalid Ġpacket Ġtype : Ġ$ packet ") ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġreceived Messages . offer ( packet ) ĊĠĠĠ Ġ} Ċ Ċ }