1 // 2 // Copyright (C) 2015 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 TPM_MANAGER_CLIENT_TPM_OWNERSHIP_DBUS_PROXY_H_ 18 #define TPM_MANAGER_CLIENT_TPM_OWNERSHIP_DBUS_PROXY_H_ 19 20 #include "tpm_manager/common/tpm_ownership_interface.h" 21 22 #include <string> 23 24 #include <base/macros.h> 25 #include <base/memory/ref_counted.h> 26 #include <dbus/bus.h> 27 #include <dbus/object_proxy.h> 28 29 #include "tpm_manager/common/export.h" 30 31 namespace tpm_manager { 32 33 // An implementation of TpmOwnershipInterface that forwards requests to 34 // tpm_managerd over D-Bus. 35 // Usage: 36 // std::unique_ptr<TpmOwnershipInterface> tpm_ = new TpmOwnershipDBusProxy(); 37 // tpm_->GetTpmStatus(...); 38 class TPM_MANAGER_EXPORT TpmOwnershipDBusProxy : public TpmOwnershipInterface { 39 public: 40 TpmOwnershipDBusProxy() = default; 41 virtual ~TpmOwnershipDBusProxy(); 42 43 // Performs initialization tasks. This method must be called before calling 44 // any other method in this class. Returns true on success. 45 bool Initialize(); 46 47 // TpmOwnershipInterface methods. 48 void GetTpmStatus(const GetTpmStatusRequest& request, 49 const GetTpmStatusCallback& callback) override; 50 void TakeOwnership(const TakeOwnershipRequest& request, 51 const TakeOwnershipCallback& callback) override; 52 void RemoveOwnerDependency( 53 const RemoveOwnerDependencyRequest& request, 54 const RemoveOwnerDependencyCallback& callback) override; 55 set_object_proxy(dbus::ObjectProxy * object_proxy)56 void set_object_proxy(dbus::ObjectProxy* object_proxy) { 57 object_proxy_ = object_proxy; 58 } 59 60 private: 61 // Template method to call a given |method_name| remotely via dbus. 62 template <typename ReplyProtobufType, 63 typename RequestProtobufType, 64 typename CallbackType> 65 void CallMethod(const std::string& method_name, 66 const RequestProtobufType& request, 67 const CallbackType& callback); 68 69 scoped_refptr<dbus::Bus> bus_; 70 dbus::ObjectProxy* object_proxy_; 71 DISALLOW_COPY_AND_ASSIGN(TpmOwnershipDBusProxy); 72 }; 73 74 } // namespace tpm_manager 75 76 #endif // TPM_MANAGER_CLIENT_TPM_OWNERSHIP_DBUS_PROXY_H_ 77