Add lttng-error.h containing every API err. code
[lttng-tools.git] / src / common / relayd / relayd.c
index 8945afea3645948d07a590b37ce81a916ab372ff..27cb58e52ae49113f877c9e31b604d349000ffaf 100644 (file)
@@ -21,6 +21,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/stat.h>
+#include <inttypes.h>
 
 #include <common/common.h>
 #include <common/defaults.h>
@@ -96,58 +97,6 @@ error:
        return ret;
 }
 
-#if 0
-/*
- * Create session on the relayd.
- *
- * On error, return ret_code negative value else return 0.
- */
-int relayd_create_session(struct lttcomm_sock *sock, const char *hostname,
-               const char *session_name)
-{
-       int ret;
-       struct lttcomm_relayd_create_session msg;
-       struct lttcomm_relayd_generic_reply reply;
-
-       /* Code flow error. Safety net. */
-       assert(sock);
-       assert(hostname);
-       assert(session_name);
-
-       DBG("Relayd creating session for hostname %s and session name %s",
-                       hostname, session_name);
-
-       strncpy(msg.hostname, hostname, sizeof(msg.hostname));
-       strncpy(msg.session_name, session_name, sizeof(msg.session_name));
-
-       /* Send command */
-       ret = send_command(sock, RELAYD_CREATE_SESSION, (void *) &msg,
-                       sizeof(msg), 0);
-       if (ret < 0) {
-               goto error;
-       }
-
-       /* Recevie response */
-       ret = recv_reply(sock, (void *) &reply, sizeof(reply));
-       if (ret < 0) {
-               goto error;
-       }
-
-       /* Return session id or negative ret code. */
-       if (reply.ret_code != LTTCOMM_OK) {
-               ret = -reply.ret_code;
-       } else {
-               /* Success */
-               ret = 0;
-       }
-
-       DBG2("Relayd created session for %s", session_name);
-
-error:
-       return ret;
-}
-#endif
-
 /*
  * Add stream on the relayd and assign stream handle to the stream_id argument.
  *
@@ -187,7 +136,7 @@ int relayd_add_stream(struct lttcomm_sock *sock, const char *channel_name,
        reply.ret_code = be32toh(reply.ret_code);
 
        /* Return session id or negative ret code. */
-       if (reply.ret_code != LTTCOMM_OK) {
+       if (reply.ret_code != LTTNG_OK) {
                ret = -reply.ret_code;
                ERR("Relayd add stream replied error %d", ret);
        } else {
@@ -196,7 +145,8 @@ int relayd_add_stream(struct lttcomm_sock *sock, const char *channel_name,
                *stream_id = reply.handle;
        }
 
-       DBG("Relayd stream added successfully with handle %zu", reply.handle);
+       DBG("Relayd stream added successfully with handle %" PRIu64,
+               reply.handle);
 
 error:
        return ret;
@@ -253,47 +203,6 @@ error:
        return ret;
 }
 
-#if 0
-/*
- * Start data command on the relayd.
- *
- * On success return 0 else return ret_code negative value.
- */
-int relayd_start_data(struct lttcomm_sock *sock)
-{
-       int ret;
-       struct lttcomm_relayd_generic_reply reply;
-
-       /* Code flow error. Safety net. */
-       assert(sock);
-
-       DBG("Relayd start data command");
-
-       /* Send command */
-       ret = send_command(sock, RELAYD_START_DATA, NULL, 0, 0);
-       if (ret < 0) {
-               goto error;
-       }
-
-       /* Recevie response */
-       ret = recv_reply(sock, (void *) &reply, sizeof(reply));
-       if (ret < 0) {
-               goto error;
-       }
-
-       /* Return session id or negative ret code. */
-       if (reply.ret_code != LTTCOMM_OK) {
-               ret = -reply.ret_code;
-       } else {
-               /* Success */
-               ret = 0;
-       }
-
-error:
-       return ret;
-}
-#endif
-
 /*
  * Add stream on the relayd and assign stream handle to the stream_id argument.
  *
@@ -306,7 +215,7 @@ int relayd_send_metadata(struct lttcomm_sock *sock, size_t len)
        /* Code flow error. Safety net. */
        assert(sock);
 
-       DBG("Relayd sending metadata of size %lu", len);
+       DBG("Relayd sending metadata of size %zu", len);
 
        /* Send command */
        ret = send_command(sock, RELAYD_SEND_METADATA, NULL, len, 0);
@@ -385,3 +294,50 @@ int relayd_send_data_hdr(struct lttcomm_sock *sock,
 error:
        return ret;
 }
+
+/*
+ * Send close stream command to the relayd.
+ */
+int relayd_send_close_stream(struct lttcomm_sock *sock, uint64_t stream_id,
+               uint64_t last_net_seq_num)
+{
+       int ret;
+       struct lttcomm_relayd_close_stream msg;
+       struct lttcomm_relayd_generic_reply reply;
+
+       /* Code flow error. Safety net. */
+       assert(sock);
+
+       DBG("Relayd closing stream id %" PRIu64, stream_id);
+
+       msg.stream_id = htobe64(stream_id);
+       msg.last_net_seq_num = htobe64(last_net_seq_num);
+
+       /* Send command */
+       ret = send_command(sock, RELAYD_CLOSE_STREAM, (void *) &msg, sizeof(msg), 0);
+       if (ret < 0) {
+               goto error;
+       }
+
+       /* Recevie response */
+       ret = recv_reply(sock, (void *) &reply, sizeof(reply));
+       if (ret < 0) {
+               goto error;
+       }
+
+       reply.ret_code = be32toh(reply.ret_code);
+
+       /* Return session id or negative ret code. */
+       if (reply.ret_code != LTTNG_OK) {
+               ret = -reply.ret_code;
+               ERR("Relayd close stream replied error %d", ret);
+       } else {
+               /* Success */
+               ret = 0;
+       }
+
+       DBG("Relayd close stream id %" PRIu64 " successfully", stream_id);
+
+error:
+       return ret;
+}
This page took 0.024821 seconds and 4 git commands to generate.