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