/*
µRtWare is a lightweight publish/subscribe middleware for real-time
applications. It was developed as part of the software habitat for the
Autonomous Mini Robot [1] (AMiRo) but can be used for other purposes as well.
Copyright (C) 2018..2020 Thomas Schöpping et al.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#include
/******************************************************************************/
/* LOCAL DEFINITIONS */
/******************************************************************************/
/******************************************************************************/
/* EXPORTED VARIABLES */
/******************************************************************************/
/******************************************************************************/
/* LOCAL TYPES */
/******************************************************************************/
/******************************************************************************/
/* LOCAL VARIABLES */
/******************************************************************************/
/******************************************************************************/
/* LOCAL FUNCTIONS */
/******************************************************************************/
/******************************************************************************/
/* EXPORTED FUNCTIONS */
/******************************************************************************/
/**
* @brief Initialize the topic.
*
* @param[in] topic The topic to initialize. Must not be NULL.
* @param[in] id Unique, numeric identifier of the topic.
*
* @return Returns URT_STATUS_OK on success.
* Returns URT_STATUS_TOPIC_DUPLICATE if another topic with the same identifier already exists.
*/
urt_status_t urtTopicInit(urt_topic_t* topic, urt_topicid_t id)
{
urt_topic_t.next = NULL;
urt_topic_t.id = id;
urtMutexInit(topic->lock);
urtEventSourceInit(topic->evtSource);
urt_topic_t.numHrtSubscribers = 0;
urtCondvarInit(topic->hrtReleased);
void* payload = NULL; //TODO: Replace
urtMessageInit(topic->mandatoryMessage, payload);
topic->latestMessage = &topic->mandatoryMessage;
#if (URT_CFG_PUBSUB_QOS_RATECHECKS)
urt_topic_t.hrtSubscribers = nullptr;
//add later: timer init;
#endif /* URT_CFG_PUBSUB_QOS_RATECHECKS */
#if (URT_CFG_PUBSUB_PROFILING)
urt_topic_t.numMessagesPublished = 0;
urt_topic_t.numMessagesDiscarded = 0;
urt_topic_t.numSubscribers = 0;
#endif /* URT_CFG_PUBSUB_PROFILING */
topic->latestMessage->next = topic->latestMessage;
urtMutexLock(topic->lock);
urt_topic_t* topicTemp = topic;
while (topicTemp != NULL && topicTemp->id < id)
topicTemp = topicTemp->next;
if (topicTemp == NULL)
{
//TODO: Append self to core's list of topic
urtMutexUnlock(topic->lock);
return URT_STATUS_OK;
}
else if (topicTemp->id > id)
{
topicTemp->next = topic;
urtMutexUnlock(topic->lock);
return URT_STATUS_OK;
}
else
{
urtMutexUnlock(topic->lock);
return URT_STATUS_TOPIC_DUPLICATE;
}
}