blob: 52252f7f36d29d48d459240e17eea8e7eda534e7 [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(
27 chromeos::machine_learning::mojom::HandwritingRecognizerRequest request);
28
29 // Called when mojom connection is destroyed.
30 ~HandwritingRecognizerImpl();
31
32 private:
33 // Creates a HandwritingRecognizer and Binds to |request| inside so that
34 // Recognize can be called on the other side for a particular handwriting
35 // reconition query.
36 HandwritingRecognizerImpl(
37 chromeos::machine_learning::mojom::HandwritingRecognizerRequest request);
38
39 // mojom::HandwritingRecognizer:
40 void Recognize(
41 chromeos::machine_learning::mojom::HandwritingRecognitionQueryPtr query,
42 RecognizeCallback callback) override;
43
44 bool successfully_loaded_;
45 // Pointer to the internal implementation of HandwritingRecognizer inside
46 // the HandwritingLibrary.
47 ::HandwritingRecognizer recognizer_;
48
49 mojo::Binding<chromeos::machine_learning::mojom::HandwritingRecognizer>
50 binding_;
51
52 DISALLOW_COPY_AND_ASSIGN(HandwritingRecognizerImpl);
53};
54
55} // namespace ml
56
57#endif // ML_HANDWRITING_RECOGNIZER_IMPL_H_