mirror of
https://gitee.com/openharmony/distributeddatamgr_udmf
synced 2024-10-07 13:53:49 +00:00
utd find
Signed-off-by: genglingxia <genglingxia3@huawei.com>
This commit is contained in:
parent
24ea2ac2bc
commit
58283a107b
@ -50,7 +50,8 @@
|
|||||||
"name": "//foundation/distributeddatamgr/udmf/interfaces/innerkits:udmf_client",
|
"name": "//foundation/distributeddatamgr/udmf/interfaces/innerkits:udmf_client",
|
||||||
"header": {
|
"header": {
|
||||||
"header_files": [
|
"header_files": [
|
||||||
"udmf_client.h"
|
"udmf_client.h",
|
||||||
|
"utd_client.h"
|
||||||
],
|
],
|
||||||
"header_base":"//foundation/distributeddatamgr/udmf/interfaces/innerkits/client"
|
"header_base":"//foundation/distributeddatamgr/udmf/interfaces/innerkits/client"
|
||||||
}
|
}
|
||||||
@ -85,6 +86,7 @@
|
|||||||
"system_defined_pixelmap.h",
|
"system_defined_pixelmap.h",
|
||||||
"system_defined_record.h",
|
"system_defined_record.h",
|
||||||
"text.h",
|
"text.h",
|
||||||
|
"type_descriptor.h",
|
||||||
"unified_data.h",
|
"unified_data.h",
|
||||||
"unified_record.h",
|
"unified_record.h",
|
||||||
"video.h"
|
"video.h"
|
||||||
|
87
framework/common/graph.cpp
Normal file
87
framework/common/graph.cpp
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
#include "graph.h"
|
||||||
|
#include "securec.h"
|
||||||
|
using namespace std;
|
||||||
|
namespace OHOS {
|
||||||
|
namespace UDMF {
|
||||||
|
void Graph::CreateAdjList(uint32_t vesNum, vector<vector<uint32_t>> edges)
|
||||||
|
{
|
||||||
|
vesNum_=vesNum;
|
||||||
|
for (uint32_t node = 0; node < vesNum_; node++) {
|
||||||
|
adjList_[node].value=node;
|
||||||
|
adjList_[node].firstEdge = nullptr;
|
||||||
|
}
|
||||||
|
uint32_t start;
|
||||||
|
uint32_t end;
|
||||||
|
EdgeNode *edge;
|
||||||
|
for (auto edgeNode : edges) {
|
||||||
|
start=edgeNode[0];
|
||||||
|
end=edgeNode[1];
|
||||||
|
edge = new EdgeNode; // add new edge
|
||||||
|
edge->adjIndex = end;
|
||||||
|
edge->next = adjList_[start].firstEdge;
|
||||||
|
adjList_[start].firstEdge = edge;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Graph::Dfs(uint32_t startNode, bool isInit, Action action)
|
||||||
|
{
|
||||||
|
if (isInit) {
|
||||||
|
(void)memset_s(visited_, sizeof(visited_), 0, sizeof(visited_));
|
||||||
|
}
|
||||||
|
stack <uint32_t>nodes;
|
||||||
|
EdgeNode *edge = nullptr;
|
||||||
|
visited_[startNode]=1;
|
||||||
|
nodes.push(startNode);
|
||||||
|
if (action(adjList_[startNode].value)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
while (!nodes.empty()) {
|
||||||
|
edge = adjList_[nodes.top()].firstEdge;
|
||||||
|
while (edge) {
|
||||||
|
if (visited_[edge->adjIndex] == 0) {
|
||||||
|
visited_[edge->adjIndex]=1;
|
||||||
|
if (action(adjList_[edge->adjIndex].value)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
nodes.push(edge->adjIndex);
|
||||||
|
edge = adjList_[edge->adjIndex].firstEdge;
|
||||||
|
} else {
|
||||||
|
edge=edge->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (edge == nullptr) {
|
||||||
|
nodes.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<uint32_t> Graph::DfsUnconnectedGraph()
|
||||||
|
{
|
||||||
|
(void)memset_s(visited_, sizeof(visited_), 0, sizeof(visited_));
|
||||||
|
vector<uint32_t> result;
|
||||||
|
for (uint32_t node = 0; node < vesNum_; node++) {
|
||||||
|
if (!visited_[node]) {
|
||||||
|
Dfs(node, false, [&](uint32_t currNode) -> bool {
|
||||||
|
result.push_back(currNode);
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
} // namespace UDMF
|
||||||
|
} // namespace OHOS
|
49
framework/common/graph.h
Normal file
49
framework/common/graph.h
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* 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_GRAPH_H
|
||||||
|
#define UDMF_GRAPH_H
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <iostream>
|
||||||
|
#include <stack>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace OHOS {
|
||||||
|
namespace UDMF {
|
||||||
|
struct EdgeNode { // 边表结点
|
||||||
|
uint32_t adjIndex; // 存储顶点的下标
|
||||||
|
EdgeNode* next; // 连接下一个邻点
|
||||||
|
};
|
||||||
|
|
||||||
|
struct VertexNode { // 顶点表结点
|
||||||
|
int value;
|
||||||
|
EdgeNode* firstEdge;
|
||||||
|
};
|
||||||
|
using Action = std::function<bool(uint32_t node)>;
|
||||||
|
class Graph {
|
||||||
|
public:
|
||||||
|
void CreateAdjList(uint32_t vesNum, std::vector<std::vector<uint32_t>> edges);
|
||||||
|
void Dfs(uint32_t startNode, bool isInit, Action action); // 指定点遍历,指定条件结束
|
||||||
|
std::vector<uint32_t> DfsUnconnectedGraph(); // dfs非联通图完全遍历
|
||||||
|
private:
|
||||||
|
static constexpr uint32_t MAX_LENGTH = 500;
|
||||||
|
uint32_t vesNum_; // 顶点数
|
||||||
|
VertexNode adjList_[MAX_LENGTH]; // 邻接表
|
||||||
|
uint32_t visited_[MAX_LENGTH]; // 判断是否有被访问过, 下标=顶点值
|
||||||
|
};
|
||||||
|
} // namespace UDMF
|
||||||
|
} // namespace OHOS
|
||||||
|
#endif // UDMF_GRAPH_H
|
@ -390,7 +390,7 @@ bool Reading(UDType &output, TLVObject &data)
|
|||||||
if (!Reading(type, data)) {
|
if (!Reading(type, data)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (type < UDType::TEXT || type >= UDType::UD_BUTT) {
|
if (type < UDType::ENTITY || type >= UDType::UD_BUTT) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
output = static_cast<UDType>(type);
|
output = static_cast<UDType>(type);
|
||||||
|
@ -164,7 +164,7 @@ bool Unmarshalling(UDType &output, MessageParcel &parcel)
|
|||||||
LOG_ERROR(UDMF_FRAMEWORK, "Unmarshal UDType failed!");
|
LOG_ERROR(UDMF_FRAMEWORK, "Unmarshal UDType failed!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (type < TEXT || type >= UD_BUTT) {
|
if (type < ENTITY || type >= UD_BUTT) {
|
||||||
LOG_ERROR(UDMF_FRAMEWORK, "invalid UDType!");
|
LOG_ERROR(UDMF_FRAMEWORK, "invalid UDType!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
68
framework/common/utd_graph.cpp
Normal file
68
framework/common/utd_graph.cpp
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "utd_graph.h"
|
||||||
|
#include "logger.h"
|
||||||
|
namespace OHOS {
|
||||||
|
namespace UDMF {
|
||||||
|
UtdGraph::UtdGraph()
|
||||||
|
{
|
||||||
|
LOG_INFO(UDMF_CLIENT, "construct UtdGraph sucess.");
|
||||||
|
}
|
||||||
|
|
||||||
|
UtdGraph::~UtdGraph()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
UtdGraph &UtdGraph::GetInstance()
|
||||||
|
{
|
||||||
|
static auto instance = new UtdGraph();
|
||||||
|
return *instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t UtdGraph::GetLocateIndex(const std::string &node) // 顶点数据和下标转换
|
||||||
|
{
|
||||||
|
std::shared_lock<decltype(vesNodesMutex_)> vesNodesLock(vesNodesMutex_);
|
||||||
|
return vesNodes_.at(node);
|
||||||
|
}
|
||||||
|
void UtdGraph::AddLocateDatas(uint32_t index, std::string node)
|
||||||
|
{
|
||||||
|
std::unique_lock<std::shared_mutex> vesNodesLock(vesNodesMutex_);
|
||||||
|
vesNodes_.insert({ node, index });
|
||||||
|
}
|
||||||
|
|
||||||
|
void UtdGraph::SetDataToGraph(uint32_t vesNum, std::vector<std::vector<uint32_t>> edges)
|
||||||
|
{
|
||||||
|
std::unique_lock<std::shared_mutex> graphLock(graphMutex_);
|
||||||
|
graph_.CreateAdjList(vesNum, edges);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UtdGraph::IsRelatedOrNot(const std::string &startNode, const std::string &endNode)
|
||||||
|
{
|
||||||
|
bool isFind = false;
|
||||||
|
uint32_t start = GetLocateIndex(startNode);
|
||||||
|
uint32_t end = GetLocateIndex(endNode);
|
||||||
|
std::shared_lock<decltype(graphMutex_)> graphLock(graphMutex_);
|
||||||
|
graph_.Dfs(start, true, [&](uint32_t currNode)-> bool {
|
||||||
|
if (end==currNode) {
|
||||||
|
isFind= true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
return isFind;
|
||||||
|
}
|
||||||
|
} // namespace UDMF
|
||||||
|
} // namespace OHOS
|
47
framework/common/utd_graph.h
Normal file
47
framework/common/utd_graph.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* 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_UTD_GRAPH_H
|
||||||
|
#define UDMF_UTD_GRAPH_H
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
|
#include <stack>
|
||||||
|
#include <string>
|
||||||
|
#include <shared_mutex>
|
||||||
|
#include <graph.h>
|
||||||
|
|
||||||
|
namespace OHOS {
|
||||||
|
namespace UDMF {
|
||||||
|
class UtdGraph {
|
||||||
|
public:
|
||||||
|
static UtdGraph &GetInstance();
|
||||||
|
uint32_t GetLocateIndex(const std::string &node); // 顶点数据和下标转换
|
||||||
|
void AddLocateDatas(uint32_t index, std::string node);
|
||||||
|
void SetDataToGraph(uint32_t vesNum, std::vector<std::vector<uint32_t>> edges);
|
||||||
|
bool IsRelatedOrNot(const std::string &startNode, const std::string &endNode);
|
||||||
|
private:
|
||||||
|
UtdGraph();
|
||||||
|
~UtdGraph();
|
||||||
|
UtdGraph(const UtdGraph &obj) = delete;
|
||||||
|
UtdGraph &operator=(const UtdGraph &obj) = delete;
|
||||||
|
mutable std::shared_mutex graphMutex_;
|
||||||
|
Graph graph_;
|
||||||
|
mutable std::shared_mutex vesNodesMutex_;
|
||||||
|
std::map<std::string, uint32_t> vesNodes_;
|
||||||
|
};
|
||||||
|
} // namespace UDMF
|
||||||
|
} // namespace OHOS
|
||||||
|
#endif // UDMF_UTD_GRAPH_H
|
@ -16,11 +16,13 @@
|
|||||||
#include "utd_client.h"
|
#include "utd_client.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "preset_type_descriptors.h"
|
#include "preset_type_descriptors.h"
|
||||||
|
#include "utd_graph.h"
|
||||||
namespace OHOS {
|
namespace OHOS {
|
||||||
namespace UDMF {
|
namespace UDMF {
|
||||||
UtdClient::UtdClient()
|
UtdClient::UtdClient()
|
||||||
{
|
{
|
||||||
|
descriptors_ = PresetTypeDescriptors::GetInstance().GetTypeDescriptors();
|
||||||
|
SetDataToGraph();
|
||||||
LOG_INFO(UDMF_CLIENT, "construct UtdClient sucess.");
|
LOG_INFO(UDMF_CLIENT, "construct UtdClient sucess.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,15 +38,69 @@ UtdClient &UtdClient::GetInstance()
|
|||||||
|
|
||||||
Status UtdClient::GetTypeDescriptor(const std::string &typeId, std::shared_ptr<TypeDescriptor> &descriptor)
|
Status UtdClient::GetTypeDescriptor(const std::string &typeId, std::shared_ptr<TypeDescriptor> &descriptor)
|
||||||
{
|
{
|
||||||
descriptors_ = PresetTypeDescriptors::GetInstance().GetTypeDescriptors();
|
|
||||||
for (const auto &utdType : descriptors_) {
|
for (const auto &utdType : descriptors_) {
|
||||||
if (utdType.GetTypeId() == typeId) {
|
if (utdType.GetTypeId() == typeId) {
|
||||||
descriptor = std::make_shared<TypeDescriptor>(utdType);
|
descriptor = std::make_shared<TypeDescriptor>(utdType);
|
||||||
LOG_DEBUG(UDMF_CLIENT, "get descriptor success. %{public}s ", typeId.c_str());
|
LOG_DEBUG(UDMF_CLIENT, "get descriptor success. %{public}s ", typeId.c_str());
|
||||||
|
return Status::E_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Status::E_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
Status UtdClient::GetUniformDataTypeByFilenameExtension(const std::string &fileExtension, const std::string &belongs,
|
||||||
|
std::string &typeId)
|
||||||
|
{
|
||||||
|
for (auto &utdType : descriptors_) {
|
||||||
|
std::vector<std::string> filenameExtensions = utdType.GetFilenameExtensions();
|
||||||
|
if (find(filenameExtensions.begin(), filenameExtensions.end(), fileExtension) != filenameExtensions.end()) {
|
||||||
|
typeId = utdType.GetTypeId();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// the find typeId is not belongs to the belongs.
|
||||||
|
if (!typeId.empty() && !belongs.empty() && belongs != typeId &&
|
||||||
|
!UtdGraph::GetInstance().IsRelatedOrNot(belongs, typeId)) {
|
||||||
|
typeId = "";
|
||||||
|
}
|
||||||
return Status::E_OK;
|
return Status::E_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Status UtdClient::GetUniformDataTypeByMIMEType(const std::string &mimeType, const std::string &belongs,
|
||||||
|
std::string &typeId)
|
||||||
|
{
|
||||||
|
for (auto &utdType : descriptors_) {
|
||||||
|
std::vector<std::string> mimeTypes = utdType.GetMimeTypes();
|
||||||
|
if (find(mimeTypes.begin(), mimeTypes.end(), mimeType) != mimeTypes.end()) {
|
||||||
|
typeId = utdType.GetTypeId();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// the find typeId is not belongs to the belongs.
|
||||||
|
if (!typeId.empty() && !belongs.empty() && belongs != typeId &&
|
||||||
|
!UtdGraph::GetInstance().IsRelatedOrNot(belongs, typeId)) {
|
||||||
|
typeId = "";
|
||||||
|
}
|
||||||
|
return Status::E_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UtdClient::SetDataToGraph()
|
||||||
|
{
|
||||||
|
uint32_t descriptorsNum = static_cast<uint32_t>(descriptors_.size());
|
||||||
|
for (uint32_t i = 0; i < descriptorsNum; i++) {
|
||||||
|
UtdGraph::GetInstance().AddLocateDatas(i, descriptors_[i].GetTypeId());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::vector<uint32_t>> edges;
|
||||||
|
for (auto &descriptor : descriptors_) {
|
||||||
|
std::set<std::string> belongs = descriptor.GetBelongingToTypes();
|
||||||
|
for (auto belongType : belongs) {
|
||||||
|
edges.push_back({UtdGraph::GetInstance().GetLocateIndex(belongType),
|
||||||
|
UtdGraph::GetInstance().GetLocateIndex(descriptor.GetTypeId())});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UtdGraph::GetInstance().SetDataToGraph(descriptorsNum, edges);
|
||||||
|
}
|
||||||
} // namespace UDMF
|
} // namespace UDMF
|
||||||
} // namespace OHOS
|
} // namespace OHOS
|
@ -21,7 +21,7 @@ namespace OHOS {
|
|||||||
namespace UDMF {
|
namespace UDMF {
|
||||||
bool UnifiedDataUtils::IsValidType(int32_t value)
|
bool UnifiedDataUtils::IsValidType(int32_t value)
|
||||||
{
|
{
|
||||||
return value >= TEXT && value < UD_BUTT;
|
return value >= ENTITY && value < UD_BUTT;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UnifiedDataUtils::IsValidIntention(int32_t value)
|
bool UnifiedDataUtils::IsValidIntention(int32_t value)
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -14,8 +14,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "type_descriptor.h"
|
#include "type_descriptor.h"
|
||||||
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
#include "utd_graph.h"
|
||||||
|
|
||||||
namespace OHOS {
|
namespace OHOS {
|
||||||
namespace UDMF {
|
namespace UDMF {
|
||||||
@ -31,6 +31,24 @@ TypeDescriptor::~TypeDescriptor()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TypeDescriptor::BelongsTo(const std::string &typeId)
|
||||||
|
{
|
||||||
|
if (typeId_ == typeId) {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
return UtdGraph::GetInstance().IsRelatedOrNot(typeId, typeId_);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TypeDescriptor::IsLowerLevelType(const std::string &typeId)
|
||||||
|
{
|
||||||
|
return UtdGraph::GetInstance().IsRelatedOrNot(typeId, typeId_);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TypeDescriptor::IsHigherLevelType(const std::string &typeId)
|
||||||
|
{
|
||||||
|
return UtdGraph::GetInstance().IsRelatedOrNot(typeId_, typeId);
|
||||||
|
}
|
||||||
|
|
||||||
bool TypeDescriptor::Equals(std::shared_ptr<TypeDescriptor> descriptor)
|
bool TypeDescriptor::Equals(std::shared_ptr<TypeDescriptor> descriptor)
|
||||||
{
|
{
|
||||||
return descriptor->GetTypeId() == this->GetTypeId();
|
return descriptor->GetTypeId() == this->GetTypeId();
|
||||||
|
@ -24,7 +24,7 @@ UnifiedRecord::UnifiedRecord()
|
|||||||
|
|
||||||
UnifiedRecord::UnifiedRecord(UDType type)
|
UnifiedRecord::UnifiedRecord(UDType type)
|
||||||
{
|
{
|
||||||
if (type < TEXT || type > UD_BUTT) {
|
if (type < ENTITY || type > UD_BUTT) {
|
||||||
dataType_ = UD_BUTT;
|
dataType_ = UD_BUTT;
|
||||||
}
|
}
|
||||||
dataType_ = type;
|
dataType_ = type;
|
||||||
|
@ -24,7 +24,10 @@ napi_value TypeDescriptorNapi::Constructor(napi_env env)
|
|||||||
{
|
{
|
||||||
LOG_DEBUG(UDMF_KITS_NAPI, "typeDescriptorNapi");
|
LOG_DEBUG(UDMF_KITS_NAPI, "typeDescriptorNapi");
|
||||||
napi_property_descriptor properties[] = {
|
napi_property_descriptor properties[] = {
|
||||||
/* UnifiedData properties */
|
/* TypeDescriptor properties */
|
||||||
|
DECLARE_NAPI_FUNCTION("belongsTo", BelongsTo),
|
||||||
|
DECLARE_NAPI_FUNCTION("isLowerLevelType", IsLowerLevelType),
|
||||||
|
DECLARE_NAPI_FUNCTION("isHigherLevelType", IsHigherLevelType),
|
||||||
DECLARE_NAPI_FUNCTION("equals", Equals),
|
DECLARE_NAPI_FUNCTION("equals", Equals),
|
||||||
DECLARE_NAPI_GETTER_SETTER("typeId", GetTypeId, nullptr),
|
DECLARE_NAPI_GETTER_SETTER("typeId", GetTypeId, nullptr),
|
||||||
DECLARE_NAPI_GETTER_SETTER("belongingToTypes", GetBelongingToTypes, nullptr),
|
DECLARE_NAPI_GETTER_SETTER("belongingToTypes", GetBelongingToTypes, nullptr),
|
||||||
@ -77,6 +80,66 @@ TypeDescriptorNapi *TypeDescriptorNapi::GetDescriptorNapi(napi_env env, napi_cal
|
|||||||
return static_cast<TypeDescriptorNapi *>(ctxt->native);
|
return static_cast<TypeDescriptorNapi *>(ctxt->native);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
napi_value TypeDescriptorNapi::BelongsTo(napi_env env, napi_callback_info info)
|
||||||
|
{
|
||||||
|
LOG_DEBUG(UDMF_KITS_NAPI, "TypeDescriptorNapi::BelongsTo()");
|
||||||
|
auto ctxt = std::make_shared<ContextBase>();
|
||||||
|
std::string typeId;
|
||||||
|
auto input = [env, ctxt, &typeId](size_t argc, napi_value* argv) {
|
||||||
|
// required 1 arguments : descriptor
|
||||||
|
ASSERT_BUSINESS_ERR(ctxt, argc >= 1, Status::E_INVALID_PARAMETERS, "invalid arguments!");
|
||||||
|
ctxt->status = NapiDataUtils::GetValue(env, argv[0], typeId);
|
||||||
|
ASSERT_BUSINESS_ERR(ctxt, ctxt->status == napi_ok, E_INVALID_PARAMETERS,
|
||||||
|
"invalid arg[0], i.e. invalid arguments!");
|
||||||
|
};
|
||||||
|
|
||||||
|
ctxt->GetCbInfoSync(env, info, input);
|
||||||
|
ASSERT_NULL(!ctxt->isThrowError, "BelongsTo Exit");
|
||||||
|
bool equalsRet = reinterpret_cast<TypeDescriptorNapi*>(ctxt->native)->value_->BelongsTo(typeId);
|
||||||
|
napi_get_boolean(env, equalsRet, &ctxt->output);
|
||||||
|
return ctxt->output;
|
||||||
|
}
|
||||||
|
|
||||||
|
napi_value TypeDescriptorNapi::IsLowerLevelType(napi_env env, napi_callback_info info)
|
||||||
|
{
|
||||||
|
LOG_DEBUG(UDMF_KITS_NAPI, "TypeDescriptorNapi::IsLowerLevelType()");
|
||||||
|
auto ctxt = std::make_shared<ContextBase>();
|
||||||
|
std::string typeId;
|
||||||
|
auto input = [env, ctxt, &typeId](size_t argc, napi_value* argv) {
|
||||||
|
// required 1 arguments : descriptor
|
||||||
|
ASSERT_BUSINESS_ERR(ctxt, argc >= 1, Status::E_INVALID_PARAMETERS, "invalid arguments!");
|
||||||
|
ctxt->status = NapiDataUtils::GetValue(env, argv[0], typeId);
|
||||||
|
ASSERT_BUSINESS_ERR(ctxt, ctxt->status == napi_ok, E_INVALID_PARAMETERS,
|
||||||
|
"invalid arg[0], i.e. invalid arguments!");
|
||||||
|
};
|
||||||
|
|
||||||
|
ctxt->GetCbInfoSync(env, info, input);
|
||||||
|
ASSERT_NULL(!ctxt->isThrowError, "IsLowerLevelType Exit");
|
||||||
|
bool equalsRet = reinterpret_cast<TypeDescriptorNapi*>(ctxt->native)->value_->IsLowerLevelType(typeId);
|
||||||
|
napi_get_boolean(env, equalsRet, &ctxt->output);
|
||||||
|
return ctxt->output;
|
||||||
|
}
|
||||||
|
|
||||||
|
napi_value TypeDescriptorNapi::IsHigherLevelType(napi_env env, napi_callback_info info)
|
||||||
|
{
|
||||||
|
LOG_DEBUG(UDMF_KITS_NAPI, "TypeDescriptorNapi::IsHigherLevelType()");
|
||||||
|
auto ctxt = std::make_shared<ContextBase>();
|
||||||
|
std::string typeId;
|
||||||
|
auto input = [env, ctxt, &typeId](size_t argc, napi_value* argv) {
|
||||||
|
// required 1 arguments : descriptor
|
||||||
|
ASSERT_BUSINESS_ERR(ctxt, argc >= 1, Status::E_INVALID_PARAMETERS, "invalid arguments!");
|
||||||
|
ctxt->status = NapiDataUtils::GetValue(env, argv[0], typeId);
|
||||||
|
ASSERT_BUSINESS_ERR(ctxt, ctxt->status == napi_ok, E_INVALID_PARAMETERS,
|
||||||
|
"invalid arg[0], i.e. invalid arguments!");
|
||||||
|
};
|
||||||
|
|
||||||
|
ctxt->GetCbInfoSync(env, info, input);
|
||||||
|
ASSERT_NULL(!ctxt->isThrowError, "IsHigherLevelType Exit");
|
||||||
|
bool equalsRet = reinterpret_cast<TypeDescriptorNapi*>(ctxt->native)->value_->IsHigherLevelType(typeId);
|
||||||
|
napi_get_boolean(env, equalsRet, &ctxt->output);
|
||||||
|
return ctxt->output;
|
||||||
|
}
|
||||||
|
|
||||||
napi_value TypeDescriptorNapi::Equals(napi_env env, napi_callback_info info)
|
napi_value TypeDescriptorNapi::Equals(napi_env env, napi_callback_info info)
|
||||||
{
|
{
|
||||||
LOG_DEBUG(UDMF_KITS_NAPI, "TypeDescriptorNapi::Equals()");
|
LOG_DEBUG(UDMF_KITS_NAPI, "TypeDescriptorNapi::Equals()");
|
||||||
|
@ -31,6 +31,8 @@ napi_value UniformTypeDescriptorNapi::UniformTypeDescriptorInit(napi_env env, na
|
|||||||
napi_property_descriptor desc[] = {
|
napi_property_descriptor desc[] = {
|
||||||
DECLARE_NAPI_PROPERTY("UniformDataType", uniformDataType),
|
DECLARE_NAPI_PROPERTY("UniformDataType", uniformDataType),
|
||||||
DECLARE_NAPI_FUNCTION("getTypeDescriptor", GetTypeDescriptor),
|
DECLARE_NAPI_FUNCTION("getTypeDescriptor", GetTypeDescriptor),
|
||||||
|
DECLARE_NAPI_FUNCTION("getUniformDataTypeByFilenameExtension", GetUniformDataTypeByFilenameExtension),
|
||||||
|
DECLARE_NAPI_FUNCTION("getUniformDataTypeByMIMEType", GetUniformDataTypeByMIMEType),
|
||||||
};
|
};
|
||||||
|
|
||||||
NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
|
NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
|
||||||
@ -83,5 +85,61 @@ napi_value UniformTypeDescriptorNapi::GetTypeDescriptor(napi_env env, napi_callb
|
|||||||
}
|
}
|
||||||
return ctxt->output;
|
return ctxt->output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
napi_value UniformTypeDescriptorNapi::GetUniformDataTypeByFilenameExtension(napi_env env, napi_callback_info info)
|
||||||
|
{
|
||||||
|
LOG_DEBUG(UDMF_KITS_NAPI, "GetUniformDataTypeByFilenameExtension is called!");
|
||||||
|
std::string filenameExtension;
|
||||||
|
std::string belongsTo;
|
||||||
|
auto ctxt = std::make_shared<ContextBase>();
|
||||||
|
auto input = [env, ctxt, &filenameExtension, &belongsTo](size_t argc, napi_value* argv) {
|
||||||
|
LOG_DEBUG(UDMF_KITS_NAPI, "GetTypeDescriptor, argc = %{public}zu !", argc);
|
||||||
|
// required 1 arguments : typeId
|
||||||
|
ASSERT_BUSINESS_ERR(ctxt, argc >= 1, Status::E_INVALID_PARAMETERS, "invalid arguments!");
|
||||||
|
ctxt->status = NapiDataUtils::GetValue(env, argv[0], filenameExtension);
|
||||||
|
ASSERT_BUSINESS_ERR(ctxt, ctxt->status == napi_ok, E_INVALID_PARAMETERS,
|
||||||
|
"invalid arg[0], i.e. invalid arguments!");
|
||||||
|
if (argc > 1) {
|
||||||
|
ctxt->status = NapiDataUtils::GetValue(env, argv[1], belongsTo);
|
||||||
|
ASSERT_BUSINESS_ERR(ctxt, ctxt->status == napi_ok, E_INVALID_PARAMETERS,
|
||||||
|
"invalid arg[1], i.e. invalid arguments!");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ctxt->GetCbInfoSync(env, info, input);
|
||||||
|
ASSERT_NULL(!ctxt->isThrowError, "GetUniformDataTypeByFilenameExtension Exit");
|
||||||
|
std::string typeId;
|
||||||
|
auto status = UtdClient::GetInstance().GetUniformDataTypeByFilenameExtension(filenameExtension, belongsTo, typeId);
|
||||||
|
ASSERT_ERR(ctxt->env, status == E_OK, status, "invalid arguments!");
|
||||||
|
NapiDataUtils::SetValue(env, typeId, ctxt->output);
|
||||||
|
return ctxt->output;
|
||||||
|
}
|
||||||
|
|
||||||
|
napi_value UniformTypeDescriptorNapi::GetUniformDataTypeByMIMEType(napi_env env, napi_callback_info info)
|
||||||
|
{
|
||||||
|
LOG_DEBUG(UDMF_KITS_NAPI, "GetUniformDataTypeByMIMEType is called!");
|
||||||
|
std::string mimeType;
|
||||||
|
std::string belongsTo;
|
||||||
|
auto ctxt = std::make_shared<ContextBase>();
|
||||||
|
auto input = [env, ctxt, &mimeType, &belongsTo](size_t argc, napi_value* argv) {
|
||||||
|
LOG_DEBUG(UDMF_KITS_NAPI, "GetTypeDescriptor, argc = %{public}zu !", argc);
|
||||||
|
// required 1 arguments : typeId
|
||||||
|
ASSERT_BUSINESS_ERR(ctxt, argc >= 1, Status::E_INVALID_PARAMETERS, "invalid arguments!");
|
||||||
|
ctxt->status = NapiDataUtils::GetValue(env, argv[0], mimeType);
|
||||||
|
ASSERT_BUSINESS_ERR(ctxt, ctxt->status == napi_ok, E_INVALID_PARAMETERS,
|
||||||
|
"invalid arg[0], i.e. invalid arguments!");
|
||||||
|
if (argc > 1) {
|
||||||
|
ctxt->status = NapiDataUtils::GetValue(env, argv[1], belongsTo);
|
||||||
|
ASSERT_BUSINESS_ERR(ctxt, ctxt->status == napi_ok, E_INVALID_PARAMETERS,
|
||||||
|
"invalid arg[1], i.e. invalid arguments!");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ctxt->GetCbInfoSync(env, info, input);
|
||||||
|
ASSERT_NULL(!ctxt->isThrowError, "GetUniformDataTypeByMIMEType Exit");
|
||||||
|
std::string typeId;
|
||||||
|
auto status = UtdClient::GetInstance().GetUniformDataTypeByMIMEType(mimeType, belongsTo, typeId);
|
||||||
|
ASSERT_ERR(ctxt->env, status == E_OK, status, "invalid arguments!");
|
||||||
|
NapiDataUtils::SetValue(env, typeId, ctxt->output);
|
||||||
|
return ctxt->output;
|
||||||
|
}
|
||||||
} // namespace UDMF
|
} // namespace UDMF
|
||||||
} // namespace OHOS
|
} // namespace OHOS
|
@ -40,7 +40,7 @@ describe('UdmfUtdJSTest', function () {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* @tc.name UdmfTestTypeDescriptor002
|
* @tc.name UdmfTestTypeDescriptor002
|
||||||
* @tc.desc Test Js Api
|
* @tc.desc Test Js Api
|
||||||
* @tc.type: FUNC
|
* @tc.type: FUNC
|
||||||
* @tc.require: issueNumber
|
* @tc.require: issueNumber
|
||||||
*/
|
*/
|
||||||
@ -61,14 +61,16 @@ describe('UdmfUtdJSTest', function () {
|
|||||||
expect(typeObj.typeId).assertEqual(UTD.UniformDataType.PHOTOSHOP_IMAGE);
|
expect(typeObj.typeId).assertEqual(UTD.UniformDataType.PHOTOSHOP_IMAGE);
|
||||||
expect(typeObj.belongingToTypes[0]).assertEqual('general.image');
|
expect(typeObj.belongingToTypes[0]).assertEqual('general.image');
|
||||||
expect(typeObj.description).assertEqual('Adobe Photoshop document.');
|
expect(typeObj.description).assertEqual('Adobe Photoshop document.');
|
||||||
expect(typeObj.referenceURL).assertEqual('');
|
let equalStr = 'https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/' +
|
||||||
|
'apis/js-apis-data-uniformTypeDescriptor.md#uniformdatatype';
|
||||||
|
expect(typeObj.referenceURL).assertEqual(equalStr);
|
||||||
expect(typeObj.iconFile).assertEqual('');
|
expect(typeObj.iconFile).assertEqual('');
|
||||||
console.info(TAG, 'end');
|
console.info(TAG, 'end');
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @tc.name UdmfTestTypeDescriptor003
|
* @tc.name UdmfTestTypeDescriptor003
|
||||||
* @tc.desc Test Js Api
|
* @tc.desc Test Js Api
|
||||||
* @tc.type: FUNC
|
* @tc.type: FUNC
|
||||||
* @tc.require: issueNumber
|
* @tc.require: issueNumber
|
||||||
*/
|
*/
|
||||||
@ -108,33 +110,35 @@ describe('UdmfUtdJSTest', function () {
|
|||||||
console.info(TAG, 'end');
|
console.info(TAG, 'end');
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @tc.name UdmfTestTypeDescriptor005
|
* @tc.name UdmfTestTypeDescriptor005
|
||||||
* @tc.desc Test Js Api
|
* @tc.desc Test Js Api
|
||||||
* @tc.type: FUNC
|
* @tc.type: FUNC
|
||||||
* @tc.require: issueNumber
|
* @tc.require: issueNumber
|
||||||
*/
|
*/
|
||||||
it('UdmfTestTypeDescriptor005', 0, function () {
|
it('UdmfTestTypeDescriptor005', 0, function () {
|
||||||
const TAG = 'UdmfTestTypeDescriptor005:';
|
const TAG = 'UdmfTestTypeDescriptor005:';
|
||||||
console.info(TAG, 'start');
|
console.info(TAG, 'start');
|
||||||
let typeObj = UTD.getTypeDescriptor('com.adobe.photoshop-image', 'safafdsaf',123456,'hahaha');
|
let typeObj = UTD.getTypeDescriptor('com.adobe.photoshop-image', 'safafdsaf',123456,'hahaha');
|
||||||
let typeId = typeObj.typeId;
|
let typeId = typeObj.typeId;
|
||||||
let belonging = typeObj.belongingToTypes;
|
let belonging = typeObj.belongingToTypes;
|
||||||
let description = typeObj.description;
|
let description = typeObj.description;
|
||||||
let referenceURL = typeObj.referenceURL;
|
let referenceURL = typeObj.referenceURL;
|
||||||
let iconFile = typeObj.iconFile;
|
let iconFile = typeObj.iconFile;
|
||||||
console.info(TAG, ', typeId: ' + typeId + ', ' + Object.prototype.toString.call(typeId) +
|
console.info(TAG, ', typeId: ' + typeId + ', ' + Object.prototype.toString.call(typeId) +
|
||||||
', belongingToTypes: ' + belonging + ', ' + Object.prototype.toString.call(belonging));
|
', belongingToTypes: ' + belonging + ', ' + Object.prototype.toString.call(belonging));
|
||||||
console.info(TAG, 'description: ' + typeObj.description + ', ' + Object.prototype.toString.call(description));
|
console.info(TAG, 'description: ' + typeObj.description + ', ' + Object.prototype.toString.call(description));
|
||||||
console.info(TAG, 'referenceURL: ' + referenceURL + ', ' + Object.prototype.toString.call(referenceURL)
|
console.info(TAG, 'referenceURL: ' + referenceURL + ', ' + Object.prototype.toString.call(referenceURL)
|
||||||
+ ', iconFile: ' + iconFile + ', ' + Object.prototype.toString.call(iconFile));
|
+ ', iconFile: ' + iconFile + ', ' + Object.prototype.toString.call(iconFile));
|
||||||
expect(typeObj.typeId).assertEqual(UTD.UniformDataType.PHOTOSHOP_IMAGE);
|
expect(typeObj.typeId).assertEqual(UTD.UniformDataType.PHOTOSHOP_IMAGE);
|
||||||
expect(typeObj.belongingToTypes[0]).assertEqual('general.image');
|
expect(typeObj.belongingToTypes[0]).assertEqual('general.image');
|
||||||
expect(typeObj.description).assertEqual('Adobe Photoshop document.');
|
expect(typeObj.description).assertEqual('Adobe Photoshop document.');
|
||||||
expect(typeObj.referenceURL).assertEqual('');
|
let equalStr = 'https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/' +
|
||||||
expect(typeObj.iconFile).assertEqual('');
|
'apis/js-apis-data-uniformTypeDescriptor.md#uniformdatatype';
|
||||||
console.info(TAG, 'end');
|
expect(typeObj.referenceURL).assertEqual(equalStr);
|
||||||
});
|
expect(typeObj.iconFile).assertEqual('');
|
||||||
|
console.info(TAG, 'end');
|
||||||
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @tc.name UdmfTestTypeDescriptor007
|
* @tc.name UdmfTestTypeDescriptor007
|
||||||
@ -185,7 +189,7 @@ describe('UdmfUtdJSTest', function () {
|
|||||||
let typeObj = UTD.getTypeDescriptor('general.type-script');
|
let typeObj = UTD.getTypeDescriptor('general.type-script');
|
||||||
console.info(TAG, 'typeDescriptor, ret ' + typeObj);
|
console.info(TAG, 'typeDescriptor, ret ' + typeObj);
|
||||||
try{
|
try{
|
||||||
typeObj.equals("1111");
|
typeObj.equals('1111');
|
||||||
} catch(e){
|
} catch(e){
|
||||||
console.error(TAG, `get e. code is ${e.code},message is ${e.message} `);
|
console.error(TAG, `get e. code is ${e.code},message is ${e.message} `);
|
||||||
expect(e.code === ERROR_PARAMETER).assertTrue();
|
expect(e.code === ERROR_PARAMETER).assertTrue();
|
||||||
@ -275,7 +279,7 @@ describe('UdmfUtdJSTest', function () {
|
|||||||
expect(UTD.UniformDataType.PCM).assertEqual('general.pcm');
|
expect(UTD.UniformDataType.PCM).assertEqual('general.pcm');
|
||||||
console.info(TAG, 'end');
|
console.info(TAG, 'end');
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @tc.name UdmfTestTypeDescriptor011
|
* @tc.name UdmfTestTypeDescriptor011
|
||||||
* @tc.desc Test Js Api enum value judge part3
|
* @tc.desc Test Js Api enum value judge part3
|
||||||
@ -316,4 +320,82 @@ describe('UdmfUtdJSTest', function () {
|
|||||||
expect(UTD.UniformDataType.OPENHARMONY_ATOMIC_SERVICE).assertEqual('openharmony.atomic-service');
|
expect(UTD.UniformDataType.OPENHARMONY_ATOMIC_SERVICE).assertEqual('openharmony.atomic-service');
|
||||||
console.info(TAG, 'end');
|
console.info(TAG, 'end');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @tc.name UdmfTestTypeDescriptor012
|
||||||
|
* @tc.desc Test Js Api belongsTo
|
||||||
|
* @tc.type: FUNC
|
||||||
|
* @tc.require: issueNumber
|
||||||
|
*/
|
||||||
|
it('UdmfTestTypeDescriptor012', 0, function () {
|
||||||
|
const TAG = 'UdmfTestTypeDescriptor012:';
|
||||||
|
console.info(TAG, 'start');
|
||||||
|
let typeObj = UTD.getTypeDescriptor('general.type-script');
|
||||||
|
let ret = typeObj.belongsTo("general.plain-text");
|
||||||
|
expect(ret == true).assertTrue();
|
||||||
|
console.info(TAG, 'typeDescriptor, ret ' + typeObj);
|
||||||
|
console.info(TAG, 'end');
|
||||||
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @tc.name UdmfTestTypeDescriptor013
|
||||||
|
* @tc.desc Test Js Api isLowerLevelType
|
||||||
|
* @tc.type: FUNC
|
||||||
|
* @tc.require: issueNumber
|
||||||
|
*/
|
||||||
|
it('UdmfTestTypeDescriptor013', 0, function () {
|
||||||
|
const TAG = 'UdmfTestTypeDescriptor013:';
|
||||||
|
console.info(TAG, 'start');
|
||||||
|
let typeObj = UTD.getTypeDescriptor('general.type-script');
|
||||||
|
let ret = typeObj.isLowerLevelType("general.plain-text");
|
||||||
|
expect(ret == true).assertTrue();
|
||||||
|
console.info(TAG, 'typeDescriptor, ret ' + ret);
|
||||||
|
console.info(TAG, 'end');
|
||||||
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @tc.name UdmfTestTypeDescriptor014
|
||||||
|
* @tc.desc Test Js Api isLowerLevelType
|
||||||
|
* @tc.type: FUNC
|
||||||
|
* @tc.require: issueNumber
|
||||||
|
*/
|
||||||
|
it('UdmfTestTypeDescriptor014', 0, function () {
|
||||||
|
const TAG = 'UdmfTestTypeDescriptor014:';
|
||||||
|
console.info(TAG, 'start');
|
||||||
|
let typeObj = UTD.getTypeDescriptor('general.plain-text');
|
||||||
|
let ret = typeObj.isHigherLevelType('general.type-script');
|
||||||
|
expect(ret == true).assertTrue();
|
||||||
|
console.info(TAG, 'typeDescriptor, ret ' + typeObj);
|
||||||
|
console.info(TAG, 'end');
|
||||||
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @tc.name UdmfTestTypeDescriptor015
|
||||||
|
* @tc.desc Test Js Api getUniformDataTypeByFilenameExtension
|
||||||
|
* @tc.type: FUNC
|
||||||
|
* @tc.require: issueNumber
|
||||||
|
*/
|
||||||
|
it('UdmfTestTypeDescriptor015', 0, function () {
|
||||||
|
const TAG = 'UdmfTestTypeDescriptor015:';
|
||||||
|
console.info(TAG, 'start');
|
||||||
|
let typeId = UTD.getUniformDataTypeByFilenameExtension('.ts', 'general.plain-text')
|
||||||
|
expect(typeId == 'general.type-script').assertTrue();
|
||||||
|
console.info(TAG, 'typeDescriptor, ret ' + typeId);
|
||||||
|
console.info(TAG, 'end');
|
||||||
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @tc.name UdmfTestTypeDescriptor016
|
||||||
|
* @tc.desc Test Js Api getUniformDataTypeByMIMEType
|
||||||
|
* @tc.type: FUNC
|
||||||
|
* @tc.require: issueNumber
|
||||||
|
*/
|
||||||
|
it('UdmfTestTypeDescriptor016', 0, function () {
|
||||||
|
const TAG = 'UdmfTestTypeDescriptor016:';
|
||||||
|
console.info(TAG, 'start');
|
||||||
|
let typeId = UTD.getUniformDataTypeByMIMEType('application/vnd.ms-excel', 'general.object')
|
||||||
|
expect(typeId == 'com.microsoft.excel.xls').assertTrue();
|
||||||
|
console.info(TAG, 'typeDescriptor, ret ' + typeId);
|
||||||
|
console.info(TAG, 'end');
|
||||||
|
});
|
||||||
});
|
});
|
@ -18,8 +18,8 @@ config("udmf_client_config") {
|
|||||||
"${udmf_interfaces_path}/innerkits/client",
|
"${udmf_interfaces_path}/innerkits/client",
|
||||||
"${udmf_interfaces_path}/innerkits/common",
|
"${udmf_interfaces_path}/innerkits/common",
|
||||||
"${udmf_interfaces_path}/innerkits/data",
|
"${udmf_interfaces_path}/innerkits/data",
|
||||||
|
|
||||||
"${udmf_framework_path}/common",
|
"${udmf_framework_path}/common",
|
||||||
|
"${udmf_framework_path}/innerkitsimpl/data",
|
||||||
"${udmf_framework_path}/service",
|
"${udmf_framework_path}/service",
|
||||||
"${kv_store_path}/frameworks/common",
|
"${kv_store_path}/frameworks/common",
|
||||||
"//third_party/libuv/include",
|
"//third_party/libuv/include",
|
||||||
@ -33,9 +33,10 @@ config("udmf_client_config") {
|
|||||||
|
|
||||||
ohos_shared_library("udmf_client") {
|
ohos_shared_library("udmf_client") {
|
||||||
sources = [
|
sources = [
|
||||||
"${udmf_framework_path}/common/preset_type_descriptors.cpp",
|
"${udmf_framework_path}/common/graph.cpp",
|
||||||
"${udmf_framework_path}/common/tlv_util.cpp",
|
"${udmf_framework_path}/common/tlv_util.cpp",
|
||||||
"${udmf_framework_path}/common/udmf_types_util.cpp",
|
"${udmf_framework_path}/common/udmf_types_util.cpp",
|
||||||
|
"${udmf_framework_path}/common/utd_graph.cpp",
|
||||||
"${udmf_framework_path}/innerkitsimpl/client/udmf_client.cpp",
|
"${udmf_framework_path}/innerkitsimpl/client/udmf_client.cpp",
|
||||||
"${udmf_framework_path}/innerkitsimpl/client/utd_client.cpp",
|
"${udmf_framework_path}/innerkitsimpl/client/utd_client.cpp",
|
||||||
"${udmf_framework_path}/innerkitsimpl/common/unified_key.cpp",
|
"${udmf_framework_path}/innerkitsimpl/common/unified_key.cpp",
|
||||||
@ -48,6 +49,7 @@ ohos_shared_library("udmf_client") {
|
|||||||
"${udmf_framework_path}/innerkitsimpl/data/image.cpp",
|
"${udmf_framework_path}/innerkitsimpl/data/image.cpp",
|
||||||
"${udmf_framework_path}/innerkitsimpl/data/link.cpp",
|
"${udmf_framework_path}/innerkitsimpl/data/link.cpp",
|
||||||
"${udmf_framework_path}/innerkitsimpl/data/plain_text.cpp",
|
"${udmf_framework_path}/innerkitsimpl/data/plain_text.cpp",
|
||||||
|
"${udmf_framework_path}/innerkitsimpl/data/preset_type_descriptors.cpp",
|
||||||
"${udmf_framework_path}/innerkitsimpl/data/system_defined_appitem.cpp",
|
"${udmf_framework_path}/innerkitsimpl/data/system_defined_appitem.cpp",
|
||||||
"${udmf_framework_path}/innerkitsimpl/data/system_defined_form.cpp",
|
"${udmf_framework_path}/innerkitsimpl/data/system_defined_form.cpp",
|
||||||
"${udmf_framework_path}/innerkitsimpl/data/system_defined_pixelmap.cpp",
|
"${udmf_framework_path}/innerkitsimpl/data/system_defined_pixelmap.cpp",
|
||||||
|
@ -30,12 +30,15 @@ class UtdClient {
|
|||||||
public:
|
public:
|
||||||
static UtdClient &GetInstance();
|
static UtdClient &GetInstance();
|
||||||
Status GetTypeDescriptor(const std::string &typeId, std::shared_ptr<TypeDescriptor> &descriptor);
|
Status GetTypeDescriptor(const std::string &typeId, std::shared_ptr<TypeDescriptor> &descriptor);
|
||||||
|
Status GetUniformDataTypeByFilenameExtension(const std::string &fileExtension, const std::string &belongs,
|
||||||
|
std::string &typeId);
|
||||||
|
Status GetUniformDataTypeByMIMEType(const std::string &mimeType, const std::string &belongs, std::string &typeId);
|
||||||
private:
|
private:
|
||||||
UtdClient();
|
UtdClient();
|
||||||
~UtdClient();
|
~UtdClient();
|
||||||
UtdClient(const UtdClient &obj) = delete;
|
UtdClient(const UtdClient &obj) = delete;
|
||||||
UtdClient &operator=(const UtdClient &obj) = delete;
|
UtdClient &operator=(const UtdClient &obj) = delete;
|
||||||
|
void SetDataToGraph();
|
||||||
std::vector<TypeDescriptor> descriptors_;
|
std::vector<TypeDescriptor> descriptors_;
|
||||||
};
|
};
|
||||||
} // namespace UDMF
|
} // namespace UDMF
|
||||||
|
@ -30,7 +30,10 @@
|
|||||||
namespace OHOS {
|
namespace OHOS {
|
||||||
namespace UDMF {
|
namespace UDMF {
|
||||||
enum UDType : int32_t {
|
enum UDType : int32_t {
|
||||||
TEXT = 0,
|
ENTITY = 0,
|
||||||
|
OBJECT,
|
||||||
|
COMPOSITE_OBJECT,
|
||||||
|
TEXT,
|
||||||
PLAIN_TEXT,
|
PLAIN_TEXT,
|
||||||
HTML,
|
HTML,
|
||||||
HYPERLINK,
|
HYPERLINK,
|
||||||
@ -120,10 +123,15 @@ enum UDType : int32_t {
|
|||||||
SYSTEM_DEFINED_PIXEL_MAP,
|
SYSTEM_DEFINED_PIXEL_MAP,
|
||||||
OPENHARMONY_ATOMIC_SERVICE,
|
OPENHARMONY_ATOMIC_SERVICE,
|
||||||
APPLICATION_DEFINED_RECORD,
|
APPLICATION_DEFINED_RECORD,
|
||||||
|
OPENHARMONY_PACKAGE,
|
||||||
|
OPENHARMONY_HAP,
|
||||||
UD_BUTT
|
UD_BUTT
|
||||||
};
|
};
|
||||||
|
|
||||||
static const std::unordered_map<int32_t, std::string> UD_TYPE_MAP {
|
static const std::unordered_map<int32_t, std::string> UD_TYPE_MAP {
|
||||||
|
{ ENTITY, "general.entity" },
|
||||||
|
{ OBJECT, "general.object" },
|
||||||
|
{ COMPOSITE_OBJECT, "general.composite-object" },
|
||||||
{ TEXT, "general.text" },
|
{ TEXT, "general.text" },
|
||||||
{ PLAIN_TEXT, "general.plain-text" },
|
{ PLAIN_TEXT, "general.plain-text" },
|
||||||
{ HTML, "general.html" },
|
{ HTML, "general.html" },
|
||||||
@ -214,10 +222,15 @@ static const std::unordered_map<int32_t, std::string> UD_TYPE_MAP {
|
|||||||
{ SYSTEM_DEFINED_PIXEL_MAP, "openharmony.pixel-map" },
|
{ SYSTEM_DEFINED_PIXEL_MAP, "openharmony.pixel-map" },
|
||||||
{ OPENHARMONY_ATOMIC_SERVICE, "openharmony.atomic-service" },
|
{ OPENHARMONY_ATOMIC_SERVICE, "openharmony.atomic-service" },
|
||||||
{ APPLICATION_DEFINED_RECORD, "ApplicationDefinedType" },
|
{ APPLICATION_DEFINED_RECORD, "ApplicationDefinedType" },
|
||||||
|
{ OPENHARMONY_PACKAGE, "openharmony.package" },
|
||||||
|
{ OPENHARMONY_HAP, "openharmony.hap" },
|
||||||
{ UD_BUTT, "INVALID"}
|
{ UD_BUTT, "INVALID"}
|
||||||
};
|
};
|
||||||
|
|
||||||
static const std::unordered_map<int32_t, std::string> JS_UD_TYPE_NAME_MAP {
|
static const std::unordered_map<int32_t, std::string> JS_UD_TYPE_NAME_MAP {
|
||||||
|
{ ENTITY, "ENTITY" },
|
||||||
|
{ OBJECT, "OBJECT" },
|
||||||
|
{ COMPOSITE_OBJECT, "COMPOSITE_OBJECT" },
|
||||||
{ TEXT, "TEXT" },
|
{ TEXT, "TEXT" },
|
||||||
{ PLAIN_TEXT, "PLAIN_TEXT" },
|
{ PLAIN_TEXT, "PLAIN_TEXT" },
|
||||||
{ HTML, "HTML" },
|
{ HTML, "HTML" },
|
||||||
@ -308,6 +321,8 @@ static const std::unordered_map<int32_t, std::string> JS_UD_TYPE_NAME_MAP {
|
|||||||
{ SYSTEM_DEFINED_PIXEL_MAP, "OPENHARMONY_PIXEL_MAP" },
|
{ SYSTEM_DEFINED_PIXEL_MAP, "OPENHARMONY_PIXEL_MAP" },
|
||||||
{ OPENHARMONY_ATOMIC_SERVICE, "OPENHARMONY_ATOMIC_SERVICE" },
|
{ OPENHARMONY_ATOMIC_SERVICE, "OPENHARMONY_ATOMIC_SERVICE" },
|
||||||
{ APPLICATION_DEFINED_RECORD, "APPLICATION_DEFINED_RECORD" },
|
{ APPLICATION_DEFINED_RECORD, "APPLICATION_DEFINED_RECORD" },
|
||||||
|
{ OPENHARMONY_PACKAGE, "OPENHARMONY_PACKAGE" },
|
||||||
|
{ OPENHARMONY_HAP, "OPENHARMONY_HAP" }
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
namespace OHOS {
|
namespace OHOS {
|
||||||
namespace UDMF {
|
namespace UDMF {
|
||||||
@ -28,6 +29,9 @@ public:
|
|||||||
const std::vector<std::string> &filenameExtensions, const std::vector<std::string> &mimeTypes,
|
const std::vector<std::string> &filenameExtensions, const std::vector<std::string> &mimeTypes,
|
||||||
const std::string &description, const std::string &referenceURL, const std::string &iconFile);
|
const std::string &description, const std::string &referenceURL, const std::string &iconFile);
|
||||||
~TypeDescriptor();
|
~TypeDescriptor();
|
||||||
|
bool BelongsTo(const std::string &typeId);
|
||||||
|
bool IsLowerLevelType(const std::string &typeId);
|
||||||
|
bool IsHigherLevelType(const std::string &typeId);
|
||||||
bool Equals(std::shared_ptr<TypeDescriptor> descriptor);
|
bool Equals(std::shared_ptr<TypeDescriptor> descriptor);
|
||||||
const std::string& GetTypeId() const;
|
const std::string& GetTypeId() const;
|
||||||
std::set<std::string> GetBelongingToTypes();
|
std::set<std::string> GetBelongingToTypes();
|
||||||
|
@ -28,6 +28,9 @@ namespace UDMF {
|
|||||||
class TypeDescriptorNapi {
|
class TypeDescriptorNapi {
|
||||||
public:
|
public:
|
||||||
static void NewInstance(napi_env env, std::shared_ptr<TypeDescriptor> in, napi_value &out);
|
static void NewInstance(napi_env env, std::shared_ptr<TypeDescriptor> in, napi_value &out);
|
||||||
|
static napi_value BelongsTo(napi_env env, napi_callback_info info);
|
||||||
|
static napi_value IsLowerLevelType(napi_env env, napi_callback_info info);
|
||||||
|
static napi_value IsHigherLevelType(napi_env env, napi_callback_info info);
|
||||||
static napi_value Equals(napi_env env, napi_callback_info info);
|
static napi_value Equals(napi_env env, napi_callback_info info);
|
||||||
static napi_value Constructor(napi_env env);
|
static napi_value Constructor(napi_env env);
|
||||||
|
|
||||||
|
@ -27,6 +27,8 @@ class UniformTypeDescriptorNapi {
|
|||||||
public:
|
public:
|
||||||
static napi_value UniformTypeDescriptorInit(napi_env env, napi_value exports);
|
static napi_value UniformTypeDescriptorInit(napi_env env, napi_value exports);
|
||||||
static napi_value GetTypeDescriptor(napi_env env, napi_callback_info info);
|
static napi_value GetTypeDescriptor(napi_env env, napi_callback_info info);
|
||||||
|
static napi_value GetUniformDataTypeByFilenameExtension(napi_env env, napi_callback_info info);
|
||||||
|
static napi_value GetUniformDataTypeByMIMEType(napi_env env, napi_callback_info info);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static napi_value CreateUniformDataType(napi_env env);
|
static napi_value CreateUniformDataType(napi_env env);
|
||||||
|
Loading…
Reference in New Issue
Block a user