• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 OHOS_CAMERA_DYNAMIC_LOADER_H
17 #define OHOS_CAMERA_DYNAMIC_LOADER_H
18 
19 #include <string>
20 
21 namespace OHOS {
22 namespace CameraStandard {
23 using namespace std;
24 
25 const std::string MEDIA_LIB_SO = "libcamera_dynamic_medialibrary.z.so";
26 const std::string PICTURE_SO = "libcamera_dynamic_picture.z.so";
27 const std::string AV_CODEC_SO = "libcamera_dynamic_avcodec.z.so";
28 const std::string MOVING_PHOTO_SO = "libcamera_dynamic_moving_photo.z.so";
29 const std::string MEDIA_MANAGER_SO = "libcamera_dynamic_media_manager.z.so";
30 const std::string NAPI_EXT_SO = "libcamera_napi_ex.z.so";
31 
32 constexpr uint32_t LIB_DELAYED_UNLOAD_TIME = 30000; // 30 second
33 
34 class Dynamiclib {
35 public:
36     explicit Dynamiclib(const std::string& libName);
37     ~Dynamiclib();
38     bool IsLoaded();
39     void* GetFunction(const std::string& functionName);
40 
41 private:
42     std::string libName_;
43     void* libHandle_ = nullptr;
44 };
45 
46 class CameraDynamicLoader {
47 public:
48     static std::shared_ptr<Dynamiclib> GetDynamiclib(const std::string& libName);
49     static void LoadDynamiclibAsync(const std::string& libName);
50     static void FreeDynamicLibDelayed(const std::string& libName, uint32_t delayMs = LIB_DELAYED_UNLOAD_TIME);
51 
52 private:
53     explicit CameraDynamicLoader() = delete;
54     CameraDynamicLoader(const CameraDynamicLoader&) = delete;
55     CameraDynamicLoader& operator=(const CameraDynamicLoader&) = delete;
56 
57     static void FreeDynamiclibNoLock(const std::string& libName);
58     static void CancelFreeDynamicLibDelayed(const std::string& libName);
59     static std::shared_ptr<Dynamiclib> GetDynamiclibNoLock(const std::string& libName);
60 };
61 
62 } // namespace CameraStandard
63 } // namespace OHOS
64 #endif // OHOS_CAMERA_DYNAMIC_LOADER_H