Statistics
| Branch: | Revision:

urtware / doc / activitydiagrams / subscriber / urtSubscriberFetchLatestMessage.uml @ 7491c395

History | View | Annotate | Download (3.81 KB)

1 7491c395 Thomas Schöpping
/'
2
µRtWare is a lightweight publish/subscribe middleware for real-time
3
applications. It was developed as part of the software habitat for the
4
Autonomous Mini Robot [1] (AMiRo) but can be used for other purposes as well.
5
6
Copyright (C) 2018..2020  Thomas Schöpping et al.
7
8
This program is free software: you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation, either version 3 of the License, or
11
(at your option) any later version.
12
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
GNU General Public License for more details.
17
18
You should have received a copy of the GNU General Public License
19
along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
'/
21
22
/'### INTRO ##################################################################'/
23
24
@startuml
25
26
title **µRtWare**\nurtSubscriberFetchLatestMessage()\n
27
28
!include ../../functions.iuml
29
30
/'### PARAMETERS & START #####################################################'/
31
32
start
33
note
34
  -- ""**subscriber** : urt_subscriber_t*"" --
35
  The subscriber that shall fetch the message.
36
  Must not be ""NULL"".
37
  -- ""**payload** : void*"" --
38
  Pointer where to copy the payload to.
39
  May be ""NULL"" for messages without payload.
40
  -- ""**bytes** : size_t"" --
41
  Payload size in bytes.
42
  -- ""**latency** : urt_delay_t*"" --
43
  The latency can be returned by reference.
44
  May be ""NULL"".
45
end note
46
47
/'### PROCEDURE ##############################################################'/
48
49
:lock topic;
50
if (Is HRT subscriber?) then (yes)
51
  :lock next message;
52
else (no)
53
  if (Has a message been read before?) then (yes)
54
    :lock last read message;
55
    if (Message timestamp equals local copy?) then (yes)
56
    else (no)
57
      partition "find oldest valid message" {
58
        :lock next message;
59
        note: Locked two messages ahead.
60
        while (Timestamp of next is younger than of current?) is (yes)
61
          fork
62
            :unlock current message;
63
          fork again
64
            :lock one message further ahead;
65
          endfork
66
        endwhile (no)
67
        :unlock next message;
68
        note: One message still locked.
69
      }
70
    endif
71
  else (no)
72
    :lock message after topic's latest message;
73
  endif
74
endif
75
partition "iterate to latest" {
76
  :lock one message further ahead;
77
  note: Locked two messages ahead.
78
  while (Timestamp of next message is younger than of current?) is (yes)
79
    fork
80
      if (Is HRT subscriber?) then (yes)
81
        fork
82
          :decrement HRT counter of current message;
83
        fork again
84
          :update QoS delay timer (@subscriber);
85
        endfork
86
      else (no)
87
      endif
88
      :unlock current message;
89
    fork again
90
      :lock one message further ahead;
91
    endfork
92
  endwhile (no)
93
  :unlock next message;
94
  note: One message still locked.
95
}
96
fork
97
  :set last fetched message pointer to locked message;
98
fork again
99
  fork
100
    :copy timestamp of message;
101
  fork again
102
    if (Optional output argument "latency" given?) then (yes)
103
      :set latency value (now - message origin time);
104
    else (no)
105
    endif
106
  endfork
107
fork again
108
  :copy message payload;
109
fork again
110
  if (Is HRT subscriber?) then (yes)
111
    fork
112
      :decrement HRT counter of current message;
113
      if (At least one HRT counter became 0?) then (yes)
114
        :signal topic's condition variable;
115
      else (no)
116
      endif
117
    fork again
118
      :update QoS delay timer (@subscriber);
119
    endfork
120
  else (no)
121
  endif
122
endfork
123
:unlock message;
124
:unlock topic;
125
126
/'### STOP & RETURN ##########################################################'/
127
128
stop
129
note
130
  -- **return** ""urt_status_t"" --
131
  Returns ""URT_STATUS_OK"".
132
end note
133
134
/'### OUTRO ##################################################################'/
135
136
@enduml