trunks_binder_proxy.h revision 9caf492818a4cc51ba471534d3fcaa84c9ce0278
1//
2// Copyright (C) 2016 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 TRUNKS_TRUNKS_BINDER_PROXY_H_
18#define TRUNKS_TRUNKS_BINDER_PROXY_H_
19
20#include <string>
21
22#include "android/trunks/ITrunks.h"
23#include "trunks/command_transceiver.h"
24#include "trunks/trunks_export.h"
25
26namespace trunks {
27
28// TrunksBinderProxy is a CommandTransceiver implementation that forwards all
29// commands to the trunksd binder daemon. See TrunksBinderService for details on
30// how the commands are handled once they reach trunksd.
31class TRUNKS_EXPORT TrunksBinderProxy : public CommandTransceiver {
32 public:
33  TrunksBinderProxy() = default;
34  ~TrunksBinderProxy() override = default;
35
36  // Initializes the client. Returns true on success.
37  bool Init() override;
38
39  // Asynchronous calls assume a message loop and binder watcher have already
40  // been configured elsewhere.
41  void SendCommand(const std::string& command,
42                   const ResponseCallback& callback) override;
43  std::string SendCommandAndWait(const std::string& command) override;
44
45 private:
46  android::sp<android::trunks::ITrunks> trunks_service_;
47
48  DISALLOW_COPY_AND_ASSIGN(TrunksBinderProxy);
49};
50
51}  // namespace trunks
52
53#endif  // TRUNKS_TRUNKS_BINDER_PROXY_H_
54