1 /* 2 * Copyright (c) 2021-2023 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 16 #ifndef CONTACT_NAPI_COMMON_H 17 #define CONTACT_NAPI_COMMON_H 18 19 #include "datashare_predicates.h" 20 #include "datashare_helper.h" 21 #include "napi/native_api.h" 22 #include "napi/native_common.h" 23 #include "napi/native_node_api.h" 24 #include "rdb_helper.h" 25 #include "rdb_open_callback.h" 26 #include "rdb_predicates.h" 27 #include "rdb_store.h" 28 29 namespace OHOS { 30 namespace ContactsApi { 31 constexpr int MAX_PARAMS = 10; 32 constexpr int ERROR = -1; 33 constexpr int SUCCESS = 0; 34 constexpr int RESULT_DATA_SIZE = 2; 35 constexpr int RDB_PERMISSION_ERROR = -2; 36 constexpr int PERMISSION_ERROR = 201; 37 constexpr int PARAMETER_ERROR = 401; 38 39 constexpr int NAPI_GET_STRING_SIZE = 256; 40 constexpr int REQUEST_PARAMS_COUNT_ONE = 1; 41 42 // NAPI callback type 43 constexpr int NAPI_CALL_TYPE_CALLBACK = 0; 44 constexpr int NAPI_CALL_TYPE_PROMISE = 1; 45 46 // NAPI type 47 constexpr int TYPE_NAPI_ERROR = -1; 48 constexpr int TYPE_NAPI_NUMBER = 0; 49 constexpr int TYPE_NAPI_STRING = 1; 50 constexpr int TYPE_HOLDER = 2; 51 constexpr int TYPE_ATTR = 3; 52 constexpr int TYPE_CONTACT = 4; 53 54 // Execute action code 55 constexpr int ADD_CONTACT = 1001; 56 constexpr int DELETE_CONTACT = 2001; 57 constexpr int UPDATE_CONTACT = 3001; 58 59 constexpr int QUERY_CONTACTS = 4001; 60 constexpr int QUERY_CONTACT = 4008; 61 62 constexpr int QUERY_CONTACTS_BY_EMAIL = 4002; 63 constexpr int QUERY_CONTACTS_BY_PHONE_NUMBER = 4003; 64 constexpr int QUERY_GROUPS = 4004; 65 constexpr int QUERY_HOLDERS = 4005; 66 constexpr int QUERY_KEY = 4006; 67 constexpr int QUERY_MY_CARD = 4007; 68 constexpr int IS_LOCAL_CONTACT = 5008; 69 constexpr int IS_MY_CARD = 5009; 70 71 constexpr int SELECT_CONTACT = 6001; 72 73 // contactsData type 74 constexpr int EMAIL = 1; 75 constexpr int IM = 2; 76 constexpr int NICKNAME = 3; 77 constexpr int ORGANIZATION = 4; 78 constexpr int PHONE = 5; 79 constexpr int NAME = 6; 80 constexpr int POSTAL_ADDRESS = 7; 81 constexpr int PHOTO = 8; 82 constexpr int GROUP_MEMBERSHIP = 9; 83 constexpr int NOTE = 10; 84 constexpr int CONTACT_EVENT = 11; 85 constexpr int WEBSITE = 12; 86 constexpr int RELATION = 13; 87 constexpr int CONTACT_MISC = 14; 88 constexpr int HICALL_DEVICE = 15; 89 constexpr int CAMCARD = 16; 90 constexpr int SIP_ADDRESS = 17; 91 92 constexpr int ARGS_ZERO = 0; 93 constexpr int ARGS_ONE = 1; 94 constexpr int ARGS_TWO = 2; 95 constexpr int ARGS_THREE = 3; 96 constexpr int ARGS_FOUR = 4; 97 constexpr int ARGS_FIVE = 5; 98 const std::string CONTACTS_DATA_URI = "datashare:///com.ohos.contactsdataability"; 99 100 struct ExecuteHelper { ExecuteHelperExecuteHelper101 ExecuteHelper() 102 : work(nullptr), deferred(nullptr), sync(NAPI_CALL_TYPE_PROMISE), 103 argc(0), abilityContext(nullptr), actionCode(-1), callBack(nullptr), 104 childActionCode(0), promise(nullptr), resultData(-1), resultSet(nullptr) {} 105 napi_async_work work; 106 napi_deferred deferred; 107 int sync; 108 unsigned int argc; 109 napi_value argv[MAX_PARAMS] = {0}; 110 napi_value abilityContext; 111 int actionCode; 112 napi_ref callBack; 113 int childActionCode; 114 napi_value promise; 115 // query 116 std::vector<std::string> columns; 117 // condition 118 DataShare::DataSharePredicates predicates; 119 // delete contact predicates for update contact 120 DataShare::DataSharePredicates deletePredicates; 121 // update 122 std::vector<DataShare::DataShareValuesBucket> valueUpdateContact; 123 // insert 124 std::vector<DataShare::DataShareValuesBucket> valueContact; 125 // insertContactData 126 std::vector<DataShare::DataShareValuesBucket> valueContactData; 127 // dataShareHelper 128 std::shared_ptr<DataShare::DataShareHelper> dataShareHelper; 129 130 // operation result 131 int resultData; 132 std::shared_ptr<DataShare::DataShareResultSet> resultSet; 133 }; 134 } // namespace ContactsApi 135 } // namespace OHOS 136 #endif // CONTACT_NAPI_COMMON_H