1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef INCLUDE_PERFETTO_TRACING_CORE_FORWARD_DECLS_H_
18 #define INCLUDE_PERFETTO_TRACING_CORE_FORWARD_DECLS_H_
19 
20 // Forward declares classes that are generated at build-time from protos.
21 // First of all, why are we forward declaring at all?
22 //  1. Chromium diverges from the Google style guide on this, because forward
23 //     declarations typically make build times faster, and that's a desirable
24 //     property for a large and complex codebase.
25 //  2. Adding #include to build-time-generated headers from headers typically
26 //     creates subtle build errors that are hard to spot in GN. This is because
27 //     once a standard header (say foo.h) has an #include "protos/foo.gen.h",
28 //     the build target that depends on foo.h needs to depend on the genrule
29 //     that generates foo.gen.h. This is achievable using public_deps in GN but
30 //     is not testable / enforceable, hence too easy to get wrong.
31 
32 // Historically the classes below used to be generated from the corresponding
33 // .proto(s) at CL *check-in* time (!= build time) in the ::perfetto namespace.
34 // Nowadays we have code everywhere that assume the right class is
35 // ::perfetto::TraceConfig or the like. Back then other headers could just
36 // forward declared ::perfetto::TraceConfig. These days, the real class is
37 // ::perfetto::protos::gen::TraceConfig and core/trace_config.h aliases that as
38 // using ::perfetto::TraceConfig = ::perfetto::protos::gen::TraceConfig.
39 // In C++ one cannot forward declare a type alias (but only the aliased type).
40 // Hence this header, which should be used every time one wants to forward
41 // declare classes like TraceConfig.
42 
43 // The overall plan is that, when one of the classes below is needed:
44 // The .h file includes this file.
45 // The .cc file includes perfetto/tracing/core/trace_config.h (or equiv). That
46 // header will pull the full declaration from trace_config.gen.h and will also
47 // setup the alias in the ::perfetto namespace.
48 
49 namespace perfetto {
50 namespace protos {
51 namespace gen {
52 
53 class ChromeConfig;
54 class CommitDataRequest;
55 class DataSourceConfig;
56 class DataSourceDescriptor;
57 class ObservableEvents;
58 class TraceConfig;
59 class TraceStats;
60 class TracingServiceCapabilities;
61 class TracingServiceState;
62 
63 }  // namespace gen
64 }  // namespace protos
65 
66 using ChromeConfig = ::perfetto::protos::gen::ChromeConfig;
67 using CommitDataRequest = ::perfetto::protos::gen::CommitDataRequest;
68 using DataSourceConfig = ::perfetto::protos::gen::DataSourceConfig;
69 using DataSourceDescriptor = ::perfetto::protos::gen::DataSourceDescriptor;
70 using ObservableEvents = ::perfetto::protos::gen::ObservableEvents;
71 using TraceConfig = ::perfetto::protos::gen::TraceConfig;
72 using TraceStats = ::perfetto::protos::gen::TraceStats;
73 using TracingServiceCapabilities =
74     ::perfetto::protos::gen::TracingServiceCapabilities;
75 using TracingServiceState = ::perfetto::protos::gen::TracingServiceState;
76 
77 }  // namespace perfetto
78 
79 #endif  // INCLUDE_PERFETTO_TRACING_CORE_FORWARD_DECLS_H_
80