You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by br...@apache.org on 2017/12/22 09:16:59 UTC
[incubator-plc4x] 05/07: Minimal implementation of a
JPlcConnectionWrapper
This is an automated email from the ASF dual-hosted git repository.
britter pushed a commit to branch PLC4X-12
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git
commit 1c8edbab3eb3a324864e327c637a0b5c00e795e7
Author: Benedikt Ritter <be...@codecentric.de>
AuthorDate: Sun Nov 19 18:33:41 2017 +0100
Minimal implementation of a JPlcConnectionWrapper
---
.../org/apache/plc4x/scala/api/PlcError.scala | 2 +-
.../plc4x/scala/api/connection/PlcConnection.scala | 2 --
.../plc4x/scala/core/JPlcConnectionWrapper.scala | 25 +++++++++++-----------
3 files changed, 13 insertions(+), 16 deletions(-)
diff --git a/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/PlcError.scala b/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/PlcError.scala
index c9b4d35..6e084db 100644
--- a/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/PlcError.scala
+++ b/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/PlcError.scala
@@ -20,4 +20,4 @@ package org.apache.plc4x.scala.api
sealed trait PlcError
-final case class PlcConnectionError(reason: String)
+final case class PlcConnectionError(reason: String) extends PlcError
diff --git a/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/connection/PlcConnection.scala b/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/connection/PlcConnection.scala
index a37105a..84213ba 100644
--- a/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/connection/PlcConnection.scala
+++ b/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/connection/PlcConnection.scala
@@ -21,8 +21,6 @@ package org.apache.plc4x.scala.api.connection
import org.apache.plc4x.java.messages.Address
import org.apache.plc4x.scala.api.PlcError
-import scala.util.Try
-
/**
* Interface defining the most basic methods a PLC4X connection should support.
* This generally handles the connection establishment itself and the parsing of
diff --git a/plc4s/core/src/main/scala/org/apache/plc4x/scala/core/JPlcConnectionWrapper.scala b/plc4s/core/src/main/scala/org/apache/plc4x/scala/core/JPlcConnectionWrapper.scala
index 8c41865..914ccac 100644
--- a/plc4s/core/src/main/scala/org/apache/plc4x/scala/core/JPlcConnectionWrapper.scala
+++ b/plc4s/core/src/main/scala/org/apache/plc4x/scala/core/JPlcConnectionWrapper.scala
@@ -19,21 +19,20 @@ under the License.
package org.apache.plc4x.scala.core
import org.apache.plc4x.java.connection.{PlcConnection => JPlcConnection}
+import org.apache.plc4x.scala.api.PlcConnectionError
import org.apache.plc4x.scala.api.connection.PlcConnection
+import scala.util.{Failure, Success, Try}
+
private[core] class JPlcConnectionWrapper(val jPlcConnection: JPlcConnection) extends PlcConnection {
- /**
- * Establishes the connection to the remote PLC.
- *
- * @return Either nothing in case the connection could be established or an PlcError.
- */
- override def connect() = ???
- /**
- * Parses a PLC/protocol dependent address string into an Address object.
- *
- * @param addressString String representation of an address for the current type of PLC/protocol.
- * @return Either the Address object identifying an address for the current type of PLC/protocol or a PlcError.
- */
- override def parseAddress(addressString: String) = ???
+ override def connect() = Try(jPlcConnection.connect()) match {
+ case Success(_) => Right(Unit)
+ case Failure(ex) => Left(PlcConnectionError(ex.getMessage))
+ }
+
+ override def parseAddress(addressString: String) = Try(jPlcConnection.parseAddress(addressString)) match {
+ case Success(address) => Right(address)
+ case Failure(ex) => Left(PlcConnectionError(ex.getMessage))
+ }
}
--
To stop receiving notification emails like this one, please contact
"commits@plc4x.apache.org" <co...@plc4x.apache.org>.