logger: use orb_exists to check if we need to subscribe to the first instance

To keep track of the configured interval, we store it as negative file
descriptor, until we do the subscription.

This frees up a considerable amount of file descriptors in most use-cases.
This commit is contained in:
Beat Küng
2017-10-18 08:40:32 +02:00
committed by Lorenz Meier
parent 4c4b528842
commit 3be252289a
2 changed files with 92 additions and 44 deletions
+15 -5
View File
@@ -76,7 +76,8 @@ inline bool operator&(SDLogProfileMask a, SDLogProfileMask b)
}
struct LoggerSubscription {
int fd[ORB_MULTI_MAX_INSTANCES];
int fd[ORB_MULTI_MAX_INSTANCES]; ///< uorb subscription. The first fd is also used to store the interval if
/// not subscribed yet (-interval - 1)
uint16_t msg_ids[ORB_MULTI_MAX_INSTANCES];
const orb_metadata *metadata = nullptr;
@@ -135,14 +136,17 @@ public:
* (because it does not write an ADD_LOGGED_MSG message).
* @param name topic name
* @param interval limit rate if >0, otherwise log as fast as the topic is updated.
* @return -1 on error, file descriptor otherwise
* @return true on success
*/
int add_topic(const char *name, unsigned interval);
bool add_topic(const char *name, unsigned interval = 0);
/**
* add a logged topic (called by add_topic() above)
* add a logged topic (called by add_topic() above).
* In addition, it subscribes to the first instance of the topic, if it's advertised,
* and sets the file descriptor of LoggerSubscription accordingly
* @return the newly added subscription on success, nullptr otherwise
*/
int add_topic(const orb_metadata *topic);
LoggerSubscription *add_topic(const orb_metadata *topic);
/**
* request the logger thread to stop (this method does not block).
@@ -251,6 +255,12 @@ private:
inline bool copy_if_updated_multi(LoggerSubscription &sub, int multi_instance, void *buffer, bool try_to_subscribe);
/**
* Check if a topic instance exists and subscribe to it
* @return true when topic exists and subscription successful
*/
bool try_to_subscribe_topic(LoggerSubscription &sub, int multi_instance);
/**
* Write exactly one ulog message to the logger and handle dropouts.
* Must be called with _writer.lock() held.