aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Odersky <jodersky@gmail.com>2013-07-22 14:04:29 +0200
committerJakob Odersky <jodersky@gmail.com>2013-07-22 14:04:29 +0200
commit5f61cd57119108dc15a5cef112a36649017204b0 (patch)
treedcc910186c8a34c148d31b0bf5ec6e7d44b216cb
parent9b22e692eda016ad0b3048717e48d4e363bc363f (diff)
downloadakka-serial-5f61cd57119108dc15a5cef112a36649017204b0.tar.gz
akka-serial-5f61cd57119108dc15a5cef112a36649017204b0.tar.bz2
akka-serial-5f61cd57119108dc15a5cef112a36649017204b0.zip
adapt acknowledgements to resemble akka
-rw-r--r--flow-main/src/main/scala/com/github/jodersky/flow/Serial.scala15
-rw-r--r--flow-main/src/main/scala/com/github/jodersky/flow/SerialOperator.scala4
2 files changed, 7 insertions, 12 deletions
diff --git a/flow-main/src/main/scala/com/github/jodersky/flow/Serial.scala b/flow-main/src/main/scala/com/github/jodersky/flow/Serial.scala
index a1ee433..46842f9 100644
--- a/flow-main/src/main/scala/com/github/jodersky/flow/Serial.scala
+++ b/flow-main/src/main/scala/com/github/jodersky/flow/Serial.scala
@@ -18,7 +18,7 @@ object Serial extends ExtensionKey[SerialExt] {
* attempt to open a serial port with the specified parameters and, if successful, create a `SerialOperator` actor associated to the port.
* The operator actor acts as an intermediate to the underlying native serial port, dealing with threading issues and the such. It will send any events
* to the sender of this message.
- * The manager will respond with an `Opened` in case the port was successfully opened, or `OpenFailed` in case of failure.
+ * The manager will respond with an `OpenFailed` in case the port could not be opened, or the operator will respond with `Opened`.
* @param port name of serial port
* @param baud baud rate to use with serial port
* @param characterSize size of a character of the data sent through the serial port
@@ -57,17 +57,12 @@ object Serial extends ExtensionKey[SerialExt] {
/**
* Write data to serial port. Send this command to an operator to write the given data to its associated serial port.
* @param data data to be written to port
- * @param ack set to true to receive acknowledgment on successful write
- * @see Wrote
+ * @param ack acknowledgment sent back to sender once data has been enqueued in kernel for sending
*/
- case class Write(data: ByteString, ack: Boolean = false) extends Command
+ case class Write(data: ByteString, ack: Event = NoAck) extends Command
- /**
- * Event sent by operator, acknowledging that data was written to its serial port. Note that such an acknowledgment only guarantees that data has been written
- * to the serial port's output buffer (managed by the operating system), the actual sending of the data to the remote device is not guaranteed.
- * @param data the data that has been written
- */
- case class Wrote(data: ByteString) extends Event
+ /** Special type of acknowledgment that is not sent back. */
+ case object NoAck extends Event
/** Request closing of port. Send this command to an operator to close its associated port. */
case object Close extends Command
diff --git a/flow-main/src/main/scala/com/github/jodersky/flow/SerialOperator.scala b/flow-main/src/main/scala/com/github/jodersky/flow/SerialOperator.scala
index 194abd3..6000778 100644
--- a/flow-main/src/main/scala/com/github/jodersky/flow/SerialOperator.scala
+++ b/flow-main/src/main/scala/com/github/jodersky/flow/SerialOperator.scala
@@ -8,8 +8,8 @@ import Serial.Close
import Serial.Closed
import Serial.Opened
import Serial.Received
+import Serial.NoAck
import Serial.Write
-import Serial.Wrote
import akka.actor.Actor
import akka.actor.ActorLogging
import akka.actor.ActorRef
@@ -70,7 +70,7 @@ class SerialOperator(handler: ActorRef, serial: InternalSerial) extends Actor wi
case Write(data, ack) => {
try {
val sent = serial.write(data.toArray)
- if (ack) sender ! Wrote(ByteString(sent))
+ if (ack != NoAck) sender ! ack
} catch {
case ex: IOException => {
handler ! Closed(Some(ex))