• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 SRC_TRACE_PROCESSOR_SQLITE_CREATE_FUNCTION_INTERNAL_H_
18 #define SRC_TRACE_PROCESSOR_SQLITE_CREATE_FUNCTION_INTERNAL_H_
19 
20 #include <sqlite3.h>
21 #include <string>
22 
23 #include "perfetto/base/status.h"
24 #include "perfetto/ext/base/optional.h"
25 #include "perfetto/ext/base/string_view.h"
26 #include "perfetto/trace_processor/basic_types.h"
27 
28 namespace perfetto {
29 namespace trace_processor {
30 
31 bool IsValidName(base::StringView str);
32 
33 base::Optional<SqlValue::Type> ParseType(base::StringView str);
34 
35 const char* SqliteTypeToFriendlyString(SqlValue::Type type);
36 
37 base::Status TypeCheckSqliteValue(sqlite3_value* value,
38                                   SqlValue::Type expected_type);
39 
40 struct Prototype {
41   struct Argument {
42     std::string name;
43     std::string dollar_name;
44     SqlValue::Type type;
45 
46     bool operator==(const Argument& other) const {
47       return name == other.name && dollar_name == other.dollar_name &&
48              type == other.type;
49     }
50   };
51   std::string function_name;
52   std::vector<Argument> arguments;
53 
54   bool operator==(const Prototype& other) const {
55     return function_name == other.function_name && arguments == other.arguments;
56   }
57   bool operator!=(const Prototype& other) const { return !(*this == other); }
58 };
59 
60 base::Status ParseFunctionName(base::StringView raw,
61                                base::StringView& function_name);
62 
63 base::Status ParsePrototype(base::StringView raw, Prototype& out);
64 
65 base::Status ParseArgs(std::string args, std::vector<Prototype::Argument>&);
66 
67 base::Status SqliteRetToStatus(sqlite3* db,
68                                const std::string& function_name,
69                                int ret);
70 
71 base::Status MaybeBindArgument(sqlite3_stmt*,
72                                const std::string& function_name,
73                                const Prototype::Argument&,
74                                sqlite3_value*);
75 
76 }  // namespace trace_processor
77 }  // namespace perfetto
78 
79 #endif  // SRC_TRACE_PROCESSOR_SQLITE_CREATE_FUNCTION_INTERNAL_H_
80