Commit 841cea4e authored by René Schöne's avatar René Schöne
Browse files

Simplify handler creation.

parent 632aa495
...@@ -61,4 +61,11 @@ aspect Navigation { ...@@ -61,4 +61,11 @@ aspect Navigation {
// --- isDefaultMappingDefinition --- // --- isDefaultMappingDefinition ---
syn boolean MappingDefinition.isDefaultMappingDefinition() = false; syn boolean MappingDefinition.isDefaultMappingDefinition() = false;
eq DefaultMappingDefinition.isDefaultMappingDefinition() = true; eq DefaultMappingDefinition.isDefaultMappingDefinition() = true;
// --- mragconnect ---
inh MRagConnect MHandler.mragconnect();
eq MRagConnect.getHandler().mragconnect() = this;
// --- rootTypeComponents ---
syn JastAddList<MTypeComponent> MHandler.rootTypeComponents() = mragconnect().getRootTypeComponents();
} }
...@@ -136,6 +136,11 @@ aspect AttributesForMustache { ...@@ -136,6 +136,11 @@ aspect AttributesForMustache {
result.addRootTypeComponent(child.asTypeComponent().toMustache()); result.addRootTypeComponent(child.asTypeComponent().toMustache());
} }
} }
// MHandler ::= <ClassName> <Construction> <AttributeName> <FieldName> <InUse:boolean>;
result.addHandler(new MHandler("MqttServerHandler", "new MqttServerHandler(\"RagConnectMQTT\")",
result.mqttHandlerAttribute(), result.mqttHandlerField(), usesMqtt));
result.addHandler(new MHandler("RestServerHandler", "new RestServerHandler(\"RagConnectREST\")",
result.restHandlerAttribute(), result.restHandlerField(), usesRest));
return result; return result;
} }
......
MRagConnect ::= ReceiveDefinition:MReceiveDefinition* SendDefinition:MSendDefinition* MappingDefinition:MMappingDefinition* DependencyDefinition:MDependencyDefinition* RootTypeComponent:MTypeComponent* TokenComponent:MTokenComponent*; MRagConnect ::= ReceiveDefinition:MReceiveDefinition* SendDefinition:MSendDefinition* MappingDefinition:MMappingDefinition* DependencyDefinition:MDependencyDefinition* RootTypeComponent:MTypeComponent* TokenComponent:MTokenComponent* Handler:MHandler*;
abstract MEndpointDefinition ::= InnerMappingDefinition:MInnerMappingDefinition*; abstract MEndpointDefinition ::= InnerMappingDefinition:MInnerMappingDefinition*;
MReceiveDefinition : MEndpointDefinition; MReceiveDefinition : MEndpointDefinition;
MSendDefinition : MEndpointDefinition; MSendDefinition : MEndpointDefinition;
...@@ -7,6 +7,7 @@ MInnerMappingDefinition; ...@@ -7,6 +7,7 @@ MInnerMappingDefinition;
MDependencyDefinition; MDependencyDefinition;
MTypeComponent; MTypeComponent;
MTokenComponent; MTokenComponent;
MHandler ::= <ClassName> <Construction> <AttributeName> <FieldName> <InUse:boolean>;
rel MRagConnect.RagConnect -> RagConnect; rel MRagConnect.RagConnect -> RagConnect;
rel MInnerMappingDefinition.MMappingDefinition -> MMappingDefinition; rel MInnerMappingDefinition.MMappingDefinition -> MMappingDefinition;
......
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.TimeUnit;aspect MqttHandler { import java.util.concurrent.TimeUnit;
aspect MqttHandler {
public class MqttServerHandler { public class MqttServerHandler {
private final java.util.Map<String, MqttHandler> handlers = new java.util.HashMap<>(); private final java.util.Map<String, MqttHandler> handlers = new java.util.HashMap<>();
private long time; private long time;
......
aspect RagConnectHandler { aspect RagConnectHandler {
interface RagConnectHandler<T> { {{#Handlers}}
boolean connectReceive(String path, java.util.function.Consumer<T> callback); {{#InUse}}
boolean sendPush(String path, T value); private {{ClassName}} {{rootNodeName}}.{{FieldName}} = {{{Construction}}};
boolean connectSendPull(String path, SupplierWithException<T> supplier); {{#rootTypeComponents}}
} {{#first}}inh {{ClassName}} ASTNode.{{AttributeName}}();{{/first}}
eq {{rootNodeName}}.get{{name}}().{{AttributeName}}() = {{FieldName}};
{{/rootTypeComponents}}
syn {{ClassName}} {{rootNodeName}}.{{AttributeName}}() = {{FieldName}};
{{/InUse}}
{{/Handlers}}
public void {{rootNodeName}}.{{closeMethod}}() {
{{#Handlers}}
{{#InUse}}{{FieldName}}.close();{{/InUse}}
{{/Handlers}}
}
} }
aspect MQTT { aspect MQTT {
private String {{rootNodeName}}.MqttName() { return "RagConnectMQTT"; }
private MqttServerHandler {{rootNodeName}}.{{mqttHandlerField}} = new MqttServerHandler(MqttName());
public void {{rootNodeName}}.{{mqttSetupWaitUntilReadyMethod}}(long time, java.util.concurrent.TimeUnit unit) { public void {{rootNodeName}}.{{mqttSetupWaitUntilReadyMethod}}(long time, java.util.concurrent.TimeUnit unit) {
{{mqttHandlerField}}.setupWaitUntilReady(time, unit); {{mqttHandlerField}}.setupWaitUntilReady(time, unit);
} }
{{#RootTypeComponents}}
{{#first}}inh MqttServerHandler ASTNode.{{mqttHandlerAttribute}}();{{/first}}
eq {{rootNodeName}}.get{{name}}().{{mqttHandlerAttribute}}() = {{mqttHandlerField}};
{{/RootTypeComponents}}
syn MqttServerHandler {{rootNodeName}}.{{mqttHandlerAttribute}}() = {{mqttHandlerField}};
} }
{{#usesMqtt}}{{> mqtt}}{{/usesMqtt}} {{#usesMqtt}}{{> mqtt}}{{/usesMqtt}}
{{#usesRest}}{{> rest}}{{/usesRest}} {{> handler}}
aspect ROS2RAG { aspect ROS2RAG {
public void {{rootNodeName}}.{{closeMethod}}() {
{{#usesMqtt}}{{mqttHandlerField}}.close();{{/usesMqtt}}
{{#usesRest}}{{restHandlerField}}.close();{{/usesRest}}
}
{{#ReceiveDefinitions}} {{#ReceiveDefinitions}}
{{> receiveDefinition}} {{> receiveDefinition}}
{{/ReceiveDefinitions}} {{/ReceiveDefinitions}}
......
aspect REST {
private String {{rootNodeName}}.RestName() { return "RagConnectREST"; }
private RestServerHandler {{rootNodeName}}.{{restHandlerField}} = new RestServerHandler(RestName());
{{#getRootTypeComponents}}
{{#first}}inh RestServerHandler ASTNode.{{restHandlerAttribute}}();{{/first}}
eq {{rootNodeName}}.get{{name}}().{{restHandlerAttribute}}() = {{restHandlerField}};
{{/getRootTypeComponents}}
{{^getRootTypeComponents}}
syn RestServerHandler {{rootNodeName}}.{{restHandlerAttribute}}() = {{restHandlerField}};
{{/getRootTypeComponents}}
}
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