plugins: implement plugin unregister
[babeltrace.git] / lib / trace-handle.c
CommitLineData
842c2b97
JD
1/*
2 * trace_handle.c
3 *
4 * Babeltrace Library
5 *
6 * Copyright 2012 EfficiOS Inc. and Linux Foundation
7 *
8 * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * Julien Desfossez <julien.desfossez@efficios.com>
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 */
21
22#include <stdint.h>
23#include <stdlib.h>
24#include <babeltrace/babeltrace.h>
25#include <babeltrace/context.h>
08c22d05 26#include <babeltrace/context-internal.h>
842c2b97
JD
27#include <babeltrace/trace-handle.h>
28#include <babeltrace/trace-handle-internal.h>
29
30struct bt_trace_handle *bt_trace_handle_create(struct bt_context *ctx)
31{
32 struct bt_trace_handle *th;
33
7f89ddce
MD
34 if (!ctx)
35 return NULL;
36
6cba487f 37 th = g_new0(struct bt_trace_handle, 1);
842c2b97
JD
38 th->id = ctx->last_trace_handle_id++;
39 return th;
40}
41
6cba487f
MD
42void bt_trace_handle_destroy(struct bt_trace_handle *th)
43{
e6d85e38 44 th->format->close_trace(th->td);
6cba487f
MD
45 g_free(th);
46}
47
48int bt_trace_handle_get_id(struct bt_trace_handle *th)
842c2b97 49{
7f89ddce
MD
50 if (!th)
51 return -1;
52
6cba487f 53 return th->id;
842c2b97
JD
54}
55
e3d12cf9 56const char *bt_trace_handle_get_path(struct bt_context *ctx, int handle_id)
842c2b97 57{
e3d12cf9
JD
58 struct bt_trace_handle *handle;
59
7f89ddce
MD
60 if (!ctx)
61 return NULL;
62
e3d12cf9
JD
63 handle = g_hash_table_lookup(ctx->trace_handles,
64 (gpointer) (unsigned long) handle_id);
5d95b2db
JD
65 if (!handle)
66 return NULL;
e3d12cf9 67 return handle->path;
842c2b97
JD
68}
69
03798a93
JD
70uint64_t bt_trace_handle_get_timestamp_begin(struct bt_context *ctx,
71 int handle_id, enum bt_clock_type type)
842c2b97 72{
e3d12cf9 73 struct bt_trace_handle *handle;
03798a93 74 uint64_t ret;
e3d12cf9 75
7f89ddce
MD
76 if (!ctx)
77 return -1ULL;
78
e3d12cf9
JD
79 handle = g_hash_table_lookup(ctx->trace_handles,
80 (gpointer) (unsigned long) handle_id);
03798a93
JD
81 if (!handle) {
82 ret = -1ULL;
83 goto end;
84 }
85 if (type == BT_CLOCK_REAL) {
86 ret = handle->real_timestamp_begin;
87 } else if (type == BT_CLOCK_CYCLES) {
88 ret = handle->cycles_timestamp_begin;
89 } else {
90 ret = -1ULL;
91 }
92
93end:
94 return ret;
842c2b97
JD
95}
96
03798a93
JD
97uint64_t bt_trace_handle_get_timestamp_end(struct bt_context *ctx,
98 int handle_id, enum bt_clock_type type)
842c2b97 99{
e3d12cf9 100 struct bt_trace_handle *handle;
03798a93 101 uint64_t ret;
e3d12cf9 102
7f89ddce
MD
103 if (!ctx)
104 return -1ULL;
105
e3d12cf9
JD
106 handle = g_hash_table_lookup(ctx->trace_handles,
107 (gpointer) (unsigned long) handle_id);
03798a93
JD
108 if (!handle) {
109 ret = -1ULL;
110 goto end;
111 }
112 if (type == BT_CLOCK_REAL) {
113 ret = handle->real_timestamp_end;
114 } else if (type == BT_CLOCK_CYCLES) {
115 ret = handle->cycles_timestamp_end;
116 } else {
117 ret = -1ULL;
118 }
119
120end:
121 return ret;
842c2b97 122}
This page took 0.028617 seconds and 4 git commands to generate.