1 // Copyright 2018 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // A helper library for connecting to the trace manager via fdio.
6 
7 #include <lib/fdio/util.h>
8 #include <lib/zx/channel.h>
9 #include <trace-provider/fdio_connect.h>
10 
11 const char kServicePath[] = "/svc/fuchsia.tracelink.Registry";
12 
trace_provider_connect_with_fdio(zx_handle_t * out_client)13 zx_status_t trace_provider_connect_with_fdio(zx_handle_t* out_client) {
14     // Connect to the trace registry.
15     zx::channel registry_client;
16     zx::channel registry_service;
17     zx_status_t status = zx::channel::create(0u, &registry_client, &registry_service);
18     if (status != ZX_OK)
19         return status;
20 
21     status = fdio_service_connect(kServicePath,
22                                   registry_service.release()); // takes ownership
23     if (status != ZX_OK)
24         return status;
25 
26     *out_client = registry_client.release();
27     return ZX_OK;
28 }
29