• 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 DISTRIBUTEDCAMERA_ALL_CONNECT_MANAGER_H
17 #define DISTRIBUTEDCAMERA_ALL_CONNECT_MANAGER_H
18 
19 #include <memory>
20 #include <map>
21 #include <mutex>
22 #include <string>
23 
24 #include "dcamera_block_obj.h"
25 #include "dcamera_collaboration_manager_capi.h"
26 #include "distributed_camera_errno.h"
27 
28 namespace OHOS {
29 namespace DistributedHardware {
30 class DCameraAllConnectManager {
31 public:
32     static DCameraAllConnectManager &GetInstance();
33     int32_t InitDCameraAllConnectManager();
34     int32_t UnInitDCameraAllConnectManager();
35     int32_t PublishServiceState(const std::string &peerNetworkId,
36                                 DCameraCollaborationBussinessStatus state);
37     int32_t ApplyAdvancedResource(const std::string &peerNetworkId,
38                                   DCameraCollaborationResourceRequestInfoSets *resourceRequest);
39     std::shared_ptr<DCameraCollaborationResourceRequestInfoSets> BuildResourceRequest();
40 
41     static void SetSourceNetworkId(const std::string &networkId, int32_t socket);
42     static void SetSinkNetWorkId(const std::string &networkId, int32_t socket);
43     static void RemoveSinkNetworkId(int32_t sessionId);
44     static void RemoveSourceNetworkId(int32_t sessionId);
45     static std::string GetSinkDevIdBySocket(int32_t socket);
46     static int32_t GetSinkSocketByNetWorkId(const std::string &networkId);
47     static int32_t GetSourceSocketByNetworkId(const std::string &networkId);
48     int32_t RegisterLifecycleCallback();
49     int32_t UnRegisterLifecycleCallback();
50     static bool IsInited();
51 private:
52     DCameraAllConnectManager();
53     ~DCameraAllConnectManager() = default;
54     int32_t GetAllConnectSoLoad();
55 
56     static int32_t OnStop(const char *peerNetworkId);
57     static int32_t ApplyResult(int32_t errorcode, int32_t result, const char *reason);
58 
59     std::mutex allConnectLock_;
60     void *dllHandle_ = nullptr;
61 
62     DCameraCollaborationApi allConnect_ = {
63         .dCameraCollaborationPublishServiceState = nullptr,
64         .dCameraCollaborationApplyAdvancedResource = nullptr,
65         .dCameraCollaborationRegisterLifecycleCallback = nullptr,
66         .dCameraCollaborationUnRegisterLifecycleCallback = nullptr,
67     };
68     DCameraCollaborationCallback allConnectCallback_;
69     std::shared_ptr<DCameraCollaboration_HardwareRequestInfo> remoteHardwareList_;
70     std::shared_ptr<DCameraCollaboration_HardwareRequestInfo> localHardwareList_;
71     std::shared_ptr<DCameraCollaborationCommunicationRequestInfo> communicationRequest_;
72 
73     static std::shared_ptr<DCameraBlockObject<bool>> applyResultBlock_;
74     static constexpr uint32_t BLOCK_INTERVAL_ALLCONNECT = 60 * 1000;
75     static inline const std::string SERVICE_NAME {"DistributedCamera"};  // to be discussed
76 
77     static std::map<std::string, int32_t> netwkIdSourceSessionIdMap_;
78     static std::mutex netwkIdSourceSessionIdMapLock_;
79 
80     static std::map<std::string, int32_t> netwkIdSinkSessionIdMap_;
81     static std::mutex netwkIdSinkSessionIdMapLock_;
82 
83     static bool bInited_;
84     static std::mutex bInitedLock_;
85 };
86 
87 } // namespace DistributedHardware
88 } // namespace OHOS
89 #endif // DISTRIBUTEDCAMERA_ALL_CONNECT_MANAGER_H