1 /* 2 * Copyright (C) 2017 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_IPC_SERVICE_DESCRIPTOR_H_ 18 #define INCLUDE_PERFETTO_IPC_SERVICE_DESCRIPTOR_H_ 19 20 #include <functional> 21 #include <string> 22 #include <utility> 23 #include <vector> 24 25 #include "perfetto/ipc/basic_types.h" 26 #include "perfetto/ipc/deferred.h" 27 28 namespace perfetto { 29 namespace ipc { 30 31 class Service; 32 33 // This is a pure data structure which holds factory methods and strings for the 34 // services and their methods that get generated in the .h/.cc files. 35 // Each autogenerated class has a GetDescriptor() method that returns one 36 // instance of these and allows both client and hosts to map service and method 37 // names to IDs and provide function pointers to the protobuf decoder fuctions. 38 class ServiceDescriptor { 39 public: 40 struct Method { 41 const char* name; 42 43 // DecoderFunc is pointer to a function that takes a string in input 44 // containing protobuf encoded data and returns a decoded protobuf message. 45 using DecoderFunc = std::unique_ptr<ProtoMessage> (*)(const std::string&); 46 47 // Function pointer to decode the request argument of the method. 48 DecoderFunc request_proto_decoder; 49 50 // Function pointer to decoded the reply argument of the method. 51 DecoderFunc reply_proto_decoder; 52 53 // Function pointer that dispatches the generic request to the corresponding 54 // method implementation. 55 using InvokerFunc = void (*)(Service*, 56 const ProtoMessage& /* request_args */, 57 DeferredBase /* deferred_reply */); 58 InvokerFunc invoker; 59 }; 60 61 const char* service_name = nullptr; 62 63 // Note that methods order is not stable. Client and Host might have different 64 // method indexes, depending on their versions. The Client can't just rely 65 // on the indexes and has to keep a [string -> remote index] translation map. 66 std::vector<Method> methods; 67 }; 68 69 } // namespace ipc 70 } // namespace perfetto 71 72 #endif // INCLUDE_PERFETTO_IPC_SERVICE_DESCRIPTOR_H_ 73