Move actions source files to src/common/actions directory
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 25 Nov 2019 19:20:31 +0000 (14:20 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 17 Apr 2020 20:31:59 +0000 (16:31 -0400)
Since more actions will be added, group them under an "actions"
directory.  The files to be added are expected to have some pretty
generic/overloaded names, such as start-session.c and snapshot.c, so
having them under the actions directory make it clear that they
implement the action described by the name.

Change-Id: Ia47160dd75531eb9bcf13f875f4bc6caa2391d7b
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/common/Makefile.am
src/common/action.c [deleted file]
src/common/actions/action.c [new file with mode: 0644]
src/common/actions/notify.c [new file with mode: 0644]
src/common/notify.c [deleted file]

index 7ca180bd38a43ad4cd647f8b301a582f827d3d87..7ec0f52a50c7c0fe2ca5a55324cc0126617ec099 100644 (file)
@@ -27,7 +27,8 @@ noinst_LTLIBRARIES = libcommon.la
 EXTRA_DIST = mi-lttng-4.0.xsd
 
 libcommon_la_SOURCES = \
-       action.c \
+       actions/action.c \
+       actions/notify.c \
        buffer-usage.c \
        buffer-view.h buffer-view.c \
        common.h \
@@ -48,7 +49,6 @@ libcommon_la_SOURCES = \
        location.c \
        mi-lttng.c mi-lttng.h \
        notification.c \
-       notify.c \
        optional.h \
        pipe.c pipe.h \
        readwrite.c readwrite.h \
diff --git a/src/common/action.c b/src/common/action.c
deleted file mode 100644 (file)
index dc72d37..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
- *
- * SPDX-License-Identifier: LGPL-2.1-only
- *
- */
-
-#include <lttng/action/action-internal.h>
-#include <lttng/action/notify-internal.h>
-#include <common/error.h>
-#include <assert.h>
-
-enum lttng_action_type lttng_action_get_type(struct lttng_action *action)
-{
-       return action ? action->type : LTTNG_ACTION_TYPE_UNKNOWN;
-}
-
-LTTNG_HIDDEN
-enum lttng_action_type lttng_action_get_type_const(
-               const struct lttng_action *action)
-{
-       return action->type;
-}
-
-void lttng_action_destroy(struct lttng_action *action)
-{
-       if (!action) {
-               return;
-       }
-
-       assert(action->destroy);
-       action->destroy(action);
-}
-
-LTTNG_HIDDEN
-bool lttng_action_validate(struct lttng_action *action)
-{
-       bool valid;
-
-       if (!action) {
-               valid = false;
-               goto end;
-       }
-
-       if (!action->validate) {
-               /* Sub-class guarantees that it can never be invalid. */
-               valid = true;
-               goto end;
-       }
-
-       valid = action->validate(action);
-end:
-       return valid;
-}
-
-LTTNG_HIDDEN
-int lttng_action_serialize(struct lttng_action *action,
-               struct lttng_dynamic_buffer *buf)
-{
-       int ret;
-       struct lttng_action_comm action_comm = {
-               .action_type = (int8_t) action->type,
-       };
-
-       ret = lttng_dynamic_buffer_append(buf, &action_comm,
-                       sizeof(action_comm));
-       if (ret) {
-               goto end;
-       }
-
-       ret = action->serialize(action, buf);
-       if (ret) {
-               goto end;
-       }
-end:
-       return ret;
-}
-
-LTTNG_HIDDEN
-ssize_t lttng_action_create_from_buffer(const struct lttng_buffer_view *view,
-               struct lttng_action **_action)
-{
-       ssize_t ret, action_size = sizeof(struct lttng_action_comm);
-       struct lttng_action *action;
-       const struct lttng_action_comm *action_comm;
-
-       if (!view || !_action) {
-               ret = -1;
-               goto end;
-       }
-
-       action_comm = (const struct lttng_action_comm *) view->data;
-       DBG("Deserializing action from buffer");
-       switch (action_comm->action_type) {
-       case LTTNG_ACTION_TYPE_NOTIFY:
-               action = lttng_action_notify_create();
-               break;
-       default:
-               ret = -1;
-               goto end;
-       }
-
-       if (!action) {
-               ret = -1;
-               goto end;
-       }
-       ret = action_size;
-       *_action = action;
-end:
-       return ret;
-}
diff --git a/src/common/actions/action.c b/src/common/actions/action.c
new file mode 100644 (file)
index 0000000..dc72d37
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ */
+
+#include <lttng/action/action-internal.h>
+#include <lttng/action/notify-internal.h>
+#include <common/error.h>
+#include <assert.h>
+
+enum lttng_action_type lttng_action_get_type(struct lttng_action *action)
+{
+       return action ? action->type : LTTNG_ACTION_TYPE_UNKNOWN;
+}
+
+LTTNG_HIDDEN
+enum lttng_action_type lttng_action_get_type_const(
+               const struct lttng_action *action)
+{
+       return action->type;
+}
+
+void lttng_action_destroy(struct lttng_action *action)
+{
+       if (!action) {
+               return;
+       }
+
+       assert(action->destroy);
+       action->destroy(action);
+}
+
+LTTNG_HIDDEN
+bool lttng_action_validate(struct lttng_action *action)
+{
+       bool valid;
+
+       if (!action) {
+               valid = false;
+               goto end;
+       }
+
+       if (!action->validate) {
+               /* Sub-class guarantees that it can never be invalid. */
+               valid = true;
+               goto end;
+       }
+
+       valid = action->validate(action);
+end:
+       return valid;
+}
+
+LTTNG_HIDDEN
+int lttng_action_serialize(struct lttng_action *action,
+               struct lttng_dynamic_buffer *buf)
+{
+       int ret;
+       struct lttng_action_comm action_comm = {
+               .action_type = (int8_t) action->type,
+       };
+
+       ret = lttng_dynamic_buffer_append(buf, &action_comm,
+                       sizeof(action_comm));
+       if (ret) {
+               goto end;
+       }
+
+       ret = action->serialize(action, buf);
+       if (ret) {
+               goto end;
+       }
+end:
+       return ret;
+}
+
+LTTNG_HIDDEN
+ssize_t lttng_action_create_from_buffer(const struct lttng_buffer_view *view,
+               struct lttng_action **_action)
+{
+       ssize_t ret, action_size = sizeof(struct lttng_action_comm);
+       struct lttng_action *action;
+       const struct lttng_action_comm *action_comm;
+
+       if (!view || !_action) {
+               ret = -1;
+               goto end;
+       }
+
+       action_comm = (const struct lttng_action_comm *) view->data;
+       DBG("Deserializing action from buffer");
+       switch (action_comm->action_type) {
+       case LTTNG_ACTION_TYPE_NOTIFY:
+               action = lttng_action_notify_create();
+               break;
+       default:
+               ret = -1;
+               goto end;
+       }
+
+       if (!action) {
+               ret = -1;
+               goto end;
+       }
+       ret = action_size;
+       *_action = action;
+end:
+       return ret;
+}
diff --git a/src/common/actions/notify.c b/src/common/actions/notify.c
new file mode 100644 (file)
index 0000000..00d1a0e
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ */
+
+#include <lttng/action/action-internal.h>
+#include <lttng/action/notify-internal.h>
+#include <common/macros.h>
+#include <assert.h>
+
+static
+void lttng_action_notify_destroy(struct lttng_action *action)
+{
+       free(action);
+}
+
+static
+int lttng_action_notify_serialize(struct lttng_action *action,
+               struct lttng_dynamic_buffer *buf)
+{
+       return 0;
+}
+
+struct lttng_action *lttng_action_notify_create(void)
+{
+       struct lttng_action_notify *notify;
+
+       notify = zmalloc(sizeof(struct lttng_action_notify));
+       if (!notify) {
+               goto end;
+       }
+
+       notify->parent.type = LTTNG_ACTION_TYPE_NOTIFY;
+       notify->parent.serialize = lttng_action_notify_serialize;
+       notify->parent.destroy = lttng_action_notify_destroy;
+end:
+       return &notify->parent;
+}
diff --git a/src/common/notify.c b/src/common/notify.c
deleted file mode 100644 (file)
index 00d1a0e..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
- *
- * SPDX-License-Identifier: LGPL-2.1-only
- *
- */
-
-#include <lttng/action/action-internal.h>
-#include <lttng/action/notify-internal.h>
-#include <common/macros.h>
-#include <assert.h>
-
-static
-void lttng_action_notify_destroy(struct lttng_action *action)
-{
-       free(action);
-}
-
-static
-int lttng_action_notify_serialize(struct lttng_action *action,
-               struct lttng_dynamic_buffer *buf)
-{
-       return 0;
-}
-
-struct lttng_action *lttng_action_notify_create(void)
-{
-       struct lttng_action_notify *notify;
-
-       notify = zmalloc(sizeof(struct lttng_action_notify));
-       if (!notify) {
-               goto end;
-       }
-
-       notify->parent.type = LTTNG_ACTION_TYPE_NOTIFY;
-       notify->parent.serialize = lttng_action_notify_serialize;
-       notify->parent.destroy = lttng_action_notify_destroy;
-end:
-       return &notify->parent;
-}
This page took 0.041205 seconds and 4 git commands to generate.