-
Notifications
You must be signed in to change notification settings - Fork 2
/
MQTTService.sedona
82 lines (76 loc) · 2.57 KB
/
MQTTService.sedona
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
**
** MQTT service (community version)
** MQTT service provides the following abilities:
** 1. publish data to a topic of a MQTT broker
** 2. subscribe topic data of a MQTT broker and update local sedona object
** 3. able to publish/subscribe multiple MQTT broker at the same time
**
** Well, there are some limitations:
** 1. it is a native kit, so svm need to be recompiled to use it
** 2. TLS/SSL is not supported yet, so use it under trusted network environment
** 3. only Linux is supported, Windows is not supported right now
**
** If you don't want to set up a local MQTT broker, you can try some online brokers for testing:
** 1. test.mosquitto.org:1883 (http://test.mosquitto.org/)
** 2. broker.hivemq.com:1883 (https://www.hivemq.com/try-out/)
**
** If possible, we recommend you to set up a local MQTT broker by mosquitto(https://mosquitto.org/),
** that is a popular and open source implementation of MQTT broker, it is fairly easy to set up under Linux.
**
class MQTTService extends Service
{
////////////////////////////////////////////////////////////////
// Life cycle
////////////////////////////////////////////////////////////////
**
** init and start MQTT service
**
virtual override void start()
{
log.message("MQTT service started")
}
**
** stop MQTT service
**
virtual override void stop()
{
log.message("MQTT service stopped")
}
////////////////////////////////////////////////////////////////
// Methods
////////////////////////////////////////////////////////////////
**
** Get first child component of type Worker (or subclass).
** Returns null if no Worker objects found.
**
private Worker getFirstWorker()
{
App app = Sys.app
for (Component c = app.lookup(children); c != null; c = app.lookup(c.nextSibling))
if (c.type.is(Worker.type))
return (Worker)c
return null
}
**
** Get next child component after 'worker' that is of type Worker (or subclass).
** Returns null if it reaches the end of the list without finding one.
**
private Worker getNextWorker(Worker worker)
{
App app = Sys.app
for (Component c = app.lookup(worker.id); c != null; c = app.lookup(c.nextSibling))
if (c.id != worker.id && c.type.is(Worker.type))
return (Worker)c
return null
}
override bool work()
{
for(Worker w = getFirstWorker(); w != null; w = getNextWorker(w))
w.work()
return false
}
////////////////////////////////////////////////////////////////
// Fields
////////////////////////////////////////////////////////////////
define Log log
}