+static
+void free_session_list(GPtrArray *session_list)
+{
+ int i;
+ struct lttng_live_relay_session *relay_session;
+
+ for (i = 0; i < session_list->len; i++) {
+ relay_session = g_ptr_array_index(session_list, i);
+ free(relay_session->name);
+ free(relay_session->hostname);
+ }
+ g_ptr_array_free(session_list, TRUE);
+}
+
+static
+void print_session_list(GPtrArray *session_list, const char *path)
+{
+ int i;
+ struct lttng_live_relay_session *relay_session;
+
+ for (i = 0; i < session_list->len; i++) {
+ relay_session = g_ptr_array_index(session_list, i);
+ fprintf(stdout, "%s/host/%s/%s (timer = %u, "
+ "%u stream(s), %u client(s) connected)\n",
+ path, relay_session->hostname,
+ relay_session->name, relay_session->timer,
+ relay_session->streams, relay_session->clients);
+ }
+}
+
+static
+void update_session_list(GPtrArray *session_list, char *hostname,
+ char *session_name, uint32_t streams, uint32_t clients,
+ uint32_t timer)
+{
+ int i, found = 0;
+ struct lttng_live_relay_session *relay_session;
+
+ for (i = 0; i < session_list->len; i++) {
+ relay_session = g_ptr_array_index(session_list, i);
+ if ((strncmp(relay_session->hostname, hostname, NAME_MAX) == 0) &&
+ strncmp(relay_session->name,
+ session_name, NAME_MAX) == 0) {
+ relay_session->streams += streams;
+ if (relay_session->clients < clients)
+ relay_session->clients = clients;
+ found = 1;
+ break;
+ }
+ }
+ if (found)
+ return;
+
+ relay_session = g_new0(struct lttng_live_relay_session, 1);
+ relay_session->hostname = strndup(hostname, NAME_MAX);
+ relay_session->name = strndup(session_name, NAME_MAX);
+ relay_session->clients = clients;
+ relay_session->streams = streams;
+ relay_session->timer = timer;
+ g_ptr_array_add(session_list, relay_session);
+}
+