// // Copyright (C) 2016 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 TRUNKS_TRUNKS_DBUS_SERVICE_H_ #define TRUNKS_TRUNKS_DBUS_SERVICE_H_ #include #include #include #include #include #include #include "trunks/command_transceiver.h" #include "trunks/interface.pb.h" namespace trunks { // TrunksDBusService registers for and handles all incoming D-Bus messages for // the trunksd system daemon. // // Example Usage: // // TrunksDBusService service; // service.set_transceiver(&my_transceiver); // service.Run(); class TrunksDBusService : public brillo::DBusServiceDaemon { public: TrunksDBusService(); ~TrunksDBusService() override = default; // The |transceiver| will be the target of all incoming TPM commands. This // class does not take ownership of |transceiver|. void set_transceiver(CommandTransceiver* transceiver) { transceiver_ = transceiver; } protected: // Exports D-Bus methods. void RegisterDBusObjectsAsync( brillo::dbus_utils::AsyncEventSequencer* sequencer) override; private: // Handles calls to the 'SendCommand' method. void HandleSendCommand(std::unique_ptr> response_sender, const SendCommandRequest& request); base::WeakPtr GetWeakPtr() { return weak_factory_.GetWeakPtr(); } std::unique_ptr trunks_dbus_object_; CommandTransceiver* transceiver_ = nullptr; // Declared last so weak pointers are invalidated first on destruction. base::WeakPtrFactory weak_factory_{this}; DISALLOW_COPY_AND_ASSIGN(TrunksDBusService); }; } // namespace trunks #endif // TRUNKS_TRUNKS_DBUS_SERVICE_H_