Clean-up: modernize pretty_xml.cpp
[lttng-tools.git] / src / bin / lttng-sessiond / session.hpp
index ad451336a5b5b430ad49a9d8e99c3bdb26a07429..8993f94681a27c9b900c93c12a39f542d5f31a5d 100644 (file)
@@ -8,28 +8,37 @@
 #ifndef _LTT_SESSION_H
 #define _LTT_SESSION_H
 
-#include <limits.h>
-#include <stdbool.h>
-#include <urcu/list.h>
+#include "consumer.hpp"
+#include "snapshot.hpp"
+#include "trace-kernel.hpp"
 
-#include <common/hashtable/hashtable.hpp>
 #include <common/dynamic-array.hpp>
-#include <lttng/rotation.h>
+#include <common/hashtable/hashtable.hpp>
+#include <common/make-unique-wrapper.hpp>
+#include <common/pthread-lock.hpp>
+
 #include <lttng/location.h>
 #include <lttng/lttng-error.h>
+#include <lttng/rotation.h>
 
-#include "snapshot.hpp"
-#include "trace-kernel.hpp"
-#include "consumer.hpp"
+#include <limits.h>
+#include <stdbool.h>
+#include <urcu/list.h>
 
 #define ASSERT_SESSION_LIST_LOCKED() LTTNG_ASSERT(session_trylock_list())
 
 struct ltt_ust_session;
 
-typedef void (*ltt_session_destroy_notifier)(const struct ltt_session *session,
-               void *user_data);
-typedef void (*ltt_session_clear_notifier)(const struct ltt_session *session,
-               void *user_data);
+using ltt_session_destroy_notifier = void (*)(const struct ltt_session *, void *);
+using ltt_session_clear_notifier = void (*)(const struct ltt_session *, void *);
+
+namespace lttng {
+namespace sessiond {
+namespace details {
+void locked_session_release(ltt_session *session);
+} /* namespace details */
+} /* namespace sessiond */
+} /* namespace lttng */
 
 /*
  * Tracing session list
@@ -67,6 +76,14 @@ struct ltt_session_list {
  * session for both LTTng and UST.
  */
 struct ltt_session {
+       using id_t = uint64_t;
+       using locked_ptr =
+               std::unique_ptr<ltt_session,
+                               lttng::memory::create_deleter_class<
+                                       ltt_session,
+                                       lttng::sessiond::details::locked_session_release>::deleter>;
+       using sptr = std::shared_ptr<ltt_session>;
+
        char name[NAME_MAX];
        bool has_auto_generated_name;
        bool name_contains_creation_time;
@@ -84,7 +101,8 @@ struct ltt_session {
         */
        pthread_mutex_t lock;
        struct cds_list_head list;
-       uint64_t id;            /* session unique identifier */
+       /* session unique identifier */
+       id_t id;
        /* Indicates if the session has been added to the session list and ht.*/
        bool published;
        /* Indicates if a destroy command has been applied to this session. */
@@ -110,12 +128,9 @@ struct ltt_session {
         */
        bool has_user_specified_directory;
        /* Did at least ONE start command has been triggered?. */
-       unsigned int has_been_started:1;
-       /*
-        * Is the session active? Start trace command sets this to 1 and the stop
-        * command reset it to 0.
-        */
-       unsigned int active:1;
+       bool has_been_started;
+       /* Is the session active? */
+       bool active;
 
        /* Snapshot representation in a session. */
        struct snapshot snapshot;
@@ -200,8 +215,8 @@ struct ltt_session {
        char *base_path;
 };
 
-enum lttng_error_code session_create(const char *name, uid_t uid, gid_t gid,
-               struct ltt_session **out_session);
+enum lttng_error_code
+session_create(const char *name, uid_t uid, gid_t gid, struct ltt_session **out_session);
 void session_lock(struct ltt_session *session);
 void session_unlock(struct ltt_session *session);
 
@@ -214,48 +229,47 @@ void session_unlock(struct ltt_session *session);
  * In other words, it prevents tracer configurations from changing while they
  * are being transmitted to the various applications.
  */
-void session_lock_list(void);
-int session_trylock_list(void);
-void session_unlock_list(void);
+void session_lock_list() noexcept;
+int session_trylock_list() noexcept;
+void session_unlock_list() noexcept;
 
 void session_destroy(struct ltt_session *session);
 int session_add_destroy_notifier(struct ltt_session *session,
-               ltt_session_destroy_notifier notifier, void *user_data);
+                                ltt_session_destroy_notifier notifier,
+                                void *user_data);
 
 int session_add_clear_notifier(struct ltt_session *session,
-               ltt_session_clear_notifier notifier, void *user_data);
-void session_notify_clear(struct ltt_session *session);
+                              ltt_session_clear_notifier notifier,
+                              void *user_data);
+void session_notify_clear(ltt_session& session);
 
 bool session_get(struct ltt_session *session);
 void session_put(struct ltt_session *session);
 
-enum consumer_dst_type session_get_consumer_destination_type(
-               const struct ltt_session *session);
-const char *session_get_net_consumer_hostname(
-               const struct ltt_session *session);
-void session_get_net_consumer_ports(
-               const struct ltt_session *session,
-               uint16_t *control_port, uint16_t *data_port);
-struct lttng_trace_archive_location *session_get_trace_archive_location(
-               const struct ltt_session *session);
+enum consumer_dst_type session_get_consumer_destination_type(const struct ltt_session *session);
+const char *session_get_net_consumer_hostname(const struct ltt_session *session);
+void session_get_net_consumer_ports(const struct ltt_session *session,
+                                   uint16_t *control_port,
+                                   uint16_t *data_port);
+struct lttng_trace_archive_location *
+session_get_trace_archive_location(const struct ltt_session *session);
 
 struct ltt_session *session_find_by_name(const char *name);
-struct ltt_session *session_find_by_id(uint64_t id);
+struct ltt_session *session_find_by_id(ltt_session::id_t id);
 
-struct ltt_session_list *session_get_list(void);
-void session_list_wait_empty(void);
+struct ltt_session_list *session_get_list();
+void session_list_wait_empty();
 
 bool session_access_ok(struct ltt_session *session, uid_t uid);
 
-int session_reset_rotation_state(struct ltt_session *session,
-               enum lttng_rotation_state result);
+int session_reset_rotation_state(ltt_session& session, enum lttng_rotation_state result);
 
 /* Create a new trace chunk object from the session's configuration. */
-struct lttng_trace_chunk *session_create_new_trace_chunk(
-               const struct ltt_session *session,
-               const struct consumer_output *consumer_output_override,
-               const char *session_base_path_override,
-               const char *chunk_name_override);
+struct lttng_trace_chunk *
+session_create_new_trace_chunk(const struct ltt_session *session,
+                              const struct consumer_output *consumer_output_override,
+                              const char *session_base_path_override,
+                              const char *chunk_name_override);
 
 /*
  * Set `new_trace_chunk` as the session's current trace chunk. A reference
@@ -266,17 +280,17 @@ struct lttng_trace_chunk *session_create_new_trace_chunk(
  * `current_session_trace_chunk` on success.
  */
 int session_set_trace_chunk(struct ltt_session *session,
-               struct lttng_trace_chunk *new_trace_chunk,
-               struct lttng_trace_chunk **current_session_trace_chunk);
+                           struct lttng_trace_chunk *new_trace_chunk,
+                           struct lttng_trace_chunk **current_session_trace_chunk);
 
 /*
  * Close a chunk on the remote peers of a session. Has no effect on the
  * ltt_session itself.
  */
 int session_close_trace_chunk(struct ltt_session *session,
-               struct lttng_trace_chunk *trace_chunk,
-               enum lttng_trace_chunk_command_type close_command,
-               char *path);
+                             struct lttng_trace_chunk *trace_chunk,
+                             enum lttng_trace_chunk_command_type close_command,
+                             char *path);
 
 /* Open a packet in all channels of a given session. */
 enum lttng_error_code session_open_packets(struct ltt_session *session);
@@ -294,4 +308,26 @@ bool session_output_supports_trace_chunks(const struct ltt_session *session);
  */
 bool sample_session_id_by_name(const char *name, uint64_t *id);
 
+namespace lttng {
+namespace sessiond {
+
+/*
+ * Session list lock must be acquired by the caller.
+ * The caller must not keep the ownership of the returned locked session
+ * for longer than strictly necessary. If your intention is to acquire
+ * a reference to an ltt_session, see `find_session_by_id()`.
+ */
+ltt_session::locked_ptr find_locked_session_by_id(ltt_session::id_t id);
+
+/*
+ * Session list lock must be acquired by the caller.
+ * The caller must not keep the ownership of the returned locked session
+ * for longer than strictly necessary. If your intention is to acquire
+ * a reference to an ltt_session, see `find_session_by_id()`.
+ */
+ltt_session::sptr find_session_by_id(ltt_session::id_t id);
+
+} /* namespace sessiond */
+} /* namespace lttng */
+
 #endif /* _LTT_SESSION_H */
This page took 0.026 seconds and 4 git commands to generate.