From ee008e8254e837c99407dc79095b00664249b01e Mon Sep 17 00:00:00 2001 From: srr101 Date: Tue, 26 Jul 2022 19:35:09 +0800 Subject: [PATCH] datashare code update Signed-off-by: srr101 --- data_share/README_zh.md | 6 +- data_share/bundle.json | 49 +- data_share/datashare.gni | 2 +- data_share/frameworks/js/napi/BUILD.gn | 2 +- .../frameworks/js/napi/dataShare/BUILD.gn | 4 +- .../dataShare/include/napi_datashare_helper.h | 1 + .../include/napi_datashare_observer.h | 36 +- .../dataShare/src/napi_datashare_helper.cpp | 437 +++--------------- .../dataShare/src/napi_datashare_observer.cpp | 199 ++------ .../dataShare/src/native_datashare_module.cpp | 2 +- .../native_datashare_predicates_module.cpp | 2 +- .../native/common/include/result_set.h | 1 - .../common/src/datashare_abs_result_set.cpp | 3 +- .../native/common/src/datashare_result.cpp | 6 +- .../common/src/datashare_values_bucket.cpp | 1 + .../consumer/include/datashare_connection.h | 1 - .../provider/include/datashare_stub_impl.h | 1 + .../provider/include/datashare_uv_queue.h | 2 - .../include/js_datashare_ext_ability.h | 5 +- .../js_datashare_ext_ability_context.h | 5 +- .../src/js_datashare_ext_ability_context.cpp | 2 +- data_share/interfaces/inner_api/BUILD.gn | 5 +- .../interfaces/inner_api/common/BUILD.gn | 2 +- .../consumer/include/datashare_helper.h | 2 +- .../provider/include/result_set_bridge.h | 1 - 25 files changed, 157 insertions(+), 620 deletions(-) diff --git a/data_share/README_zh.md b/data_share/README_zh.md index f5f3b488..7da848c9 100644 --- a/data_share/README_zh.md +++ b/data_share/README_zh.md @@ -16,7 +16,7 @@ ## 目录 ``` -/foundation/distributeddatamgr/appdatamgr/data_share +/foundation/distributeddatamgr/data_share ├── frameworks # 框架代码 │   ├── js │   │   └── napi # NAPI代码存放目录 @@ -45,8 +45,8 @@ ## 相关仓 -[分布式数据管理子系统](https://gitee.com/openharmony/distributeddatamgr_appdatamgr/blob/master/README_zh.md) +[分布式数据管理子系统](https://gitee.com/openharmony/distributeddatamgr_data_share/blob/master/README_zh.md) [distributeddatamgr_datamgr](https://gitee.com/openharmony/distributeddatamgr_datamgr/blob/master/README_zh.md) -[**distributeddatamgr_appdatamgr**](https://gitee.com/openharmony/distributeddatamgr_appdatamgr/blob/master/README_zh.md) \ No newline at end of file +[**distributeddatamgr_data_share**](https://gitee.com/openharmony/distributeddatamgr_data_share/blob/master/README_zh.md) \ No newline at end of file diff --git a/data_share/bundle.json b/data_share/bundle.json index b7760051..7b567c16 100644 --- a/data_share/bundle.json +++ b/data_share/bundle.json @@ -1,10 +1,10 @@ { - "name": "@ohos/distributeddatamgr_appdatamgr", + "name": "@ohos/distributeddatamgr_data_share", "version": "3.1.0", "description": "Local Data Management", "homePage": "https://gitee.com/openharmony", "license": "Apache V2", - "repository": "https://gitee.com/openharmony/distributeddatamgr_appdatamgr", + "repository": "https://gitee.com/openharmony/distributeddatamgr_data_share", "domain": "os", "language": "", "publishAs": "code-segment", @@ -15,7 +15,7 @@ ], "keywords": [ "distributeddatamgr", - "appdatamgr" + "data_share" ], "envs": [], "dirs": {}, @@ -32,7 +32,7 @@ } ], "segment": { - "destPath": "foundation/distributeddatamgr/appdatamgr" + "destPath": "foundation/distributeddatamgr/data_share" }, "component": { "name": "data_share", @@ -50,55 +50,50 @@ "ram": "", "deps": { "components": [ - "ability_base", - "ability_runtime", - "want", - "libhilog", - "ipc_core", - "ace_napi", - "samgr_proxy", "relational_store", + "access_token", + "ability_runtime", + "ipc_js", "napi", - "utils_base", - "ipc", - "eventhandler", - "bundle_framework", "hiviewdfx_hilog_native", - "ipc_js", "libuv", - "access_token" + "ipc", + "bundle_framework", + "utils_base", + "ability_base", + "eventhandler" ], "third_party": [] }, "build": { "sub_component": [ - "//foundation/distributeddatamgr/appdatamgr/data_share/interfaces/inner_api:datashare_abilitykit", - "//foundation/distributeddatamgr/appdatamgr/data_share/interfaces/inner_api:datashare_ext_ability_module", - "//foundation/distributeddatamgr/appdatamgr/data_share/frameworks/js/napi:datashare_napi_packages", - "//foundation/distributeddatamgr/appdatamgr/data_share/interfaces/inner_api/common:datashare_common" + "//foundation/distributeddatamgr/data_share/interfaces/inner_api:datashare_abilitykit", + "//foundation/distributeddatamgr/data_share/interfaces/inner_api:datashare_ext_ability_module", + "//foundation/distributeddatamgr/data_share/frameworks/js/napi:datashare_napi_packages", + "//foundation/distributeddatamgr/data_share/interfaces/inner_api/common:datashare_common" ], "inner_kits": [ { - "name": "//foundation/distributeddatamgr/appdatamgr/data_share/interfaces/inner_api:datashare_abilitykit", + "name": "//foundation/distributeddatamgr/data_share/interfaces/inner_api:datashare_abilitykit", "header": { "header_files": [ "datashare_helper.h", "datashare_result_set.h" ], - "header_base": "//foundation/distributeddatamgr/appdatamgr/data_share/interfaces/inner_api/consumer/include" + "header_base": "//foundation/distributeddatamgr/data_share/interfaces/inner_api/consumer/include" } }, { - "name": "//foundation/distributeddatamgr/appdatamgr/data_share/interfaces/inner_api:datashare_abilitykit", + "name": "//foundation/distributeddatamgr/data_share/interfaces/inner_api:datashare_abilitykit", "header": { "header_files": [ "result_set_bridge.h" ], - "header_base": "//foundation/distributeddatamgr/appdatamgr/data_share/interfaces/inner_api/provider/include" + "header_base": "//foundation/distributeddatamgr/data_share/interfaces/inner_api/provider/include" } }, { - "name": "//foundation/distributeddatamgr/appdatamgr/data_share/interfaces/inner_api/common:datashare_common", + "name": "//foundation/distributeddatamgr/data_share/interfaces/inner_api/common:datashare_common", "header": { "header_files": [ "datashare_errno.h", @@ -109,7 +104,7 @@ "datashare_value_object.h", "datashare_values_bucket.h" ], - "header_base": "//foundation/distributeddatamgr/appdatamgr/data_share/interfaces/inner_api/common/include" + "header_base": "//foundation/distributeddatamgr/data_share/interfaces/inner_api/common/include" } } ] diff --git a/data_share/datashare.gni b/data_share/datashare.gni index 64e6bfbc..6513a330 100644 --- a/data_share/datashare.gni +++ b/data_share/datashare.gni @@ -21,7 +21,7 @@ ability_runtime_services_path = "${ability_runtime_path}/services" ability_runtime_napi_path = "${ability_runtime_path}/frameworks/js/napi" -datashare_base_path = "//foundation/distributeddatamgr/appdatamgr/data_share" +datashare_base_path = "//foundation/distributeddatamgr/data_share" datashare_common_native_path = "${datashare_base_path}/frameworks/native/common" diff --git a/data_share/frameworks/js/napi/BUILD.gn b/data_share/frameworks/js/napi/BUILD.gn index f70b25f9..0a8dca07 100644 --- a/data_share/frameworks/js/napi/BUILD.gn +++ b/data_share/frameworks/js/napi/BUILD.gn @@ -12,7 +12,7 @@ # limitations under the License. import("//build/ohos.gni") -import("//foundation/distributeddatamgr/appdatamgr/data_share/datashare.gni") +import("//foundation/distributeddatamgr/data_share/datashare.gni") group("datashare_napi_packages") { deps = [ diff --git a/data_share/frameworks/js/napi/dataShare/BUILD.gn b/data_share/frameworks/js/napi/dataShare/BUILD.gn index 4e32bf8d..cf34d375 100644 --- a/data_share/frameworks/js/napi/dataShare/BUILD.gn +++ b/data_share/frameworks/js/napi/dataShare/BUILD.gn @@ -12,15 +12,13 @@ # limitations under the License. import("//build/ohos.gni") -import("//foundation/distributeddatamgr/appdatamgr/data_share/datashare.gni") +import("//foundation/distributeddatamgr/data_share/datashare.gni") ohos_shared_library("datashare") { include_dirs = [ "${datashare_napi_path}/dataShare/include", "${datashare_common_napi_path}/include", "${datashare_common_native_path}/include", - "//third_party/node/src", - "//third_party/libuv/include", ] sources = [ diff --git a/data_share/frameworks/js/napi/dataShare/include/napi_datashare_helper.h b/data_share/frameworks/js/napi/dataShare/include/napi_datashare_helper.h index 4cd15e77..b2f195cf 100644 --- a/data_share/frameworks/js/napi/dataShare/include/napi_datashare_helper.h +++ b/data_share/frameworks/js/napi/dataShare/include/napi_datashare_helper.h @@ -59,6 +59,7 @@ private: static void FindRegisterObsByCallBack(napi_env env, DSHelperOnOffCB *data); std::shared_ptr datashareHelper_ = nullptr; + std::map> observerMap_; struct ContextInfo : public AsyncCall::Context { NapiDataShareHelper *proxy = nullptr; diff --git a/data_share/frameworks/js/napi/dataShare/include/napi_datashare_observer.h b/data_share/frameworks/js/napi/dataShare/include/napi_datashare_observer.h index b333fc3e..97c599c5 100644 --- a/data_share/frameworks/js/napi/dataShare/include/napi_datashare_observer.h +++ b/data_share/frameworks/js/napi/dataShare/include/napi_datashare_observer.h @@ -15,38 +15,30 @@ #ifndef NAPI_DATASHARE_OBSERVER_H #define NAPI_DATASHARE_OBSERVER_H + +#include #include "data_ability_observer_stub.h" -#include "data_share_common.h" +#include "napi/native_common.h" +#include "napi/native_api.h" +#include "napi/native_node_api.h" namespace OHOS { namespace DataShare { class NAPIDataShareObserver : public AAFwk::DataAbilityObserverStub { public: + NAPIDataShareObserver(napi_env env, napi_value callback); + virtual ~NAPIDataShareObserver(); void OnChange() override; - void SetEnv(const napi_env &env); - void SetCallbackRef(const napi_ref &ref); - void ReleaseJSCallback(); - - void SetAssociatedObject(DSHelperOnOffCB* object); - const DSHelperOnOffCB* GetAssociatedObject(void); - - void ChangeWorkPre(); - void ChangeWorkRun(); - void ChangeWorkInt(); - void ChangeWorkPreDone(); - void ChangeWorkRunDone(); - int GetWorkPre(); - int GetWorkRun(); - int GetWorkInt(); - private: + struct ObserverWorker { + const NAPIDataShareObserver *observer_ = nullptr; + napi_env env_ = nullptr; + ObserverWorker(const NAPIDataShareObserver *observerIn) : observer_(observerIn) {} + }; + napi_env env_ = nullptr; napi_ref ref_ = nullptr; - DSHelperOnOffCB* onCB_ = nullptr; - int workPre_ = 0; - int workRun_ = 0; - int intrust_ = 0; - std::mutex mutex_; + uv_loop_s *loop_ = nullptr; }; } // namespace DataShare } // namespace OHOS diff --git a/data_share/frameworks/js/napi/dataShare/src/napi_datashare_helper.cpp b/data_share/frameworks/js/napi/dataShare/src/napi_datashare_helper.cpp index fe87ee5b..79dce395 100644 --- a/data_share/frameworks/js/napi/dataShare/src/napi_datashare_helper.cpp +++ b/data_share/frameworks/js/napi/dataShare/src/napi_datashare_helper.cpp @@ -15,11 +15,9 @@ #include "napi_datashare_helper.h" -#include "ability.h" #include "napi_common_util.h" #include "datashare_helper.h" #include "datashare_log.h" -#include "data_share_common.h" #include "napi_base_context.h" #include "napi_datashare_values_bucket.h" #include "datashare_predicates_proxy.h" @@ -30,10 +28,8 @@ using namespace OHOS::AppExecFwk; namespace OHOS { namespace DataShare { -constexpr int NO_ERROR = 0; -constexpr int INVALID_PARAMETER = -1; +constexpr int MAX_ARGC = 6; -static std::vector registerInstances_; std::list> g_dataShareHelperList; void UnwrapDataSharePredicates(DataSharePredicates &predicates, napi_env env, napi_value value) @@ -166,16 +162,7 @@ napi_value NapiDataShareHelper::Initialize(napi_env env, napi_callback_info info g_dataShareHelperList.emplace_back(proxy->datashareHelper_); auto finalize = [](napi_env env, void * data, void * hint) { NapiDataShareHelper *proxy = reinterpret_cast(data); - auto helper = std::find_if(registerInstances_.begin(), registerInstances_.end(), - [&proxy](const DSHelperOnOffCB *helper) { - return helper->dataShareHelper == proxy->datashareHelper_.get(); - }); - if (helper != registerInstances_.end()) { - LOG_INFO("DataShareHelper finalize_cb find helper"); - (*helper)->dataShareHelper->Release(); - delete *helper; - registerInstances_.erase(helper); - } + delete proxy; }; if (napi_wrap(env, self, proxy, finalize, nullptr, nullptr) != napi_ok) { finalize(env, proxy, nullptr); @@ -663,396 +650,92 @@ napi_value NapiDataShareHelper::Napi_NotifyChange(napi_env env, napi_callback_in napi_value NapiDataShareHelper::Napi_On(napi_env env, napi_callback_info info) { LOG_INFO("Napi_On in"); - DSHelperOnOffCB *onCB = new (std::nothrow) DSHelperOnOffCB; - if (onCB == nullptr) { - LOG_ERROR("Napi_On onCB == nullptr."); - return WrapVoidToJS(env); - } - onCB->cbBase.cbInfo.env = env; - onCB->cbBase.asyncWork = nullptr; - onCB->cbBase.deferred = nullptr; - onCB->cbBase.ability = nullptr; - - napi_value ret = RegisterWrap(env, info, onCB); - if (ret == nullptr) { - LOG_ERROR("ret == nullptr."); - delete onCB; - onCB = nullptr; - ret = WrapVoidToJS(env); - } - LOG_INFO("Napi_On out"); - return ret; -} + napi_value self = nullptr; + size_t argc = MAX_ARGC; + napi_value argv[MAX_ARGC] = {nullptr}; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &self, nullptr)); + NAPI_ASSERT(env, argc == ARGS_THREE, "wrong count of args"); -napi_value NapiDataShareHelper::RegisterWrap(napi_env env, napi_callback_info info, DSHelperOnOffCB *onCB) -{ - LOG_INFO("RegisterWrap in"); - size_t argcAsync = ARGS_THREE; - const size_t argcPromise = ARGS_TWO; - const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; - napi_value args[ARGS_MAX_COUNT] = {nullptr}; - napi_value ret = 0; - napi_value thisVar = nullptr; + NapiDataShareHelper *proxy = nullptr; + NAPI_CALL_BASE(env, napi_unwrap(env, self, reinterpret_cast(&proxy)), nullptr); + NAPI_ASSERT_BASE(env, proxy != nullptr, "there is no NapiDataShareHelper instance", nullptr); + NAPI_ASSERT_BASE(env, proxy->datashareHelper_ != nullptr, "there is no DataShareHelper instance", nullptr); - NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr)); - if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) { - LOG_ERROR("Wrong argument count."); + napi_valuetype valueType; + NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valueType)); + if (valueType != napi_string) { + LOG_ERROR("type is not string"); return nullptr; } - - onCB->result = NO_ERROR; - napi_valuetype valuetype = napi_undefined; - NAPI_CALL(env, napi_typeof(env, args[PARAM0], &valuetype)); - if (valuetype == napi_string) { - std::string type = DataShareJSUtils::Convert2String(env, args[PARAM0]); - if (type == "dataChange") { - LOG_INFO("Wrong type : %{public}s", type.c_str()); - } else { - LOG_ERROR("Wrong argument type is %{public}s.", type.c_str()); - onCB->result = INVALID_PARAMETER; - } - } else { - LOG_ERROR("Wrong argument type."); - onCB->result = INVALID_PARAMETER; - } - - NAPI_CALL(env, napi_typeof(env, args[PARAM1], &valuetype)); - if (valuetype == napi_string) { - onCB->uri = DataShareJSUtils::Convert2String(env, args[PARAM1]); - LOG_INFO("uri : %{public}s", onCB->uri.c_str()); - } else { - LOG_ERROR("Wrong argument type."); - onCB->result = INVALID_PARAMETER; - } - - NapiDataShareHelper *objectInfo = nullptr; - napi_unwrap(env, thisVar, (void **)&objectInfo); - LOG_INFO("Set NapiDataShareHelper objectInfo"); - onCB->dataShareHelper = objectInfo->datashareHelper_.get(); - - ret = RegisterAsync(env, args, argcAsync, argcPromise, onCB); - return ret; -} - -napi_value NapiDataShareHelper::RegisterAsync( - napi_env env, napi_value *args, size_t argcAsync, const size_t argcPromise, DSHelperOnOffCB *onCB) -{ - LOG_INFO("RegisterAsync in."); - if (args == nullptr || onCB == nullptr) { - LOG_ERROR("param == nullptr."); + std::string type = DataShareJSUtils::Convert2String(env, argv[PARAM0]); + if (type != "dataChange") { + LOG_ERROR("wrong register type : %{public}s", type.c_str()); return nullptr; } - napi_value resourceName = 0; - NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); - napi_valuetype valuetype = napi_undefined; - NAPI_CALL(env, napi_typeof(env, args[argcPromise], &valuetype)); - if (valuetype == napi_function) { - LOG_INFO("valuetype is napi_function"); - NAPI_CALL(env, napi_create_reference(env, args[argcPromise], 1, &onCB->cbBase.cbInfo.callback)); - } else { - LOG_INFO("not valuetype isn't napi_function"); - onCB->result = INVALID_PARAMETER; - } + NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valueType)); + NAPI_ASSERT_BASE(env, valueType == napi_string, "uri is not string", nullptr); + std::string uri = DataShareJSUtils::Convert2String(env, argv[PARAM1]); - sptr observer(new (std::nothrow) NAPIDataShareObserver()); - observer->SetEnv(env); - observer->SetCallbackRef(onCB->cbBase.cbInfo.callback); - onCB->observer = observer; + NAPI_CALL(env, napi_typeof(env, argv[PARAM2], &valueType)); + NAPI_ASSERT_BASE(env, valueType == napi_function, "callback is not a function", nullptr); + sptr observer(new (std::nothrow) NAPIDataShareObserver(env, argv[PARAM2])); - if (onCB->result == NO_ERROR) { - registerInstances_.emplace_back(onCB); + auto obs = proxy->observerMap_.find(uri); + if (obs != proxy->observerMap_.end()) { + proxy->datashareHelper_->UnregisterObserver(Uri(uri), obs->second); + proxy->observerMap_.erase(uri); } + proxy->datashareHelper_->RegisterObserver(Uri(uri), observer); + proxy->observerMap_.emplace(uri, observer); - NAPI_CALL(env, - napi_create_async_work( - env, - nullptr, - resourceName, - RegisterExecuteCB, - RegisterCompleteCB, - (void *)onCB, - &onCB->cbBase.asyncWork)); - NAPI_CALL(env, napi_queue_async_work(env, onCB->cbBase.asyncWork)); - napi_value result = 0; - NAPI_CALL(env, napi_get_null(env, &result)); - return result; -} - -void NapiDataShareHelper::RegisterExecuteCB(napi_env env, void *data) -{ - LOG_INFO("RegisterExecuteCB in."); - DSHelperOnOffCB *onCB = static_cast(data); - if (onCB->dataShareHelper != nullptr) { - if (onCB->result != INVALID_PARAMETER && !onCB->uri.empty() && onCB->cbBase.cbInfo.callback != nullptr) { - OHOS::Uri uri(onCB->uri); - onCB->dataShareHelper->RegisterObserver(uri, onCB->observer); - } else { - LOG_ERROR("dataShareHelper uri is empty or callback is nullptr."); - } - } -} - -void NapiDataShareHelper::RegisterCompleteCB(napi_env env, napi_status status, void *data) -{ - LOG_INFO("RegisterCompleteCB in."); - DSHelperOnOffCB *onCB = static_cast(data); - if (onCB == nullptr) { - LOG_ERROR("input params onCB is nullptr."); - return; - } - if (onCB->result == NO_ERROR) { - return; - } - if (onCB->observer) { - LOG_INFO("RegisterCompleteCB, call ReleaseJSCallback"); - onCB->observer->ReleaseJSCallback(); - } - delete onCB; - onCB = nullptr; - LOG_INFO("RegisterCompleteCB out."); + return nullptr; } napi_value NapiDataShareHelper::Napi_Off(napi_env env, napi_callback_info info) { LOG_INFO("Napi_Off in"); - DSHelperOnOffCB *offCB = new (std::nothrow) DSHelperOnOffCB; - if (offCB == nullptr) { - LOG_ERROR("offCB == nullptr."); - return WrapVoidToJS(env); - } - offCB->cbBase.cbInfo.env = env; - offCB->cbBase.asyncWork = nullptr; - offCB->cbBase.deferred = nullptr; - offCB->cbBase.ability = nullptr; + napi_value self = nullptr; + size_t argc = MAX_ARGC; + napi_value argv[MAX_ARGC] = {nullptr}; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &self, nullptr)); + NAPI_ASSERT(env, argc == ARGS_TWO || argc == ARGS_THREE, "wrong count of args"); - napi_value ret = UnRegisterWrap(env, info, offCB); - if (ret == nullptr) { - LOG_ERROR("ret == nullptr."); - delete offCB; - offCB = nullptr; - ret = WrapVoidToJS(env); - } - LOG_INFO("Napi_Off out"); - return ret; -} + NapiDataShareHelper *proxy = nullptr; + NAPI_CALL_BASE(env, napi_unwrap(env, self, reinterpret_cast(&proxy)), nullptr); + NAPI_ASSERT_BASE(env, proxy != nullptr, "there is no NapiDataShareHelper instance", nullptr); + NAPI_ASSERT_BASE(env, proxy->datashareHelper_ != nullptr, "there is no DataShareHelper instance", nullptr); -napi_value NapiDataShareHelper::UnRegisterWrap(napi_env env, napi_callback_info info, DSHelperOnOffCB *offCB) -{ - LOG_INFO("UnRegisterWrap in"); - size_t argc = ARGS_THREE; - const size_t argcPromise = ARGS_TWO; - const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; - napi_value args[ARGS_MAX_COUNT] = {nullptr}; - napi_value ret = 0; - napi_value thisVar = nullptr; - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, &thisVar, nullptr)); - NAPI_ASSERT(env, argc <= argCountWithAsync && argc <= ARGS_MAX_COUNT, "UnRegisterWrap: Wrong argument count"); - offCB->result = INVALID_PARAMETER; - napi_valuetype valuetype = napi_undefined; - NAPI_CALL(env, napi_typeof(env, args[PARAM0], &valuetype)); - if (valuetype == napi_string) { - std::string type = DataShareJSUtils::Convert2String(env, args[PARAM0]); - if (type == "dataChange") { - offCB->result = NO_ERROR; - } - } - offCB->uri = ""; - if (argc > ARGS_TWO) { - NAPI_CALL(env, napi_typeof(env, args[PARAM1], &valuetype)); - if (valuetype == napi_string) { - offCB->uri = DataShareJSUtils::Convert2String(env, args[PARAM1]); - } else { - offCB->result = INVALID_PARAMETER; - } - NAPI_CALL(env, napi_typeof(env, args[PARAM2], &valuetype)); - if (valuetype == napi_function) { - NAPI_CALL(env, napi_create_reference(env, args[PARAM2], 1, &offCB->cbBase.cbInfo.callback)); - } else { - offCB->result = INVALID_PARAMETER; - } - } else { - NAPI_CALL(env, napi_typeof(env, args[PARAM1], &valuetype)); - if (valuetype == napi_string) { - offCB->uri = DataShareJSUtils::Convert2String(env, args[PARAM1]); - } else if (valuetype == napi_function) { - NAPI_CALL(env, napi_create_reference(env, args[PARAM1], 1, &offCB->cbBase.cbInfo.callback)); - } else { - offCB->result = INVALID_PARAMETER; - } - } - LOG_INFO("uri : %{public}s", offCB->uri.c_str()); - NapiDataShareHelper *objectInfo = nullptr; - napi_unwrap(env, thisVar, (void **)&objectInfo); - offCB->dataShareHelper = objectInfo->datashareHelper_.get(); - ret = UnRegisterAsync(env, args, argc, argcPromise, offCB); - return ret; -} - -napi_value NapiDataShareHelper::UnRegisterAsync( - napi_env env, napi_value *args, size_t argc, const size_t argcPromise, DSHelperOnOffCB *offCB) -{ - LOG_INFO("UnRegisterAsync in."); - if (args == nullptr || offCB == nullptr) { - LOG_ERROR("param == nullptr."); + napi_valuetype valueType; + NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valueType)); + if (valueType != napi_string) { + LOG_ERROR("type is not string"); return nullptr; } - napi_value resourceName = 0; - NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); - - if (offCB->result == NO_ERROR) { - FindRegisterObs(env, offCB); + std::string type = DataShareJSUtils::Convert2String(env, argv[PARAM0]); + if (type != "dataChange") { + LOG_ERROR("wrong register type : %{public}s", type.c_str()); + return nullptr; } - NAPI_CALL(env, - napi_create_async_work( - env, - nullptr, - resourceName, - UnRegisterExecuteCB, - UnRegisterCompleteCB, - (void *)offCB, - &offCB->cbBase.asyncWork)); - NAPI_CALL(env, napi_queue_async_work(env, offCB->cbBase.asyncWork)); - napi_value result = 0; - NAPI_CALL(env, napi_get_null(env, &result)); - return result; -} - -void NapiDataShareHelper::UnRegisterExecuteCB(napi_env env, void *data) -{ - LOG_INFO("UnRegisterExecuteCB in."); - DSHelperOnOffCB *offCB = static_cast(data); - if (offCB == nullptr || offCB->dataShareHelper == nullptr) { - LOG_ERROR("NAPI_UnRegister, param is null."); - if (offCB != nullptr) { - delete offCB; - offCB = nullptr; - } - return; - } - LOG_INFO("UnRegisterExecuteCB, offCB->DestoryList size is %{public}zu", offCB->NotifyList.size()); - for (auto &iter : offCB->NotifyList) { - if (iter != nullptr && iter->observer != nullptr) { - OHOS::Uri uri(iter->uri); - iter->dataShareHelper->UnregisterObserver(uri, iter->observer); - offCB->DestoryList.emplace_back(iter); - } - } - offCB->NotifyList.clear(); - LOG_INFO("UnRegisterExecuteCB out."); -} + NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valueType)); + NAPI_ASSERT_BASE(env, valueType == napi_string, "uri is not string", nullptr); + std::string uri = DataShareJSUtils::Convert2String(env, argv[PARAM1]); -void NapiDataShareHelper::UnRegisterCompleteCB(napi_env env, napi_status status, void *data) -{ - LOG_INFO("UnRegisterCompleteCB in."); - // cannot run it in executeCB, because need to use napi_strict_equals compare callbacks. - DSHelperOnOffCB *offCB = static_cast(data); - if (offCB == nullptr || offCB->dataShareHelper == nullptr) { - LOG_ERROR("NAPI_UnRegister, param is null."); - if (offCB != nullptr) { - delete offCB; - offCB = nullptr; - } - return; - } - LOG_INFO("UnRegisterCompleteCB, offCB->DestoryList size is %{public}zu", offCB->DestoryList.size()); - for (auto &iter : offCB->DestoryList) { - if (iter->observer != nullptr) { - if (iter->observer->GetWorkPre() == 1 && iter->observer->GetWorkRun() == 0) { - iter->observer->SetAssociatedObject(iter); - iter->observer->ChangeWorkInt(); - LOG_INFO("UnRegisterCompleteCB ChangeWorkInt"); - } else { - iter->observer->ReleaseJSCallback(); - delete iter; - iter = nullptr; - LOG_INFO("UnRegisterCompleteCB ReleaseJSCallback"); - } - } + if (argc == ARGS_THREE) { + NAPI_CALL(env, napi_typeof(env, argv[PARAM2], &valueType)); + NAPI_ASSERT_BASE(env, valueType == napi_function, "callback is not a function", nullptr); } - offCB->DestoryList.clear(); - delete offCB; - offCB = nullptr; - LOG_INFO("UnRegisterCompleteCB out"); -} - -void NapiDataShareHelper::FindRegisterObs(napi_env env, DSHelperOnOffCB *data) -{ - LOG_INFO("FindRegisterObs in."); - if (data == nullptr || data->dataShareHelper == nullptr) { - LOG_ERROR("FindRegisterObs, param is null."); - return; - } - if (data->cbBase.cbInfo.callback != nullptr) { - LOG_INFO("FindRegisterObs, UnRegisterExecuteCB callback is not null."); - FindRegisterObsByCallBack(env, data); + auto obs = proxy->observerMap_.find(uri); + if (obs != proxy->observerMap_.end()) { + proxy->datashareHelper_->UnregisterObserver(Uri(uri), obs->second); + proxy->observerMap_.erase(uri); } else { - if (data->uri.empty()) { - LOG_ERROR("FindRegisterObs, error: uri is empty."); - return; - } - - LOG_INFO("FindRegisterObs, uri : %{public}s.", data->uri.c_str()); - std::string strUri = data->uri; - do { - auto helper = std::find_if(registerInstances_.begin(), registerInstances_.end(), - [strUri](const DSHelperOnOffCB *helper) { return helper->uri == strUri; }); - if (helper != registerInstances_.end()) { - OHOS::Uri uri((*helper)->uri); - data->NotifyList.emplace_back(*helper); - registerInstances_.erase(helper); - LOG_INFO("FindRegisterObs Instances erase size : %{public}zu", registerInstances_.size()); - } else { - LOG_INFO("FindRegisterObs not match any uri."); - break; - } - } while (true); + LOG_DEBUG("this uri hasn't been registered"); } - LOG_INFO("FindRegisterObs out, data->NotifyList.size : %{public}zu", data->NotifyList.size()); -} -void NapiDataShareHelper::FindRegisterObsByCallBack(napi_env env, DSHelperOnOffCB *data) -{ - LOG_INFO("FindRegisterObsByCallBack in."); - if (data == nullptr || data->dataShareHelper == nullptr) { - LOG_ERROR("FindRegisterObsByCallBack, param is null."); - return; - } - napi_value callbackA = 0; - napi_get_reference_value(data->cbBase.cbInfo.env, data->cbBase.cbInfo.callback, &callbackA); - std::string strUri = data->uri; - do { - auto helper = std::find_if( - registerInstances_.begin(), - registerInstances_.end(), - [callbackA, strUri](const DSHelperOnOffCB *helper) { - bool result = false; - if (helper == nullptr || helper->cbBase.cbInfo.callback == nullptr) { - LOG_ERROR("%{public}s is nullptr", ((helper == nullptr) ? "helper" : "cbBase.cbInfo.callback")); - return result; - } - if (helper->uri != strUri) { - LOG_ERROR("uri inconsistent, h=[%{public}s] u=[%{public}s]", helper->uri.c_str(), strUri.c_str()); - return result; - } - napi_value callbackB = 0; - napi_get_reference_value(helper->cbBase.cbInfo.env, helper->cbBase.cbInfo.callback, &callbackB); - auto ret = napi_strict_equals(helper->cbBase.cbInfo.env, callbackA, callbackB, &result); - LOG_INFO("FindRegisterObsByCallBack cb equals status : %{public}d result : %{public}d.", ret, result); - return result; - }); - if (helper != registerInstances_.end()) { - data->NotifyList.emplace_back(*helper); - registerInstances_.erase(helper); - LOG_INFO("FindRegisterObsByCallBack Instances erase size = %{public}zu", registerInstances_.size()); - } else { - LOG_INFO("FindRegisterObsByCallBack not match any callback. %{public}zu", registerInstances_.size()); - break; - } - } while (true); - LOG_INFO("FindRegisterObsByCallBack out."); + return nullptr; } } // namespace DataShare } // namespace OHOS diff --git a/data_share/frameworks/js/napi/dataShare/src/napi_datashare_observer.cpp b/data_share/frameworks/js/napi/dataShare/src/napi_datashare_observer.cpp index d2230fa6..c2701789 100644 --- a/data_share/frameworks/js/napi/dataShare/src/napi_datashare_observer.cpp +++ b/data_share/frameworks/js/napi/dataShare/src/napi_datashare_observer.cpp @@ -14,190 +14,61 @@ */ #include "napi_datashare_observer.h" -#include #include "datashare_log.h" namespace OHOS { namespace DataShare { -void NAPIDataShareObserver::ReleaseJSCallback() +NAPIDataShareObserver::NAPIDataShareObserver(napi_env env, napi_value callback) + : env_(env) { - if (ref_ == nullptr) { - LOG_ERROR("NAPIDataShareObserver::ReleaseJSCallback, ref_ is null."); - return; - } - napi_delete_reference(env_, ref_); - LOG_INFO("NAPIDataShareObserver::%{public}s, called. end", __func__); + napi_create_reference(env, callback, 1, &ref_); + napi_get_uv_event_loop(env, &loop_); } -void NAPIDataShareObserver::SetAssociatedObject(DSHelperOnOffCB* object) -{ - onCB_ = object; - LOG_INFO("NAPIDataShareObserver::%{public}s, called. end", __func__); -} - -void NAPIDataShareObserver::ChangeWorkPre() -{ - LOG_INFO("NAPIDataShareObserver::%{public}s, called.", __func__); - std::lock_guard lock_l(mutex_); - workPre_ = 1; - LOG_INFO("NAPIDataShareObserver::%{public}s, called. end %{public}d", __func__, workPre_); -} -void NAPIDataShareObserver::ChangeWorkRun() +NAPIDataShareObserver::~NAPIDataShareObserver() { - workRun_ = 1; - LOG_INFO("NAPIDataShareObserver::%{public}s, called. end %{public}d", __func__, workRun_); -} -void NAPIDataShareObserver::ChangeWorkInt() -{ - intrust_ = 1; - LOG_INFO("NAPIDataShareObserver::%{public}s, called. end %{public}d", __func__, intrust_); -} - -void NAPIDataShareObserver::ChangeWorkPreDone() -{ - LOG_INFO("NAPIDataShareObserver::%{public}s, called.", __func__); - std::lock_guard lock_l(mutex_); - workPre_ = 0; - LOG_INFO("NAPIDataShareObserver::%{public}s, called. end %{public}d", __func__, workPre_); -} - -void NAPIDataShareObserver::ChangeWorkRunDone() -{ - workRun_ = 0; - intrust_ = 0; - LOG_INFO("NAPIDataShareObserver::%{public}s, called end %{public}d %{public}d", __func__, workRun_, intrust_); -} - -int NAPIDataShareObserver::GetWorkPre() -{ - LOG_INFO("NAPIDataShareObserver::%{public}s, called.", __func__); - std::lock_guard lock_l(mutex_); - LOG_INFO("NAPIDataShareObserver::%{public}s, called. end %{public}d", __func__, workPre_); - return workPre_; -} - -int NAPIDataShareObserver::GetWorkInt() -{ - LOG_INFO("NAPIDataShareObserver::%{public}s, called. end %{public}d", __func__, intrust_); - return intrust_; -} - -int NAPIDataShareObserver::GetWorkRun() -{ - LOG_INFO("NAPIDataShareObserver::%{public}s, called. %{public}d", __func__, workRun_); - return workRun_; -} - -const DSHelperOnOffCB* NAPIDataShareObserver::GetAssociatedObject(void) -{ - LOG_INFO("NAPIDataShareObserver::%{public}s, called.", __func__); - return onCB_; -} - -void NAPIDataShareObserver::SetEnv(const napi_env &env) -{ - env_ = env; - LOG_INFO("NAPIDataShareObserver::%{public}s, called. end", __func__); -} - -void NAPIDataShareObserver::SetCallbackRef(const napi_ref &ref) -{ - ref_ = ref; - LOG_INFO("NAPIDataShareObserver::%{public}s, called. end", __func__); -} - -static void OnChangeJSThreadWorker(uv_work_t *work, int status) -{ - LOG_INFO("OnChange, uv_queue_work"); - if (work == nullptr) { - LOG_ERROR("OnChange, uv_queue_work input work is nullptr"); - return; - } - DSHelperOnOffCB *onCB = (DSHelperOnOffCB *)work->data; - NAPIDataShareObserver* obs = onCB->observer; - onCB->observer = nullptr; - if (obs != nullptr) { - obs->ChangeWorkRun(); - } - napi_value result[ARGS_TWO] = {0}; - result[PARAM0] = GetCallbackErrorValue(onCB->cbBase.cbInfo.env, NO_ERROR); - napi_value callback = 0; - napi_value undefined = 0; - napi_get_undefined(onCB->cbBase.cbInfo.env, &undefined); - napi_value callResult = 0; - napi_get_reference_value(onCB->cbBase.cbInfo.env, onCB->cbBase.cbInfo.callback, &callback); - napi_call_function(onCB->cbBase.cbInfo.env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult); - if (obs != nullptr) { - if (obs->GetWorkInt() == 1) { - obs->ReleaseJSCallback(); - const DSHelperOnOffCB* assicuated = obs->GetAssociatedObject(); - if (assicuated != nullptr) { - LOG_INFO("OnChange, uv_queue_work ReleaseJSCallback Called"); - obs->SetAssociatedObject(nullptr); - delete assicuated; - assicuated = nullptr; - } - } else { - obs->ChangeWorkRunDone(); - obs->ChangeWorkPreDone(); - } - } - delete onCB; - onCB = nullptr; - if (work != nullptr) { - delete work; + if (ref_ != nullptr) { + napi_delete_reference(env_, ref_); } - LOG_INFO("OnChange, uv_queue_work. end"); } void NAPIDataShareObserver::OnChange() { - if (ref_ == nullptr) { - LOG_ERROR("%{public}s, OnChange ref is nullptr.", __func__); + LOG_DEBUG("OnChange called"); + ObserverWorker *observerWorker = new (std::nothrow)ObserverWorker(this); + if (observerWorker == nullptr) { + LOG_ERROR("Failed to create observerWorker"); return; } - ChangeWorkPre(); - uv_loop_s *loop = nullptr; - napi_get_uv_event_loop(env_, &loop); - if (loop == nullptr) { - LOG_ERROR("%{public}s, loop == nullptr.", __func__); - ChangeWorkPreDone(); - return; - } - uv_work_t *work = new uv_work_t; + uv_work_t *work = new (std::nothrow)uv_work_t(); if (work == nullptr) { - LOG_ERROR("%{public}s, work==nullptr.", __func__); - ChangeWorkPreDone(); - return; - } - DSHelperOnOffCB *onCB = new (std::nothrow) DSHelperOnOffCB; - if (onCB == nullptr) { - LOG_ERROR("%{public}s, onCB == nullptr.", __func__); - if (work != nullptr) { - delete work; - work = nullptr; - } - ChangeWorkPreDone(); + LOG_ERROR("Failed to create uv work"); return; } - onCB->cbBase.cbInfo.env = env_; - onCB->cbBase.cbInfo.callback = ref_; - onCB->observer = this; - work->data = (void *)onCB; - int rev = uv_queue_work( - loop, - work, + work->data = observerWorker; + int ret = uv_queue_work(loop_, work, [](uv_work_t *work) {}, - OnChangeJSThreadWorker); - if (rev != 0) { - delete onCB; - onCB = nullptr; - if (work != nullptr) { - delete work; - work = nullptr; - } + [](uv_work_t *work, int status) { + LOG_DEBUG("uv_queue_work start"); + std::shared_ptr innerWorker(reinterpret_cast(work->data)); + napi_value callback = nullptr; + napi_value args[2] = {0}; + napi_value global = nullptr; + napi_value result; + napi_get_reference_value(innerWorker->observer_->env_, + innerWorker->observer_->ref_, &callback); + napi_get_global(innerWorker->observer_->env_, &global); + napi_status callStatus = + napi_call_function(innerWorker->observer_->env_, global, callback, 2, args, &result); + if (callStatus != napi_ok) { + LOG_ERROR("napi_call_function failed status : %{public}d", callStatus); + } + }); + if (ret != 0) { + LOG_ERROR("uv_queue_work failed"); + delete observerWorker; + delete work; } - LOG_INFO("%{public}s, called. end", __func__); } } // namespace DataShare } // namespace OHOS diff --git a/data_share/frameworks/js/napi/dataShare/src/native_datashare_module.cpp b/data_share/frameworks/js/napi/dataShare/src/native_datashare_module.cpp index 2ab308f5..a4cb3a7b 100644 --- a/data_share/frameworks/js/napi/dataShare/src/native_datashare_module.cpp +++ b/data_share/frameworks/js/napi/dataShare/src/native_datashare_module.cpp @@ -53,7 +53,7 @@ static napi_module _module = { /* * The module registration. */ -static __attribute__((constructor)) void RegisterModule(void) +extern "C" __attribute__((constructor)) void RegisterModule(void) { napi_module_register(&_module); } diff --git a/data_share/frameworks/js/napi/dataShare/src/native_datashare_predicates_module.cpp b/data_share/frameworks/js/napi/dataShare/src/native_datashare_predicates_module.cpp index 03ec4f1d..a26a45c4 100644 --- a/data_share/frameworks/js/napi/dataShare/src/native_datashare_predicates_module.cpp +++ b/data_share/frameworks/js/napi/dataShare/src/native_datashare_predicates_module.cpp @@ -50,7 +50,7 @@ static napi_module _module = { /* * The module registration. */ -static __attribute__((constructor)) void RegisterModule(void) +extern "C" __attribute__((constructor)) void RegisterModule(void) { napi_module_register(&_module); } diff --git a/data_share/frameworks/native/common/include/result_set.h b/data_share/frameworks/native/common/include/result_set.h index e0b85473..ff94b1df 100644 --- a/data_share/frameworks/native/common/include/result_set.h +++ b/data_share/frameworks/native/common/include/result_set.h @@ -17,7 +17,6 @@ #define NATIVE_DATASHARE_COMMON_INCLUDE_RESULT_SET_H #include -#include namespace OHOS { namespace DataShare { /* Value returned by getDataType(int) */ diff --git a/data_share/frameworks/native/common/src/datashare_abs_result_set.cpp b/data_share/frameworks/native/common/src/datashare_abs_result_set.cpp index 79f7de14..d2b58449 100644 --- a/data_share/frameworks/native/common/src/datashare_abs_result_set.cpp +++ b/data_share/frameworks/native/common/src/datashare_abs_result_set.cpp @@ -12,12 +12,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#define LOG_TAG "DataShareAbsResultSet" + #include "datashare_abs_result_set.h" #include #include "datashare_log.h" #include "datashare_errno.h" -#include namespace OHOS { namespace DataShare { diff --git a/data_share/frameworks/native/common/src/datashare_result.cpp b/data_share/frameworks/native/common/src/datashare_result.cpp index 0fb5ed46..1346a6b0 100644 --- a/data_share/frameworks/native/common/src/datashare_result.cpp +++ b/data_share/frameworks/native/common/src/datashare_result.cpp @@ -16,9 +16,11 @@ #include "datashare_result.h" #include "datashare_log.h" +#include "parcel_macro.h" namespace OHOS { namespace DataShare { +using namespace AppExecFwk; /** * @brief A constructor used to create a DataShareResult instance * with the input parameter count specified. @@ -112,9 +114,7 @@ bool DataShareResult::Marshalling(Parcel &parcel) const { // uri_ if (uri_.ToString().empty()) { - if (!parcel.WriteInt32(VALUE_NULL)) { - return false; - } + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, VALUE_NULL); } else { if (!parcel.WriteInt32(VALUE_OBJECT)) { return false; diff --git a/data_share/frameworks/native/common/src/datashare_values_bucket.cpp b/data_share/frameworks/native/common/src/datashare_values_bucket.cpp index 305d91d4..8e1ad6c3 100644 --- a/data_share/frameworks/native/common/src/datashare_values_bucket.cpp +++ b/data_share/frameworks/native/common/src/datashare_values_bucket.cpp @@ -14,6 +14,7 @@ */ #include "datashare_values_bucket.h" +#include "datashare_value_object.h" namespace OHOS { namespace DataShare { diff --git a/data_share/frameworks/native/consumer/include/datashare_connection.h b/data_share/frameworks/native/consumer/include/datashare_connection.h index 7242f2fb..e2acc0a5 100644 --- a/data_share/frameworks/native/consumer/include/datashare_connection.h +++ b/data_share/frameworks/native/consumer/include/datashare_connection.h @@ -17,7 +17,6 @@ #define DATASHARE_CONNECTION_H #include -#include #include "ability_connect_callback_stub.h" #include "event_handler.h" diff --git a/data_share/frameworks/native/provider/include/datashare_stub_impl.h b/data_share/frameworks/native/provider/include/datashare_stub_impl.h index 27dcb99e..a443bc53 100644 --- a/data_share/frameworks/native/provider/include/datashare_stub_impl.h +++ b/data_share/frameworks/native/provider/include/datashare_stub_impl.h @@ -20,6 +20,7 @@ #include "datashare_stub.h" #include "datashare_uv_queue.h" #include "js_datashare_ext_ability.h" +#include "native_engine/native_value.h" namespace OHOS { namespace DataShare { diff --git a/data_share/frameworks/native/provider/include/datashare_uv_queue.h b/data_share/frameworks/native/provider/include/datashare_uv_queue.h index 6a511082..34cac599 100644 --- a/data_share/frameworks/native/provider/include/datashare_uv_queue.h +++ b/data_share/frameworks/native/provider/include/datashare_uv_queue.h @@ -17,8 +17,6 @@ #define DATASHARE_UV_QUEUE_H #include -#include -#include #include "napi/native_api.h" #include "napi/native_common.h" diff --git a/data_share/frameworks/native/provider/include/js_datashare_ext_ability.h b/data_share/frameworks/native/provider/include/js_datashare_ext_ability.h index f3e505e8..f42e7892 100644 --- a/data_share/frameworks/native/provider/include/js_datashare_ext_ability.h +++ b/data_share/frameworks/native/provider/include/js_datashare_ext_ability.h @@ -20,9 +20,8 @@ #include "datashare_predicates.h" #include "datashare_ext_ability.h" #include "js_runtime.h" -#include "napi/native_api.h" -#include "napi/native_common.h" -#include "napi/native_node_api.h" +#include "native_engine/native_reference.h" +#include "native_engine/native_value.h" namespace OHOS { namespace DataShare { diff --git a/data_share/frameworks/native/provider/include/js_datashare_ext_ability_context.h b/data_share/frameworks/native/provider/include/js_datashare_ext_ability_context.h index 4c3492ac..e97c142a 100644 --- a/data_share/frameworks/native/provider/include/js_datashare_ext_ability_context.h +++ b/data_share/frameworks/native/provider/include/js_datashare_ext_ability_context.h @@ -20,8 +20,9 @@ #include "ability_connect_callback.h" #include "datashare_ext_ability_context.h" -class NativeEngine; -class NativeValue; +#include "native_engine/native_engine.h" +#include "native_engine/native_value.h" + namespace OHOS { namespace DataShare { using namespace AbilityRuntime; diff --git a/data_share/frameworks/native/provider/src/js_datashare_ext_ability_context.cpp b/data_share/frameworks/native/provider/src/js_datashare_ext_ability_context.cpp index 05b57261..fa1a9648 100644 --- a/data_share/frameworks/native/provider/src/js_datashare_ext_ability_context.cpp +++ b/data_share/frameworks/native/provider/src/js_datashare_ext_ability_context.cpp @@ -26,7 +26,7 @@ #include "napi_remote_object.h" #include "napi_common_start_options.h" #include "start_options.h" -#include "native_engine/native_value.h" + namespace OHOS { namespace DataShare { using namespace AbilityRuntime; diff --git a/data_share/interfaces/inner_api/BUILD.gn b/data_share/interfaces/inner_api/BUILD.gn index c53100b6..fdc2f4c6 100644 --- a/data_share/interfaces/inner_api/BUILD.gn +++ b/data_share/interfaces/inner_api/BUILD.gn @@ -12,7 +12,8 @@ # limitations under the License. import("//build/ohos.gni") -import("//foundation/distributeddatamgr/appdatamgr/data_share/datashare.gni") +import("//foundation/distributeddatamgr/data_share/datashare.gni") +import("//foundation/distributeddatamgr/relational_store/relational_store.gni") config("ability_config") { visibility = [ ":*" ] @@ -24,7 +25,7 @@ config("ability_config") { "${datashare_native_consumer_path}/include", "${datashare_native_provider_path}/include", "${ability_runtime_napi_path}/inner/napi_common", - "//foundation/distributeddatamgr/appdatamgr/relational_store/interfaces/inner_api/rdb/include", + "${relational_store_innerapi_path}/rdb/include", "//foundation/distributeddatamgr/distributeddatamgr/frameworks/innerkitsimpl/rdb/include", ] diff --git a/data_share/interfaces/inner_api/common/BUILD.gn b/data_share/interfaces/inner_api/common/BUILD.gn index 807f6e44..40592ed8 100644 --- a/data_share/interfaces/inner_api/common/BUILD.gn +++ b/data_share/interfaces/inner_api/common/BUILD.gn @@ -12,7 +12,7 @@ # limitations under the License. import("//build/ohos.gni") -import("//foundation/distributeddatamgr/appdatamgr/data_share/datashare.gni") +import("//foundation/distributeddatamgr/data_share/datashare.gni") config("ability_config") { visibility = [ ":*" ] diff --git a/data_share/interfaces/inner_api/consumer/include/datashare_helper.h b/data_share/interfaces/inner_api/consumer/include/datashare_helper.h index 8f8f87fa..125ab160 100644 --- a/data_share/interfaces/inner_api/consumer/include/datashare_helper.h +++ b/data_share/interfaces/inner_api/consumer/include/datashare_helper.h @@ -22,7 +22,7 @@ #include "context.h" #include "datashare_connection.h" -#include "appkit/ability_runtime/context/context.h" +#include "foundation/ability/ability_runtime/interfaces/kits/native/appkit/ability_runtime/context/context.h" #include "idatashare.h" #include "uri.h" #include "datashare_operation.h" diff --git a/data_share/interfaces/inner_api/provider/include/result_set_bridge.h b/data_share/interfaces/inner_api/provider/include/result_set_bridge.h index b0722713..3db71cc4 100644 --- a/data_share/interfaces/inner_api/provider/include/result_set_bridge.h +++ b/data_share/interfaces/inner_api/provider/include/result_set_bridge.h @@ -17,7 +17,6 @@ #define DATASHARE_RESULT_SET_BRIDGE_H #include -#include namespace OHOS { namespace DataShare { // build the bridge between the database's ResultSet and DataShare's ResultSet -- Gitee