blob: a5c7896331ca8057c76b668e9e972c79f007eec1 [file] [log] [blame]
Steven Morelandb0057e72018-08-27 01:44:11 -07001/*
2 * Copyright (C) 2018, 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#pragma once
18
19#include <string>
Jooyung Han7a9aceb2019-12-17 14:18:15 +000020#include <type_traits>
Steven Morelandb0057e72018-08-27 01:44:11 -070021
22#include "aidl_language.h"
23
24// This is used to help generate code targetting C++ (the language) whether using the libbinder or
25// libbinder_ndk backend.
26
27namespace android {
28namespace aidl {
29namespace cpp {
30
31// These roughly correspond to the various class names in the C++ hierarchy:
32enum class ClassNames {
33 BASE, // Foo (not a real class, but useful in some circumstances).
34 CLIENT, // BpFoo
35 SERVER, // BnFoo
36 INTERFACE, // IFoo
37 DEFAULT_IMPL, // IFooDefault
Jiyong Park5b7e5322019-04-03 20:05:01 +090038 RAW, // (as shown in the file)
Steven Morelandb0057e72018-08-27 01:44:11 -070039};
40
41string ClassName(const AidlDefinedType& defined_type, ClassNames type);
42
43// Generate the relative path to a header file. If |use_os_sep| we'll use the
44// operating system specific path separator rather than C++'s expected '/' when
45// including headers.
46std::string HeaderFile(const AidlDefinedType& defined_type, ClassNames class_type,
47 bool use_os_sep = true);
48
49void EnterNamespace(CodeWriter& out, const AidlDefinedType& defined_type);
50void LeaveNamespace(CodeWriter& out, const AidlDefinedType& defined_type);
51
Steven Moreland3b1325f2018-09-20 14:45:40 -070052string BuildVarName(const AidlArgument& a);
Jeongik Cha37e2ad52019-04-18 13:44:26 +090053const string GenLogBeforeExecute(const string className, const AidlMethod& method, bool isServer,
54 bool isNdk);
55const string GenLogAfterExecute(const string className, const AidlInterface& interface,
56 const AidlMethod& method, const string& statusVarName,
57 const string& returnVarName, bool isServer, bool isNdk);
Jooyung Han7a9aceb2019-12-17 14:18:15 +000058
59template <typename T, typename = std::enable_if_t<std::is_copy_constructible_v<T>>>
60std::vector<T> Append(std::vector<T> as, const std::vector<T>& bs) {
61 as.insert(as.end(), bs.begin(), bs.end());
62 return as;
63}
64
65template <typename T>
66std::vector<T> Append(std::vector<T>&& as, std::vector<T>&& bs) {
67 std::vector<T> appended = std::move(as);
68 std::copy(std::move_iterator(bs.begin()), std::move_iterator(bs.end()),
69 std::back_inserter(appended));
70 return appended;
71}
72
73std::string GenerateEnumValues(const AidlEnumDeclaration& enum_decl,
74 const std::vector<std::string>& enclosing_namespaces_of_enum_decl);
75
Steven Morelandb0057e72018-08-27 01:44:11 -070076} // namespace cpp
77} // namespace aidl
78} // namespace android