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 {
// --- isDefaultMappingDefinition ---
syn boolean MappingDefinition.isDefaultMappingDefinition() = false;
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 {
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;
}
......
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*;
MReceiveDefinition : MEndpointDefinition;
MSendDefinition : MEndpointDefinition;
......@@ -7,6 +7,7 @@ MInnerMappingDefinition;
MDependencyDefinition;
MTypeComponent;
MTokenComponent;
MHandler ::= <ClassName> <Construction> <AttributeName> <FieldName> <InUse:boolean>;
rel MRagConnect.RagConnect -> RagConnect;
rel MInnerMappingDefinition.MMappingDefinition -> MMappingDefinition;
......
import java.io.IOException;
import java.util.concurrent.TimeUnit;aspect MqttHandler {
import java.util.concurrent.TimeUnit;
aspect MqttHandler {
public class MqttServerHandler {
private final java.util.Map<String, MqttHandler> handlers = new java.util.HashMap<>();
private long time;
......
aspect RagConnectHandler {
interface RagConnectHandler<T> {
boolean connectReceive(String path, java.util.function.Consumer<T> callback);
boolean sendPush(String path, T value);
boolean connectSendPull(String path, SupplierWithException<T> supplier);
}
{{#Handlers}}
{{#InUse}}
private {{ClassName}} {{rootNodeName}}.{{FieldName}} = {{{Construction}}};
{{#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 {
private String {{rootNodeName}}.MqttName() { return "RagConnectMQTT"; }
private MqttServerHandler {{rootNodeName}}.{{mqttHandlerField}} = new MqttServerHandler(MqttName());
public void {{rootNodeName}}.{{mqttSetupWaitUntilReadyMethod}}(long time, java.util.concurrent.TimeUnit 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}}
{{#usesRest}}{{> rest}}{{/usesRest}}
{{> handler}}
aspect ROS2RAG {
public void {{rootNodeName}}.{{closeMethod}}() {
{{#usesMqtt}}{{mqttHandlerField}}.close();{{/usesMqtt}}
{{#usesRest}}{{restHandlerField}}.close();{{/usesRest}}
}
{{#ReceiveDefinitions}}
{{> receiveDefinition}}
{{/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