| 1 | /* |
| 2 | * SPDX-License-Identifier: MIT |
| 3 | * |
| 4 | * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com> |
| 5 | * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
| 6 | */ |
| 7 | |
| 8 | #define BT_LOG_TAG "LIB/MSG" |
| 9 | #include "lib/logging.h" |
| 10 | |
| 11 | #include "common/assert.h" |
| 12 | #include "lib/assert-pre.h" |
| 13 | #include "lib/assert-post.h" |
| 14 | #include <babeltrace2/graph/message.h> |
| 15 | #include "lib/graph/message/message.h" |
| 16 | #include "lib/graph/graph.h" |
| 17 | |
| 18 | BT_HIDDEN |
| 19 | void bt_message_init(struct bt_message *message, |
| 20 | enum bt_message_type type, |
| 21 | bt_object_release_func release, |
| 22 | struct bt_graph *graph) |
| 23 | { |
| 24 | message->type = type; |
| 25 | bt_object_init_shared(&message->base, release); |
| 26 | message->graph = graph; |
| 27 | |
| 28 | if (graph) { |
| 29 | bt_graph_add_message(graph, message); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | enum bt_message_type bt_message_get_type( |
| 34 | const struct bt_message *message) |
| 35 | { |
| 36 | BT_ASSERT_PRE_DEV_NON_NULL(message, "Message"); |
| 37 | return message->type; |
| 38 | } |
| 39 | |
| 40 | BT_HIDDEN |
| 41 | void bt_message_unlink_graph(struct bt_message *msg) |
| 42 | { |
| 43 | BT_ASSERT(msg); |
| 44 | msg->graph = NULL; |
| 45 | } |
| 46 | |
| 47 | void bt_message_get_ref(const struct bt_message *message) |
| 48 | { |
| 49 | bt_object_get_ref(message); |
| 50 | } |
| 51 | |
| 52 | void bt_message_put_ref(const struct bt_message *message) |
| 53 | { |
| 54 | bt_object_put_ref(message); |
| 55 | } |