1 package de.dlr.bt.stc.source.mqtt;
2
3 import javax.annotation.Nullable;
4
5 import org.apache.commons.configuration2.HierarchicalConfiguration;
6
7 import de.dlr.bt.stc.config.CfgFactory;
8 import de.dlr.bt.stc.init.Register;
9 import de.dlr.bt.stc.source.AEndpointSourceCfg;
10 import de.dlr.bt.stc.source.rsi.SourceRSICfg.SourceDataType;
11
12 public class SourceMQTTCfg extends AEndpointSourceCfg {
13
14 protected SourceMQTTCfg(HierarchicalConfiguration<?> config) {
15 super(config);
16 }
17
18 private static SourceMQTTCfg createInstance(HierarchicalConfiguration<?> config) {
19 return new SourceMQTTCfg(config);
20 }
21
22 @Register
23 public static void register() {
24 CfgFactory.getInstance().registerCreator("mqtt", SourceMQTTCfg::createInstance);
25 }
26
27 @Nullable
28 public String getTopic() {
29 return config.getString("topic", null);
30 }
31
32 @Nullable
33 public int getQos() {
34 return config.getInt("qos", 1);
35 }
36
37
38
39 @Nullable
40 public String getExports() {
41 return config.getString("exports", null);
42 }
43
44 public SourceDataType getDatatype() {
45 var cdt = config.getString("datatype", "String");
46 switch (cdt.toLowerCase()) {
47 case "int", "integer":
48 return SourceDataType.INTEGER;
49 case "float", "double":
50 return SourceDataType.FLOAT;
51 case "bool", "boolean":
52 return SourceDataType.BOOL;
53 default:
54 return SourceDataType.STRING;
55 }
56 }
57
58 }