1 //
2 // Copyright (C) 2014 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_COMMAND_TRANSCEIVER_H_
18 #define TRUNKS_COMMAND_TRANSCEIVER_H_
19 
20 #include <string>
21 
22 #include <base/callback_forward.h>
23 
24 namespace trunks {
25 
26 // CommandTransceiver is an interface that sends commands to a TPM device and
27 // receives responses. It can operate synchronously or asynchronously.
28 class CommandTransceiver {
29  public:
30   typedef base::Callback<void(const std::string& response)> ResponseCallback;
31 
~CommandTransceiver()32   virtual ~CommandTransceiver() {}
33 
34   // Sends a TPM |command| asynchronously. When a |response| is received,
35   // |callback| will be called with the |response| data from the TPM. If a
36   // transmission error occurs |callback| will be called with a well-formed
37   // error |response|.
38   virtual void SendCommand(
39       const std::string& command,
40       const ResponseCallback& callback) = 0;
41 
42   // Sends a TPM |command| synchronously (i.e. waits for a response) and returns
43   // the response. If a transmission error occurs the response will be populated
44   // with a well-formed error response.
45   virtual std::string SendCommandAndWait(const std::string& command) = 0;
46 
47   // Initializes the actual interface, replaced by the derived classes, where
48   // needed.
Init()49   virtual bool Init() { return true; }
50 };
51 
52 }  // namespace trunks
53 
54 #endif  // TRUNKS_COMMAND_TRANSCEIVER_H_
55