Skip to content
Snippets Groups Projects
Select Git revision
  • 527efe995fb91e66cfd16f7411de8f10e2beb3f3
  • master default
  • branch2
3 results

launcher.launch

Blame
  • Forked from CeTI / ROS / panda_gazebo_workspace
    Source project has a limited visibility.
    sendDefinition.mustache 2.48 KiB
    private Runnable {{parentTypeName}}.{{sender}} = null;
    private byte[] {{parentTypeName}}.{{lastValue}} = null;
    
    public boolean {{parentTypeName}}.{{connectMethod}}(String {{connectParameterName}}, boolean writeCurrentValue) throws java.io.IOException {
      {{>handleUri}}
      switch (scheme) {
      {{#usesMqtt}}
        case "mqtt":
          final MqttHandler handler = {{mqttHandlerAttribute}}().resolveHandler(uri);
          final String topic = {{mqttHandlerAttribute}}().extractTopic(uri);
          {{sender}} = () -> {
            {{#loggingEnabledForWrites}}
            System.out.println("[Send] {{tokenName}} = " + get{{tokenName}}() + " -> " + {{connectParameterName}});
            {{/loggingEnabledForWrites}}
            handler.publish(topic, {{lastValue}});
          };
          {{updateMethod}}();
          if (writeCurrentValue) {
            {{writeMethod}}();
          }
          break;
      {{/usesMqtt}}
      {{#usesRest}}
        case "rest":
          ConnectToken connectToken = {{restHandlerAttribute}}().newGETConnection(uri, () -> {
            {{updateMethod}}();
            return new String({{lastValue}});
          });
          if (connectToken == null) {
            return false;
          }
          connectTokens.computeIfAbsent(this, astNode -> new java.util.HashMap<java.net.URI, ConnectToken>())
                       .put(uri, connectToken);
          break;
      {{/usesRest}}
        default:
          System.err.println("Unknown protocol '" + scheme + "'.");
          return false;
      }
      _ragConnectObserver().add(this, "{{parentTypeName}}.get{{tokenName}}()", () -> {
        if (this.{{updateMethod}}()) {
          this.{{writeMethod}}();
        }
      });
      return true;
    }
    
    public boolean {{parentTypeName}}.{{disconnectMethod}}(String {{connectParameterName}}) throws java.io.IOException {
      {{>handleUri}}
      switch (scheme) {
      {{#usesMqtt}}
        case "mqtt":
          {{sender}} = null;
          {{lastValue}} = null;
          break;
      {{/usesMqtt}}
      {{#usesRest}}
        case "rest":
          {{restHandlerAttribute}}().disconnect(connectTokens.get(this).get(uri));
          break;
      {{/usesRest}}
        default:
          System.err.println("Unknown protocol '" + scheme + "'.");
          return false;
      }
      return true;
    }
    
    protected boolean {{parentTypeName}}.{{updateMethod}}() {
      {{^shouldSendValue}}