blob: e4cec82a4184b0b0e13ed0b4a3bfc3e2fadd9309 [file] [log] [blame]
Primiano Tucci4f9b6d72017-12-05 20:59:16 +00001/*
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// This file is only meant to be included in autogenerated .cc files.
18
19#ifndef INCLUDE_PERFETTO_IPC_CODEGEN_HELPERS_H_
20#define INCLUDE_PERFETTO_IPC_CODEGEN_HELPERS_H_
21
22// A templated protobuf message decoder. Returns nullptr in case of failure.
23template <typename T>
24::std::unique_ptr<::perfetto::ipc::ProtoMessage> _IPC_Decoder(
25 const std::string& proto_data) {
26 ::std::unique_ptr<::perfetto::ipc::ProtoMessage> msg(new T());
27 if (msg->ParseFromString(proto_data))
28 return msg;
29 return nullptr;
30}
31
32// Templated method dispatcher. Used to obtain a function pointer to a given
33// IPC method (Method) of a given service (TSvc) that can be invoked by the
34// host-side machinery starting from a generic Service pointer and a generic
35// ProtoMessage request argument.
36template <typename TSvc, // Type of the actual Service subclass.
37 typename TReq, // Type of the request argument.
38 typename TReply, // Type of the reply argument.
39 void (TSvc::*Method)(const TReq&, ::perfetto::ipc::Deferred<TReply>)>
40void _IPC_Invoker(::perfetto::ipc::Service* s,
41 const ::perfetto::ipc::ProtoMessage& req,
42 ::perfetto::ipc::DeferredBase reply) {
43 (*static_cast<TSvc*>(s).*Method)(
44 static_cast<const TReq&>(req),
45 ::perfetto::ipc::Deferred<TReply>(::std::move(reply)));
46}
47
48#endif // INCLUDE_PERFETTO_IPC_CODEGEN_HELPERS_H_