Commit fed74dd5 authored by aw613's avatar aw613
Browse files

added thread to execute a configuration rule

parent 7b5d8dcf
......@@ -41,6 +41,8 @@ import org.ws4d.java.util.Log;
public class ConfigurationClient extends DefaultClient implements ConfigurationServiceInterface {
private ArrayList<DPWSInterface> dpwsInterfaces;
DPWSRule rule;
private Thread ruleExecution;
/**
* air conditioner device object
......@@ -82,7 +84,9 @@ public class ConfigurationClient extends DefaultClient implements ConfigurationS
// we know the searched service's id
// DefaultServiceReference sRef = (DefaultServiceReference) dev.getServiceReference(DocuExampleService.DOCU_EXAMPLE_SERVICE_ID, SecurityKey.EMPTY_KEY);
// Service serv = sRef.getService();
//
ruleExecution = new Thread(new ruleExe(this, dev, serviceReference));
// // we are looking for an Operation by its name
// Operation op = serv.getOperation(null, "DocuExampleSimpleOperation", null, null);
//
......@@ -132,6 +136,9 @@ public class ConfigurationClient extends DefaultClient implements ConfigurationS
public void setRule(DPWSRule rule) {
// TODO Auto-generated method stub
this.rule = rule;
ruleExecution.start();
}
......
......@@ -306,6 +306,8 @@ public class ConfigurationService extends DefaultService {
}
rulesList1.put(dpwsRule.id, dpwsRule);
client.setRule(dpwsRule);
// create suitable response ...
ParameterValue result = operation.createOutputValue();
......
package com.pi.lightbulb.configuration;
import org.ws4d.java.communication.CommunicationException;
import org.ws4d.java.dispatch.DefaultServiceReference;
import org.ws4d.java.service.DefaultService;
import org.ws4d.java.service.Device;
import org.ws4d.java.service.InvocationException;
import org.ws4d.java.service.Operation;
import org.ws4d.java.service.parameter.ParameterValue;
import org.ws4d.java.service.parameter.ParameterValueManagement;
import org.ws4d.java.types.QName;
import com.pi.lightbulb.configuration.ConfigurationServiceInterface.DPWSRule;
import com.pi.lightbulb.device.BulbGPIOListener;
public class ruleExe implements Runnable {
ConfigurationClient cl;
Device dev;
DefaultServiceReference serv;
public ruleExe(ConfigurationClient clExt, Device dev, DefaultServiceReference serv){
cl = clExt;
this.dev = dev;
this.serv = serv;
}
@Override
public void run() {
DPWSRule rule = cl.rule;
try {
Operation op = serv.getService().getOperation(new QName("Brightness", "http://www.demo.com/bbsr"), "LightOperation", null, null);
while(true){
ParameterValue result = op.invoke(null, null);
//
int light = Integer.parseInt(ParameterValueManagement.getString(result, "light"));
rule.conditions.get(0);
int i = Integer.parseInt(rule.conditions.get(0).value);
if(light < i)
BulbGPIOListener.getInstance().setBulbStateOn();
else
BulbGPIOListener.getInstance().setBulbStateOff();
Thread.sleep(1000);
}
} catch (CommunicationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment