blob: 1f7f490513e20369772ce276788f1b082b450b55 [file] [log] [blame]
Steven Morelande8a3a192018-09-20 14:14:28 -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#pragma once
17
18#include "aidl_language.h"
Steven Moreland2bea13b2018-10-03 15:12:33 -070019#include "aidl_to_cpp_common.h"
Steven Morelande8a3a192018-09-20 14:14:28 -070020
21namespace android {
22namespace aidl {
23namespace ndk {
24
25enum class StorageMode {
26 STACK,
27 ARGUMENT, // Value for primitives, const& for larger types
28 OUT_ARGUMENT, // Pointer to raw type
29};
30
Steven Moreland7c933372018-10-11 15:20:04 -070031std::string NdkHeaderFile(const AidlDefinedType& defined_type, cpp::ClassNames name,
32 bool use_os_sep = true);
33
Daniel Norman37d43dd2019-09-09 17:22:34 -070034std::string ConstantValueDecorator(const AidlTypeSpecifier& type, const std::string& raw_value);
35
Steven Moreland2bea13b2018-10-03 15:12:33 -070036// Returns ::aidl::some_package::some_sub_package::foo::IFoo/BpFoo/BnFoo
37std::string NdkFullClassName(const AidlDefinedType& type, cpp::ClassNames name);
38
Steven Morelande8a3a192018-09-20 14:14:28 -070039// Returns the corresponding Ndk type name for an AIDL type spec including
40// array modifiers.
Steven Moreland2bea13b2018-10-03 15:12:33 -070041std::string NdkNameOf(const AidlTypenames& types, const AidlTypeSpecifier& aidl, StorageMode mode);
Steven Morelande8a3a192018-09-20 14:14:28 -070042
43struct CodeGeneratorContext {
44 CodeWriter& writer;
Steven Moreland2bea13b2018-10-03 15:12:33 -070045
46 const AidlTypenames& types;
Steven Morelande8a3a192018-09-20 14:14:28 -070047 const AidlTypeSpecifier& type;
Steven Moreland2bea13b2018-10-03 15:12:33 -070048
Steven Morelande8a3a192018-09-20 14:14:28 -070049 const string parcel;
50 const string var;
51};
52
53void WriteToParcelFor(const CodeGeneratorContext& c);
54void ReadFromParcelFor(const CodeGeneratorContext& c);
55
Jiyong Park965c5b92018-11-21 13:37:15 +090056// Returns argument list of a method where each arg is formatted by the fomatter
57std::string NdkArgList(
58 const AidlTypenames& types, const AidlMethod& method,
59 std::function<std::string(const std::string& type, const std::string& name, bool isOut)>
60 formatter);
Steven Morelandaada3422018-09-20 15:55:33 -070061
Jiyong Park965c5b92018-11-21 13:37:15 +090062inline std::string FormatArgForDecl(const std::string& type, const std::string& name,
63 bool /*isOut*/) {
64 return type + " " + name;
65}
66
67inline std::string FormatArgNameUnused(const std::string& type, const std::string& name,
68 bool /*isOut*/) {
69 return type + " /*" + name + "*/";
70}
71
72inline std::string FormatArgForCall(const std::string& /*type*/, const std::string& name,
73 bool isOut) {
74 std::string reference_prefix = isOut ? "&" : "";
75 return reference_prefix + name;
76}
77
78inline std::string FormatArgNameOnly(const std::string& /*type*/, const std::string& name,
79 bool /*isOut*/) {
80 return name;
81}
Steven Morelandaada3422018-09-20 15:55:33 -070082
83// -> 'status (class::)name(type name, ...)' for a method
Steven Moreland2bea13b2018-10-03 15:12:33 -070084std::string NdkMethodDecl(const AidlTypenames& types, const AidlMethod& method,
85 const std::string& clazz = "");
Steven Morelandaada3422018-09-20 15:55:33 -070086
Steven Morelande8a3a192018-09-20 14:14:28 -070087} // namespace ndk
88} // namespace aidl
89} // namespace android