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 2020/04/05 19:04:52 UTC

[plc4x] branch develop updated: - Added a dummy template for c (generates empty c and h files) - Enabled the modbus and s7 c-type driver library compilation (empty however)

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


The following commit(s) were added to refs/heads/develop by this push:
     new e3bf6fa  - Added a dummy template for c (generates empty c and h files) - Enabled the modbus and s7 c-type driver library compilation (empty however)
e3bf6fa is described below

commit e3bf6facb4a554079eb1338891d9796643a22a8e
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Sun Apr 5 21:04:45 2020 +0200

    - Added a dummy template for c (generates empty c and h files)
    - Enabled the modbus and s7 c-type driver library compilation (empty however)
---
 build-utils/language-c/pom.xml                     | 58 +++++++++++++++++
 .../apache/plc4x/language/c/CLanguageOutput.java   | 72 ++++++++++++++++++++++
 .../plc4x/language/c/CLanguageTemplateHelper.java  | 39 ++++++++++++
 ...x.plugins.codegenerator.language.LanguageOutput | 19 ++++++
 .../resources/templates/c/pojo-template-c.ftlh     | 38 ++++++++++++
 .../resources/templates/c/pojo-template-h.ftlh     | 38 ++++++++++++
 build-utils/pom.xml                                |  1 +
 sandbox/plc4c/CMakeLists.txt                       |  2 +-
 sandbox/plc4c/drivers/modbus/CMakeLists.txt        | 12 +++-
 .../CMakeLists.txt => modbus/src/main/c/Test.c}    |  8 +--
 .../src/main/include/Test.h}                       |  8 +--
 sandbox/plc4c/drivers/s7/CMakeLists.txt            | 12 +++-
 .../s7/{CMakeLists.txt => src/main/c/Test.c}       |  8 +--
 .../s7/{CMakeLists.txt => src/main/include/Test.h} |  8 +--
 sandbox/plc4c/pom.xml                              | 55 +++++++++++++++--
 15 files changed, 345 insertions(+), 33 deletions(-)

diff --git a/build-utils/language-c/pom.xml b/build-utils/language-c/pom.xml
new file mode 100644
index 0000000..27b5c5e
--- /dev/null
+++ b/build-utils/language-c/pom.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+  -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.plc4x</groupId>
+    <artifactId>plc4x-build-utils</artifactId>
+    <version>0.7.0-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>plc4x-build-utils-language-c</artifactId>
+
+  <name>PLC4X: Build Utils: Language: C</name>
+  <description>Code generation template for generating C code</description>
+
+  <dependencies>
+    <!-- We are using the Freemarker module to generate Java code -->
+    <dependency>
+      <groupId>org.apache.plc4x</groupId>
+      <artifactId>plc4x-build-utils-language-base-freemarker</artifactId>
+      <version>0.7.0-SNAPSHOT</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.plc4x.plugins</groupId>
+      <artifactId>plc4x-code-generation-types-base</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.freemarker</groupId>
+      <artifactId>freemarker</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-text</artifactId>
+    </dependency>
+  </dependencies>
+
+</project>
\ No newline at end of file
diff --git a/build-utils/language-c/src/main/java/org/apache/plc4x/language/c/CLanguageOutput.java b/build-utils/language-c/src/main/java/org/apache/plc4x/language/c/CLanguageOutput.java
new file mode 100644
index 0000000..f37350e
--- /dev/null
+++ b/build-utils/language-c/src/main/java/org/apache/plc4x/language/c/CLanguageOutput.java
@@ -0,0 +1,72 @@
+/*
+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.language.c;
+
+import freemarker.template.Configuration;
+import freemarker.template.Template;
+import org.apache.plc4x.plugins.codegenerator.protocol.freemarker.FreemarkerLanguageOutput;
+import org.apache.plc4x.plugins.codegenerator.protocol.freemarker.FreemarkerLanguageTemplateHelper;
+import org.apache.plc4x.plugins.codegenerator.types.definitions.TypeDefinition;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+public class CLanguageOutput extends FreemarkerLanguageOutput {
+
+    @Override
+    public String getName() {
+        return "C";
+    }
+
+    @Override
+    public List<String> supportedOutputFlavors() {
+        return Collections.singletonList("read-write");
+    }
+
+    @Override
+    protected List<Template> getSpecTemplates(Configuration freemarkerConfiguration) throws IOException {
+        return Collections.emptyList();
+    }
+
+    @Override
+    protected List<Template> getComplexTypeTemplates(Configuration freemarkerConfiguration) throws IOException {
+        return Arrays.asList(
+            freemarkerConfiguration.getTemplate("templates/c/pojo-template-h.ftlh"),
+            freemarkerConfiguration.getTemplate("templates/c/pojo-template-c.ftlh"));
+    }
+
+    @Override
+    protected List<Template> getEnumTypeTemplates(Configuration freemarkerConfiguration) throws IOException {
+        return Collections.emptyList();
+    }
+
+    @Override
+    protected List<Template> getDataIoTemplates(Configuration freemarkerConfiguration) throws IOException {
+        return Collections.emptyList();
+    }
+
+    @Override
+    protected FreemarkerLanguageTemplateHelper getHelper(Map<String, TypeDefinition> types) {
+        return new CLanguageTemplateHelper(types);
+    }
+
+}
diff --git a/build-utils/language-c/src/main/java/org/apache/plc4x/language/c/CLanguageTemplateHelper.java b/build-utils/language-c/src/main/java/org/apache/plc4x/language/c/CLanguageTemplateHelper.java
new file mode 100644
index 0000000..18994c1
--- /dev/null
+++ b/build-utils/language-c/src/main/java/org/apache/plc4x/language/c/CLanguageTemplateHelper.java
@@ -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.language.c;
+
+import org.apache.plc4x.plugins.codegenerator.protocol.freemarker.FreemarkerLanguageTemplateHelper;
+import org.apache.plc4x.plugins.codegenerator.types.definitions.TypeDefinition;
+
+import java.util.Map;
+
+public class CLanguageTemplateHelper implements FreemarkerLanguageTemplateHelper {
+
+    public CLanguageTemplateHelper(Map<String, TypeDefinition> types) {
+    }
+
+    public String getSourceDirectory(String protocolName) {
+        return String.join("", protocolName.split("-")) + ".src.main.c";
+    }
+
+    public String getIncludesDirectory(String protocolName) {
+        return String.join("", protocolName.split("-"))  + ".src.main.include";
+    }
+
+}
diff --git a/build-utils/language-c/src/main/resources/META-INF/services/org.apache.plc4x.plugins.codegenerator.language.LanguageOutput b/build-utils/language-c/src/main/resources/META-INF/services/org.apache.plc4x.plugins.codegenerator.language.LanguageOutput
new file mode 100644
index 0000000..31f7050
--- /dev/null
+++ b/build-utils/language-c/src/main/resources/META-INF/services/org.apache.plc4x.plugins.codegenerator.language.LanguageOutput
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+org.apache.plc4x.language.c.CLanguageOutput
diff --git a/build-utils/language-c/src/main/resources/templates/c/pojo-template-c.ftlh b/build-utils/language-c/src/main/resources/templates/c/pojo-template-c.ftlh
new file mode 100644
index 0000000..cc5634c
--- /dev/null
+++ b/build-utils/language-c/src/main/resources/templates/c/pojo-template-c.ftlh
@@ -0,0 +1,38 @@
+<#--
+  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.
+-->
+${helper.getSourceDirectory(protocolName)?replace(".", "/")}/${typeName}.c
+/*
+  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.
+*/
+
diff --git a/build-utils/language-c/src/main/resources/templates/c/pojo-template-h.ftlh b/build-utils/language-c/src/main/resources/templates/c/pojo-template-h.ftlh
new file mode 100644
index 0000000..5bfd7ee
--- /dev/null
+++ b/build-utils/language-c/src/main/resources/templates/c/pojo-template-h.ftlh
@@ -0,0 +1,38 @@
+<#--
+  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.
+-->
+${helper.getIncludesDirectory(protocolName)?replace(".", "/")}/${typeName}.h
+/*
+  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.
+*/
+
diff --git a/build-utils/pom.xml b/build-utils/pom.xml
index 975898b..99282dd 100644
--- a/build-utils/pom.xml
+++ b/build-utils/pom.xml
@@ -37,6 +37,7 @@
     <module>language-base-freemarker</module>
     <module>protocol-base-mspec</module>
 
+    <module>language-c</module>
     <module>language-java</module>
     <module>protocol-test</module>
   </modules>
diff --git a/sandbox/plc4c/CMakeLists.txt b/sandbox/plc4c/CMakeLists.txt
index fb6da71..b1558ca 100644
--- a/sandbox/plc4c/CMakeLists.txt
+++ b/sandbox/plc4c/CMakeLists.txt
@@ -73,6 +73,6 @@ endif()
 add_subdirectory(api)
 #add_subdirectory(spi)
 #add_subdirectory(transports)
-#add_subdirectory(drivers)
+add_subdirectory(drivers)
 #add_subdirectory(integrations)
 add_subdirectory(examples)
\ No newline at end of file
diff --git a/sandbox/plc4c/drivers/modbus/CMakeLists.txt b/sandbox/plc4c/drivers/modbus/CMakeLists.txt
index 3c61e0a..48c0bac 100644
--- a/sandbox/plc4c/drivers/modbus/CMakeLists.txt
+++ b/sandbox/plc4c/drivers/modbus/CMakeLists.txt
@@ -17,7 +17,15 @@
   under the License.
 ]]
 
-add_library(plc4c-drivers-modbus
-        )
+include_directories("src/main/include"
+                    "${PLC4C_ROOT_DIR}/target/generated-sources/plc4x/modbus/src/main/include")
+
+# Add the sources
+file(GLOB sources "src/main/c/*.c")
+
+# Add the generated sources
+file(GLOB generatedSources "${PLC4C_ROOT_DIR}/target/generated-sources/plc4x/modbus/src/main/c/*.c")
+
+add_library(plc4c-drivers-modbus ${sources} ${generatedSources})
 
 target_link_libraries (plc4c-drivers-modbus ${CMAKE_DL_LIBS})
\ No newline at end of file
diff --git a/sandbox/plc4c/drivers/s7/CMakeLists.txt b/sandbox/plc4c/drivers/modbus/src/main/c/Test.c
similarity index 88%
copy from sandbox/plc4c/drivers/s7/CMakeLists.txt
copy to sandbox/plc4c/drivers/modbus/src/main/c/Test.c
index 6e1b386..a031845 100644
--- a/sandbox/plc4c/drivers/s7/CMakeLists.txt
+++ b/sandbox/plc4c/drivers/modbus/src/main/c/Test.c
@@ -1,4 +1,4 @@
-#[[
+/*
   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
@@ -15,9 +15,5 @@
   KIND, either express or implied.  See the License for the
   specific language governing permissions and limitations
   under the License.
-]]
+*/
 
-add_library(plc4c-drivers-s7
-        )
-
-target_link_libraries (plc4c-drivers-s7 ${CMAKE_DL_LIBS})
\ No newline at end of file
diff --git a/sandbox/plc4c/drivers/s7/CMakeLists.txt b/sandbox/plc4c/drivers/modbus/src/main/include/Test.h
similarity index 88%
copy from sandbox/plc4c/drivers/s7/CMakeLists.txt
copy to sandbox/plc4c/drivers/modbus/src/main/include/Test.h
index 6e1b386..a031845 100644
--- a/sandbox/plc4c/drivers/s7/CMakeLists.txt
+++ b/sandbox/plc4c/drivers/modbus/src/main/include/Test.h
@@ -1,4 +1,4 @@
-#[[
+/*
   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
@@ -15,9 +15,5 @@
   KIND, either express or implied.  See the License for the
   specific language governing permissions and limitations
   under the License.
-]]
+*/
 
-add_library(plc4c-drivers-s7
-        )
-
-target_link_libraries (plc4c-drivers-s7 ${CMAKE_DL_LIBS})
\ No newline at end of file
diff --git a/sandbox/plc4c/drivers/s7/CMakeLists.txt b/sandbox/plc4c/drivers/s7/CMakeLists.txt
index 6e1b386..441ab59 100644
--- a/sandbox/plc4c/drivers/s7/CMakeLists.txt
+++ b/sandbox/plc4c/drivers/s7/CMakeLists.txt
@@ -17,7 +17,15 @@
   under the License.
 ]]
 
-add_library(plc4c-drivers-s7
-        )
+include_directories("src/main/include"
+                    "${PLC4C_ROOT_DIR}/target/generated-sources/plc4x/s7/src/main/include")
+
+# Add the sources
+file(GLOB sources "src/main/c/*.c")
+
+# Add the generated sources
+file(GLOB generatedSources "${PLC4C_ROOT_DIR}/target/generated-sources/plc4x/s7/src/main/c/*.c")
+
+add_library(plc4c-drivers-s7 ${sources} ${generatedSources})
 
 target_link_libraries (plc4c-drivers-s7 ${CMAKE_DL_LIBS})
\ No newline at end of file
diff --git a/sandbox/plc4c/drivers/s7/CMakeLists.txt b/sandbox/plc4c/drivers/s7/src/main/c/Test.c
similarity index 88%
copy from sandbox/plc4c/drivers/s7/CMakeLists.txt
copy to sandbox/plc4c/drivers/s7/src/main/c/Test.c
index 6e1b386..a031845 100644
--- a/sandbox/plc4c/drivers/s7/CMakeLists.txt
+++ b/sandbox/plc4c/drivers/s7/src/main/c/Test.c
@@ -1,4 +1,4 @@
-#[[
+/*
   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
@@ -15,9 +15,5 @@
   KIND, either express or implied.  See the License for the
   specific language governing permissions and limitations
   under the License.
-]]
+*/
 
-add_library(plc4c-drivers-s7
-        )
-
-target_link_libraries (plc4c-drivers-s7 ${CMAKE_DL_LIBS})
\ No newline at end of file
diff --git a/sandbox/plc4c/drivers/s7/CMakeLists.txt b/sandbox/plc4c/drivers/s7/src/main/include/Test.h
similarity index 88%
copy from sandbox/plc4c/drivers/s7/CMakeLists.txt
copy to sandbox/plc4c/drivers/s7/src/main/include/Test.h
index 6e1b386..a031845 100644
--- a/sandbox/plc4c/drivers/s7/CMakeLists.txt
+++ b/sandbox/plc4c/drivers/s7/src/main/include/Test.h
@@ -1,4 +1,4 @@
-#[[
+/*
   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
@@ -15,9 +15,5 @@
   KIND, either express or implied.  See the License for the
   specific language governing permissions and limitations
   under the License.
-]]
+*/
 
-add_library(plc4c-drivers-s7
-        )
-
-target_link_libraries (plc4c-drivers-s7 ${CMAKE_DL_LIBS})
\ No newline at end of file
diff --git a/sandbox/plc4c/pom.xml b/sandbox/plc4c/pom.xml
index cbcad64..7c550e4 100644
--- a/sandbox/plc4c/pom.xml
+++ b/sandbox/plc4c/pom.xml
@@ -159,6 +159,39 @@
         </executions>
       </plugin>
       <!--
+        Generate the driver code.
+      -->
+      <plugin>
+        <groupId>org.apache.plc4x.plugins</groupId>
+        <artifactId>plc4x-maven-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>generate-driver-modbus</id>
+            <phase>generate-sources</phase>
+            <goals>
+              <goal>generate-driver</goal>
+            </goals>
+            <configuration>
+              <protocolName>modbus</protocolName>
+              <languageName>c</languageName>
+              <outputFlavor>read-write</outputFlavor>
+            </configuration>
+          </execution>
+          <execution>
+            <id>generate-driver-s7</id>
+            <phase>generate-sources</phase>
+            <goals>
+              <goal>generate-driver</goal>
+            </goals>
+            <configuration>
+              <protocolName>s7</protocolName>
+              <languageName>c</languageName>
+              <outputFlavor>read-write</outputFlavor>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+      <!--
         Do the actual build.
       -->
       <plugin>
@@ -255,10 +288,24 @@
   <dependencies>
     <dependency>
       <groupId>org.apache.plc4x</groupId>
-      <artifactId>plc4x-tools-thrift</artifactId>
-      <version>${project.version}</version>
-      <type>zip</type>
-      <classifier>compiler-${os.classifier}</classifier>
+      <artifactId>plc4x-build-utils-language-c</artifactId>
+      <version>0.7.0-SNAPSHOT</version>
+      <!-- Scope is 'provided' as this way it's not shipped with the driver -->
+      <scope>provided</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.plc4x</groupId>
+      <artifactId>plc4x-protocols-modbus</artifactId>
+      <version>0.7.0-SNAPSHOT</version>
+      <!-- Scope is 'provided' as this way it's not shipped with the driver -->
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.plc4x</groupId>
+      <artifactId>plc4x-protocols-s7</artifactId>
+      <version>0.7.0-SNAPSHOT</version>
+      <!-- Scope is 'provided' as this way it's not shipped with the driver -->
       <scope>provided</scope>
     </dependency>
   </dependencies>