ragconnect.mustache 2.99 KB
Newer Older
1
{{#usesMqtt}}{{> mqtt}}{{/usesMqtt}}
René Schöne's avatar
René Schöne committed
2
{{> handler}}
René Schöne's avatar
René Schöne committed
3
aspect ROS2RAG {
4
  {{#ReceiveDefinitions}}
René Schöne's avatar
René Schöne committed
5
  {{> receiveDefinition}}
6
  {{/ReceiveDefinitions}}
René Schöne's avatar
René Schöne committed
7

8
  {{#SendDefinitions}}
René Schöne's avatar
René Schöne committed
9
  {{> sendDefinition}}
10
  {{/SendDefinitions}}
René Schöne's avatar
René Schöne committed
11
12

  {{#MappingDefinitions}}
René Schöne's avatar
René Schöne committed
13
  {{> mappingDefinition}}
René Schöne's avatar
René Schöne committed
14
15
16
  {{/MappingDefinitions}}

  {{#DependencyDefinitions}}
René Schöne's avatar
René Schöne committed
17
  {{> dependencyDefinition}}
René Schöne's avatar
René Schöne committed
18
19
20
  {{/DependencyDefinitions}}

  {{#TokenComponents}}
René Schöne's avatar
René Schöne committed
21
  {{> tokenComponent}}
René Schöne's avatar
René Schöne committed
22
23
  {{/TokenComponents}}
}
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82

{{#incrementalOptionActive}}
aspect RagConnectObserver {
  class RagConnectObserver implements ASTState.Trace.Receiver {
    ASTState.Trace.Receiver oldReceiver;
    class RagConnectObserverEntry {
      final ConnectToken connectToken;
      final ASTNode node;
      final String attributeString;
      final Runnable attributeCall;
      RagConnectObserverEntry(ConnectToken connectToken, ASTNode node, String attributeString, Runnable attributeCall) {
        this.connectToken = connectToken;
        this.node = node;
        this.attributeString = attributeString;
        this.attributeCall = attributeCall;
      }
    }
    java.util.List<RagConnectObserverEntry> observedNodes = new java.util.ArrayList<>();
    RagConnectObserver(ASTNode node) {
      // set the receiver. potentially dangerous because overriding existing receiver!
      oldReceiver = node.trace().getReceiver();
      node.trace().setReceiver(this);
    }
    void add(ConnectToken connectToken, ASTNode node, String attributeString, Runnable attributeCall) {
      System.out.println("** observer add " + node + " on " + attributeString);
      observedNodes.add(new RagConnectObserverEntry(connectToken, node, attributeString, attributeCall));
    }
    void remove(ConnectToken connectToken) {
      observedNodes.removeIf(entry -> entry.connectToken.equals(connectToken));
    }
    @Override
    public void accept(ASTState.Trace.Event event, ASTNode node, String attribute, Object params, Object value) {
      oldReceiver.accept(event, node, attribute, params, value);
      // ignore all events but INC_FLUSH_ATTR
      if (event != ASTState.Trace.Event.INC_FLUSH_ATTR) {
        return;
      }
      System.out.println("** observer check INC_FLUSH_ATTR event");
      // iterate through list, if matching pair. could maybe be more efficient.
      for (RagConnectObserverEntry entry : observedNodes) {
        if (entry.node.equals(node) && entry.attributeString.equals(attribute)) {
          // hit. call the attribute/nta-token
          System.out.println("** observer hit " + entry.node + " on " + entry.attributeString);
          entry.attributeCall.run();
        }
      }
    }
  }

  private static RagConnectObserver ASTNode._ragConnectObserverInstance;
  RagConnectObserver ASTNode._ragConnectObserver() {
    if (_ragConnectObserverInstance == null) {
      // does not matter, which node is used to create the observer as ASTState/tracing is also static
      _ragConnectObserverInstance = new RagConnectObserver(this);
    }
    return _ragConnectObserverInstance;
  }
}
{{/incrementalOptionActive}}