commit fb72e91b1fcb99de893710031303ab33dc230d0d
Author: skenneweg <skenneweg@techfak.uni-bielefeld.de>
Date:   Mon Aug 3 19:34:05 2020 +0200

    Nearly finished the publisher.
    Fixed errors, warnings in publisher, subscriber, topic, ...

diff --git a/src/urt_publisher.c b/src/urt_publisher.c
index 6b44295..f6ca759 100644
--- a/src/urt_publisher.c
+++ b/src/urt_publisher.c
@@ -60,19 +60,20 @@ void urtPublisherInit(urt_publisher_t* publisher, urt_topic_t* topic, urt_messag
   urtDebugAssert(publisher);
   urtDebugAssert(topic);
 
-  urt_publisher_t.topic = topic;
+  publisher->topic = topic;
 #if (URT_CFG_PUBSUB_PROFILING == true)
-  urt_publisher_t.publishAttempts = 0;
-  urt_publisher_t.publishFails = 0;
+  publisher->publishAttempts = 0;
+  publisher->publishFails = 0;
 #endif /* URT_CFG_PUBSUB_PROFILING */
   if (messages != NULL) {
-    urtMutexLock(topic->lock);
+    urtMutexLock(&topic->lock);
     urt_message_t* lastMessage = messages;
     while (lastMessage->next != NULL) {
       lastMessage = lastMessage->next;
     }
-    //TODO: setnextpointer of last message to contribute to the message after the topic's latest message
+    lastMessage->next = topic->latestMessage->next;
     topic->latestMessage->next = messages;
+    urtMutexUnlock(&topic->lock);
   }
 
   return;
@@ -92,55 +93,56 @@ void urtPublisherInit(urt_publisher_t* publisher, urt_topic_t* topic, urt_messag
  */
 urt_status_t urtPublisherPublish(urt_publisher_t* publisher, void* payload, size_t bytes, urt_osTime_t t, urt_delay_t timeout)
 {
-  urtMutexLock(publisher->topic->lock);
-  urt_message_t* message = publisher->topic->next->latestMessage;
-  urt_osTime_t messageTime =  message->originTime;
+  urtMutexLock(&publisher->topic->lock);
+  urt_message_t* latestMessage = publisher->topic->next->latestMessage;
+  urt_osTime_t messageTime =  latestMessage->originTime;
 #if (URT_CFG_PUBSUB_PROFILING == true)
   publisher->publishAttempts++;
 #endif /* URT_CFG_PUBSUB_PROFILING */
 
-  while (message->numHrtConsumersLeft > 0) {
-    urt_osCondvarWaitStatus_t timeout = urtCondvarWait(publisher->topic->hrtReleased, publisher->topic->lock, URT_DELAY_INFINITE);
+  while (latestMessage->numHrtConsumersLeft > 0) {
+    //TODO: urt_osCondvarWaitStatus_t timeout = urtCondvarWait(&publisher->topic->hrtReleased, &publisher->topic->lock, URT_DELAY_INFINITE);
     if (timeout == URT_CONDVAR_WAITSTATUS_TIMEOUT) {
 #if (URT_CFG_PUBSUB_PROFILING == true)
       publisher->publishFails++;
 #endif /* URT_CFG_PUBSUB_PROFILING */
-      urtMutexUnlock(publisher->topic->lock);
+      urtMutexUnlock(&publisher->topic->lock);
       return URT_STATUS_PUBLISH_TIMEOUT;
     }
 
-    if (messageTime != message->originTime) {
-      messageTime = message->originTime;
-      message = message->next;
-      while (message->originTime < messageTime) {
-        message = message->next;
+    if (messageTime != latestMessage->originTime) {
+      messageTime = latestMessage->originTime;
+      latestMessage = latestMessage->next;
+      while (latestMessage->originTime < messageTime) {
+        latestMessage = latestMessage->next;
       }
     }
   }
 
 #if (URT_CFG_PUBSUB_PROFILING == true)
-  if (message->numHrtConsumersLeft > 0) { //TODO: never true because of while?
+  if (latestMessage->numConsumersLeft > 0) {
     publisher->topic->numMessagesDiscarded++;
   }
 #endif /* URT_CFG_PUBSUB_PROFILING */
 
-  publisher->topic->latestMessage = message; //TODO: Iterate topic's pointer to this message?
-  memcpy(message->payload, payload, bytes); //TODO: copy payload to message?
-  //TODO: Set origin time of message
-  publisher->topic->numHrtSubscribers = message->numHrtConsumersLeft;
+  publisher->topic->latestMessage = latestMessage;
+  memcpy(latestMessage->payload, payload, bytes);
+  latestMessage->originTime = t;
+  publisher->topic->numHrtSubscribers = latestMessage->numHrtConsumersLeft;
 #if (URT_CFG_PUBSUB_PROFILING == true)
-  publisher->topic->numSubscribers = message->numHrtConsumersLeft; //TODO: Set number of comsumers?
+  publisher->topic->numSubscribers = latestMessage->numConsumersLeft;
 #endif /* URT_CFG_PUBSUB_PROFILING */
 
 #if (URT_CFG_PUBSUB_QOS_RATECHECKS == true)
-  publisher->topic->qosRateTimer =  NULL; //TODO: Set QoS rate timer wrt. most critical HRT Subscriber
+  publisher->topic->qosRateTimer =  publisher->topic->hrtSubscribers;
+  //TODO: Set QoS rate timer (@topic) wrt. most critical HRT Subscriber (here different types?)
 #endif /* URT_CFG_PUBSUB_QOS_RATECHECKS */
 
 #if (URT_CFG_PUBSUB_QOS_DEADLINECHECKS == true)
   urt_hrtsubscriber_t* hrtSubscriber = publisher->topic->hrtSubscribers;
   while (hrtSubscriber != NULL) {
     if (!urtTimerIsArmed(hrtSubscriber->qosDeadlineTimer)) {
-      *hrtSubscriber->qosDeadlineTimer = message->originTime;
+      *hrtSubscriber->qosDeadlineTimer = latestMessage->originTime;
     }
     hrtSubscriber = hrtSubscriber->next;
   }
@@ -150,7 +152,7 @@ urt_status_t urtPublisherPublish(urt_publisher_t* publisher, void* payload, size
   publisher->topic->numMessagesPublished++;
 #endif /* URT_CFG_PUBSUB_PROFILING */
 
-  //TODO: Fire event
-  urtMutexUnlock(publisher->topic->lock);
+  urtEventSourceBroadcast(&publisher->topic->evtSource, URT_EVENTFLAG_PROCEED);
+  urtMutexUnlock(&publisher->topic->lock);
   return URT_STATUS_OK;
 }
