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

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

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>.