blob: 9b188b01d9e5477c74060cc3c50e3b9c49f19205 [file] [log] [blame]
Andrew Moylanff6be512018-07-03 11:05:01 +10001// 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 Martisa74af932018-08-13 16:52:36 +10008#include <map>
9#include <string>
10
Andrew Moylanff6be512018-07-03 11:05:01 +100011#include <base/callback_forward.h>
12#include <base/macros.h>
13#include <mojo/public/cpp/bindings/binding.h>
14
Michael Martisa74af932018-08-13 16:52:36 +100015#include "ml/model_metadata.h"
Andrew Moylanff6be512018-07-03 11:05:01 +100016#include "mojom/machine_learning_service.mojom.h"
17
18namespace ml {
19
20class 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 Martisa74af932018-08-13 16:52:36 +100029 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 Moylanff6be512018-07-03 11:05:01 +100036 private:
37 // chromeos::machine_learning::mojom::MachineLearningService:
Michael Martisa74af932018-08-13 16:52:36 +100038 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 Moylanff6be512018-07-03 11:05:01 +100046
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_