You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cg...@apache.org on 2024/09/10 12:06:45 UTC

(plc4x-extras) branch feature/merlot updated: Modified device model and started group and item manager.

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

cgarcia pushed a commit to branch feature/merlot
in repository https://gitbox.apache.org/repos/asf/plc4x-extras.git


The following commit(s) were added to refs/heads/feature/merlot by this push:
     new 1e351bc  Modified device model and started group and item manager.
1e351bc is described below

commit 1e351bc934a5ebc948a49dca2a370103579c592b
Author: César García <ce...@ceos.com.ve>
AuthorDate: Tue Sep 10 08:04:07 2024 -0400

    Modified device model and started group and item manager.
---
 .../merlot/api/core/PlcGroupManagedService.java    | 46 ++++++++++++++++++++++
 .../merlot/api/core/PlcItemManagedService.java     | 45 +++++++++++++++++++++
 .../plc4x/merlot/api/impl/PlcDeviceImpl.java       |  5 ++-
 .../resources/OSGI-INF/blueprint/api-service.xml   | 32 +++++++++++++++
 4 files changed, 127 insertions(+), 1 deletion(-)

diff --git a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/core/PlcGroupManagedService.java b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/core/PlcGroupManagedService.java
new file mode 100644
index 0000000..b23749f
--- /dev/null
+++ b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/core/PlcGroupManagedService.java
@@ -0,0 +1,46 @@
+/*
+ * 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.merlot.api.core;
+
+import java.util.Dictionary;
+import java.util.Enumeration;
+import org.osgi.service.cm.ConfigurationEvent;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ConfigurationListener;
+import org.osgi.service.cm.ManagedService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class PlcGroupManagedService implements ManagedService, ConfigurationListener {
+    private static final Logger LOGGER = LoggerFactory.getLogger(PlcGroupManagedService.class);      
+
+    @Override
+    public void updated(Dictionary<String, ?> properties) throws ConfigurationException {
+        if (null != properties){
+            Enumeration<String> keys = properties.keys();            
+            keys.asIterator().forEachRemaining(k -> LOGGER.info("Grupo: " + k));
+        }
+        
+    }
+
+    @Override
+    public void configurationEvent(ConfigurationEvent event) {
+        LOGGER.info("configurationEvent: " + event.toString());        
+    }
+    
+}
diff --git a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/core/PlcItemManagedService.java b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/core/PlcItemManagedService.java
new file mode 100644
index 0000000..93d16b2
--- /dev/null
+++ b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/core/PlcItemManagedService.java
@@ -0,0 +1,45 @@
+/*
+ * 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.merlot.api.core;
+
+import java.util.Dictionary;
+import java.util.Enumeration;
+import org.osgi.service.cm.ConfigurationEvent;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ConfigurationListener;
+import org.osgi.service.cm.ManagedService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class PlcItemManagedService implements ManagedService, ConfigurationListener {
+    private static final Logger LOGGER = LoggerFactory.getLogger(PlcItemManagedService.class);
+    
+    @Override
+    public void updated(Dictionary<String, ?> properties) throws ConfigurationException {
+        if (null != properties){
+            Enumeration<String> keys = properties.keys();            
+            keys.asIterator().forEachRemaining(k -> LOGGER.info("Grupo: " + k));
+        }
+    }
+
+    @Override
+    public void configurationEvent(ConfigurationEvent event) {
+        LOGGER.info("configurationEvent: " + event.toString());
+    }
+    
+}
diff --git a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcDeviceImpl.java b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcDeviceImpl.java
index 1f3dc3c..340c2f6 100644
--- a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcDeviceImpl.java
+++ b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcDeviceImpl.java
@@ -333,6 +333,7 @@ public class PlcDeviceImpl implements PlcDevice {
                     if (null != plcEventConnectionFunction)
                         plcEventConnectionFunction.addEventListener(plcConnection, this);                    
                     enable = false;
+                    deviceProperties.put(Device.SERVICE_STATUS, Device.STATUS_OFFLINE);                     
                     LOGGER.info("Device [{}] connection was close.", deviceProperties.get(Device.SERVICE_NAME));
                 }
             }
@@ -511,6 +512,7 @@ public class PlcDeviceImpl implements PlcDevice {
     @Override
     public void connected() {
         LOGGER.info("Device: {} establish connection with the device.", deviceProperties.get(Device.SERVICE_NAME));
+        deviceProperties.put(Device.SERVICE_STATUS, Device.STATUS_ONLINE);         
     }
 
     /*
@@ -521,7 +523,8 @@ public class PlcDeviceImpl implements PlcDevice {
     */
     @Override
     public void disconnected() {
-        LOGGER.info("Device: {} disconnected from the device.", deviceProperties.get(Device.SERVICE_NAME));        
+        LOGGER.info("Device: {} disconnected from the device.", deviceProperties.get(Device.SERVICE_NAME)); 
+        deviceProperties.put(Device.SERVICE_STATUS, Device.STATUS_OFFLINE);          
     }
 
     /*
diff --git a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/resources/OSGI-INF/blueprint/api-service.xml b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/resources/OSGI-INF/blueprint/api-service.xml
index 43b7ea6..e4cfb89 100644
--- a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/resources/OSGI-INF/blueprint/api-service.xml
+++ b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/resources/OSGI-INF/blueprint/api-service.xml
@@ -80,6 +80,18 @@
             <argument ref="blueprintBundleContext" />
     </bean> 
     
+    <bean id="PlcGroupManagedServiceBean" 
+            class="org.apache.plc4x.merlot.api.core.PlcGroupManagedService" 
+            scope="singleton"
+            activation="eager">
+    </bean> 
+    
+    <bean id="PlcItemManagedServiceBean" 
+            class="org.apache.plc4x.merlot.api.core.PlcItemManagedService" 
+            scope="singleton"
+            activation="eager">
+    </bean>              
+    
     <!--
     -->    
     <bean id="beanPlcItemClientService" 
@@ -177,6 +189,26 @@
             <entry key="scheduler.concurrent" value="false"/>                                                                    
      	</service-properties>        
     </service>   
+    
+    <service ref="PlcGroupManagedServiceBean" auto-export="interfaces">
+    	<service-properties>
+            <entry key="service.pid" value="org.apache.plc4x.merlot.das.groups"/>  
+<!--            <entry key="scheduler.name" value="PlcDeviceManagedService"/>  
+            <entry key="scheduler.period" value="5000"/>
+            <entry key="scheduler.immediate" value="true"/>
+            <entry key="scheduler.concurrent" value="false"/>                                                                    -->
+     	</service-properties>        
+    </service>   
+    
+    <service ref="PlcItemManagedServiceBean" auto-export="interfaces">
+    	<service-properties>
+            <entry key="service.pid" value="org.apache.plc4x.merlot.das.items"/>  
+<!--            <entry key="scheduler.name" value="PlcDeviceManagedService"/>  
+            <entry key="scheduler.period" value="5000"/>
+            <entry key="scheduler.immediate" value="true"/>
+            <entry key="scheduler.concurrent" value="false"/>                                                                    -->
+     	</service-properties>        
+    </service>              
          
     <!--
     -->