• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "paste_data_record.h"
19 #include "pasteboard_js_err.h"
20 #include "systempasteboard_napi.h"
21 #include "napi_data_utils.h"
22 namespace OHOS {
23 namespace MiscServicesNapi {
24 napi_value GetCallbackErrorValue(napi_env env, int32_t errorCode);
25 void SetCallback(const napi_env &env, const napi_ref &callbackIn, const napi_value *result);
26 napi_value NapiGetNull(napi_env env);
27 napi_value CreateNapiNumber(napi_env env, int32_t num);
28 napi_value CreateNapiString(napi_env env, std::string str);
29 bool GetValue(napi_env env, napi_value in, std::string &out);
30 bool GetValue(napi_env env, napi_value in, std::set<MiscServices::Pattern> &out);
31 napi_status SetValue(napi_env env, std::set<MiscServices::Pattern> &in, napi_value &result);
32 bool CheckArgsType(napi_env env, napi_value in, napi_valuetype expectedType, const char *message);
33 bool CheckExpression(napi_env env, bool expression, MiscServices::JSErrorCode errCode, const char *message);
34 bool CheckArgs(napi_env env, napi_value *argv, size_t argc, std::string &mimeType);
35 bool CheckArgsMimeType(napi_env env, napi_value in, std::string &mimeType);
36 bool CheckArgsArray(napi_env env, napi_value in, std::vector<std::string> &mimeTypes);
37 bool CheckArgsFunc(napi_env env, napi_value in, napi_ref &provider);
38 bool CheckArgsVector(napi_env env, napi_value in,
39     std::shared_ptr<std::vector<std::pair<std::string, std::shared_ptr<MiscServices::EntryValue>>>> result);
40 bool CheckRetCode(napi_env env, int32_t retCode, const std::vector<MiscServices::JSErrorCode> &focusErrCodes);
41 bool GetContextSetErr(const std::shared_ptr<GetContextInfo> context, int32_t retCode,
42     const std::vector<MiscServices::JSErrorCode> &focusErrCodes, std::string defaultMsg = "");
43 bool UnifiedContextSetErr(const std::shared_ptr<GetUnifiedContextInfo> context, int32_t retCode,
44     const std::vector<MiscServices::JSErrorCode> &focusErrCodes, std::string defaultMsg = "");
45 napi_status ConvertEntryValue(napi_env env, napi_value *result, std::string &udtType,
46     std::shared_ptr<MiscServices::PasteDataEntry> value);
47 bool GetNativeValue(napi_env env, const std::string &type, napi_value valueNapi, MiscServices::EntryValue &value);
48 } // namespace MiscServicesNapi
49 } // namespace OHOS
50 #endif