You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2019/08/30 14:51:14 UTC

[plc4x] branch develop updated (1689aa8 -> 01e02b0)

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

cdutz pushed a change to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git.


    from 1689aa8  - Added an "outputFlavor" element to the plugin configuration which allows selecting different variants of output. - Made sure the generated sources contain the output flavor in the package names to avoid collisions in fat-jar installations.
     new 7f3847f  - Adjusted the java template to respect the "passive" output flavor
     new 01e02b0  - Refactored the AbEthProtocol to use a generic netty driver layer build to support generated drivers

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


Summary of changes:
 .../main/resources/templates/java/io-template.ftlh |  4 ++-
 .../resources/templates/java/pojo-template.ftlh    |  5 ++-
 plc4j/protocols/driver-bases/base/pom.xml          |  5 +++
 .../base/GeneratedDriverByteToMessageCodec.java    | 25 +++++++-------
 .../java/org/apache/plc4x/java/utils/Message.java  |  3 ++
 .../org/apache/plc4x/java/utils/SizeAware.java     | 26 --------------
 .../protocol/test/ProtocolTestsuiteRunner.java     |  2 +-
 .../plc4x/java/abeth/protocol/AbEthProtocol.java   | 40 ++--------------------
 8 files changed, 29 insertions(+), 81 deletions(-)
 copy sandbox/test-java-ab-eth-driver/src/main/java/org/apache/plc4x/java/abeth/protocol/AbEthProtocol.java => plc4j/protocols/driver-bases/base/src/main/java/org/apache/plc4x/java/base/GeneratedDriverByteToMessageCodec.java (67%)
 delete mode 100644 plc4j/utils/driver-base-java/src/main/java/org/apache/plc4x/java/utils/SizeAware.java


[plc4x] 01/02: - Adjusted the java template to respect the "passive" output flavor

Posted by cd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit 7f3847fecb53ffff7f0453e034bee6db39e595e0
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Fri Aug 30 16:18:09 2019 +0200

    - Adjusted the java template to respect the "passive" output flavor
---
 .../language-java/src/main/resources/templates/java/io-template.ftlh  | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/build-utils/language-java/src/main/resources/templates/java/io-template.ftlh b/build-utils/language-java/src/main/resources/templates/java/io-template.ftlh
index 27d7421..b42dfbc 100644
--- a/build-utils/language-java/src/main/resources/templates/java/io-template.ftlh
+++ b/build-utils/language-java/src/main/resources/templates/java/io-template.ftlh
@@ -48,7 +48,7 @@ import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.*;
 
-public class ${typeName}IO implements MessageIO<${typeName}<#if helper.isDiscriminatedType(type)>IO.${typeName}Builder</#if>, ${typeName}> {
+public class ${typeName}IO implements <#if outputFlavor == "passive">MessageInput<${typeName}<#if helper.isDiscriminatedType(type)>IO.${typeName}Builder</#if>><#else>MessageIO<${typeName}<#if helper.isDiscriminatedType(type)>IO.${typeName}Builder</#if>, ${typeName}></#if> {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(${typeName}IO.class);
 
@@ -281,6 +281,7 @@ public class ${typeName}IO implements MessageIO<${typeName}<#if helper.isDiscrim
         </#if>
     }
 
+<#if outputFlavor != "passive">
     public void serialize(WriteBuffer io, ${typeName} value, Object... args) throws ParseException {
 <#if type.parserArguments?has_content>
 <#list type.parserArguments as parserArgument>
@@ -389,6 +390,7 @@ public class ${typeName}IO implements MessageIO<${typeName}<#if helper.isDiscrim
 </#switch>
 </#list>
     }
+</#if>
 
     private static int COUNT(Object obj) {
         if(obj.getClass().isArray()) {


[plc4x] 02/02: - Refactored the AbEthProtocol to use a generic netty driver layer build to support generated drivers

Posted by cd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit 01e02b00f6d2b54ed5ee731afe53fcbe57f4cb75
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Fri Aug 30 16:51:07 2019 +0200

    - Refactored the AbEthProtocol to use a generic netty driver layer build to support generated drivers
---
 .../resources/templates/java/pojo-template.ftlh    |  5 ++-
 plc4j/protocols/driver-bases/base/pom.xml          |  5 +++
 .../base/GeneratedDriverByteToMessageCodec.java    | 25 +++++++-------
 .../java/org/apache/plc4x/java/utils/Message.java  |  3 ++
 .../org/apache/plc4x/java/utils/SizeAware.java     | 26 --------------
 .../protocol/test/ProtocolTestsuiteRunner.java     |  2 +-
 .../plc4x/java/abeth/protocol/AbEthProtocol.java   | 40 ++--------------------
 7 files changed, 26 insertions(+), 80 deletions(-)

diff --git a/build-utils/language-java/src/main/resources/templates/java/pojo-template.ftlh b/build-utils/language-java/src/main/resources/templates/java/pojo-template.ftlh
index b3fbaf8..c8c5fb6 100644
--- a/build-utils/language-java/src/main/resources/templates/java/pojo-template.ftlh
+++ b/build-utils/language-java/src/main/resources/templates/java/pojo-template.ftlh
@@ -40,10 +40,9 @@ package ${helper.packageName(protocolName, languageName, outputFlavor)};
 
 import com.fasterxml.jackson.annotation.*;
 import org.apache.plc4x.java.utils.Message;
-import org.apache.plc4x.java.utils.SizeAware;
 
 <#if type.abstract>@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "className")</#if>
-public<#if type.abstract> abstract</#if> class ${typeName}<#if type.parentType??> extends ${type.parentType.name}</#if> implements SizeAware, Message {
+public<#if type.abstract> abstract</#if> class ${typeName}<#if type.parentType??> extends ${type.parentType.name}</#if> implements Message {
 
 <#if helper.isDiscriminatedType(type)>
 
@@ -117,7 +116,7 @@ public<#if type.abstract> abstract</#if> class ${typeName}<#if type.parentType??
         <#if helper.isSimpleType(field.type)>
         lengthInBits += ${field.type.size} * ${field.name}.length;
         <#else>
-        for(SizeAware element : ${field.name}) {
+        for(Message element : ${field.name}) {
             lengthInBits += element.getLengthInBytes() * 8;
         }
         </#if>
diff --git a/plc4j/protocols/driver-bases/base/pom.xml b/plc4j/protocols/driver-bases/base/pom.xml
index aa0cbcc..e27b060 100644
--- a/plc4j/protocols/driver-bases/base/pom.xml
+++ b/plc4j/protocols/driver-bases/base/pom.xml
@@ -37,6 +37,11 @@
       <artifactId>plc4j-api</artifactId>
       <version>0.5.0-SNAPSHOT</version>
     </dependency>
+    <dependency>
+      <groupId>org.apache.plc4x</groupId>
+      <artifactId>plc4j-utils-driver-base-java</artifactId>
+      <version>0.5.0-SNAPSHOT</version>
+    </dependency>
 
     <dependency>
       <groupId>org.apache.commons</groupId>
diff --git a/sandbox/test-java-ab-eth-driver/src/main/java/org/apache/plc4x/java/abeth/protocol/AbEthProtocol.java b/plc4j/protocols/driver-bases/base/src/main/java/org/apache/plc4x/java/base/GeneratedDriverByteToMessageCodec.java
similarity index 67%
copy from sandbox/test-java-ab-eth-driver/src/main/java/org/apache/plc4x/java/abeth/protocol/AbEthProtocol.java
copy to plc4j/protocols/driver-bases/base/src/main/java/org/apache/plc4x/java/base/GeneratedDriverByteToMessageCodec.java
index e8ad9e0..4ac7fb6 100644
--- a/sandbox/test-java-ab-eth-driver/src/main/java/org/apache/plc4x/java/abeth/protocol/AbEthProtocol.java
+++ b/plc4j/protocols/driver-bases/base/src/main/java/org/apache/plc4x/java/base/GeneratedDriverByteToMessageCodec.java
@@ -16,13 +16,12 @@ KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
 */
-package org.apache.plc4x.java.abeth.protocol;
+package org.apache.plc4x.java.base;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.channel.ChannelHandlerContext;
-import org.apache.plc4x.java.abeth.readwrite.CIPEncapsulationPacket;
-import org.apache.plc4x.java.abeth.readwrite.io.CIPEncapsulationPacketIO;
-import org.apache.plc4x.java.base.PlcByteToMessageCodec;
+import org.apache.plc4x.java.utils.Message;
+import org.apache.plc4x.java.utils.MessageIO;
 import org.apache.plc4x.java.utils.ReadBuffer;
 import org.apache.plc4x.java.utils.WriteBuffer;
 import org.slf4j.Logger;
@@ -30,20 +29,20 @@ import org.slf4j.LoggerFactory;
 
 import java.util.List;
 
-public class AbEthProtocol extends PlcByteToMessageCodec<CIPEncapsulationPacket> {
+public abstract class GeneratedDriverByteToMessageCodec<T extends Message> extends PlcByteToMessageCodec<T> {
 
-    private static final Logger logger = LoggerFactory.getLogger(AbEthProtocol.class);
+    private static final Logger logger = LoggerFactory.getLogger(GeneratedDriverByteToMessageCodec.class);
 
-    private CIPEncapsulationPacketIO io;
+    private MessageIO<T, T> io;
 
-    public AbEthProtocol() {
-        io = new CIPEncapsulationPacketIO();
+    public GeneratedDriverByteToMessageCodec(MessageIO<T, T> io) {
+        this.io = io;
     }
 
     @Override
-    protected void encode(ChannelHandlerContext ctx, CIPEncapsulationPacket cipEncapsulationPacket, ByteBuf byteBuf) throws Exception {
-        WriteBuffer buffer = new WriteBuffer(cipEncapsulationPacket.getLengthInBytes());
-        io.serialize(buffer, cipEncapsulationPacket);
+    protected void encode(ChannelHandlerContext ctx, T packet, ByteBuf byteBuf) throws Exception {
+        WriteBuffer buffer = new WriteBuffer(packet.getLengthInBytes());
+        io.serialize(buffer, packet);
         byteBuf.writeBytes(buffer.getData());
     }
 
@@ -54,7 +53,7 @@ public class AbEthProtocol extends PlcByteToMessageCodec<CIPEncapsulationPacket>
         ReadBuffer readBuffer = new ReadBuffer(bytes);
         while (readBuffer.getPos() < bytes.length) {
             try {
-                CIPEncapsulationPacket packet = io.parse(readBuffer);
+                T packet = io.parse(readBuffer);
                 out.add(packet);
             } catch (Exception e) {
                 logger.warn("Error decoding package: " + e.getMessage());
diff --git a/plc4j/utils/driver-base-java/src/main/java/org/apache/plc4x/java/utils/Message.java b/plc4j/utils/driver-base-java/src/main/java/org/apache/plc4x/java/utils/Message.java
index 7bc60b6..e12a6bb 100644
--- a/plc4j/utils/driver-base-java/src/main/java/org/apache/plc4x/java/utils/Message.java
+++ b/plc4j/utils/driver-base-java/src/main/java/org/apache/plc4x/java/utils/Message.java
@@ -20,4 +20,7 @@
 package org.apache.plc4x.java.utils;
 
 public interface Message {
+
+    int getLengthInBytes();
+
 }
diff --git a/plc4j/utils/driver-base-java/src/main/java/org/apache/plc4x/java/utils/SizeAware.java b/plc4j/utils/driver-base-java/src/main/java/org/apache/plc4x/java/utils/SizeAware.java
deleted file mode 100644
index c11d379..0000000
--- a/plc4j/utils/driver-base-java/src/main/java/org/apache/plc4x/java/utils/SizeAware.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- 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.java.utils;
-
-public interface SizeAware {
-
-    int getLengthInBytes();
-
-}
diff --git a/plc4j/utils/protocol-test-utils/src/main/java/org/apache/plc4x/protocol/test/ProtocolTestsuiteRunner.java b/plc4j/utils/protocol-test-utils/src/main/java/org/apache/plc4x/protocol/test/ProtocolTestsuiteRunner.java
index 7e1f299..9e8a3f1 100644
--- a/plc4j/utils/protocol-test-utils/src/main/java/org/apache/plc4x/protocol/test/ProtocolTestsuiteRunner.java
+++ b/plc4j/utils/protocol-test-utils/src/main/java/org/apache/plc4x/protocol/test/ProtocolTestsuiteRunner.java
@@ -112,7 +112,7 @@ public class ProtocolTestsuiteRunner {
                 System.out.println(xmlString);
                 throw new ProtocolTestsuiteException("Differences were found after parsing.\n" + diff.toString());
             }
-            WriteBuffer writeBuffer = new WriteBuffer(((SizeAware) msg).getLengthInBytes(), testSuite.isLittleEndian());
+            WriteBuffer writeBuffer = new WriteBuffer(((Message) msg).getLengthInBytes(), testSuite.isLittleEndian());
             messageIO.serialize(writeBuffer, msg);
             byte[] data = writeBuffer.getData();
             if(testcase.getRaw().length != data.length) {
diff --git a/sandbox/test-java-ab-eth-driver/src/main/java/org/apache/plc4x/java/abeth/protocol/AbEthProtocol.java b/sandbox/test-java-ab-eth-driver/src/main/java/org/apache/plc4x/java/abeth/protocol/AbEthProtocol.java
index e8ad9e0..34c6e64 100644
--- a/sandbox/test-java-ab-eth-driver/src/main/java/org/apache/plc4x/java/abeth/protocol/AbEthProtocol.java
+++ b/sandbox/test-java-ab-eth-driver/src/main/java/org/apache/plc4x/java/abeth/protocol/AbEthProtocol.java
@@ -18,48 +18,14 @@ under the License.
 */
 package org.apache.plc4x.java.abeth.protocol;
 
-import io.netty.buffer.ByteBuf;
-import io.netty.channel.ChannelHandlerContext;
 import org.apache.plc4x.java.abeth.readwrite.CIPEncapsulationPacket;
 import org.apache.plc4x.java.abeth.readwrite.io.CIPEncapsulationPacketIO;
-import org.apache.plc4x.java.base.PlcByteToMessageCodec;
-import org.apache.plc4x.java.utils.ReadBuffer;
-import org.apache.plc4x.java.utils.WriteBuffer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.apache.plc4x.java.base.GeneratedDriverByteToMessageCodec;
 
-import java.util.List;
-
-public class AbEthProtocol extends PlcByteToMessageCodec<CIPEncapsulationPacket> {
-
-    private static final Logger logger = LoggerFactory.getLogger(AbEthProtocol.class);
-
-    private CIPEncapsulationPacketIO io;
+public class AbEthProtocol extends GeneratedDriverByteToMessageCodec<CIPEncapsulationPacket> {
 
     public AbEthProtocol() {
-        io = new CIPEncapsulationPacketIO();
-    }
-
-    @Override
-    protected void encode(ChannelHandlerContext ctx, CIPEncapsulationPacket cipEncapsulationPacket, ByteBuf byteBuf) throws Exception {
-        WriteBuffer buffer = new WriteBuffer(cipEncapsulationPacket.getLengthInBytes());
-        io.serialize(buffer, cipEncapsulationPacket);
-        byteBuf.writeBytes(buffer.getData());
-    }
-
-    @Override
-    protected void decode(ChannelHandlerContext ctx, ByteBuf byteBuf, List<Object> out) throws Exception {
-        byte[] bytes = new byte[byteBuf.readableBytes()];
-        byteBuf.readBytes(bytes);
-        ReadBuffer readBuffer = new ReadBuffer(bytes);
-        while (readBuffer.getPos() < bytes.length) {
-            try {
-                CIPEncapsulationPacket packet = io.parse(readBuffer);
-                out.add(packet);
-            } catch (Exception e) {
-                logger.warn("Error decoding package: " + e.getMessage());
-            }
-        }
+        super(new CIPEncapsulationPacketIO());
     }
 
 }