Update quickstart
[lttng-tools.git] / liblttngctl / liblttngctl.c
index c851ce6ad70bdf847cd2b8f26ae715b31d527c8e..e0a81588281b1f1e82955627abe7eb22c7300331 100644 (file)
@@ -1,19 +1,23 @@
 /*
+ * liblttngctl.c
+ *
+ * Linux Trace Toolkit Control Library
+ *
  * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful,
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; only
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #define _GNU_SOURCE
@@ -204,6 +208,14 @@ static int disconnect_sessiond(void)
        return ret;
 }
 
+/*
+ * Reset the session message structure.
+ */
+static void reset_session_msg(void)
+{
+       memset(&lsm, 0, sizeof(struct lttcomm_session_msg));
+}
+
 /*
  *  ask_sessiond
  *
@@ -244,6 +256,7 @@ static int ask_sessiond(enum lttcomm_sessiond_command lct, void **buf)
 
        size = llm.data_size;
        if (size == 0) {
+               ret = 0;
                goto end;
        }
 
@@ -261,41 +274,37 @@ static int ask_sessiond(enum lttcomm_sessiond_command lct, void **buf)
 
 end:
        disconnect_sessiond();
+       reset_session_msg();
        return ret;
 }
 
 /*
- *  lttng_start_tracing
- *
  *  Start tracing for all trace of the session.
  */
-int lttng_start_tracing(char *session_name)
+int lttng_start_tracing(const char *session_name)
 {
        strncpy(lsm.session_name, session_name, NAME_MAX);
        return ask_sessiond(LTTNG_START_TRACE, NULL);
 }
 
 /*
- *  lttng_stop_tracing
- *
  *  Stop tracing for all trace of the session.
  */
-int lttng_stop_tracing(char *session_name)
+int lttng_stop_tracing(const char *session_name)
 {
        strncpy(lsm.session_name, session_name, NAME_MAX);
        return ask_sessiond(LTTNG_STOP_TRACE, NULL);
 }
 
 /*
- * BEGIN Kernel control API
- */
-
-/*
- *  lttng_kernel_add_context
+ *  lttng_add_context
  */
-int lttng_kernel_add_context(struct lttng_kernel_context *ctx,
-               char *event_name, char *channel_name)
+int lttng_add_context(struct lttng_domain *domain,
+               struct lttng_event_context *ctx, const char *event_name,
+               const char *channel_name)
 {
+       int ret;
+
        if (channel_name != NULL) {
                strncpy(lsm.u.context.channel_name, channel_name, NAME_MAX);
        }
@@ -304,14 +313,28 @@ int lttng_kernel_add_context(struct lttng_kernel_context *ctx,
                strncpy(lsm.u.context.event_name, event_name, NAME_MAX);
        }
 
-       memcpy(&lsm.u.context.ctx, ctx, sizeof(struct lttng_kernel_context));
-       return ask_sessiond(LTTNG_KERNEL_ADD_CONTEXT, NULL);
+       memcpy(&lsm.u.context.ctx, ctx, sizeof(struct lttng_event_context));
+
+       switch (domain->type) {
+       case LTTNG_DOMAIN_KERNEL:
+               ret = ask_sessiond(LTTNG_KERNEL_ADD_CONTEXT, NULL);
+               break;
+       case LTTNG_DOMAIN_UST:
+               ret = LTTCOMM_NOT_IMPLEMENTED;
+               break;
+       default:
+               ret = LTTCOMM_UNKNOWN_DOMAIN;
+               break;
+       };
+
+       return ret;
 }
 
 /*
- *  lttng_kernel_enable_event
+ *  lttng_enable_event
  */
-int lttng_kernel_enable_event(struct lttng_event *ev, char *channel_name)
+int lttng_enable_event(struct lttng_domain *domain,
+               struct lttng_event *ev, const char *channel_name)
 {
        int ret;
 
@@ -321,22 +344,31 @@ int lttng_kernel_enable_event(struct lttng_event *ev, char *channel_name)
                strncpy(lsm.u.enable.channel_name, channel_name, NAME_MAX);
        }
 
-       if (ev == NULL) {
-               ret = ask_sessiond(LTTNG_KERNEL_ENABLE_ALL_EVENT, NULL);
-       } else {
-               memcpy(&lsm.u.enable.event, ev, sizeof(struct lttng_event));
-               ret = ask_sessiond(LTTNG_KERNEL_ENABLE_EVENT, NULL);
-       }
+       switch (domain->type) {
+               case LTTNG_DOMAIN_KERNEL:
+                       if (ev == NULL) {
+                               ret = ask_sessiond(LTTNG_KERNEL_ENABLE_ALL_EVENT, NULL);
+                       } else {
+                               memcpy(&lsm.u.enable.event, ev, sizeof(struct lttng_event));
+                               ret = ask_sessiond(LTTNG_KERNEL_ENABLE_EVENT, NULL);
+                       }
+                       break;
+               case LTTNG_DOMAIN_UST:
+                       ret = LTTCOMM_NOT_IMPLEMENTED;
+                       break;
+               default:
+                       ret = LTTCOMM_UNKNOWN_DOMAIN;
+                       break;
+       };
 
        return ret;
 }
 
 /*
- *  lttng_kernel_disable_event
- *
- *  Disable an event in the kernel tracer.
+ * Disable an event in the kernel tracer.
  */
-int lttng_kernel_disable_event(char *name, char *channel_name)
+int lttng_disable_event(struct lttng_domain *domain, const char *name,
+               const char *channel_name)
 {
        int ret;
 
@@ -346,131 +378,116 @@ int lttng_kernel_disable_event(char *name, char *channel_name)
                strncpy(lsm.u.disable.channel_name, channel_name, NAME_MAX);
        }
 
-       if (name == NULL) {
-               ret = ask_sessiond(LTTNG_KERNEL_DISABLE_ALL_EVENT, NULL);
-       } else {
-               strncpy(lsm.u.disable.name, name, NAME_MAX);
-               ret = ask_sessiond(LTTNG_KERNEL_DISABLE_EVENT, NULL);
-       }
+       switch (domain->type) {
+               case LTTNG_DOMAIN_KERNEL:
+                       if (name == NULL) {
+                               ret = ask_sessiond(LTTNG_KERNEL_DISABLE_ALL_EVENT, NULL);
+                       } else {
+                               strncpy(lsm.u.disable.name, name, NAME_MAX);
+                               ret = ask_sessiond(LTTNG_KERNEL_DISABLE_EVENT, NULL);
+                       }
+                       break;
+               case LTTNG_DOMAIN_UST:
+                       ret = LTTCOMM_NOT_IMPLEMENTED;
+                       break;
+               default:
+                       ret = LTTCOMM_UNKNOWN_DOMAIN;
+                       break;
+       };
 
        return ret;
 }
 
 /*
- *  lttng_kernel_enable_channel
- *
- *  Enable recording for a channel for the kernel tracer.
+ * Enable recording for a channel for the kernel tracer.
  */
-int lttng_kernel_enable_channel(char *name)
+int lttng_enable_channel(struct lttng_domain *domain,
+               struct lttng_channel *chan)
 {
-       strncpy(lsm.u.enable.channel_name, name, NAME_MAX);
-       return ask_sessiond(LTTNG_KERNEL_ENABLE_CHANNEL, NULL);
-}
-
-/*
- *  lttng_kernel_disable_channel
- *
- *  Disable recording for the channel for the kernel tracer.
- */
-int lttng_kernel_disable_channel(char *name)
-{
-       strncpy(lsm.u.disable.channel_name, name, NAME_MAX);
-       return ask_sessiond(LTTNG_KERNEL_DISABLE_CHANNEL, NULL);
-}
+       int ret;
 
-/*
- *  lttng_kernel_create_channel
- *
- *  Create a channel in the kernel tracer.
- */
-int lttng_kernel_create_channel(struct lttng_channel *chan)
-{
        memcpy(&lsm.u.channel.chan, chan, sizeof(struct lttng_channel));
-       return ask_sessiond(LTTNG_KERNEL_CREATE_CHANNEL, NULL);
+
+       switch (domain->type) {
+               case LTTNG_DOMAIN_KERNEL:
+                       ret = ask_sessiond(LTTNG_KERNEL_ENABLE_CHANNEL, NULL);
+                       break;
+               case LTTNG_DOMAIN_UST:
+                       ret = LTTCOMM_NOT_IMPLEMENTED;
+                       break;
+               default:
+                       ret = LTTCOMM_UNKNOWN_DOMAIN;
+                       break;
+       };
+
+       return ret;
 }
 
 /*
- *  lttng_list_events
- *
- *  List all available events in the kernel.
- *
- *  Return the size (bytes) of the list and set the event_list array.
- *  On error, return negative value.
+ * Disable recording for the channel for the kernel tracer.
  */
-int lttng_kernel_list_events(char **event_list)
+int lttng_disable_channel(struct lttng_domain *domain, const char *name)
 {
-       return ask_sessiond(LTTNG_KERNEL_LIST_EVENTS, (void **) event_list);
-}
+       int ret;
 
-/*
- * END Kernel control API
- */
+       strncpy(lsm.u.disable.channel_name, name, NAME_MAX);
 
-/*
- *  lttng_get_readable_code
- *
- *  Return a human readable string of code
- */
-const char *lttng_get_readable_code(int code)
-{
-       if (code > -LTTCOMM_OK) {
-               return "Ended with errors";
-       }
+       switch (domain->type) {
+               case LTTNG_DOMAIN_KERNEL:
+                       ret = ask_sessiond(LTTNG_KERNEL_DISABLE_CHANNEL, NULL);
+                       break;
+               case LTTNG_DOMAIN_UST:
+                       ret = LTTCOMM_NOT_IMPLEMENTED;
+                       break;
+               default:
+                       ret = LTTCOMM_UNKNOWN_DOMAIN;
+                       break;
+       };
 
-       return lttcomm_get_readable_code(code);
+       return ret;
 }
 
 /*
- *  lttng_ust_list_apps
- *
- *  Ask the session daemon for all UST traceable applications.
+ * List all available events in the kernel.
  *
- *  Return the number of pids.
- *  On error, return negative value.
+ * Return the size (bytes) of the list and set the event_list array.
+ * On error, return negative value.
  */
-int lttng_ust_list_traceable_apps(pid_t **pids)
+int lttng_list_events(struct lttng_domain *domain, char **event_list)
 {
        int ret;
 
-       ret = ask_sessiond(LTTNG_LIST_TRACEABLE_APPS, (void**) pids);
-       if (ret < 0) {
-               return ret;
-       }
+       switch (domain->type) {
+               case LTTNG_DOMAIN_KERNEL:
+                       ret = ask_sessiond(LTTNG_KERNEL_LIST_EVENTS, (void **) event_list);
+                       break;
+               case LTTNG_DOMAIN_UST:
+                       ret = LTTCOMM_NOT_IMPLEMENTED;
+                       break;
+               default:
+                       ret = LTTCOMM_UNKNOWN_DOMAIN;
+                       break;
+       };
 
-       return ret / sizeof(pid_t);
+       return ret;
 }
 
 /*
- *  lttng_list_traces
- *
- *  Ask the session daemon for all traces (kernel and ust) for the session
- *  identified by name.
- *
- *  Return the number of traces.
- *  On error, return negative value.
+ *  Return a human readable string of code
  */
-/*
-int lttng_list_traces(char *session_name, struct lttng_trace **traces)
+const char *lttng_get_readable_code(int code)
 {
-       int ret;
-
-       strncpy(lsm.session_name, session_name, NAME_MAX);
-
-       ret = ask_sessiond(LTTNG_LIST_TRACES, (void **) traces);
-       if (ret < 0) {
-               return ret;
+       if (code > -LTTCOMM_OK) {
+               return "Ended with errors";
        }
 
-       return ret / sizeof(struct lttng_trace);
+       return lttcomm_get_readable_code(code);
 }
-*/
 
 /*
- *  lttng_create_session
- *
  *  Create a brand new session using name.
  */
-int lttng_create_session(char *name, char *path)
+int lttng_create_session(const char *name, const char *path)
 {
        strncpy(lsm.session_name, name, NAME_MAX);
        strncpy(lsm.path, path, PATH_MAX);
@@ -478,19 +495,15 @@ int lttng_create_session(char *name, char *path)
 }
 
 /*
- *  lttng_destroy_session
- *
  *  Destroy session using name.
  */
-int lttng_destroy_session(char *name)
+int lttng_destroy_session(const char *name)
 {
        strncpy(lsm.session_name, name, NAME_MAX);
        return ask_sessiond(LTTNG_DESTROY_SESSION, NULL);
 }
 
 /*
- *  lttng_list_sessions
- *
  *  Ask the session daemon for all available sessions.
  *
  *  Return number of session.
@@ -508,7 +521,10 @@ int lttng_list_sessions(struct lttng_session **sessions)
        return ret / sizeof(struct lttng_session);
 }
 
-void lttng_set_session_name(char *name)
+/*
+ * Set session name for the current lsm.
+ */
+void lttng_set_session_name(const char *name)
 {
        strncpy(lsm.session_name, name, NAME_MAX);
 }
This page took 0.101597 seconds and 4 git commands to generate.