-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdaemon.h
66 lines (49 loc) · 1.85 KB
/
daemon.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2018 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ML_DAEMON_H_
#define ML_DAEMON_H_
#include <memory>
#include <base/memory/weak_ptr.h>
#include <brillo/daemons/dbus_daemon.h>
#include <dbus/exported_object.h>
#include <mojo/core/embedder/scoped_ipc_support.h>
#include "ml/metrics.h"
#include "ml/mojom/machine_learning_service.mojom.h"
namespace dbus {
class MethodCall;
} // namespace dbus
namespace ml {
class Daemon : public brillo::DBusDaemon {
public:
Daemon();
~Daemon() override;
protected:
// brillo::DBusDaemon:
int OnInit() override;
private:
// This function initializes the D-Bus service. The primary function of the
// D-Bus interface is to receive a FD from the Chrome process so that we can
// bootstrap a Mojo IPC channel. Since we should expect requests for client
// registration to occur as soon as the D-Bus channel is up, this
// initialization should be the last thing that happens in Daemon::OnInit().
void InitDBus();
// Handles org.chromium.BootstrapMojoConnection D-Bus method calls.
void BootstrapMojoConnection(
dbus::MethodCall* method_call,
dbus::ExportedObject::ResponseSender response_sender);
// Responds to Mojo disconnection by quitting the daemon.
void OnMojoDisconnection();
// IPC Support
std::unique_ptr<mojo::core::ScopedIPCSupport> ipc_support_;
// The top-level interface. Empty until it is created & bound to a pipe by
// BootstrapMojoConnection.
std::unique_ptr<chromeos::machine_learning::mojom::MachineLearningService>
machine_learning_service_;
// For periodic and on-demand UMA metrics logging.
Metrics metrics_;
// Must be last class member.
base::WeakPtrFactory<Daemon> weak_ptr_factory_;
};
} // namespace ml
#endif // ML_DAEMON_H_