Chun-Ta Lin | b6b59b5 | 2018-11-08 10:13:57 +0800 | [diff] [blame] | 1 | // Copyright 2018 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef RUNTIME_PROBE_DAEMON_H_ |
| 6 | #define RUNTIME_PROBE_DAEMON_H_ |
| 7 | |
| 8 | #include <brillo/daemons/dbus_daemon.h> |
| 9 | #include <dbus/exported_object.h> |
| 10 | |
| 11 | #include "runtime_probe/proto_bindings/runtime_probe.pb.h" |
| 12 | |
| 13 | namespace dbus { |
| 14 | class MethodCall; |
| 15 | } // namespace dbus |
| 16 | |
| 17 | namespace runtime_probe { |
| 18 | |
| 19 | class Daemon : public brillo::DBusDaemon { |
| 20 | public: |
| 21 | Daemon(); |
| 22 | ~Daemon() override; |
Chun-Ta Lin | b6b59b5 | 2018-11-08 10:13:57 +0800 | [diff] [blame] | 23 | |
| 24 | protected: |
| 25 | // brillo::DBusDaemon: |
| 26 | int OnInit() override; |
| 27 | |
| 28 | private: |
| 29 | // This function initializes the D-Bus service. Since we expect requests |
| 30 | // from client occurs as soon as the D-Bus channel is up, this |
| 31 | // initialization should be the last thing that happens in Daemon::OnInit(). |
| 32 | void InitDBus(); |
| 33 | |
| 34 | // Sugar wrapper for packing protocol buffer with error handling. |
Kevin Lin | 66adcf8 | 2021-03-30 21:36:27 +0800 | [diff] [blame] | 35 | void SendMessage(const google::protobuf::Message& reply, |
| 36 | dbus::MethodCall* method_call, |
| 37 | dbus::ExportedObject::ResponseSender response_sender); |
Chun-Ta Lin | b6b59b5 | 2018-11-08 10:13:57 +0800 | [diff] [blame] | 38 | |
Kevin Lin | 66adcf8 | 2021-03-30 21:36:27 +0800 | [diff] [blame] | 39 | // Handler of org.chromium.RuntimeProbe.ProbeCategories method calls. |
Hong-Min Chu | 9caafda | 2018-11-27 16:51:52 +0800 | [diff] [blame] | 40 | void ProbeCategories(dbus::MethodCall* method_call, |
| 41 | dbus::ExportedObject::ResponseSender response_sender); |
Chun-Ta Lin | b6b59b5 | 2018-11-08 10:13:57 +0800 | [diff] [blame] | 42 | |
Kevin Lin | 66adcf8 | 2021-03-30 21:36:27 +0800 | [diff] [blame] | 43 | // Handler of org.chromium.RuntimeProbe.GetKnownComponents method calls. |
| 44 | // Get known components from probe config. |
| 45 | void GetKnownComponents(dbus::MethodCall* method_call, |
| 46 | dbus::ExportedObject::ResponseSender response_sender); |
| 47 | |
Chun-Ta Lin | e6c61b4 | 2018-11-26 14:22:29 +0800 | [diff] [blame] | 48 | // Schedule an asynchronous D-Bus shutdown and exit the daemon. |
| 49 | void PostQuitTask(); |
| 50 | |
| 51 | // Underlying function that performs D-Bus shutdown. This QuitDaemonInternal() |
| 52 | // is *not* expected to be invoked while we're still processing the method |
| 53 | // call, because it will create racing on variable |bus_| (i.e.: freed before |
| 54 | // other usage depends on it.) |
| 55 | void QuitDaemonInternal(); |
| 56 | |
Chun-Ta Lin | b6b59b5 | 2018-11-08 10:13:57 +0800 | [diff] [blame] | 57 | // Because members are destructed in reverse-order that they appear in the |
| 58 | // class definition. Member variables should appear before the WeakPtrFactory, |
| 59 | // to ensure hat any WeakPtrs are invalidated before its members variable's |
| 60 | // destructors are executed, making them invalid. |
| 61 | base::WeakPtrFactory<Daemon> weak_ptr_factory_{this}; |
| 62 | }; |
| 63 | |
| 64 | } // namespace runtime_probe |
| 65 | #endif // RUNTIME_PROBE_DAEMON_H_ |