Skip to content
Snippets Groups Projects
Select Git revision
  • 221fa66edd773b89de322e10a8559032c6e8e02c
  • dev default protected
  • main protected
  • feature/ros-java-integration
4 results

sendDefinition.mustache

Blame
  • sendDefinition.mustache 6.82 KiB
    private RagConnect{{#IndexBasedListAccess}}Mapping{{/IndexBasedListAccess}}Publisher {{parentTypeName}}.{{senderName}} = new RagConnect{{#IndexBasedListAccess}}Mapping{{/IndexBasedListAccess}}Publisher();
    
    public boolean {{parentTypeName}}.{{connectMethodName}}(String {{connectParameterName}}{{#IndexBasedListAccess}}, int index{{/IndexBasedListAccess}}, boolean writeCurrentValue) throws java.io.IOException {
      {{>handleUri}}
      RagConnectToken connectToken = new RagConnectToken(uri, "{{entityName}}");
      boolean success;
      switch (scheme) {
      {{#javaHandler}}
      {{#InUse}}
        case "java":
        final JavaHandler handler = {{attributeName}}();
    
        {{senderName}}.add(() -> {
          handler.push(path, {{lastValueGetterCall}});
        }{{#IndexBasedListAccess}}, index{{/IndexBasedListAccess}}, connectToken);
        {{updateMethodName}}();
        if (writeCurrentValue) {
          {{writeMethodName}}({{#IndexBasedListAccess}}index, {{/IndexBasedListAccess}}connectToken);
        }
        success = true;
        break;
      {{/InUse}}
      {{/javaHandler}}
      {{#mqttHandler}}
      {{#InUse}}
        case "mqtt":
          final MqttHandler handler = {{attributeName}}().resolveHandler(uri);
          final String topic = {{attributeName}}().extractTopic(uri);
          {{senderName}}.add(() -> {
            {{#configLoggingEnabledForWrites}}
            {{!FIXME circular computation for collection attributes!!}}
            {{logDebug}}("[Send] {{entityName}} = {{log_}} -> {{log_}}", {{getterMethodCall}}, {{connectParameterName}});
            {{/configLoggingEnabledForWrites}}
            if ({{lastValueGetterCall}} != null) {
              handler.publish(topic, {{lastValueGetterCall}});
            {{#configLoggingEnabledForWrites}}
            } else {
              {{logWarn}}("[Send] {{entityName}} -> {{log_}}: can't send null.", {{connectParameterName}});
            {{/configLoggingEnabledForWrites}}
            }
            }{{#IndexBasedListAccess}}, index{{/IndexBasedListAccess}}, connectToken);
          {{updateMethodName}}({{#IndexBasedListAccess}}index{{/IndexBasedListAccess}});
          if (writeCurrentValue) {
            {{writeMethodName}}({{#IndexBasedListAccess}}index, {{/IndexBasedListAccess}}connectToken);
          }
          success = true;
          break;
      {{/InUse}}
      {{/mqttHandler}}
      {{#restHandler}}
      {{#InUse}}
        case "rest":
          success = {{attributeName}}().newGETConnection(connectToken, () -> {
            {{updateMethodName}}({{#IndexBasedListAccess}}index{{/IndexBasedListAccess}});
            return new String({{lastValueGetterCall}});
          });
          break;
      {{/InUse}}
      {{/restHandler}}
        default:
          {{logError}}("Unknown protocol '{{log_}}'.", scheme);
          success = false;
      }
      if (success) {
        connectTokenMap.add(this, false, connectToken);
        {{#configIncrementalOptionActive}}
        {{#sendIncrementalObserverEntries}}
        {{observerInstanceSingletonMethodName}}().add(
          connectToken,
          this,