• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 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_DCAMERA_SOURCE_HANDLER_H
17 #define OHOS_DCAMERA_SOURCE_HANDLER_H
18 
19 #include <mutex>
20 #include <condition_variable>
21 
22 #include "iremote_proxy.h"
23 #include "iremote_broker.h"
24 #include "refbase.h"
25 
26 #include "dcamera_source_callback.h"
27 #include "idistributed_hardware_source.h"
28 #include "single_instance.h"
29 
30 namespace OHOS {
31 namespace DistributedHardware {
32 class DCameraSourceHandler : public IDistributedHardwareSource {
33 DECLARE_SINGLE_INSTANCE_BASE(DCameraSourceHandler);
34 public:
35     int32_t InitSource(const std::string& params) override;
36     int32_t ReleaseSource() override;
37     int32_t RegisterDistributedHardware(const std::string& devId, const std::string& dhId,
38         const EnableParam& param, std::shared_ptr<RegisterCallback> callback) override;
39     int32_t UnregisterDistributedHardware(const std::string& devId, const std::string& dhId,
40         std::shared_ptr<UnregisterCallback> callback) override;
41     int32_t ConfigDistributedHardware(const std::string& devId, const std::string& dhId, const std::string& key,
42         const std::string& value) override;
43     void RegisterDistributedHardwareStateListener(std::shared_ptr<DistributedHardwareStateListener> listener) override;
44     void UnregisterDistributedHardwareStateListener() override;
45     void RegisterDataSyncTriggerListener(std::shared_ptr<DataSyncTriggerListener> listener) override;
46     void UnregisterDataSyncTriggerListener() override;
47     int32_t LoadDistributedHDF(std::shared_ptr<HdfDeathCallback> callback) override;
48     int32_t UnLoadDistributedHDF() override;
49     void SetSAState();
50 private:
51     typedef enum {
52         DCAMERA_SA_STATE_STOP = 0,
53         DCAMERA_SA_STATE_START = 1,
54     } DCameraSAState;
55     DCameraSourceHandler();
56     ~DCameraSourceHandler();
57     void FinishStartSA(const std::string &params);
58     void FinishStartSAFailed(const int32_t systemAbilityId);
59 private:
60     std::mutex optLock_;
61     sptr<DCameraSourceCallback> callback_;
62     std::condition_variable producerCon_;
63     std::mutex producerMutex_;
64     DCameraSAState state_ = DCAMERA_SA_STATE_STOP;
65     friend class DCameraSourceLoadCallback;
66 };
67 
68 #ifdef __cplusplus
69 extern "C" {
70 #endif // __cplusplus
71 __attribute__((visibility("default"))) IDistributedHardwareSource *GetSourceHardwareHandler();
72 #ifdef __cplusplus
73 }
74 #endif // __cplusplus
75 } // namespace DistributedHardware
76 } // namespace OHOS
77 #endif // OHOS_DCAMERA_SOURCE_HANDLER_H
78