Andrew Moylan | ff6be51 | 2018-07-03 11:05:01 +1000 | [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_MACHINE_LEARNING_SERVICE_IMPL_H_ |
| 6 | #define ML_MACHINE_LEARNING_SERVICE_IMPL_H_ |
| 7 | |
Michael Martis | a74af93 | 2018-08-13 16:52:36 +1000 | [diff] [blame^] | 8 | #include <map> |
| 9 | #include <string> |
| 10 | |
Andrew Moylan | ff6be51 | 2018-07-03 11:05:01 +1000 | [diff] [blame] | 11 | #include <base/callback_forward.h> |
| 12 | #include <base/macros.h> |
| 13 | #include <mojo/public/cpp/bindings/binding.h> |
| 14 | |
Michael Martis | a74af93 | 2018-08-13 16:52:36 +1000 | [diff] [blame^] | 15 | #include "ml/model_metadata.h" |
Andrew Moylan | ff6be51 | 2018-07-03 11:05:01 +1000 | [diff] [blame] | 16 | #include "mojom/machine_learning_service.mojom.h" |
| 17 | |
| 18 | namespace ml { |
| 19 | |
| 20 | class MachineLearningServiceImpl |
| 21 | : public chromeos::machine_learning::mojom::MachineLearningService { |
| 22 | public: |
| 23 | // Creates an instance bound to |pipe|. The specified |
| 24 | // |connection_error_handler| will be invoked if the binding encounters a |
| 25 | // connection error. |
| 26 | MachineLearningServiceImpl(mojo::ScopedMessagePipeHandle pipe, |
| 27 | base::Closure connection_error_handler); |
| 28 | |
Michael Martis | a74af93 | 2018-08-13 16:52:36 +1000 | [diff] [blame^] | 29 | protected: |
| 30 | // Testing constructor that allows overriding of the model dir. Should not be |
| 31 | // used outside of tests. |
| 32 | MachineLearningServiceImpl(mojo::ScopedMessagePipeHandle pipe, |
| 33 | base::Closure connection_error_handler, |
| 34 | const std::string& model_dir); |
| 35 | |
Andrew Moylan | ff6be51 | 2018-07-03 11:05:01 +1000 | [diff] [blame] | 36 | private: |
| 37 | // chromeos::machine_learning::mojom::MachineLearningService: |
Michael Martis | a74af93 | 2018-08-13 16:52:36 +1000 | [diff] [blame^] | 38 | void LoadModel(chromeos::machine_learning::mojom::ModelSpecPtr spec, |
| 39 | chromeos::machine_learning::mojom::ModelRequest request, |
| 40 | const LoadModelCallback& callback) override; |
| 41 | |
| 42 | // Metadata required to load models. Initialized at construction. |
| 43 | const std::map<chromeos::machine_learning::mojom::ModelId, ModelMetadata> |
| 44 | model_metadata_; |
| 45 | const std::string model_dir_; |
Andrew Moylan | ff6be51 | 2018-07-03 11:05:01 +1000 | [diff] [blame] | 46 | |
| 47 | mojo::Binding<chromeos::machine_learning::mojom::MachineLearningService> |
| 48 | binding_; |
| 49 | |
| 50 | DISALLOW_COPY_AND_ASSIGN(MachineLearningServiceImpl); |
| 51 | }; |
| 52 | |
| 53 | } // namespace ml |
| 54 | |
| 55 | #endif // ML_MACHINE_LEARNING_SERVICE_IMPL_H_ |