• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #include "interfaces/inner_api/ace/serializeable_object.h"
17 
18 #include "utils.h"
19 
20 namespace OHOS::Ace {
21 namespace {
22 
23 #if defined(WINDOWS_PLATFORM)
24 constexpr char ACE_LIB_NAME[] = "libace.dll";
25 #elif defined(MAC_PLATFORM)
26 constexpr char ACE_LIB_NAME[] = "libace.dylib";
27 #elif defined(LINUX_PLATFORM)
28 constexpr char ACE_LIB_NAME[] = "libace.so";
29 #else
30 constexpr char ACE_LIB_NAME[] = "libace.z.so";
31 #endif
32 
33 using CreateFunction = SerializeableObject* (*)();
34 constexpr char NODE_OBJECT_CREATE_FUNC[] = "OHOS_ACE_CreateNodeObject";
35 
CreateNodeObjectInner()36 SerializeableObject* CreateNodeObjectInner()
37 {
38     LIBHANDLE handle = LOADLIB(ACE_LIB_NAME);
39     if (handle == nullptr) {
40         return nullptr;
41     }
42 
43     auto entry = reinterpret_cast<CreateFunction>(LOADSYM(handle, NODE_OBJECT_CREATE_FUNC));
44     if (entry == nullptr) {
45         FREELIB(handle);
46         return nullptr;
47     }
48 
49     auto nodeObject = entry();
50     return nodeObject;
51 }
52 } // namespace
53 
CreateNodeObject()54 std::unique_ptr<SerializeableObject> SerializeableObject::CreateNodeObject()
55 {
56     std::unique_ptr<SerializeableObject> obj;
57     obj.reset(CreateNodeObjectInner());
58     return obj;
59 }
60 } // namespace OHOS::Ace
61