type_namespace.h revision b656a3b1954bbe4b548a3c11274c833bbca35935
1/*
2 * Copyright (C) 2015, 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 AIDL_TYPE_NAMESPACE_H_
18#define AIDL_TYPE_NAMESPACE_H_
19
20#include <memory>
21#include <string>
22
23#include <base/macros.h>
24
25#include "aidl_language.h"
26
27namespace android {
28namespace aidl {
29
30class ValidatableType {
31 public:
32  ValidatableType() = default;
33  virtual ~ValidatableType() = default;
34
35  virtual bool CanBeArray() const = 0;
36  virtual bool CanBeOutParameter() const = 0;
37  virtual bool CanWriteToParcel() const = 0;
38
39 private:
40  DISALLOW_COPY_AND_ASSIGN(ValidatableType);
41};
42
43class TypeNamespace {
44 public:
45  // Load this TypeNamespace with user defined types.
46  virtual bool AddParcelableType(const AidlParcelable* p,
47                                 const std::string& filename) = 0;
48  virtual bool AddBinderType(const AidlInterface* b,
49                             const std::string& filename) = 0;
50  // We dynamically create container types as we discover them in the parse
51  // tree.  Returns false iff this is an invalid type.  Silently discards
52  // duplicates and non-container types.
53  virtual bool AddContainerType(const std::string& type_name) = 0;
54
55  // Returns true iff this has a type for |type_name|.
56  virtual bool HasType(const std::string& type_name) const;
57
58  // Returns true iff |package| is a valid package name.
59  virtual bool IsValidPackage(const std::string& package) const;
60
61  // Returns true iff |raw_type| is a valid return type.
62  virtual bool IsValidReturnType(const AidlType& raw_type,
63                                 const std::string& filename) const;
64
65  // Returns true iff |arg_type| is a valid method argument.
66  virtual bool IsValidArg(const AidlArgument& a,
67                          int arg_index,
68                          const std::string& filename) const;
69
70 protected:
71  TypeNamespace() = default;
72  virtual ~TypeNamespace() = default;
73
74  virtual const ValidatableType* GetValidatableType(
75      const std::string& name) const = 0;
76
77 private:
78  DISALLOW_COPY_AND_ASSIGN(TypeNamespace);
79};
80
81}  // namespace aidl
82}  // namespace android
83
84#endif  // AIDL_TYPE_NAMESPACE_H_
85