1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef N_NAPI_PASTEBOARD_COMMON_H
16 #define N_NAPI_PASTEBOARD_COMMON_H
17 
18 #include <string>
19 
20 #include "napi/native_api.h"
21 #include "napi/native_node_api.h"
22 #include "napi_common_want.h"
23 #include "paste_data_record.h"
24 #include "pasteboard_js_err.h"
25 #include "pasteboard_pattern.h"
26 #include "pixel_map_napi.h"
27 #include "tlv_object.h"
28 #include "napi_data_utils.h"
29 namespace OHOS {
30 namespace MiscServicesNapi {
31 napi_value GetCallbackErrorValue(napi_env env, int32_t errorCode);
32 void SetCallback(const napi_env &env, const napi_ref &callbackIn, const napi_value *result);
33 napi_value NapiGetNull(napi_env env);
34 napi_value CreateNapiNumber(napi_env env, int32_t num);
35 napi_value CreateNapiString(napi_env env, std::string str);
36 bool GetValue(napi_env env, napi_value in, std::string &out);
37 bool GetValue(napi_env env, napi_value in, std::set<MiscServices::Pattern> &out);
38 napi_status SetValue(napi_env env, std::set<MiscServices::Pattern> &in, napi_value &result);
39 napi_status SetValue(napi_env env, const std::vector<std::string> &in, napi_value &out);
40 bool CheckArgsType(napi_env env, napi_value in, napi_valuetype expectedType, const char *message);
41 bool CheckExpression(napi_env env, bool expression, MiscServices::JSErrorCode errCode, const char *message);
42 bool CheckArgs(napi_env env, napi_value *argv, size_t argc, std::string &mimeType);
43 bool CheckArgsMimeType(napi_env env, napi_value in, std::string &mimeType);
44 bool CheckArgsArray(napi_env env, napi_value in, std::vector<std::string> &mimeTypes);
45 bool CheckArgsFunc(napi_env env, napi_value in, napi_ref &provider);
46 bool CheckArgsVector(napi_env env, napi_value in,
47     std::shared_ptr<std::vector<std::pair<std::string, std::shared_ptr<MiscServices::EntryValue>>>> result);
48 napi_status ConvertEntryValue(napi_env env, napi_value *result, std::string &udtType,
49     std::shared_ptr<MiscServices::PasteDataEntry> value);
50 bool GetNativeValue(napi_env env, std::string type, napi_value valueNapi, MiscServices::EntryValue &value);
51 } // namespace MiscServicesNapi
52 } // namespace OHOS
53 #endif