1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifndef CPP_ABCKIT_ARKTS_MODULE_IMPL_H
17 #define CPP_ABCKIT_ARKTS_MODULE_IMPL_H
18
19 #include "./module.h"
20 #include "./import_descriptor.h"
21 #include "../core/import_descriptor.h"
22 #include "./annotation_interface.h"
23 #include "../core/annotation_interface.h"
24
25 // NOLINTBEGIN(performance-unnecessary-value-param)
26 namespace abckit::arkts {
27
TargetCast()28 inline AbckitArktsModule *Module::TargetCast() const
29 {
30 auto ret = GetApiConfig()->cArktsIapi_->coreModuleToArktsModule(GetView());
31 CheckError(GetApiConfig());
32 return ret;
33 }
34
Module(const core::Module & coreOther)35 inline Module::Module(const core::Module &coreOther) : core::Module(coreOther), targetChecker_(this) {}
36
AddImportFromArktsV1ToArktsV1(Module imported,std::string_view name,std::string_view alias)37 inline arkts::ImportDescriptor Module::AddImportFromArktsV1ToArktsV1(Module imported, std::string_view name,
38 std::string_view alias) const
39 {
40 const AbckitArktsImportFromDynamicModuleCreateParams params {name.data(), alias.data()};
41 AbckitArktsImportDescriptor *arktsid =
42 GetApiConfig()->cArktsMapi_->moduleAddImportFromArktsV1ToArktsV1(TargetCast(), imported.TargetCast(), ¶ms);
43 CheckError(GetApiConfig());
44 AbckitCoreImportDescriptor *coreid =
45 GetApiConfig()->cArktsIapi_->arktsImportDescriptorToCoreImportDescriptor(arktsid);
46 CheckError(GetApiConfig());
47 return arkts::ImportDescriptor(core::ImportDescriptor(coreid, GetApiConfig(), GetResource()));
48 }
49
AddExportFromArktsV1ToArktsV1(arkts::Module exported,std::string_view name,std::string_view alias)50 inline arkts::ExportDescriptor Module::AddExportFromArktsV1ToArktsV1(arkts::Module exported, std::string_view name,
51 std::string_view alias) const
52 {
53 const AbckitArktsDynamicModuleExportCreateParams params {name.data(), alias.data()};
54 auto arktsExported = exported.TargetCast();
55 auto arktsEd =
56 GetApiConfig()->cArktsMapi_->moduleAddExportFromArktsV1ToArktsV1(TargetCast(), arktsExported, ¶ms);
57 CheckError(GetApiConfig());
58 auto coreEd = GetApiConfig()->cArktsIapi_->arktsExportDescriptorToCoreExportDescriptor(arktsEd);
59 CheckError(GetApiConfig());
60 return ExportDescriptor(core::ExportDescriptor(coreEd, GetApiConfig(), GetResource()));
61 }
62
RemoveImport(arkts::ImportDescriptor desc)63 inline Module Module::RemoveImport(arkts::ImportDescriptor desc) const
64 {
65 auto arktsId = desc.TargetCast();
66 auto arktsMod = TargetCast();
67 GetApiConfig()->cArktsMapi_->moduleRemoveImport(arktsMod, arktsId);
68 CheckError(GetApiConfig());
69 return *this;
70 }
71
RemoveExport(arkts::ExportDescriptor desc)72 inline Module Module::RemoveExport(arkts::ExportDescriptor desc) const
73 {
74 auto arktsId = desc.TargetCast();
75 auto arktsMod = TargetCast();
76 GetApiConfig()->cArktsMapi_->moduleRemoveExport(arktsMod, arktsId);
77 CheckError(GetApiConfig());
78 return *this;
79 }
80
AddAnnotationInterface(std::string_view name)81 inline arkts::AnnotationInterface Module::AddAnnotationInterface(std::string_view name) const
82 {
83 const AbckitArktsAnnotationInterfaceCreateParams params {name.data()};
84 auto arktsMod = TargetCast();
85 auto arktsAi = GetApiConfig()->cArktsMapi_->moduleAddAnnotationInterface(arktsMod, ¶ms);
86 CheckError(GetApiConfig());
87 auto coreAi = GetApiConfig()->cArktsIapi_->arktsAnnotationInterfaceToCoreAnnotationInterface(arktsAi);
88 CheckError(GetApiConfig());
89 return AnnotationInterface(core::AnnotationInterface(coreAi, GetApiConfig(), GetResource()));
90 }
91
92 } // namespace abckit::arkts
93 // NOLINTEND(performance-unnecessary-value-param)
94
95 #endif // CPP_ABCKIT_ARKTS_MODULE_IMPL_H
96