• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 "platform_adp.h"
17 #ifndef _WIN32
18 #include <dlfcn.h>
19 #endif
20 #include "directory_ex.h"
21 #include "hilog/log.h"
22 #include "log_tags.h"
23 
24 namespace OHOS {
25 namespace MultimediaPlugin {
26 using std::string;
27 using namespace OHOS::HiviewDFX;
28 
29 static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "PlatformAdp" };
30 
31 const string PlatformAdp::DIR_SEPARATOR = "/";
32 const string PlatformAdp::LIBRARY_FILE_SUFFIX = "so";
33 
34 #ifdef _WIN32
AdpLoadLibrary(const string & packageName)35 HMODULE PlatformAdp::AdpLoadLibrary(const string &packageName)
36 {
37     return LoadLibrary(packageName.c_str());
38 }
39 
AdpFreeLibrary(HMODULE handle)40 void PlatformAdp::AdpFreeLibrary(HMODULE handle)
41 {
42     FreeLibrary(handle);
43 }
44 
AdpGetSymAddress(HMODULE handle,const string & symbol)45 FARPROC PlatformAdp::AdpGetSymAddress(HMODULE handle, const string &symbol)
46 {
47     return GetProcAddress(handle, symbol.c_str());
48 }
49 #else
LoadLibrary(const string & packageName)50 void *PlatformAdp::LoadLibrary(const string &packageName)
51 {
52     return dlopen(packageName.c_str(), RTLD_LAZY);
53 }
54 
FreeLibrary(void * handle)55 void PlatformAdp::FreeLibrary(void *handle)
56 {
57     dlclose(handle);
58 }
59 
GetSymAddress(void * handle,const string & symbol)60 void *PlatformAdp::GetSymAddress(void *handle, const string &symbol)
61 {
62     return dlsym(handle, symbol.c_str());
63 }
64 #endif
65 
CheckAndNormalizePath(string & path)66 uint32_t PlatformAdp::CheckAndNormalizePath(string &path)
67 {
68 #if !defined(_WIN32) && !defined(_APPLE)
69     if (path.empty()) {
70         HiLog::Error(LABEL, "check path empty.");
71         return ERR_GENERAL;
72     }
73 #endif
74 
75     string realPath;
76     if (!PathToRealPath(path, realPath)) {
77         HiLog::Error(LABEL, "path to real path error.");
78         return ERR_GENERAL;
79     }
80 
81     path = std::move(realPath);
82 
83     return SUCCESS;
84 }
85 
86 // ------------------------------- private method -------------------------------
PlatformAdp()87 PlatformAdp::PlatformAdp() {}
88 
~PlatformAdp()89 PlatformAdp::~PlatformAdp() {}
90 } // namespace MultimediaPlugin
91 } // namespace OHOS
92