invoke
method in the original service, except that the current values of the copied service will be used for the Datas. <services> <event name="myService"> <data name="intValue" type="int" /> <data name="boolValue" type="bool" /> </event> </services>We might want to prepare two set of datas for this service, for example one where the toggle is true, and another when the toggle is false.
public class MyModule { ServiceInstance serviceToggleOff = null; ServiceInstance serviceToggleOn = null; public MyModule() { } public void init(Module module) { serviceToggleOff = module.getService("myService").createCopy(); serviceToggleOn = module.getService("myService").createCopy(); } }Then we can prepare values for the datas independently for the two states of a toggle. For example:
public class MyModule { ServiceInstance serviceToggleOff = null; ServiceInstance serviceToggleOn = null; public MyModule() { } public void init(Module module) { serviceToggleOff = module.getService("myService").createCopy(); serviceToggleOn = module.getService("myService").createCopy(); serviceToggleOff.getData("intData").setValue(1); serviceToggleOff.getData("boolData").setValue(true); serviceToggleOn.getData("intData").setValue(2); serviceToggleOn.getData("boolData").setValue(false); } }And then send one set or the other depending of the context, for example:
if (isToggle) { serviceToggleOn.invoke(); } else { serviceToggleOff.invoke(); }
ServiceInstance
which provide datas. For example if a module subscribe to an event Service, using this method on this service will do nothing and return falseservice1
and service1
event services, it is possible to perform service1Instance.copyFromService(service2Instance)
<services> <publish name="service1"> <data name="data1" type="int" /> <data name="data2" type="float" /> <data name="data3" type="bool" /> </publish> <publish name="service2" > <data name="data1" type="int" /> <data name="data2" type="float" /> <data name="data3" type="bool" /> </publish> </services>The following code will copy the data1 and data2 data values from
service2
to service1
when service2
is notified:public class MyModule { ServiceInstance service1 = null; public MyModule() { } public void init(Module module) { service1 = module.getService("service1"); } public void subscribe(ServiceInstance service) { if (service.getName().equals("service2")) { service1.copyFromService(service); service1.invoke(); } } }
Copyright 2017-2020 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v3 licence