blob: d7218a2960e0c77d0f23cdaf75b06169d7fcb803 [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>
alanlxlcb1f8562018-11-01 15:16:11 +11009#include <memory>
Michael Martisa74af932018-08-13 16:52:36 +100010#include <string>
11
Andrew Moylanff6be512018-07-03 11:05:01 +100012#include <base/callback_forward.h>
13#include <base/macros.h>
14#include <mojo/public/cpp/bindings/binding.h>
15
Michael Martisa74af932018-08-13 16:52:36 +100016#include "ml/model_metadata.h"
Hidehiko Abeaa488c32018-08-31 23:49:41 +090017#include "ml/mojom/machine_learning_service.mojom.h"
Andrew Moylanff6be512018-07-03 11:05:01 +100018
19namespace ml {
20
21class MachineLearningServiceImpl
22 : public chromeos::machine_learning::mojom::MachineLearningService {
23 public:
24 // Creates an instance bound to |pipe|. The specified
25 // |connection_error_handler| will be invoked if the binding encounters a
26 // connection error.
27 MachineLearningServiceImpl(mojo::ScopedMessagePipeHandle pipe,
28 base::Closure connection_error_handler);
29
Michael Martisa74af932018-08-13 16:52:36 +100030 protected:
31 // Testing constructor that allows overriding of the model dir. Should not be
32 // used outside of tests.
33 MachineLearningServiceImpl(mojo::ScopedMessagePipeHandle pipe,
34 base::Closure connection_error_handler,
35 const std::string& model_dir);
36
Andrew Moylanff6be512018-07-03 11:05:01 +100037 private:
38 // chromeos::machine_learning::mojom::MachineLearningService:
Michael Martisa74af932018-08-13 16:52:36 +100039 void LoadModel(chromeos::machine_learning::mojom::ModelSpecPtr spec,
40 chromeos::machine_learning::mojom::ModelRequest request,
41 const LoadModelCallback& callback) override;
42
43 // Metadata required to load models. Initialized at construction.
44 const std::map<chromeos::machine_learning::mojom::ModelId, ModelMetadata>
45 model_metadata_;
46 const std::string model_dir_;
Andrew Moylanff6be512018-07-03 11:05:01 +100047
48 mojo::Binding<chromeos::machine_learning::mojom::MachineLearningService>
49 binding_;
50
51 DISALLOW_COPY_AND_ASSIGN(MachineLearningServiceImpl);
52};
53
54} // namespace ml
55
56#endif // ML_MACHINE_LEARNING_SERVICE_IMPL_H_