+int bt_context_add_trace(struct bt_context *ctx, const char *path,
+ const char *format_str)
+{
+ struct trace_descriptor *td;
+ struct format *fmt;
+ struct bt_trace_handle *handle;
+
+ fmt = bt_lookup_format(g_quark_from_string(format_str));
+ td = fmt->open_trace(path, O_RDONLY,
+ ctf_move_pos_slow, NULL);
+ if (!td) {
+ fprintf(stdout, "[error] [Context] Cannot Open_trace of the format %s .\n\n",
+ path);
+ return 0;
+ }
+
+ /* Create an handle for the trace */
+ handle = bt_trace_handle_create(ctx);
+ if (handle < 0) {
+ fprintf(stdout, "[error] [Context] Creating trace handle %s .\n\n",
+ path);
+ return 0;
+ }
+ handle->format = fmt;
+ handle->td = td;
+ strncpy(handle->path, path, PATH_MAX);
+ handle->path[PATH_MAX - 1] = '\0';
+
+ /* Add new handle to container */
+ g_hash_table_insert(ctx->trace_handles,
+ (gpointer) (unsigned long) handle->id,
+ handle);
+ trace_collection_add(ctx->tc, td);
+ return handle->id;