blob: 2df34f2b82ae41bc7092c9d4850e528b316a479c [file] [log] [blame]
Ken Turneredb93932018-02-14 05:27:31 +11001// 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 ML_DAEMON_H_
6#define ML_DAEMON_H_
7
Andrew Moylanff6be512018-07-03 11:05:01 +10008#include <memory>
9
Andrew Moylanef116f92018-04-11 15:12:38 +100010#include <brillo/daemons/dbus_daemon.h>
Ken Turneredb93932018-02-14 05:27:31 +110011#include <dbus/exported_object.h>
12
Andrew Moylanff6be512018-07-03 11:05:01 +100013#include "mojom/machine_learning_service.mojom.h"
14
Ken Turneredb93932018-02-14 05:27:31 +110015namespace dbus {
16class MethodCall;
17} // namespace dbus
18
19namespace ml {
20
Andrew Moylanef116f92018-04-11 15:12:38 +100021class Daemon : public brillo::DBusDaemon {
Ken Turneredb93932018-02-14 05:27:31 +110022 public:
23 Daemon();
24 ~Daemon() override;
25
26 protected:
Andrew Moylanff6be512018-07-03 11:05:01 +100027 // brillo::DBusDaemon:
Ken Turneredb93932018-02-14 05:27:31 +110028 int OnInit() override;
29
30 private:
31 // This function initializes the D-Bus service. The primary function of the
32 // D-Bus interface is to receive a FD from the Chrome process so that we can
33 // bootstrap a Mojo IPC channel. Since we should expect requests for client
34 // registration to occur as soon as the D-Bus channel is up, this
35 // initialization should be the last thing that happens in Daemon::OnInit().
36 void InitDBus();
37
Andrew Moylanef116f92018-04-11 15:12:38 +100038 // Handles org.chromium.BootstrapMojoConnection D-Bus method calls.
Ken Turneredb93932018-02-14 05:27:31 +110039 void BootstrapMojoConnection(
40 dbus::MethodCall* method_call,
41 dbus::ExportedObject::ResponseSender response_sender);
42
Andrew Moylanff6be512018-07-03 11:05:01 +100043 // Responds to Mojo connection errors by quitting the daemon.
44 void OnConnectionError();
45
46 // The top-level interface. Empty until it is created & bound to a pipe by
47 // BootstrapMojoConnection.
48 std::unique_ptr<chromeos::machine_learning::mojom::MachineLearningService>
49 machine_learning_service_;
50
Andrew Moylanef116f92018-04-11 15:12:38 +100051 // Must be last class member.
52 base::WeakPtrFactory<Daemon> weak_ptr_factory_;
Ken Turneredb93932018-02-14 05:27:31 +110053};
54
55} // namespace ml
56
57#endif // ML_DAEMON_H_