Home | History | Annotate | Download | only in trunks
      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 
     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(const std::string& command,
     39                            const ResponseCallback& callback) = 0;
     40 
     41   // Sends a TPM |command| synchronously (i.e. waits for a response) and returns
     42   // the response. If a transmission error occurs the response will be populated
     43   // with a well-formed error response.
     44   virtual std::string SendCommandAndWait(const std::string& command) = 0;
     45 
     46   // Initializes the actual interface, replaced by the derived classes, where
     47   // needed.
     48   virtual bool Init() { return true; }
     49 };
     50 
     51 }  // namespace trunks
     52 
     53 #endif  // TRUNKS_COMMAND_TRANSCEIVER_H_
     54