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