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:54 UTC

[incubator-plc4x] branch PLC4X-12 created (now b6b345f)

This is an automated email from the ASF dual-hosted git repository.

britter pushed a change to branch PLC4X-12
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git.


      at b6b345f  Move conversions between Java and Scala API objects to separate file

This branch includes the following new commits:

     new a1f7b8d  PoC for compiling Scala with Maven
     new c0eec96  Draft Scala API entry point
     new 87b0e72  First Scala wrapper implementations
     new f316703  Configure build to run Scala compilation
     new 1c8edba  Minimal implementation of a JPlcConnectionWrapper
     new ca7583f  Add very simple reader implementation
     new b6b345f  Move conversions between Java and Scala API objects to separate file

The 7 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


-- 
To stop receiving notification emails like this one, please contact
['"commits@plc4x.apache.org" <co...@plc4x.apache.org>'].

[incubator-plc4x] 03/07: First Scala wrapper implementations

Posted by br...@apache.org.
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 87b0e7290b98f23ad5b1fe831837b0bb521039bd
Author: Benedikt Ritter <be...@codecentric.de>
AuthorDate: Sat Nov 18 17:47:38 2017 +0100

    First Scala wrapper implementations
---
 .../org/apache/plc4x/scala/api/PlcDriver.scala     |  2 +-
 plc4s/{ => core}/pom.xml                           | 62 ++++++++++------------
 .../plc4x/scala/core/JPlcConnectionWrapper.scala   | 39 ++++++++++++++
 .../plc4x/scala/core/JPlcDriverWrapper.scala       | 42 +++++++++++++++
 .../apache/plc4x/scala/core/PlcDriverManager.scala | 40 ++++++++++++++
 plc4s/pom.xml                                      |  1 +
 6 files changed, 150 insertions(+), 36 deletions(-)

diff --git a/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/PlcDriver.scala b/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/PlcDriver.scala
index edf93a4..647ef0f 100644
--- a/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/PlcDriver.scala
+++ b/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/PlcDriver.scala
@@ -19,7 +19,7 @@ under the License.
 package org.apache.plc4x.scala.api
 
 import org.apache.plc4x.java.authentication.PlcAuthentication
-import org.apache.plc4x.java.connection.PlcConnection
+import org.apache.plc4x.scala.api.connection.PlcConnection
 
 /**
   * General interface defining the minimal methods required for adding a new type of driver to the PLC4J system.
diff --git a/plc4s/pom.xml b/plc4s/core/pom.xml
similarity index 53%
copy from plc4s/pom.xml
copy to plc4s/core/pom.xml
index bc3bd0c..07d6fb1 100644
--- a/plc4s/pom.xml
+++ b/plc4s/core/pom.xml
@@ -24,48 +24,40 @@
 
   <parent>
     <groupId>org.apache.plx4x</groupId>
-    <artifactId>plc4x-parent</artifactId>
+    <artifactId>plc4s</artifactId>
     <version>0.0.1-SNAPSHOT</version>
   </parent>
 
-  <artifactId>plc4s</artifactId>
+  <artifactId>plc4s-core</artifactId>
   <version>0.0.1-SNAPSHOT</version>
-  <packaging>pom</packaging>
 
-  <name>PLC4S</name>
-  <description>Implementation of the protocol adapters for usage as Scala library.</description>
-
-  <modules>
-    <module>api</module>
-  </modules>
+  <name>PLC4S: Core</name>
+  <description>Implementation of the core PLC4J system containing the DriverManger.</description>
 
   <build>
-    <pluginManagement>
-      <plugins>
-        <plugin>
-          <groupId>net.alchim31.maven</groupId>
-          <artifactId>scala-maven-plugin</artifactId>
-          <version>3.3.1</version>
-          <configuration>
-            <scalaVersion>2.12.4</scalaVersion>
-          </configuration>
-        </plugin>
-      </plugins>
-    </pluginManagement>
+    <sourceDirectory>src/main/scala</sourceDirectory>
+    <plugins>
+      <plugin>
+        <groupId>net.alchim31.maven</groupId>
+        <artifactId>scala-maven-plugin</artifactId>
+      </plugin>
+    </plugins>
   </build>
 
-  <dependencyManagement>
-    <dependencies>
-      <dependency>
-        <groupId>org.apache.plx4x</groupId>
-        <artifactId>plc4j-api</artifactId>
-        <version>0.0.1-SNAPSHOT</version>
-      </dependency>
-      <dependency>
-        <groupId>org.apache.plx4x</groupId>
-        <artifactId>plc4j-core</artifactId>
-        <version>0.0.1-SNAPSHOT</version>
-      </dependency>
-    </dependencies>
-  </dependencyManagement>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.plx4x</groupId>
+      <artifactId>plc4j-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.plx4x</groupId>
+      <artifactId>plc4j-core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.plx4x</groupId>
+      <artifactId>plc4s-api</artifactId>
+      <version>0.0.1-SNAPSHOT</version>
+    </dependency>
+  </dependencies>
+
 </project>
\ No newline at end of file
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
new file mode 100644
index 0000000..8c41865
--- /dev/null
+++ b/plc4s/core/src/main/scala/org/apache/plc4x/scala/core/JPlcConnectionWrapper.scala
@@ -0,0 +1,39 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+package org.apache.plc4x.scala.core
+
+import org.apache.plc4x.java.connection.{PlcConnection => JPlcConnection}
+import org.apache.plc4x.scala.api.connection.PlcConnection
+
+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) = ???
+}
diff --git a/plc4s/core/src/main/scala/org/apache/plc4x/scala/core/JPlcDriverWrapper.scala b/plc4s/core/src/main/scala/org/apache/plc4x/scala/core/JPlcDriverWrapper.scala
new file mode 100644
index 0000000..49859ec
--- /dev/null
+++ b/plc4s/core/src/main/scala/org/apache/plc4x/scala/core/JPlcDriverWrapper.scala
@@ -0,0 +1,42 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+package org.apache.plc4x.scala.core
+
+import org.apache.plc4x.java.authentication.PlcAuthentication
+import org.apache.plc4x.java.{PlcDriver => JPlcDriver}
+import org.apache.plc4x.scala.api.{PlcConnectionError, PlcDriver}
+
+import scala.util.{Failure, Success, Try}
+
+private[core] class JPlcDriverWrapper(val jPlcDriver: JPlcDriver) extends PlcDriver {
+
+    override def protocolCode = jPlcDriver.getProtocolCode
+
+    override def protocolName = jPlcDriver.getProtocolCode
+
+    override def connect(url: String) = Try(jPlcDriver.connect(url)) match {
+        case Success(jConnection) => Right(new JPlcConnectionWrapper(jConnection))
+        case Failure(ex) => Left(PlcConnectionError(ex.getMessage))
+    }
+
+    override def connect(url: String, authentication: PlcAuthentication) = Try(jPlcDriver.connect(url, authentication)) match {
+        case Success(jConnection) => Right(new JPlcConnectionWrapper(jConnection))
+        case Failure(ex) => Left(PlcConnectionError(ex.getMessage))
+    }
+}
diff --git a/plc4s/core/src/main/scala/org/apache/plc4x/scala/core/PlcDriverManager.scala b/plc4s/core/src/main/scala/org/apache/plc4x/scala/core/PlcDriverManager.scala
new file mode 100644
index 0000000..093033f
--- /dev/null
+++ b/plc4s/core/src/main/scala/org/apache/plc4x/scala/core/PlcDriverManager.scala
@@ -0,0 +1,40 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+package org.apache.plc4x.scala.core
+
+import org.apache.plc4x.java.{PlcDriverManager => JPlcDriverManager}
+import org.apache.plc4x.scala.api.PlcDriver
+import org.apache.plc4x.scala.api.PlcConnectionError
+
+import scala.util.{Failure, Success, Try}
+import scala.util.control.Exception._
+
+class PlcDriverManager private(val jPlcDriverManager: JPlcDriverManager){
+
+    def this(classLoader: ClassLoader) = this(new JPlcDriverManager(classLoader))
+
+    def this() = this(Thread.currentThread.getContextClassLoader)
+
+    def getDriver(url: String): Either[PlcConnectionError, PlcDriver] = {
+        Try(jPlcDriverManager.getDriver(url)) match {
+            case Success(jDriver) => Right(new JPlcDriverWrapper(jDriver))
+            case Failure(ex) => Left(PlcConnectionError(ex.getMessage))
+        }
+    }
+}
diff --git a/plc4s/pom.xml b/plc4s/pom.xml
index bc3bd0c..08235bf 100644
--- a/plc4s/pom.xml
+++ b/plc4s/pom.xml
@@ -37,6 +37,7 @@
 
   <modules>
     <module>api</module>
+    <module>core</module>
   </modules>
 
   <build>

-- 
To stop receiving notification emails like this one, please contact
"commits@plc4x.apache.org" <co...@plc4x.apache.org>.

[incubator-plc4x] 04/07: Configure build to run Scala compilation

Posted by br...@apache.org.
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 f316703235053c0441f81aa6cabec3a3a5245c7a
Author: Benedikt Ritter <be...@codecentric.de>
AuthorDate: Sun Nov 19 17:57:15 2017 +0100

    Configure build to run Scala compilation
---
 plc4s/pom.xml | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/plc4s/pom.xml b/plc4s/pom.xml
index 08235bf..2a9b115 100644
--- a/plc4s/pom.xml
+++ b/plc4s/pom.xml
@@ -53,6 +53,29 @@
         </plugin>
       </plugins>
     </pluginManagement>
+    <plugins>
+      <plugin>
+        <groupId>net.alchim31.maven</groupId>
+        <artifactId>scala-maven-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>scala-compile-first</id>
+            <phase>process-resources</phase>
+            <goals>
+              <goal>add-source</goal>
+              <goal>compile</goal>
+            </goals>
+          </execution>
+          <execution>
+            <id>scala-test-compile</id>
+            <phase>process-test-resources</phase>
+            <goals>
+              <goal>testCompile</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
   </build>
 
   <dependencyManagement>

-- 
To stop receiving notification emails like this one, please contact
"commits@plc4x.apache.org" <co...@plc4x.apache.org>.

[incubator-plc4x] 05/07: Minimal implementation of a JPlcConnectionWrapper

Posted by br...@apache.org.
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>.

[incubator-plc4x] 02/07: Draft Scala API entry point

Posted by br...@apache.org.
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 c0eec96c668ecb445cef02a3b3bd62f7251c4a34
Author: Benedikt Ritter <be...@codecentric.de>
AuthorDate: Sat Nov 18 16:06:08 2017 +0100

    Draft Scala API entry point
---
 plc4s/{ => api}/pom.xml                            | 18 ++-----
 .../org/apache/plc4x/scala/api/PlcDriver.scala     | 56 ++++++++++++++++++++++
 .../org/apache/plc4x/scala/api/PlcError.scala}     | 10 ++--
 .../plc4x/scala/api/connection/PlcConnection.scala | 50 +++++++++++++++++++
 plc4s/pom.xml                                      | 49 ++++++++++---------
 5 files changed, 142 insertions(+), 41 deletions(-)

diff --git a/plc4s/pom.xml b/plc4s/api/pom.xml
similarity index 79%
copy from plc4s/pom.xml
copy to plc4s/api/pom.xml
index 5069048..5a80c34 100644
--- a/plc4s/pom.xml
+++ b/plc4s/api/pom.xml
@@ -24,29 +24,22 @@
 
   <parent>
     <groupId>org.apache.plx4x</groupId>
-    <artifactId>plc4x-parent</artifactId>
+    <artifactId>plc4s</artifactId>
     <version>0.0.1-SNAPSHOT</version>
   </parent>
 
-  <artifactId>plc4s</artifactId>
+  <artifactId>plc4s-api</artifactId>
   <version>0.0.1-SNAPSHOT</version>
-  <packaging>pom</packaging>
 
-  <name>PLC4S</name>
-  <description>Implementation of the protocol adapters for usage as Scala library.</description>
-
-  <modules>
-    
-  </modules>
+  <name>PLC4S: API</name>
+  <description>Central Module for the Scala API.</description>
 
   <build>
     <sourceDirectory>src/main/scala</sourceDirectory>
-    <testSourceDirectory>src/test/scala</testSourceDirectory>
     <plugins>
       <plugin>
         <groupId>net.alchim31.maven</groupId>
         <artifactId>scala-maven-plugin</artifactId>
-        <version>3.3.1</version>
       </plugin>
     </plugins>
   </build>
@@ -55,12 +48,11 @@
     <dependency>
       <groupId>org.apache.plx4x</groupId>
       <artifactId>plc4j-api</artifactId>
-      <version>0.0.1-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.apache.plx4x</groupId>
       <artifactId>plc4j-core</artifactId>
-      <version>0.0.1-SNAPSHOT</version>
     </dependency>
   </dependencies>
+
 </project>
\ No newline at end of file
diff --git a/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/PlcDriver.scala b/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/PlcDriver.scala
new file mode 100644
index 0000000..edf93a4
--- /dev/null
+++ b/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/PlcDriver.scala
@@ -0,0 +1,56 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+package org.apache.plc4x.scala.api
+
+import org.apache.plc4x.java.authentication.PlcAuthentication
+import org.apache.plc4x.java.connection.PlcConnection
+
+/**
+  * General interface defining the minimal methods required for adding a new type of driver to the PLC4J system.
+  */
+trait PlcDriver {
+
+    /**
+      * @return code of the implemented protocol. This is usually a lot shorter than the String returned by @seeĀ #getProtocolName().
+      */
+    def protocolCode: String
+
+    /**
+      * @return name of the implemented protocol.
+      */
+    def protocolName: String
+
+    /**
+      * Connects to a PLC using the given plc connection string.
+      *
+      * @param url plc connection string.
+      * @return Either the established PlcConnection or an PlcConnectionError.
+      */
+    def connect(url: String): Either[PlcConnectionError, PlcConnection]
+
+    /**
+      * Connects to a PLC using the given plc connection string using given authentication credentials.
+      *
+      * @param url            plc connection string.
+      * @param authentication authentication credentials.
+      * @return Either the established PlcConnection or an PlcConnectionError.
+      */
+    def connect(url: String, authentication: PlcAuthentication): Either[PlcConnectionError, PlcConnection]
+
+}
diff --git a/plc4s/src/main/scala/org/apache/plc4x/scala/Test.scala b/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/PlcError.scala
similarity index 85%
rename from plc4s/src/main/scala/org/apache/plc4x/scala/Test.scala
rename to plc4s/api/src/main/scala/org/apache/plc4x/scala/api/PlcError.scala
index 19f7c64..c9b4d35 100644
--- a/plc4s/src/main/scala/org/apache/plc4x/scala/Test.scala
+++ b/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/PlcError.scala
@@ -16,10 +16,8 @@ KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
 */
-package org.apache.plc4x.scala
+package org.apache.plc4x.scala.api
 
-class Test {
-    def main(args: Array[String]): Unit = {
-        println("Hello World!")
-    }
-}
+sealed trait PlcError
+
+final case class PlcConnectionError(reason: String)
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
new file mode 100644
index 0000000..a37105a
--- /dev/null
+++ b/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/connection/PlcConnection.scala
@@ -0,0 +1,50 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+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
+  * address strings to the platform dependent Address instances.
+  *
+  * The individual operations are then defined by other interfaces within this package.
+  */
+trait PlcConnection {
+
+    /**
+      * Establishes the connection to the remote PLC.
+      *
+      * @return Either nothing in case the connection could be established or an PlcError.
+      */
+    def connect(): Either[PlcError, Unit]
+
+    /**
+      * 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.
+      */
+    def parseAddress(addressString: String): Either[PlcError, Address]
+
+}
diff --git a/plc4s/pom.xml b/plc4s/pom.xml
index 5069048..bc3bd0c 100644
--- a/plc4s/pom.xml
+++ b/plc4s/pom.xml
@@ -36,31 +36,36 @@
   <description>Implementation of the protocol adapters for usage as Scala library.</description>
 
   <modules>
-    
+    <module>api</module>
   </modules>
 
   <build>
-    <sourceDirectory>src/main/scala</sourceDirectory>
-    <testSourceDirectory>src/test/scala</testSourceDirectory>
-    <plugins>
-      <plugin>
-        <groupId>net.alchim31.maven</groupId>
-        <artifactId>scala-maven-plugin</artifactId>
-        <version>3.3.1</version>
-      </plugin>
-    </plugins>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>net.alchim31.maven</groupId>
+          <artifactId>scala-maven-plugin</artifactId>
+          <version>3.3.1</version>
+          <configuration>
+            <scalaVersion>2.12.4</scalaVersion>
+          </configuration>
+        </plugin>
+      </plugins>
+    </pluginManagement>
   </build>
 
-  <dependencies>
-    <dependency>
-      <groupId>org.apache.plx4x</groupId>
-      <artifactId>plc4j-api</artifactId>
-      <version>0.0.1-SNAPSHOT</version>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.plx4x</groupId>
-      <artifactId>plc4j-core</artifactId>
-      <version>0.0.1-SNAPSHOT</version>
-    </dependency>
-  </dependencies>
+  <dependencyManagement>
+    <dependencies>
+      <dependency>
+        <groupId>org.apache.plx4x</groupId>
+        <artifactId>plc4j-api</artifactId>
+        <version>0.0.1-SNAPSHOT</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.plx4x</groupId>
+        <artifactId>plc4j-core</artifactId>
+        <version>0.0.1-SNAPSHOT</version>
+      </dependency>
+    </dependencies>
+  </dependencyManagement>
 </project>
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
"commits@plc4x.apache.org" <co...@plc4x.apache.org>.

[incubator-plc4x] 06/07: Add very simple reader implementation

Posted by br...@apache.org.
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 ca7583f310fef12cee8690b96adbe8cf0a833ab7
Author: Benedikt Ritter <be...@codecentric.de>
AuthorDate: Tue Nov 21 14:48:35 2017 +0100

    Add very simple reader implementation
---
 plc4s/api/pom.xml                                  |  5 +++
 .../plc4x/scala/api/connection/PlcReader.scala     | 48 ++++++++++++++++++++++
 .../plc4x/scala/api/messages/PlcMessage.scala      | 36 ++++++++++++++++
 .../plc4x/scala/core/JPlcConnectionWrapper.scala   |  2 +-
 4 files changed, 90 insertions(+), 1 deletion(-)

diff --git a/plc4s/api/pom.xml b/plc4s/api/pom.xml
index 5a80c34..3406be9 100644
--- a/plc4s/api/pom.xml
+++ b/plc4s/api/pom.xml
@@ -53,6 +53,11 @@
       <groupId>org.apache.plx4x</groupId>
       <artifactId>plc4j-core</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.scala-lang.modules</groupId>
+      <artifactId>scala-java8-compat_2.12</artifactId>
+      <version>0.8.0</version>
+    </dependency>
   </dependencies>
 
 </project>
\ No newline at end of file
diff --git a/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/connection/PlcReader.scala b/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/connection/PlcReader.scala
new file mode 100644
index 0000000..dd6c323
--- /dev/null
+++ b/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/connection/PlcReader.scala
@@ -0,0 +1,48 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+package org.apache.plc4x.scala.api.connection
+
+import org.apache.plc4x.java.connection.{PlcReader => JPlcReader}
+import org.apache.plc4x.java.messages.PlcSimpleReadRequest
+import org.apache.plc4x.java.types.Value
+import org.apache.plc4x.scala.api.messages.{SimpleReadRequest, SimpleReadResponse}
+
+import scala.compat.java8.FutureConverters._
+import scala.concurrent.{ExecutionContext, Future}
+
+/**
+  * Interface implemented by all PlcConnections that are able to read from remote resources.
+  */
+trait PlcReader {
+
+    def reader: JPlcReader
+
+    /**
+      * Reads a requested value from a PLC.
+      *
+      * @param readRequest object describing the type and location of the value.
+      * @param T The value type that should be used.
+      * @return a { @link Future} giving async access to the returned value.
+      */
+    def read[T](readRequest: SimpleReadRequest[T])(implicit ec: ExecutionContext): Future[SimpleReadResponse[T]] = {
+        val jRequest = new PlcSimpleReadRequest[Value[T]](classOf[Value[T]], readRequest.address)
+        reader.read(jRequest).toScala.map { response => SimpleReadResponse(response.getAddress, response.getValue.getValue) }
+    }
+
+}
diff --git a/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/messages/PlcMessage.scala b/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/messages/PlcMessage.scala
new file mode 100644
index 0000000..d6f74e5
--- /dev/null
+++ b/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/messages/PlcMessage.scala
@@ -0,0 +1,36 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+package org.apache.plc4x.scala.api.messages
+
+import org.apache.plc4x.java.messages.Address
+
+sealed trait PlcMessage
+
+sealed trait PlcRequest extends PlcMessage {
+    def address: Address
+}
+
+final case class SimpleReadRequest[T](address: Address)
+
+sealed trait PlcResponse[T] extends PlcMessage {
+    def address: Address
+    def value: T
+}
+
+final case class SimpleReadResponse[T](address: Address, value: T)
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 914ccac..65ac689 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
@@ -24,7 +24,7 @@ import org.apache.plc4x.scala.api.connection.PlcConnection
 
 import scala.util.{Failure, Success, Try}
 
-private[core] class JPlcConnectionWrapper(val jPlcConnection: JPlcConnection) extends PlcConnection  {
+private[core] class JPlcConnectionWrapper(val jPlcConnection: JPlcConnection) extends PlcConnection {
 
     override def connect() = Try(jPlcConnection.connect()) match {
         case Success(_) => Right(Unit)

-- 
To stop receiving notification emails like this one, please contact
"commits@plc4x.apache.org" <co...@plc4x.apache.org>.

[incubator-plc4x] 07/07: Move conversions between Java and Scala API objects to separate file

Posted by br...@apache.org.
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 b6b345ff4bb59142dad6dd2a311195e9d28f75fa
Author: Benedikt Ritter <be...@codecentric.de>
AuthorDate: Tue Nov 21 17:28:47 2017 +0100

    Move conversions between Java and Scala API objects to separate file
---
 .../PlcMessageConversions.scala}                   | 24 +++++++++++-----------
 .../plc4x/scala/api/connection/PlcReader.scala     | 13 +++++-------
 .../plc4x/scala/api/messages/PlcMessage.scala      |  4 ++--
 3 files changed, 19 insertions(+), 22 deletions(-)

diff --git a/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/messages/PlcMessage.scala b/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/connection/PlcMessageConversions.scala
similarity index 51%
copy from plc4s/api/src/main/scala/org/apache/plc4x/scala/api/messages/PlcMessage.scala
copy to plc4s/api/src/main/scala/org/apache/plc4x/scala/api/connection/PlcMessageConversions.scala
index d6f74e5..7ec2a2f 100644
--- a/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/messages/PlcMessage.scala
+++ b/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/connection/PlcMessageConversions.scala
@@ -16,21 +16,21 @@ KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
 */
-package org.apache.plc4x.scala.api.messages
+package org.apache.plc4x.scala.api.connection
 
-import org.apache.plc4x.java.messages.Address
+import org.apache.plc4x.java.messages.{PlcSimpleReadRequest, PlcSimpleReadResponse}
+import org.apache.plc4x.java.types.Value
+import org.apache.plc4x.scala.api.messages.{SimpleReadRequest, SimpleReadResponse}
 
-sealed trait PlcMessage
+private[connection] object PlcMessageConversions {
 
-sealed trait PlcRequest extends PlcMessage {
-    def address: Address
-}
+    implicit class SimpleRequestOps[T](req: SimpleReadRequest[T]) {
 
-final case class SimpleReadRequest[T](address: Address)
+        def toJava: PlcSimpleReadRequest[Value[T]] = new PlcSimpleReadRequest[Value[T]](classOf[Value[T]], req.address, req.size)
+    }
 
-sealed trait PlcResponse[T] extends PlcMessage {
-    def address: Address
-    def value: T
-}
+    implicit class PlcSimpleReadResponseOps[T](resp: PlcSimpleReadResponse[Value[T]]) {
 
-final case class SimpleReadResponse[T](address: Address, value: T)
+        def toScala: SimpleReadResponse[T] = SimpleReadResponse(resp.getAddress, resp.getValue.getValue, resp.getSize)
+    }
+}
diff --git a/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/connection/PlcReader.scala b/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/connection/PlcReader.scala
index dd6c323..4fe8380 100644
--- a/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/connection/PlcReader.scala
+++ b/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/connection/PlcReader.scala
@@ -19,8 +19,7 @@ under the License.
 package org.apache.plc4x.scala.api.connection
 
 import org.apache.plc4x.java.connection.{PlcReader => JPlcReader}
-import org.apache.plc4x.java.messages.PlcSimpleReadRequest
-import org.apache.plc4x.java.types.Value
+import org.apache.plc4x.scala.api.connection.PlcMessageConversions._
 import org.apache.plc4x.scala.api.messages.{SimpleReadRequest, SimpleReadResponse}
 
 import scala.compat.java8.FutureConverters._
@@ -37,12 +36,10 @@ trait PlcReader {
       * Reads a requested value from a PLC.
       *
       * @param readRequest object describing the type and location of the value.
-      * @param T The value type that should be used.
-      * @return a { @link Future} giving async access to the returned value.
+      * @tparam T The value type that should be used.
+      * @return a [[Future]] giving async access to the returned value.
       */
-    def read[T](readRequest: SimpleReadRequest[T])(implicit ec: ExecutionContext): Future[SimpleReadResponse[T]] = {
-        val jRequest = new PlcSimpleReadRequest[Value[T]](classOf[Value[T]], readRequest.address)
-        reader.read(jRequest).toScala.map { response => SimpleReadResponse(response.getAddress, response.getValue.getValue) }
-    }
+    def read[T](readRequest: SimpleReadRequest[T])(implicit ec: ExecutionContext): Future[SimpleReadResponse[T]] =
+        reader.read(readRequest.toJava).toScala.map { _.toScala }
 
 }
diff --git a/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/messages/PlcMessage.scala b/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/messages/PlcMessage.scala
index d6f74e5..b08f270 100644
--- a/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/messages/PlcMessage.scala
+++ b/plc4s/api/src/main/scala/org/apache/plc4x/scala/api/messages/PlcMessage.scala
@@ -26,11 +26,11 @@ sealed trait PlcRequest extends PlcMessage {
     def address: Address
 }
 
-final case class SimpleReadRequest[T](address: Address)
+final case class SimpleReadRequest[T](address: Address, size: Int = 1)
 
 sealed trait PlcResponse[T] extends PlcMessage {
     def address: Address
     def value: T
 }
 
-final case class SimpleReadResponse[T](address: Address, value: T)
+final case class SimpleReadResponse[T](address: Address, value: T, size: Int)

-- 
To stop receiving notification emails like this one, please contact
"commits@plc4x.apache.org" <co...@plc4x.apache.org>.

[incubator-plc4x] 01/07: PoC for compiling Scala with Maven

Posted by br...@apache.org.
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 a1f7b8d4f0afc8a2694016ea842aef969ce36d26
Author: Benedikt Ritter <be...@codecentric.de>
AuthorDate: Sat Nov 18 14:43:53 2017 +0100

    PoC for compiling Scala with Maven
---
 plc4s/pom.xml                                      | 24 +++++++++++++++++++++
 .../main/scala/org/apache/plc4x/scala/Test.scala   | 25 ++++++++++++++++++++++
 2 files changed, 49 insertions(+)

diff --git a/plc4s/pom.xml b/plc4s/pom.xml
index 97ed883..5069048 100644
--- a/plc4s/pom.xml
+++ b/plc4s/pom.xml
@@ -39,4 +39,28 @@
     
   </modules>
 
+  <build>
+    <sourceDirectory>src/main/scala</sourceDirectory>
+    <testSourceDirectory>src/test/scala</testSourceDirectory>
+    <plugins>
+      <plugin>
+        <groupId>net.alchim31.maven</groupId>
+        <artifactId>scala-maven-plugin</artifactId>
+        <version>3.3.1</version>
+      </plugin>
+    </plugins>
+  </build>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.plx4x</groupId>
+      <artifactId>plc4j-api</artifactId>
+      <version>0.0.1-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.plx4x</groupId>
+      <artifactId>plc4j-core</artifactId>
+      <version>0.0.1-SNAPSHOT</version>
+    </dependency>
+  </dependencies>
 </project>
\ No newline at end of file
diff --git a/plc4s/src/main/scala/org/apache/plc4x/scala/Test.scala b/plc4s/src/main/scala/org/apache/plc4x/scala/Test.scala
new file mode 100644
index 0000000..19f7c64
--- /dev/null
+++ b/plc4s/src/main/scala/org/apache/plc4x/scala/Test.scala
@@ -0,0 +1,25 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+package org.apache.plc4x.scala
+
+class Test {
+    def main(args: Array[String]): Unit = {
+        println("Hello World!")
+    }
+}

-- 
To stop receiving notification emails like this one, please contact
"commits@plc4x.apache.org" <co...@plc4x.apache.org>.