rename object_data to lttng_ust_object_data
[lttng-ust.git] / libustctl / ustctl.c
index 3d886d3305c569f7df4092ae90ec076a932e0695..8e6e2f31402397d1dbfbaa933cd188cec6c2bbf4 100644 (file)
 #include <ust/lttng-ust-ctl.h>
 #include <ust/lttng-ust-abi.h>
 #include <ust/usterr-signal-safe.h>
-#include "lttng-ust-comm.h"
+#include <ust/lttng-ust-comm.h>
 
 #include "../libringbuffer/backend.h"
 #include "../libringbuffer/frontend.h"
 
+volatile enum ust_loglevel ust_loglevel;
+
 static
-void init_object(struct object_data *data)
+void init_object(struct lttng_ust_object_data *data)
 {
        data->handle = -1;
        data->shm_fd = -1;
@@ -35,7 +37,7 @@ void init_object(struct object_data *data)
        data->memory_map_size = 0;
 }
 
-void release_object(int sock, struct object_data *data)
+void release_object(int sock, struct lttng_ust_object_data *data)
 {
        struct ustcomm_ust_msg lum;
        struct ustcomm_ust_reply lur;
@@ -53,6 +55,32 @@ void release_object(int sock, struct object_data *data)
        free(data);
 }
 
+/*
+ * Send registration done packet to the application.
+ */
+int ustctl_register_done(int sock)
+{
+       struct ustcomm_ust_msg lum;
+       struct ustcomm_ust_reply lur;
+       int ret;
+
+       DBG("Sending register done command to %d", sock);
+       memset(&lum, 0, sizeof(lum));
+       lum.handle = LTTNG_UST_ROOT_HANDLE;
+       lum.cmd = LTTNG_UST_REGISTER_DONE;
+       ret = ustcomm_send_app_cmd(sock, &lum, &lur);
+       if (ret)
+               return ret;
+       if (lur.ret_code != USTCOMM_OK) {
+               DBG("Return code: %s", ustcomm_get_readable_code(lur.ret_code));
+               goto error;
+       }
+       return 0;
+
+error:
+       return -1;
+}
+
 /*
  * returns session handle.
  */
@@ -77,11 +105,11 @@ int ustctl_create_session(int sock)
 /* open the metadata global channel */
 int ustctl_open_metadata(int sock, int session_handle,
                struct lttng_ust_channel_attr *chops,
-               struct object_data **_metadata_data)
+               struct lttng_ust_object_data **_metadata_data)
 {
        struct ustcomm_ust_msg lum;
        struct ustcomm_ust_reply lur;
-       struct object_data *metadata_data;
+       struct lttng_ust_object_data *metadata_data;
        int ret;
 
        metadata_data = malloc(sizeof(*metadata_data));
@@ -130,11 +158,11 @@ error:
 
 int ustctl_create_channel(int sock, int session_handle,
                struct lttng_ust_channel_attr *chops,
-               struct object_data **_channel_data)
+               struct lttng_ust_object_data **_channel_data)
 {
        struct ustcomm_ust_msg lum;
        struct ustcomm_ust_reply lur;
-       struct object_data *channel_data;
+       struct lttng_ust_object_data *channel_data;
        int ret;
 
        channel_data = malloc(sizeof(*channel_data));
@@ -186,12 +214,12 @@ error:
  * Return 0 on success.
  * Return negative error value on error.
  */
-int ustctl_create_stream(int sock, struct object_data *channel_data,
-               struct object_data **_stream_data)
+int ustctl_create_stream(int sock, struct lttng_ust_object_data *channel_data,
+               struct lttng_ust_object_data **_stream_data)
 {
        struct ustcomm_ust_msg lum;
        struct ustcomm_ust_reply lur;
-       struct object_data *stream_data;
+       struct lttng_ust_object_data *stream_data;
        int ret, fd;
 
        stream_data = malloc(sizeof(*stream_data));
@@ -233,12 +261,12 @@ error:
 }
 
 int ustctl_create_event(int sock, struct lttng_ust_event *ev,
-               struct object_data *channel_data,
-               struct object_data **_event_data)
+               struct lttng_ust_object_data *channel_data,
+               struct lttng_ust_object_data **_event_data)
 {
        struct ustcomm_ust_msg lum;
        struct ustcomm_ust_reply lur;
-       struct object_data *event_data;
+       struct lttng_ust_object_data *event_data;
        int ret;
 
        event_data = malloc(sizeof(*event_data));
@@ -263,12 +291,12 @@ int ustctl_create_event(int sock, struct lttng_ust_event *ev,
 }
 
 int ustctl_add_context(int sock, struct lttng_ust_context *ctx,
-               struct object_data *channel_data,
-               struct object_data **_context_data)
+               struct lttng_ust_object_data *obj_data,
+               struct lttng_ust_object_data **_context_data)
 {
        struct ustcomm_ust_msg lum;
        struct ustcomm_ust_reply lur;
-       struct object_data *context_data;
+       struct lttng_ust_object_data *context_data;
        int ret;
 
        context_data = malloc(sizeof(*context_data));
@@ -276,7 +304,7 @@ int ustctl_add_context(int sock, struct lttng_ust_context *ctx,
                return -ENOMEM;
        init_object(context_data);
        memset(&lum, 0, sizeof(lum));
-       lum.handle = channel_data->handle;
+       lum.handle = obj_data->handle;
        lum.cmd = LTTNG_UST_CONTEXT;
        lum.u.context.ctx = ctx->ctx;
        ret = ustcomm_send_app_cmd(sock, &lum, &lur);
@@ -291,7 +319,7 @@ int ustctl_add_context(int sock, struct lttng_ust_context *ctx,
 }
 
 /* Enable event, channel and session ioctl */
-int ustctl_enable(int sock, struct object_data *object)
+int ustctl_enable(int sock, struct lttng_ust_object_data *object)
 {
        struct ustcomm_ust_msg lum;
        struct ustcomm_ust_reply lur;
@@ -308,7 +336,7 @@ int ustctl_enable(int sock, struct object_data *object)
 }
 
 /* Disable event, channel and session ioctl */
-int ustctl_disable(int sock, struct object_data *object)
+int ustctl_disable(int sock, struct lttng_ust_object_data *object)
 {
        struct ustcomm_ust_msg lum;
        struct ustcomm_ust_reply lur;
@@ -324,14 +352,20 @@ int ustctl_disable(int sock, struct object_data *object)
        return 0;
 }
 
-int ustctl_start_session(int sock, struct object_data *object)
+int ustctl_start_session(int sock, int handle)
 {
-       return ustctl_enable(sock, object);
+       struct lttng_ust_object_data obj;
+
+       obj.handle = handle;
+       return ustctl_enable(sock, &obj);
 }
 
-int ustctl_stop_session(int sock, struct object_data *object)
+int ustctl_stop_session(int sock, int handle)
 {
-       return ustctl_disable(sock, object);
+       struct lttng_ust_object_data obj;
+
+       obj.handle = handle;
+       return ustctl_disable(sock, &obj);
 }
 
 
@@ -373,6 +407,17 @@ int ustctl_wait_quiescent(int sock)
        return 0;
 }
 
+int ustctl_flush_buffer(int sock, struct lttng_ust_object_data *channel_data)
+{
+       struct ustcomm_ust_msg lum;
+       struct ustcomm_ust_reply lur;
+
+       memset(&lum, 0, sizeof(lum));
+       lum.handle = channel_data->handle;
+       lum.cmd = LTTNG_UST_FLUSH_BUFFER;
+       return ustcomm_send_app_cmd(sock, &lum, &lur);
+}
+
 int ustctl_calibrate(int sock, struct lttng_ust_calibrate *calibrate)
 {
        return -ENOSYS;
@@ -381,7 +426,7 @@ int ustctl_calibrate(int sock, struct lttng_ust_calibrate *calibrate)
 /* Buffer operations */
 
 /* Map channel shm into process memory */
-struct shm_handle *ustctl_map_channel(struct object_data *chan_data)
+struct shm_handle *ustctl_map_channel(struct lttng_ust_object_data *chan_data)
 {
        struct shm_handle *handle;
        struct channel *chan;
@@ -420,7 +465,7 @@ struct shm_handle *ustctl_map_channel(struct object_data *chan_data)
 
 /* Add stream to channel shm and map its shm into process memory */
 int ustctl_add_stream(struct shm_handle *handle,
-               struct object_data *stream_data)
+               struct lttng_ust_object_data *stream_data)
 {
        int ret;
 
@@ -444,8 +489,47 @@ int ustctl_add_stream(struct shm_handle *handle,
        return 0;
 }
 
+void ustctl_unmap_channel(struct shm_handle *handle)
+{
+       struct channel *chan;
+
+       chan = shmp(handle, handle->chan);
+       channel_destroy(chan, handle, 1);
+}
+
+struct lib_ring_buffer *ustctl_open_stream_read(struct shm_handle *handle,
+       int cpu)
+{
+       struct channel *chan = handle->shadow_chan;
+       int shm_fd, wait_fd;
+       uint64_t memory_map_size;
+       struct lib_ring_buffer *buf;
+       int ret;
+
+       buf = channel_get_ring_buffer(&chan->backend.config,
+               chan, cpu, handle, &shm_fd, &wait_fd, &memory_map_size);
+       if (!buf)
+               return NULL;
+       ret = lib_ring_buffer_open_read(buf, handle, 1);
+       if (ret)
+               return NULL;
+       return buf;
+}
+
+void ustctl_close_stream_read(struct shm_handle *handle,
+               struct lib_ring_buffer *buf)
+{
+       lib_ring_buffer_release_read(buf, handle, 1);
+}
+
 /* For mmap mode, readable without "get" operation */
 
+void *ustctl_get_mmap_base(struct shm_handle *handle,
+               struct lib_ring_buffer *buf)
+{
+       return shmp(handle, buf->backend.memory_map);
+}
+
 /* returns the length to mmap. */
 int ustctl_get_mmap_len(struct shm_handle *handle,
                struct lib_ring_buffer *buf,
This page took 0.02889 seconds and 4 git commands to generate.