// // Copyright (C) 2015 The Android Open Source Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #ifndef TPM_MANAGER_SERVER_DBUS_SERVICE_H_ #define TPM_MANAGER_SERVER_DBUS_SERVICE_H_ #include #include #include #include #include #include "tpm_manager/common/tpm_nvram_interface.h" #include "tpm_manager/common/tpm_ownership_interface.h" namespace tpm_manager { using brillo::dbus_utils::DBusMethodResponse; // Handles D-Bus communication with the TpmManager daemon. class DBusService : public brillo::DBusServiceDaemon { public: // Does not take ownership of |nvram_service| or |ownership_service|. The // services provided must be initialized, and must remain valid for the // lifetime of this instance. DBusService(TpmNvramInterface* nvram_service, TpmOwnershipInterface* ownership_service); // Used to inject a mock bus. DBusService(scoped_refptr bus, TpmNvramInterface* nvram_service, TpmOwnershipInterface* ownership_service); virtual ~DBusService() = default; // Registers objects exported by this service. void RegisterDBusObjectsAsync( brillo::dbus_utils::AsyncEventSequencer* sequencer) override; private: friend class DBusServiceTest; template using HandlerFunction = void (TpmInterface::*)( const RequestProtobufType&, const base::Callback&); // Templates to handle D-Bus calls. template func> void HandleNvramDBusMethod( std::unique_ptr> response, const RequestProtobufType& request); template func> void HandleOwnershipDBusMethod( std::unique_ptr> response, const RequestProtobufType& request); std::unique_ptr dbus_object_; TpmNvramInterface* nvram_service_; TpmOwnershipInterface* ownership_service_; DISALLOW_COPY_AND_ASSIGN(DBusService); }; } // namespace tpm_manager #endif // TPM_MANAGER_SERVER_DBUS_SERVICE_H_