!633 [Feature] Cangjie API FFI code

Merge pull request !633 from myc13381/dev_dataSharePredicates
This commit is contained in:
openharmony_ci 2024-11-19 06:18:36 +00:00 committed by Gitee
commit 03ab7c8b5e
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
10 changed files with 551 additions and 1 deletions

View File

@ -78,12 +78,24 @@
"//foundation/distributeddatamgr/data_share/interfaces/inner_api:datashare_provider",
"//foundation/distributeddatamgr/data_share/interfaces/inner_api/common:datashare_common",
"//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/frameworks/js/napi:datashare_napi_packages",
"//foundation/distributeddatamgr/data_share/frameworks/cj/ffi:datashare_cj_ffi_packages"
],
"service_group": [
]
},
"inner_api": [
{
"name": "//foundation/distributeddatamgr/data_share/frameworks/cj/ffi/data_share_predicates:cj_data_share_predicates_ffi",
"header": {
"header_files": [
"data_share_predicates_ffi.h",
"data_share_predicates_impl.h",
"data_share_predicates_utils.h"
],
"header_base": "//foundation/distributeddatamgr/data_share/frameworks/cj/ffi/data_share_predicates/include"
}
},
{
"name": "//foundation/distributeddatamgr/data_share/interfaces/inner_api:datashare_consumer",
"header": {

View File

@ -19,6 +19,8 @@ datashare_common_napi_path = "${datashare_base_path}/frameworks/js/napi/common"
datashare_napi_path = "${datashare_base_path}/frameworks/js/napi"
datashare_cj_ffi_path = "${datashare_base_path}/frameworks/cj/ffi"
datashare_innerapi_path = "${datashare_base_path}/interfaces/inner_api"
datashare_native_provider_path =

View File

@ -0,0 +1,19 @@
# Copyright (c) 2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/ohos.gni")
import("//foundation/distributeddatamgr/data_share/datashare.gni")
group("datashare_cj_ffi_packages") {
deps = [ "${datashare_cj_ffi_path}/data_share_predicates:cj_data_share_predicates_ffi" ]
}

View File

@ -0,0 +1,59 @@
# Copyright (c) 2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/ohos.gni")
import("//foundation/distributeddatamgr/data_share/datashare.gni")
config("public_ffi_config") {
include_dirs = [ "include" ]
cflags_cc = [ "-std=c++17" ]
}
ohos_shared_library("cj_data_share_predicates_ffi") {
branch_protector_ret = "pac_ret"
include_dirs = []
sanitize = {
cfi = true
cfi_cross_dso = true
debug = false
boundary_sanitize = true
integer_overflow = true
ubsan = true
}
public_configs = [ ":public_ffi_config" ]
sources = [
"src/data_share_predicates_ffi.cpp",
"src/data_share_predicates_impl.cpp",
"src/data_share_predicates_utils.cpp",
]
deps = [ "${datashare_innerapi_path}/common:datashare_common" ]
external_deps = [
"c_utils:utils",
"hilog:libhilog",
"napi:ace_napi",
"napi:cj_bind_ffi",
"napi:cj_bind_native",
"relational_store:native_rdb",
]
innerapi_tags = [ "platformsdk" ]
subsystem_name = "distributeddatamgr"
part_name = "data_share"
}

View File

@ -0,0 +1,58 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef DATA_SHARE_PREDICATES_FFI_H
#define DATA_SHARE_PREDICATES_FFI_H
#include "data_share_predicates_utils.h"
#include "ffi_remote_data.h"
namespace OHOS {
namespace DataShare {
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif
FFI_EXPORT int64_t FfiOHOSDataSharePredicatesCreateDataSharePredicates();
FFI_EXPORT int32_t FfiOHOSDataSharePredicatesEqualTo(int64_t id, const char *field, CValueType value);
FFI_EXPORT int32_t FfiOHOSDataSharePredicatesAnd(int64_t id);
FFI_EXPORT int32_t FfiOHOSDataSharePredicatesOrderByAsc(int64_t id, const char *field);
FFI_EXPORT int32_t FfiOHOSDataSharePredicatesOrderByDesc(int64_t id, const char *field);
FFI_EXPORT int32_t FfiOHOSDataSharePredicatesLimit(int64_t id, const int32_t field, const int32_t value);
FFI_EXPORT int32_t FfiOHOSDataSharePredicatesIn(int64_t id, const char *field, CValueType *values, int64_t valuesSize);
FFI_EXPORT int32_t FfiOHOSDataSharePredicatesOr(int64_t id);
FFI_EXPORT int32_t FfiOHOSDataSharePredicatesBeginWrap(int64_t id);
FFI_EXPORT int32_t FfiOHOSDataSharePredicatesEndWrap(int64_t id);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif
} // namespace DataShare
} // namespace OHOS
#endif // endif DATA_SHARE_PREDICATES_FFI_H

View File

@ -0,0 +1,59 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef DATA_SHARE_PREDICATES_IMPL_PREDICATES_H
#define DATA_SHARE_PREDICATES_IMPL_PREDICATES_H
#include <memory>
#include "cj_common_ffi.h"
#include "data_share_predicates_utils.h"
#include "ffi_remote_data.h"
namespace OHOS {
namespace DataShare {
class DataSharePredicatesImpl : public OHOS::FFI::FFIData {
DECL_TYPE(DataSharePredicatesImpl, OHOS::FFI::FFIData)
public:
explicit DataSharePredicatesImpl();
std::shared_ptr<DataSharePredicates> GetPredicates();
void EqualTo(const char *field, CValueType value);
void And();
void OrderByAsc(const char *field);
void OrderByDesc(const char *field);
void Limit(const int32_t total, const int32_t offset);
void In(const char *field, CValueType *values, int64_t valuesSize);
void Or();
void BeginWrap();
void EndWrap();
private:
std::shared_ptr<DataSharePredicates> predicates_;
};
} // namespace DataShare
} // namespace OHOS
#endif // endif DATA_SHARE_PREDICATES_IMPL_H

View File

@ -0,0 +1,41 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef DATA_SHARE_PREDICATES_UTILS_H
#define DATA_SHARE_PREDICATES_UTILS_H
#include <cstdint>
#include <memory>
#include "datashare_predicates.h"
#include "datashare_value_object.h"
#include "value_object.h"
namespace OHOS {
namespace DataShare {
struct CValueType {
int64_t integer;
double dou;
bool boolean;
char *string;
uint8_t tag;
};
SingleValue::Type parseValueType(const CValueType &value);
MutliValue::Type parseValueTypeArray(const CValueType *array, int64_t size);
} // namespace DataShare
} // namespace OHOS
#endif // endif DATA_SHARE_PREDICATES_UTILS_H

View File

@ -0,0 +1,133 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "data_share_predicates_ffi.h"
#include "data_share_predicates_impl.h"
#include "data_share_predicates_utils.h"
using namespace OHOS::FFI;
namespace OHOS {
namespace DataShare {
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif
int64_t FfiOHOSDataSharePredicatesCreateDataSharePredicates()
{
auto impl = FFIData::Create<DataSharePredicatesImpl>();
if (impl == nullptr) {
return -1;
}
return impl->GetID();
}
int32_t FfiOHOSDataSharePredicatesEqualTo(int64_t id, const char *field, CValueType value)
{
auto impl = FFIData::GetData<DataSharePredicatesImpl>(id);
if (impl == nullptr) {
return -1;
}
impl->EqualTo(field, value);
return 0;
}
int32_t FfiOHOSDataSharePredicatesAnd(int64_t id)
{
auto impl = FFIData::GetData<DataSharePredicatesImpl>(id);
if (impl == nullptr) {
return -1;
}
impl->And();
return 0;
}
int32_t FfiOHOSDataSharePredicatesOrderByAsc(int64_t id, const char *field)
{
auto impl = FFIData::GetData<DataSharePredicatesImpl>(id);
if (impl == nullptr) {
return -1;
}
impl->OrderByAsc(field);
return 0;
}
int32_t FfiOHOSDataSharePredicatesOrderByDesc(int64_t id, const char *field)
{
auto impl = FFIData::GetData<DataSharePredicatesImpl>(id);
if (impl == nullptr) {
return -1;
}
impl->OrderByDesc(field);
return 0;
}
int32_t FfiOHOSDataSharePredicatesLimit(int64_t id, const int32_t field, const int32_t value)
{
auto impl = FFIData::GetData<DataSharePredicatesImpl>(id);
if (impl == nullptr) {
return -1;
}
impl->Limit(field, value);
return 0;
}
int32_t FfiOHOSDataSharePredicatesIn(int64_t id, const char *field, CValueType *values, int64_t valuesSize)
{
auto impl = FFIData::GetData<DataSharePredicatesImpl>(id);
if (impl == nullptr) {
return -1;
}
impl->In(field, values, valuesSize);
return 0;
}
int32_t FfiOHOSDataSharePredicatesOr(int64_t id)
{
auto impl = FFIData::GetData<DataSharePredicatesImpl>(id);
if (impl == nullptr) {
return -1;
}
impl->Or();
return 0;
}
int32_t FfiOHOSDataSharePredicatesBeginWrap(int64_t id)
{
auto impl = FFIData::GetData<DataSharePredicatesImpl>(id);
if (impl == nullptr) {
return -1;
}
impl->BeginWrap();
return 0;
}
int32_t FfiOHOSDataSharePredicatesEndWrap(int64_t id)
{
auto impl = FFIData::GetData<DataSharePredicatesImpl>(id);
if (impl == nullptr) {
return -1;
}
impl->EndWrap();
return 0;
}
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif
} // namespace DataShare
} // namespace OHOS

View File

@ -0,0 +1,83 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "data_share_predicates_impl.h"
#include "data_share_predicates_utils.h"
namespace OHOS {
namespace DataShare {
DataSharePredicatesImpl::DataSharePredicatesImpl()
{
predicates_ = std::make_shared<DataSharePredicates>();
}
std::shared_ptr<DataSharePredicates> DataSharePredicatesImpl::GetPredicates()
{
return this->predicates_;
}
void DataSharePredicatesImpl::EqualTo(const char *field, CValueType value)
{
std::string cField = field;
SingleValue::Type valueObject = parseValueType(value);
predicates_->EqualTo(cField, valueObject);
}
void DataSharePredicatesImpl::And()
{
predicates_->And();
}
void DataSharePredicatesImpl::OrderByAsc(const char *field)
{
std::string cField = field;
predicates_->OrderByAsc(cField);
}
void DataSharePredicatesImpl::OrderByDesc(const char *field)
{
std::string cField = field;
predicates_->OrderByDesc(cField);
}
void DataSharePredicatesImpl::Limit(const int32_t total, const int32_t offset)
{
predicates_->Limit(static_cast<int>(total), static_cast<int>(offset));
}
void DataSharePredicatesImpl::In(const char *field, CValueType *values, int64_t valuesSize)
{
std::string cField = field;
auto valuesArray = parseValueTypeArray(values, valuesSize);
predicates_->In(cField, valuesArray);
}
void DataSharePredicatesImpl::Or()
{
predicates_->Or();
}
void DataSharePredicatesImpl::BeginWrap()
{
predicates_->BeginWrap();
}
void DataSharePredicatesImpl::EndWrap()
{
predicates_->EndWrap();
}
} // namespace DataShare
} // namespace OHOS

View File

@ -0,0 +1,84 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "data_share_predicates_utils.h"
namespace OHOS {
namespace DataShare {
SingleValue::Type parseValueType(const CValueType &value)
{
SingleValue::Type ret;
switch (static_cast<int32_t>(value.tag)) {
case DataShareValueObjectType::TYPE_INT: {
ret = value.integer;
break;
}
case DataShareValueObjectType::TYPE_DOUBLE: {
ret = value.dou;
break;
}
case DataShareValueObjectType::TYPE_STRING: {
ret = std::string(value.string);
break;
}
case DataShareValueObjectType::TYPE_BOOL: {
ret = value.boolean;
break;
}
default:
ret = 0;
break;
}
return ret;
}
MutliValue::Type parseValueTypeArray(const CValueType *array, int64_t size)
{
MutliValue::Type ret;
CValueType value = array[0];
switch (static_cast<int32_t>(value.tag)) {
case DataShareValueObjectType::TYPE_INT: {
std::vector<int> arr(size);
for (int64_t i = 0; i < size; ++i) {
arr[i] = array[i].integer;
}
ret = arr;
break;
}
case DataShareValueObjectType::TYPE_DOUBLE: {
std::vector<double> arr(size);
for (int64_t i = 0; i < size; ++i) {
arr[i] = array[i].dou;
}
ret = arr;
break;
}
case DataShareValueObjectType::TYPE_STRING: {
std::vector<std::string> arr(size);
for (int64_t i = 0; i < size; ++i) {
arr[i] = std::string(array[i].string);
}
ret = arr;
break;
}
default:
break;
}
return ret;
}
} // namespace DataShare
} // namespace OHOS