blob: b3a97e124210a51ad336b51efb6f9d420fd479a0 [file] [log] [blame]
// Copyright 2014 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <string>
#include <base/callback_forward.h>
namespace trunks {
// CommandTransceiver is an interface that sends commands to a TPM device and
// receives responses. It can operate synchronously or asynchronously.
class CommandTransceiver {
typedef base::Callback<void(const std::string& response)> ResponseCallback;
virtual ~CommandTransceiver() {}
// Sends a TPM |command| asynchronously. When a |response| is received,
// |callback| will be called with the |response| data from the TPM. If a
// transmission error occurs |callback| will be called with a well-formed
// error |response|.
virtual void SendCommand(
const std::string& command,
const ResponseCallback& callback) = 0;
// Sends a TPM |command| synchronously (i.e. waits for a response) and returns
// the response. If a transmission error occurs the response will be populated
// with a well-formed error response.
virtual std::string SendCommandAndWait(const std::string& command) = 0;
// Initializes the actual interface, replaced by the derived classes, where
// needed.
virtual bool Init() { return true; }
} // namespace trunks