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 #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     void SetSAState();
48 private:
49     typedef enum {
50         DCAMERA_SA_STATE_STOP = 0,
51         DCAMERA_SA_STATE_START = 1,
52     } DCameraSAState;
53     DCameraSourceHandler();
54     ~DCameraSourceHandler();
55     void FinishStartSA(const std::string &params);
56     void FinishStartSAFailed(const int32_t systemAbilityId);
57 private:
58     std::mutex optLock_;
59     sptr<DCameraSourceCallback> callback_;
60     std::condition_variable producerCon_;
61     std::mutex producerMutex_;
62     DCameraSAState state_ = DCAMERA_SA_STATE_STOP;
63     friend class DCameraSourceLoadCallback;
64 };
65 
66 #ifdef __cplusplus
67 extern "C" {
68 #endif // __cplusplus
69 __attribute__((visibility("default"))) IDistributedHardwareSource *GetSourceHardwareHandler();
70 #ifdef __cplusplus
71 }
72 #endif // __cplusplus
73 } // namespace DistributedHardware
74 } // namespace OHOS
75 #endif // OHOS_DCAMERA_SOURCE_HANDLER_H
76