blob: a6916849c85452d73221940616e572413c33ec10 [file] [log] [blame]
Chun-Ta Linb6b59b52018-11-08 10:13:57 +08001// 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
13namespace dbus {
14class MethodCall;
15} // namespace dbus
16
17namespace runtime_probe {
18
19class Daemon : public brillo::DBusDaemon {
20 public:
21 Daemon();
22 ~Daemon() override;
Chun-Ta Linb6b59b52018-11-08 10:13:57 +080023
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 Lin66adcf82021-03-30 21:36:27 +080035 void SendMessage(const google::protobuf::Message& reply,
36 dbus::MethodCall* method_call,
37 dbus::ExportedObject::ResponseSender response_sender);
Chun-Ta Linb6b59b52018-11-08 10:13:57 +080038
Kevin Lin66adcf82021-03-30 21:36:27 +080039 // Handler of org.chromium.RuntimeProbe.ProbeCategories method calls.
Hong-Min Chu9caafda2018-11-27 16:51:52 +080040 void ProbeCategories(dbus::MethodCall* method_call,
41 dbus::ExportedObject::ResponseSender response_sender);
Chun-Ta Linb6b59b52018-11-08 10:13:57 +080042
Kevin Lin66adcf82021-03-30 21:36:27 +080043 // 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 Line6c61b42018-11-26 14:22:29 +080048 // 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 Linb6b59b52018-11-08 10:13:57 +080057 // 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_