mirror of
https://gitee.com/openharmony/distributeddatamgr_udmf
synced 2024-10-06 21:33:30 +00:00
fix crossPlatformcompile
Signed-off-by: quguiren <quguiren@huawei.com>
This commit is contained in:
parent
06b2b87671
commit
cb5d43d210
3
adapter/BUILD.gn
Normal file → Executable file
3
adapter/BUILD.gn
Normal file → Executable file
@ -73,6 +73,7 @@ config("arkui_x_udmf_config") {
|
||||
}
|
||||
|
||||
arkui_x_public_source = [
|
||||
"${udmf_framework_path}/innerkitsimpl/client/getter_system.cpp",
|
||||
"${udmf_framework_path}/innerkitsimpl/common/unified_key.cpp",
|
||||
"${udmf_framework_path}/innerkitsimpl/common/unified_meta.cpp",
|
||||
"${udmf_framework_path}/innerkitsimpl/data/application_defined_record.cpp",
|
||||
@ -102,9 +103,9 @@ ohos_source_set("arkui_x_udmf_data") {
|
||||
"${udmf_framework_path}/common/custom_utd_json_parser.cpp",
|
||||
"${udmf_framework_path}/common/custom_utd_store.cpp",
|
||||
"${udmf_framework_path}/common/graph.cpp",
|
||||
"${udmf_framework_path}/common/udmf_utils.cpp",
|
||||
"${udmf_framework_path}/common/utd_cfgs_checker.cpp",
|
||||
"${udmf_framework_path}/common/utd_graph.cpp",
|
||||
"${udmf_root_path}/adapter/framework/common/udmf_utils.cpp",
|
||||
]
|
||||
|
||||
sources += arkui_x_public_source
|
||||
|
65
adapter/framework/common/udmf_utils.cpp
Executable file
65
adapter/framework/common/udmf_utils.cpp
Executable file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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 "udmf_utils.h"
|
||||
#include <random>
|
||||
#include <sstream>
|
||||
|
||||
namespace OHOS {
|
||||
namespace UDMF {
|
||||
namespace UTILS {
|
||||
static constexpr int ID_LEN = 32;
|
||||
static constexpr int MINIMUM = 48;
|
||||
static constexpr int MAXIMUM = 121;
|
||||
constexpr char SPECIAL = '^';
|
||||
|
||||
std::vector<std::string> StrSplit(const std::string &str, const std::string &delimiter)
|
||||
{
|
||||
std::vector<std::string> result;
|
||||
size_t start = 0;
|
||||
size_t end = str.find(delimiter);
|
||||
while (end != std::string::npos) {
|
||||
result.push_back(str.substr(start, end - start));
|
||||
start = end + delimiter.length();
|
||||
end = str.find(delimiter, start);
|
||||
}
|
||||
result.push_back(str.substr(start));
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> Random(int32_t len, int32_t minimum, int32_t maximum)
|
||||
{
|
||||
std::random_device randomDevice;
|
||||
std::uniform_int_distribution<int> distribution(minimum, maximum);
|
||||
std::vector<uint8_t> key(len);
|
||||
for (int32_t i = 0; i < len; i++) {
|
||||
key[i] = static_cast<uint8_t>(distribution(randomDevice));
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
std::string GenerateId()
|
||||
{
|
||||
std::vector<uint8_t> randomDevices = Random(ID_LEN, MINIMUM, MAXIMUM);
|
||||
std::stringstream idStr;
|
||||
for (auto &randomDevice : randomDevices) {
|
||||
auto asc = randomDevice;
|
||||
asc = asc >= SPECIAL ? asc + 1 : asc;
|
||||
idStr << static_cast<uint8_t>(asc);
|
||||
}
|
||||
return idStr.str();
|
||||
}
|
||||
} // namespace UTILS
|
||||
} // namespace UDMF
|
||||
} // namespace OHOS
|
33
adapter/framework/common/udmf_utils.h
Executable file
33
adapter/framework/common/udmf_utils.h
Executable file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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 UDMF_UTILS_H
|
||||
#define UDMF_UTILS_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
namespace OHOS {
|
||||
namespace UDMF {
|
||||
namespace UTILS {
|
||||
std::vector<std::string> StrSplit(const std::string &str, const std::string &delimiter);
|
||||
std::vector<uint8_t> Random(int32_t len, int32_t minimum = 0,
|
||||
int32_t maximum = std::numeric_limits<uint8_t>::max());
|
||||
std::string GenerateId();
|
||||
|
||||
} // namespace UTILS
|
||||
} // namespace UDMF
|
||||
} // namespace OHOS
|
||||
|
||||
#endif /* UDMF_UTILS_H */
|
60
adapter/framework/innerkitsimpl/client/udmf_client.h
Executable file
60
adapter/framework/innerkitsimpl/client/udmf_client.h
Executable file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 UDMF_CLIENT_H
|
||||
#define UDMF_CLIENT_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <shared_mutex>
|
||||
|
||||
#include "concurrent_map.h"
|
||||
#include "error_code.h"
|
||||
#include "unified_data.h"
|
||||
#include "unified_meta.h"
|
||||
#include "unified_types.h"
|
||||
#include "visibility.h"
|
||||
namespace OHOS {
|
||||
namespace UDMF {
|
||||
class API_EXPORT UdmfClient {
|
||||
public:
|
||||
static UdmfClient &GetInstance();
|
||||
|
||||
Status SetData(CustomOption &option, UnifiedData &unifiedData, std::string &key);
|
||||
Status GetData(const QueryOption &query, UnifiedData &unifiedData);
|
||||
Status GetBatchData(const QueryOption &query, std::vector<UnifiedData> &unifiedDataSet);
|
||||
Status UpdateData(const QueryOption &query, UnifiedData &unifiedData);
|
||||
Status DeleteData(const QueryOption &query, std::vector<UnifiedData> &unifiedDataSet);
|
||||
Status GetSummary(const QueryOption &query, Summary& summary);
|
||||
Status AddPrivilege(const QueryOption &query, Privilege &privilege);
|
||||
Status Sync(const QueryOption &query, const std::vector<std::string> &devices);
|
||||
Status IsRemoteData(const QueryOption &query, bool &result);
|
||||
Status SetAppShareOption(const std::string &intention, enum ShareOptions shareOption);
|
||||
Status RemoveAppShareOption(const std::string &intention);
|
||||
Status GetAppShareOption(const std::string &intention, enum ShareOptions &shareOption);
|
||||
|
||||
private:
|
||||
UdmfClient() = default;
|
||||
~UdmfClient() = default;
|
||||
UdmfClient(const UdmfClient &obj) = delete;
|
||||
UdmfClient &operator=(const UdmfClient &obj) = delete;
|
||||
std::string GetSelfBundleName();
|
||||
|
||||
ConcurrentMap<std::string, UnifiedData> dataCache_;
|
||||
};
|
||||
} // namespace UDMF
|
||||
} // namespace OHOS
|
||||
#endif // UDMF_CLIENT_H
|
27
adapter/framework/innerkitsimpl/client/utd_client.cpp
Normal file → Executable file
27
adapter/framework/innerkitsimpl/client/utd_client.cpp
Normal file → Executable file
@ -70,5 +70,32 @@ Status UtdClient::IsUtd(std::string typeId, bool &result)
|
||||
{
|
||||
return Status::E_OK;
|
||||
}
|
||||
|
||||
Status UtdClient::GetUniformDataTypesByFilenameExtension(const std::string &fileExtension,
|
||||
std::vector<std::string> &typeIds, const std::string &belongsTo)
|
||||
{
|
||||
return Status::E_OK;
|
||||
}
|
||||
|
||||
std::string UtdClient::GetTypeIdFromCfg(const std::string &mimeType)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
std::vector<std::string> UtdClient::GetTypeIdsFromCfg(const std::string &mimeType)
|
||||
{
|
||||
std::vector<std::string> typeIdsInCfg;
|
||||
return typeIdsInCfg;
|
||||
}
|
||||
|
||||
void UtdClient::SubscribeUtdChange()
|
||||
{
|
||||
}
|
||||
|
||||
Status UtdClient::GetUniformDataTypesByMIMEType(const std::string &mimeType, std::vector<std::string> &typeIds,
|
||||
const std::string &belongsTo)
|
||||
{
|
||||
return Status::E_OK;
|
||||
}
|
||||
} // namespace UDMF
|
||||
} // namespace OHOS
|
||||
|
71
adapter/framework/innerkitsimpl/client/utd_client.h
Executable file
71
adapter/framework/innerkitsimpl/client/utd_client.h
Executable file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 UTD_CLIENT_H
|
||||
#define UTD_CLIENT_H
|
||||
|
||||
#include <shared_mutex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "error_code.h"
|
||||
#include "flexible_type.h"
|
||||
#include "preset_type_descriptors.h"
|
||||
#include "preset_type_descriptors.h"
|
||||
#include "type_descriptor.h"
|
||||
#include "utd_common.h"
|
||||
#include "visibility.h"
|
||||
namespace OHOS {
|
||||
namespace UDMF {
|
||||
class TypeDescriptor;
|
||||
class UtdChangeSubscriber;
|
||||
class API_EXPORT UtdClient {
|
||||
public:
|
||||
static UtdClient &GetInstance();
|
||||
Status GetTypeDescriptor(const std::string &typeId, std::shared_ptr<TypeDescriptor> &descriptor);
|
||||
Status GetUniformDataTypeByFilenameExtension(const std::string &fileExtension, std::string &typeId,
|
||||
std::string belongsTo = DEFAULT_TYPE_ID);
|
||||
Status GetUniformDataTypesByFilenameExtension(const std::string &fileExtension,
|
||||
std::vector<std::string> &typeIds, const std::string &belongsTo = DEFAULT_TYPE_ID);
|
||||
Status GetUniformDataTypeByMIMEType(const std::string &mimeType, std::string &typeId,
|
||||
std::string belongsTo = DEFAULT_TYPE_ID);
|
||||
Status GetUniformDataTypesByMIMEType(const std::string &mimeType, std::vector<std::string> &typeIds,
|
||||
const std::string &belongsTo = DEFAULT_TYPE_ID);
|
||||
Status IsUtd(std::string typeId, bool &result);
|
||||
|
||||
private:
|
||||
UtdClient();
|
||||
~UtdClient();
|
||||
UtdClient(const UtdClient &obj) = delete;
|
||||
UtdClient &operator=(const UtdClient &obj) = delete;
|
||||
void Init();
|
||||
bool IsHapTokenType();
|
||||
std::string GetCustomUtdPath();
|
||||
Status GetCurrentActiveUserId(int32_t& userId);
|
||||
bool IsValidFileExtension(const std::string &fileExtension);
|
||||
bool IsValidMimeType(const std::string &mimeType);
|
||||
Status GetFlexibleTypeDescriptor(const std::string &typeId, std::shared_ptr<TypeDescriptor> &descriptor);
|
||||
std::string GetTypeIdFromCfg(const std::string &mimeType);
|
||||
std::vector<std::string> GetTypeIdsFromCfg(const std::string &mimeType);
|
||||
void SubscribeUtdChange();
|
||||
|
||||
std::vector<TypeDescriptorCfg> descriptorCfgs_;
|
||||
std::shared_ptr<UtdChangeSubscriber> subscriber_;
|
||||
std::shared_mutex utdMutex_;
|
||||
};
|
||||
} // namespace UDMF
|
||||
} // namespace OHOS
|
||||
#endif // UTD_CLIENT_H
|
Loading…
Reference in New Issue
Block a user