Revision 33aa05c5 src/urt_publisher.c
| 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 |
} |
|
Also available in: Unified diff