blob: e812b1f8ee82b0354d458390608759d42a9f7ff3 [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>
Andrew Moylanb481af72020-07-09 15:22:00 +100010#include <mojo/public/cpp/bindings/pending_receiver.h>
11#include <mojo/public/cpp/bindings/receiver.h>
charleszhao17777f92020-04-23 12:53:11 +100012
Honglin Yucfb19302020-08-17 17:13:14 +100013#include "chrome/knowledge/handwriting/handwriting_interface.pb.h"
charleszhao17777f92020-04-23 12:53:11 +100014#include "ml/handwriting.h"
15#include "ml/mojom/handwriting_recognizer.mojom.h"
16
17namespace ml {
18
19// The implementation of HandwritingRecognizer.
20class HandwritingRecognizerImpl
21 : public chromeos::machine_learning::mojom::HandwritingRecognizer {
22 public:
Andrew Moylanb481af72020-07-09 15:22:00 +100023 // Constructs a HandwritingRecognizerImpl; and set disconnect handler so
charleszhao17777f92020-04-23 12:53:11 +100024 // that the HandwritingRecognizerImpl will be deleted when the mojom
25 // connection is destroyed.
26 // Returns whether the object is create successfully.
27 static bool Create(
charleszhao05c5a4a2020-06-09 16:49:54 +100028 chromeos::machine_learning::mojom::HandwritingRecognizerSpecPtr spec,
Andrew Moylanb481af72020-07-09 15:22:00 +100029 mojo::PendingReceiver<
30 chromeos::machine_learning::mojom::HandwritingRecognizer> receiver);
charleszhao17777f92020-04-23 12:53:11 +100031
32 // Called when mojom connection is destroyed.
33 ~HandwritingRecognizerImpl();
34
35 private:
Andrew Moylanb481af72020-07-09 15:22:00 +100036 // Creates a HandwritingRecognizer and Binds to `receiver` inside so that
charleszhao17777f92020-04-23 12:53:11 +100037 // Recognize can be called on the other side for a particular handwriting
38 // reconition query.
39 HandwritingRecognizerImpl(
charleszhao05c5a4a2020-06-09 16:49:54 +100040 chromeos::machine_learning::mojom::HandwritingRecognizerSpecPtr spec,
Andrew Moylanb481af72020-07-09 15:22:00 +100041 mojo::PendingReceiver<
42 chromeos::machine_learning::mojom::HandwritingRecognizer> receiver);
charleszhao17777f92020-04-23 12:53:11 +100043
44 // mojom::HandwritingRecognizer:
45 void Recognize(
46 chromeos::machine_learning::mojom::HandwritingRecognitionQueryPtr query,
47 RecognizeCallback callback) override;
48
49 bool successfully_loaded_;
50 // Pointer to the internal implementation of HandwritingRecognizer inside
51 // the HandwritingLibrary.
52 ::HandwritingRecognizer recognizer_;
Charles Zhaoc882eb02020-07-27 10:02:35 +100053 const ml::HandwritingLibrary* const library_;
charleszhao17777f92020-04-23 12:53:11 +100054
Andrew Moylanb481af72020-07-09 15:22:00 +100055 mojo::Receiver<chromeos::machine_learning::mojom::HandwritingRecognizer>
56 receiver_;
charleszhao17777f92020-04-23 12:53:11 +100057
58 DISALLOW_COPY_AND_ASSIGN(HandwritingRecognizerImpl);
59};
60
61} // namespace ml
62
63#endif // ML_HANDWRITING_RECOGNIZER_IMPL_H_