Revision 33aa05c5
inc/urt_core.h | ||
---|---|---|
63 | 63 |
urt_node_t* urtCoreGetNodes(void); |
64 | 64 |
urt_status_t urtCoreAddNode(urt_node_t* node); |
65 | 65 |
|
66 |
#if (URT_CFG_PUBSUB_ENABLED) |
|
66 |
#if (URT_CFG_PUBSUB_ENABLED == true)
|
|
67 | 67 |
urt_status_t urtCoreAddTopic(urt_topic_t* topic); |
68 | 68 |
urt_topic_t* urtCoreGetTopic(urt_topicid_t id); |
69 | 69 |
#endif /* URT_CFG_PUBSUB_ENABLED */ |
70 | 70 |
|
71 |
#if (URT_CFG_RPC_ENABLED) |
|
71 |
#if (URT_CFG_RPC_ENABLED == true)
|
|
72 | 72 |
urt_status_t urtCoreAddService(urt_service_t* service); |
73 | 73 |
urt_service_t* urtCoreGetService(urt_serviceid_t id); |
74 | 74 |
#endif /* URT_CFG_RPC_ENABLED */ |
75 | 75 |
|
76 |
#if (URT_CFG_PUBSUB_QOS_DEADLINECHECKS) |
|
76 |
#if (URT_CFG_PUBSUB_QOS_DEADLINECHECKS == true)
|
|
77 | 77 |
urt_osTimerCallback_t urtCoreCallbackDefault(void* params) |
78 | 78 |
#endif /* URT_CFG_PUBSUB_QOS_DEADLINECHECKS */ |
79 | 79 |
|
inc/urt_publisher.h | ||
---|---|---|
22 | 22 |
#ifndef URTWARE_PUBLISHER_H |
23 | 23 |
#define URTWARE_PUBLISHER_H |
24 | 24 |
|
25 |
#include <urt_types.h> |
|
26 | 25 |
#include <urtware.h> |
27 | 26 |
|
28 | 27 |
/******************************************************************************/ |
... | ... | |
65 | 64 |
extern "C" { |
66 | 65 |
#endif /* defined(__cplusplus) */ |
67 | 66 |
|
68 |
void urtPublisherInit(urt_publisher_t* publisher, urt_topic_t* topic, urt_message_t* message); |
|
67 |
void urtPublisherInit(urt_publisher_t* publisher, urt_topic_t* topic, urt_message_t* messages);
|
|
69 | 68 |
urt_status_t urtPublisherPublish(urt_publisher_t* publisher, void* payload, size_t bytes, urt_osTime_t t, urt_delay_t timeout); |
70 | 69 |
#if defined(__cplusplus) |
71 | 70 |
} |
src/urt_core.c | ||
---|---|---|
128 | 128 |
{ |
129 | 129 |
urtThreadStart(node->thread); |
130 | 130 |
node = node->next; |
131 |
urtThreadMSleep(100); //TODO: delete |
|
132 | 131 |
} |
133 | 132 |
urtMutexUnlock(&core._lock); |
134 | 133 |
return; |
... | ... | |
208 | 207 |
urt_osEventFlags_t flag = URT_EVENTFLAG_TERMINATE; |
209 | 208 |
urtEventSourceBroadcast(&core._evtSource, flag); |
210 | 209 |
urtMutexUnlock(&core._lock); |
211 |
if (priorityBoosted) |
|
210 |
if (priorityBoosted) {
|
|
212 | 211 |
core._nodes->thread->prio = oldPrio; |
212 |
} |
|
213 | 213 |
return URT_STATUS_OK; |
214 | 214 |
} |
215 | 215 |
else |
... | ... | |
256 | 256 |
* |
257 | 257 |
* @return Returns a pointer to the requested service. Returns NULL if no service matches the given ID. |
258 | 258 |
*/ |
259 |
# if (URT_CFG_PUBSUB_ENABLED)
|
|
259 |
#if (URT_CFG_PUBSUB_ENABLED == true)
|
|
260 | 260 |
|
261 | 261 |
/** |
262 | 262 |
* @brief Append topic to core's list of topics. |
... | ... | |
295 | 295 |
else |
296 | 296 |
return NULL; |
297 | 297 |
} |
298 |
# endif /* URT_CFG_PUBSUB_ENABLED */
|
|
298 |
#endif /* URT_CFG_PUBSUB_ENABLED */ |
|
299 | 299 |
|
300 | 300 |
|
301 | 301 |
# if (URT_CFG_RPC_ENABLED) |
... | ... | |
327 | 327 |
urt_service_t* urtCoreGetService(urt_serviceid_t id) {return urt_service_t;} |
328 | 328 |
# endif /* URT_CFG_RPC_ENABLED */ |
329 | 329 |
|
330 |
#if (URT_CFG_PUBSUB_QOS_DEADLINECHECKS) |
|
330 |
#if (URT_CFG_PUBSUB_QOS_DEADLINECHECKS == true)
|
|
331 | 331 |
urt_osTimerCallback_t urtCoreCallbackDefault(void* params) |
332 | 332 |
{ |
333 | 333 |
urtMutexLock(&core._lock); |
src/urt_node.c | ||
---|---|---|
69 | 69 |
urtCoreSynchronizeNodes(((urt_node_t*)arg)); |
70 | 70 |
} |
71 | 71 |
|
72 |
while (urtThreadShouldTerminate()) |
|
72 |
while (!urtThreadShouldTerminate())
|
|
73 | 73 |
{ |
74 | 74 |
urt_osEventMask_t temp = urtEventWait(mask, URT_EVENT_WAIT_ONE, URT_DELAY_INFINITE); |
75 | 75 |
if (temp == urtCoreGetEventMask()) |
... | ... | |
91 | 91 |
} |
92 | 92 |
urtEventUnregister(urtCoreGetEvtSource(), &((urt_node_t*)arg)->listener); |
93 | 93 |
|
94 |
|
|
95 | 94 |
//Terminate all children and siblings |
96 | 95 |
urt_osThread_t* threadToTerminate = urtThreadGetSelf()->children; |
97 | 96 |
while (threadToTerminate != urtThreadGetSelf() && threadToTerminate != NULL) |
... | ... | |
199 | 198 |
#if (URT_CFG_PUBSUB_PROFILING || URT_CFG_RPC_PROFILING) |
200 | 199 |
node->loops = 0; |
201 | 200 |
#endif /* URT_CFG_PUBSUB_PROFILING || URT_CFG_RPC_PROFILING */ |
202 |
urt_osMutex_t* mutexTemp = urtCoreGetMutex(); |
|
203 |
urtMutexLock(mutexTemp); |
|
204 |
node->next = urtCoreGetNodes(); |
|
205 |
urtCoreAddNode(node); |
|
206 |
urtMutexUnlock(mutexTemp); |
|
201 |
node->next = urtCoreGetNodes(); |
|
202 |
urtCoreAddNode(node); |
|
207 | 203 |
return; |
208 | 204 |
} |
src/urt_publisher.c | ||
---|---|---|
46 | 46 |
/******************************************************************************/ |
47 | 47 |
|
48 | 48 |
/** |
49 |
* @brief Initalize the publisher. |
|
49 |
* @brief Initialize the publisher.
|
|
50 | 50 |
* |
51 | 51 |
* @param[in] publisher The publisher to initialize. Must not be NULL. |
52 | 52 |
* @param[in] topic The topic, this publisher is associated to. Must not be NULL. |
... | ... | |
55 | 55 |
* Once a message has been contributed, it cannot be removed later. |
56 | 56 |
* May be NULL (no messages to contribute). |
57 | 57 |
*/ |
58 |
void urtPublisherInit(urt_publisher_t* publisher, urt_topic_t* topic, urt_message_t* message) |
|
58 |
void urtPublisherInit(urt_publisher_t* publisher, urt_topic_t* topic, urt_message_t* messages)
|
|
59 | 59 |
{ |
60 |
urtDebugAssert(publisher); |
|
61 |
urtDebugAssert(topic); |
|
62 |
|
|
60 | 63 |
urt_publisher_t.topic = topic; |
61 |
#if (URT_CFG_PUBSUB_PROFILING) |
|
62 |
urt_publisher_t.publishAttempts = 0; |
|
63 |
urt_publisher_t.publishFails = 0; |
|
64 |
endif /* URT_CFG_PUBSUB_PROFILING */ |
|
65 |
//add later: messages to contribute,... |
|
64 |
#if (URT_CFG_PUBSUB_PROFILING == true) |
|
65 |
urt_publisher_t.publishAttempts = 0; |
|
66 |
urt_publisher_t.publishFails = 0; |
|
67 |
#endif /* URT_CFG_PUBSUB_PROFILING */ |
|
68 |
if (messages != NULL) { |
|
69 |
urtMutexLock(topic->lock); |
|
70 |
urt_message_t* lastMessage = messages; |
|
71 |
while (lastMessage->next != NULL) { |
|
72 |
lastMessage = lastMessage->next; |
|
73 |
} |
|
74 |
//TODO: setnextpointer of last message to contribute to the message after the topic's latest message |
|
75 |
topic->latestMessage->next = messages; |
|
76 |
} |
|
77 |
|
|
66 | 78 |
return; |
67 | 79 |
} |
68 | 80 |
|
... | ... | |
78 | 90 |
* |
79 | 91 |
* @return Returns URT_STATUS_OK on success. Returns URT_STATUS_PUBLISH_TIMEOUT on timeout. |
80 | 92 |
*/ |
81 |
urt_status_t urtPublisherPublish(urt_publisher_t* publisher, void* payload, size_t bytes, urt_osTime_t t, urt_delay_t timeout) {return URT_STATUS_OK;} |
|
93 |
urt_status_t urtPublisherPublish(urt_publisher_t* publisher, void* payload, size_t bytes, urt_osTime_t t, urt_delay_t timeout) |
|
94 |
{ |
|
95 |
urtMutexLock(publisher->topic->lock); |
|
96 |
urt_message_t* message = publisher->topic->next->latestMessage; |
|
97 |
urt_osTime_t messageTime = message->originTime; |
|
98 |
#if (URT_CFG_PUBSUB_PROFILING == true) |
|
99 |
publisher->publishAttempts++; |
|
100 |
#endif /* URT_CFG_PUBSUB_PROFILING */ |
|
101 |
|
|
102 |
while (message->numHrtConsumersLeft > 0) { |
|
103 |
urt_osCondvarWaitStatus_t timeout = urtCondvarWait(publisher->topic->hrtReleased, publisher->topic->lock, URT_DELAY_INFINITE); |
|
104 |
if (timeout == URT_CONDVAR_WAITSTATUS_TIMEOUT) { |
|
105 |
#if (URT_CFG_PUBSUB_PROFILING == true) |
|
106 |
publisher->publishFails++; |
|
107 |
#endif /* URT_CFG_PUBSUB_PROFILING */ |
|
108 |
urtMutexUnlock(publisher->topic->lock); |
|
109 |
return URT_STATUS_PUBLISH_TIMEOUT; |
|
110 |
} |
|
111 |
|
|
112 |
if (messageTime != message->originTime) { |
|
113 |
messageTime = message->originTime; |
|
114 |
message = message->next; |
|
115 |
while (message->originTime < messageTime) { |
|
116 |
message = message->next; |
|
117 |
} |
|
118 |
} |
|
119 |
} |
|
120 |
|
|
121 |
#if (URT_CFG_PUBSUB_PROFILING == true) |
|
122 |
if (message->numHrtConsumersLeft > 0) { //TODO: never true because of while? |
|
123 |
publisher->topic->numMessagesDiscarded++; |
|
124 |
} |
|
125 |
#endif /* URT_CFG_PUBSUB_PROFILING */ |
|
126 |
|
|
127 |
publisher->topic->latestMessage = message; //TODO: Iterate topic's pointer to this message? |
|
128 |
memcpy(message->payload, payload, bytes); //TODO: copy payload to message? |
|
129 |
//TODO: Set origin time of message |
|
130 |
publisher->topic->numHrtSubscribers = message->numHrtConsumersLeft; |
|
131 |
#if (URT_CFG_PUBSUB_PROFILING == true) |
|
132 |
publisher->topic->numSubscribers = message->numHrtConsumersLeft; //TODO: Set number of comsumers? |
|
133 |
#endif /* URT_CFG_PUBSUB_PROFILING */ |
|
134 |
|
|
135 |
#if (URT_CFG_PUBSUB_QOS_RATECHECKS == true) |
|
136 |
publisher->topic->qosRateTimer = NULL; //TODO: Set QoS rate timer wrt. most critical HRT Subscriber |
|
137 |
#endif /* URT_CFG_PUBSUB_QOS_RATECHECKS */ |
|
138 |
|
|
139 |
#if (URT_CFG_PUBSUB_QOS_DEADLINECHECKS == true) |
|
140 |
urt_hrtsubscriber_t* hrtSubscriber = publisher->topic->hrtSubscribers; |
|
141 |
while (hrtSubscriber != NULL) { |
|
142 |
if (!urtTimerIsArmed(hrtSubscriber->qosDeadlineTimer)) { |
|
143 |
*hrtSubscriber->qosDeadlineTimer = message->originTime; |
|
144 |
} |
|
145 |
hrtSubscriber = hrtSubscriber->next; |
|
146 |
} |
|
147 |
#endif /* URT_CFG_PUBSUB_QOS_DEADLINECHECKS */ |
|
148 |
|
|
149 |
#if (URT_CFG_PUBSUB_PROFILING == true) |
|
150 |
publisher->topic->numMessagesPublished++; |
|
151 |
#endif /* URT_CFG_PUBSUB_PROFILING */ |
|
152 |
|
|
153 |
//TODO: Fire event |
|
154 |
urtMutexUnlock(publisher->topic->lock); |
|
155 |
return URT_STATUS_OK; |
|
156 |
} |
urtware.h | ||
---|---|---|
98 | 98 |
#include <apps_urtosal.h> |
99 | 99 |
#include <urt_message.h> |
100 | 100 |
#include <urt_topic.h> |
101 |
#include <urt_publisher.h> |
|
101 | 102 |
#include <urt_subscriber.h> |
102 | 103 |
#include <urt_node.h> |
103 | 104 |
#include <urt_core.h> |
Also available in: Unified diff