Ken Turner | edb9393 | 2018-02-14 05:27:31 +1100 | [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 ML_DAEMON_H_ |
| 6 | #define ML_DAEMON_H_ |
| 7 | |
Andrew Moylan | ff6be51 | 2018-07-03 11:05:01 +1000 | [diff] [blame^] | 8 | #include <memory> |
| 9 | |
Andrew Moylan | ef116f9 | 2018-04-11 15:12:38 +1000 | [diff] [blame] | 10 | #include <brillo/daemons/dbus_daemon.h> |
Ken Turner | edb9393 | 2018-02-14 05:27:31 +1100 | [diff] [blame] | 11 | #include <dbus/exported_object.h> |
| 12 | |
Andrew Moylan | ff6be51 | 2018-07-03 11:05:01 +1000 | [diff] [blame^] | 13 | #include "mojom/machine_learning_service.mojom.h" |
| 14 | |
Ken Turner | edb9393 | 2018-02-14 05:27:31 +1100 | [diff] [blame] | 15 | namespace dbus { |
| 16 | class MethodCall; |
| 17 | } // namespace dbus |
| 18 | |
| 19 | namespace ml { |
| 20 | |
Andrew Moylan | ef116f9 | 2018-04-11 15:12:38 +1000 | [diff] [blame] | 21 | class Daemon : public brillo::DBusDaemon { |
Ken Turner | edb9393 | 2018-02-14 05:27:31 +1100 | [diff] [blame] | 22 | public: |
| 23 | Daemon(); |
| 24 | ~Daemon() override; |
| 25 | |
| 26 | protected: |
Andrew Moylan | ff6be51 | 2018-07-03 11:05:01 +1000 | [diff] [blame^] | 27 | // brillo::DBusDaemon: |
Ken Turner | edb9393 | 2018-02-14 05:27:31 +1100 | [diff] [blame] | 28 | 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 Moylan | ef116f9 | 2018-04-11 15:12:38 +1000 | [diff] [blame] | 38 | // Handles org.chromium.BootstrapMojoConnection D-Bus method calls. |
Ken Turner | edb9393 | 2018-02-14 05:27:31 +1100 | [diff] [blame] | 39 | void BootstrapMojoConnection( |
| 40 | dbus::MethodCall* method_call, |
| 41 | dbus::ExportedObject::ResponseSender response_sender); |
| 42 | |
Andrew Moylan | ff6be51 | 2018-07-03 11:05:01 +1000 | [diff] [blame^] | 43 | // 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 Moylan | ef116f9 | 2018-04-11 15:12:38 +1000 | [diff] [blame] | 51 | // Must be last class member. |
| 52 | base::WeakPtrFactory<Daemon> weak_ptr_factory_; |
Ken Turner | edb9393 | 2018-02-14 05:27:31 +1100 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | } // namespace ml |
| 56 | |
| 57 | #endif // ML_DAEMON_H_ |