diff options
author | Jakob Odersky <jodersky@gmail.com> | 2015-05-24 14:00:52 +0200 |
---|---|---|
committer | Jakob Odersky <jodersky@gmail.com> | 2015-05-24 15:53:33 +0200 |
commit | 5cc9c4d4377cd0225675d5996c5df5ddc993ab68 (patch) | |
tree | 6525720eb09ba7698cbe014ab25a77ee32c263c1 /flow-main/src/main/scala | |
parent | 0d73d35eff1e92deea7e78ed69d5ede7213ef3e9 (diff) | |
download | akka-serial-5cc9c4d4377cd0225675d5996c5df5ddc993ab68.tar.gz akka-serial-5cc9c4d4377cd0225675d5996c5df5ddc993ab68.tar.bz2 akka-serial-5cc9c4d4377cd0225675d5996c5df5ddc993ab68.zip |
style uniformisation
Diffstat (limited to 'flow-main/src/main/scala')
11 files changed, 39 insertions, 66 deletions
diff --git a/flow-main/src/main/scala/com/github/jodersky/flow/Parity.scala b/flow-main/src/main/scala/com/github/jodersky/flow/Parity.scala index 9bf52a6..04d64a9 100644 --- a/flow-main/src/main/scala/com/github/jodersky/flow/Parity.scala +++ b/flow-main/src/main/scala/com/github/jodersky/flow/Parity.scala @@ -6,4 +6,4 @@ object Parity extends Enumeration { val None = Value(0) val Odd = Value(1) val Even = Value(2) -}
\ No newline at end of file +} diff --git a/flow-main/src/main/scala/com/github/jodersky/flow/SerialExt.scala b/flow-main/src/main/scala/com/github/jodersky/flow/SerialExt.scala index 38e140a..5c1ddf6 100644 --- a/flow-main/src/main/scala/com/github/jodersky/flow/SerialExt.scala +++ b/flow-main/src/main/scala/com/github/jodersky/flow/SerialExt.scala @@ -1,10 +1,9 @@ package com.github.jodersky.flow -import akka.actor.ExtendedActorSystem -import akka.actor.Props +import akka.actor.{ ExtendedActorSystem, Props } import akka.io.IO /** Provides the serial IO manager. */ class SerialExt(system: ExtendedActorSystem) extends IO.Extension { lazy val manager = system.systemActorOf(Props(classOf[SerialManager]), name = "IO-SERIAL") -}
\ No newline at end of file +} diff --git a/flow-main/src/main/scala/com/github/jodersky/flow/SerialManager.scala b/flow-main/src/main/scala/com/github/jodersky/flow/SerialManager.scala index 40739ca..686cdb3 100644 --- a/flow-main/src/main/scala/com/github/jodersky/flow/SerialManager.scala +++ b/flow-main/src/main/scala/com/github/jodersky/flow/SerialManager.scala @@ -1,17 +1,9 @@ package com.github.jodersky.flow -import scala.util.Failure -import scala.util.Success -import scala.util.Try - -import com.github.jodersky.flow.internal.SerialConnection -import com.github.jodersky.flow.internal.Watcher - -import akka.actor.Actor -import akka.actor.ActorLogging -import akka.actor.OneForOneStrategy +import akka.actor.{ Actor, ActorLogging, OneForOneStrategy } import akka.actor.SupervisorStrategy.Stop -import akka.actor.actorRef2Scala +import internal.{ SerialConnection, Watcher } +import scala.util.{ Failure, Success, Try } /** * Entry point to the serial API. Actor that manages serial port creation. Once opened, a serial port is handed over to 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 f40f4de..ec0ee27 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 @@ -1,23 +1,9 @@ package com.github.jodersky.flow +import akka.actor.{ Actor, ActorLogging, ActorRef, Props, Terminated, actorRef2Scala } +import internal.{ Reader, SerialConnection, ThreadDied } import java.nio.ByteBuffer -import com.github.jodersky.flow.internal.Reader -import com.github.jodersky.flow.internal.ThreadDied -import com.github.jodersky.flow.internal.SerialConnection - -import Serial.Close -import Serial.Closed -import Serial.NoAck -import Serial.Opened -import Serial.Write -import akka.actor.Actor -import akka.actor.ActorLogging -import akka.actor.ActorRef -import akka.actor.Props -import akka.actor.Terminated -import akka.actor.actorRef2Scala - /** * Operator associated to an open serial port. All communication with a port is done via an operator. Operators are created though the serial manager. * @see SerialManager @@ -31,7 +17,7 @@ class SerialOperator(connection: SerialConnection, bufferSize: Int, client: Acto val writeBuffer = ByteBuffer.allocateDirect(bufferSize) context.watch(client) - client ! Opened(connection.port) + client ! Serial.Opened(connection.port) reader.start() override def postStop = { @@ -40,18 +26,18 @@ class SerialOperator(connection: SerialConnection, bufferSize: Int, client: Acto def receive: Receive = { - case Write(data, ack) => { + case Serial.Write(data, ack) => { writeBuffer.clear() data.copyToBuffer(writeBuffer) val sent = connection.write(writeBuffer) - if (ack != NoAck) sender ! ack(sent) + if (ack != Serial.NoAck) sender ! ack(sent) } - case Close => { - client ! Closed + case Serial.Close => { + client ! Serial.Closed context stop self } - + case Terminated(`client`) => { context stop self } diff --git a/flow-main/src/main/scala/com/github/jodersky/flow/SerialSettings.scala b/flow-main/src/main/scala/com/github/jodersky/flow/SerialSettings.scala index 08a5556..087fa6e 100644 --- a/flow-main/src/main/scala/com/github/jodersky/flow/SerialSettings.scala +++ b/flow-main/src/main/scala/com/github/jodersky/flow/SerialSettings.scala @@ -7,4 +7,4 @@ package com.github.jodersky.flow * @param twoStopBits set to use two stop bits instead of one * @param parity type of parity to use with serial port */ -case class SerialSettings(baud: Int, characterSize: Int = 8, twoStopBits: Boolean = false, parity: Parity.Parity = Parity.None)
\ No newline at end of file +case class SerialSettings(baud: Int, characterSize: Int = 8, twoStopBits: Boolean = false, parity: Parity.Parity = Parity.None) diff --git a/flow-main/src/main/scala/com/github/jodersky/flow/exceptions.scala b/flow-main/src/main/scala/com/github/jodersky/flow/exceptions.scala index adefcea..ebc0e65 100644 --- a/flow-main/src/main/scala/com/github/jodersky/flow/exceptions.scala +++ b/flow-main/src/main/scala/com/github/jodersky/flow/exceptions.scala @@ -16,4 +16,4 @@ class InvalidSettingsException(message: String) extends Exception(message) class PortInterruptedException(message: String) extends Exception(message) /** The specified port has been closed. */ -class PortClosedException(message: String) extends Exception(message)
\ No newline at end of file +class PortClosedException(message: String) extends Exception(message) diff --git a/flow-main/src/main/scala/com/github/jodersky/flow/internal/NativeLoader.scala b/flow-main/src/main/scala/com/github/jodersky/flow/internal/NativeLoader.scala index dc539ea..a5fdc40 100644 --- a/flow-main/src/main/scala/com/github/jodersky/flow/internal/NativeLoader.scala +++ b/flow-main/src/main/scala/com/github/jodersky/flow/internal/NativeLoader.scala @@ -1,9 +1,7 @@ -package com.github.jodersky.flow.internal +package com.github.jodersky.flow +package internal -import java.io.File -import java.io.FileOutputStream -import java.io.InputStream -import java.io.OutputStream +import java.io.{ File, FileOutputStream, InputStream, OutputStream } /** Handles loading of the current platform's native library for flow. */ object NativeLoader { @@ -46,8 +44,8 @@ object NativeLoader { extract(path, fqlib) match { case Some(file) => System.load(file.getAbsolutePath) case None => throw new UnsatisfiedLinkError("Cannot extract flow's native library, " + - "the native library does not exist for your specific architecture/OS combination." + - "Could not find " + path + ".") + "the native library does not exist for your specific architecture/OS combination." + + "Could not find " + path + ".") } } diff --git a/flow-main/src/main/scala/com/github/jodersky/flow/internal/Reader.scala b/flow-main/src/main/scala/com/github/jodersky/flow/internal/Reader.scala index 42400c8..59ad575 100644 --- a/flow-main/src/main/scala/com/github/jodersky/flow/internal/Reader.scala +++ b/flow-main/src/main/scala/com/github/jodersky/flow/internal/Reader.scala @@ -1,13 +1,9 @@ -package com.github.jodersky.flow.internal +package com.github.jodersky.flow +package internal -import java.nio.ByteBuffer - -import com.github.jodersky.flow.PortInterruptedException -import com.github.jodersky.flow.Serial.Received - -import akka.actor.Actor -import akka.actor.ActorRef +import akka.actor.{ Actor, ActorRef } import akka.util.ByteString +import java.nio.ByteBuffer class Reader(serial: SerialConnection, buffer: ByteBuffer, operator: ActorRef, client: ActorRef) extends Thread { def readLoop() = { @@ -18,7 +14,7 @@ class Reader(serial: SerialConnection, buffer: ByteBuffer, operator: ActorRef, c val length = serial.read(buffer) buffer.limit(length) val data = ByteString.fromByteBuffer(buffer) - client.tell(Received(data), operator) + client.tell(Serial.Received(data), operator) } catch { //don't do anything if port is interrupted diff --git a/flow-main/src/main/scala/com/github/jodersky/flow/internal/SerialConnection.scala b/flow-main/src/main/scala/com/github/jodersky/flow/internal/SerialConnection.scala index b4242fe..73416e3 100644 --- a/flow-main/src/main/scala/com/github/jodersky/flow/internal/SerialConnection.scala +++ b/flow-main/src/main/scala/com/github/jodersky/flow/internal/SerialConnection.scala @@ -1,11 +1,9 @@ -package com.github.jodersky.flow.internal +package com.github.jodersky.flow +package internal import java.nio.ByteBuffer import java.util.concurrent.atomic.AtomicBoolean -import com.github.jodersky.flow.PortClosedException -import com.github.jodersky.flow.SerialSettings - /** * Represents a serial connection in a more secure and object-oriented style than `NativeSerial`. In contrast * to the latter, this class encapsulates and secures any pointers used to communicate with the native @@ -16,7 +14,8 @@ import com.github.jodersky.flow.SerialSettings class SerialConnection private ( val port: String, val settings: SerialSettings, - private val pointer: Long) { + private val pointer: Long +) { import SerialConnection._ @@ -74,7 +73,8 @@ class SerialConnection private ( try { transfer( b => NativeSerial.readDirect(pointer, b), - b => NativeSerial.read(pointer, b.array()))(buffer) + b => NativeSerial.read(pointer, b.array()) + )(buffer) } finally { reading = false if (closed.get) readLock.notify() @@ -105,7 +105,8 @@ class SerialConnection private ( try { transfer( b => NativeSerial.writeDirect(pointer, b, b.position()), - b => NativeSerial.write(pointer, b.array(), b.position()))(buffer) + b => NativeSerial.write(pointer, b.array(), b.position()) + )(buffer) } finally { writing = false if (closed.get) writeLock.notify() @@ -154,4 +155,4 @@ object SerialConnection { */ def debug(value: Boolean) = NativeSerial.debug(value) -}
\ No newline at end of file +} diff --git a/flow-main/src/main/scala/com/github/jodersky/flow/internal/ThreadDied.scala b/flow-main/src/main/scala/com/github/jodersky/flow/internal/ThreadDied.scala index 0674354..1470aa5 100644 --- a/flow-main/src/main/scala/com/github/jodersky/flow/internal/ThreadDied.scala +++ b/flow-main/src/main/scala/com/github/jodersky/flow/internal/ThreadDied.scala @@ -1,3 +1,4 @@ -package com.github.jodersky.flow.internal +package com.github.jodersky.flow +package internal case class ThreadDied(thread: Thread, reason: Exception) diff --git a/flow-main/src/main/scala/com/github/jodersky/flow/internal/Watcher.scala b/flow-main/src/main/scala/com/github/jodersky/flow/internal/Watcher.scala index 4548aa0..3c30ccb 100644 --- a/flow-main/src/main/scala/com/github/jodersky/flow/internal/Watcher.scala +++ b/flow-main/src/main/scala/com/github/jodersky/flow/internal/Watcher.scala @@ -1,7 +1,7 @@ -package com.github.jodersky.flow.internal +package com.github.jodersky.flow +package internal import akka.actor.{ Actor, ActorRef, Props } -import com.github.jodersky.flow.Serial import java.nio.file.{ ClosedWatchServiceException, FileSystems, Path, Paths, WatchEvent, WatchKey } import java.nio.file.StandardWatchEventKinds._ import scala.collection.JavaConversions._ |