blob: e993d0af9ab7e33f3644e2bd9eac177eb2fd20d0 [file] [log] [blame]
charleszhao17777f92020-04-23 12:53:11 +10001// Copyright 2020 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_HANDWRITING_RECOGNIZER_IMPL_H_
6#define ML_HANDWRITING_RECOGNIZER_IMPL_H_
7
8#include <base/callback_forward.h>
9#include <base/macros.h>
10#include <mojo/public/cpp/bindings/binding.h>
11
12#include "chrome/knowledge/handwriting/interface.pb.h"
13#include "ml/handwriting.h"
14#include "ml/mojom/handwriting_recognizer.mojom.h"
15
16namespace ml {
17
18// The implementation of HandwritingRecognizer.
19class HandwritingRecognizerImpl
20 : public chromeos::machine_learning::mojom::HandwritingRecognizer {
21 public:
22 // Constructs a HandwritingRecognizerImpl; and set_connection_error_handler so
23 // that the HandwritingRecognizerImpl will be deleted when the mojom
24 // connection is destroyed.
25 // Returns whether the object is create successfully.
26 static bool Create(
charleszhao05c5a4a2020-06-09 16:49:54 +100027 chromeos::machine_learning::mojom::HandwritingRecognizerSpecPtr spec,
charleszhao17777f92020-04-23 12:53:11 +100028 chromeos::machine_learning::mojom::HandwritingRecognizerRequest request);
29
30 // Called when mojom connection is destroyed.
31 ~HandwritingRecognizerImpl();
32
33 private:
Andrew Moylan79b34a42020-07-08 11:13:11 +100034 // Creates a HandwritingRecognizer and Binds to `request` inside so that
charleszhao17777f92020-04-23 12:53:11 +100035 // Recognize can be called on the other side for a particular handwriting
36 // reconition query.
37 HandwritingRecognizerImpl(
charleszhao05c5a4a2020-06-09 16:49:54 +100038 chromeos::machine_learning::mojom::HandwritingRecognizerSpecPtr spec,
charleszhao17777f92020-04-23 12:53:11 +100039 chromeos::machine_learning::mojom::HandwritingRecognizerRequest request);
40
41 // mojom::HandwritingRecognizer:
42 void Recognize(
43 chromeos::machine_learning::mojom::HandwritingRecognitionQueryPtr query,
44 RecognizeCallback callback) override;
45
46 bool successfully_loaded_;
47 // Pointer to the internal implementation of HandwritingRecognizer inside
48 // the HandwritingLibrary.
49 ::HandwritingRecognizer recognizer_;
50
51 mojo::Binding<chromeos::machine_learning::mojom::HandwritingRecognizer>
52 binding_;
53
54 DISALLOW_COPY_AND_ASSIGN(HandwritingRecognizerImpl);
55};
56
57} // namespace ml
58
59#endif // ML_HANDWRITING_RECOGNIZER_IMPL_H_