• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef PINYINIME_INCLUDE_SYNC_H__
18 #define PINYINIME_INCLUDE_SYNC_H__
19 
20 #define ___SYNC_ENABLED___
21 
22 #ifdef ___SYNC_ENABLED___
23 
24 #include "userdict.h"
25 
26 namespace ime_pinyin {
27 
28 // Class for user dictionary synchronization
29 // This class is not thread safe
30 // Normal invoking flow will be
31 //   begin() ->
32 //   put_lemmas() x N ->
33 //   {
34 //     get_lemmas() ->
35 //     [ get_last_got_count() ] ->
36 //     clear_last_got() ->
37 //   } x N ->
38 //   finish()
39 class Sync {
40  public:
41   Sync();
42   ~Sync();
43 
44   static const int kUserDictMaxLemmaCount = 5000;
45   static const int kUserDictMaxLemmaSize = 200000;
46   static const int kUserDictRatio = 20;
47 
48   bool begin(const char * filename);
49 
50   // Merge lemmas downloaded from sync server into local dictionary
51   // lemmas, lemmas string encoded in UTF16LE
52   // len, length of lemmas string
53   // Return how many lemmas merged successfully
54   int put_lemmas(char16 * lemmas, int len);
55 
56   // Get local new user lemmas into UTF16LE string
57   // str, buffer ptr to store new user lemmas
58   // size, size of buffer
59   // Return length of returned buffer in measure of UTF16LE
60   int get_lemmas(char16 * str, int size);
61 
62   // Return lemmas count in last get_lemmas()
63   int get_last_got_count();
64 
65   // Return total lemmas count need get_lemmas()
66   int get_total_count();
67 
68   // Clear lemmas got by recent get_lemmas()
69   void clear_last_got();
70 
71   void finish();
72 
73   int get_capacity();
74 
75  private:
76   UserDict * userdict_;
77   char * dictfile_;
78   int last_count_;
79 };
80 
81 }
82 
83 #endif
84 
85 #endif  // PINYINIME_INCLUDE_SYNC_H__
86