1 /*
2  * Copyright (c) 2021-2023 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_DISTRIBUTED_CAMERA_SINK_SERVICE_H
17 #define OHOS_DISTRIBUTED_CAMERA_SINK_SERVICE_H
18 
19 #include <mutex>
20 #include "system_ability.h"
21 #include "ipc_object_stub.h"
22 
23 #include "dcamera_sink_dev.h"
24 #include "dcamera_sink_hidumper.h"
25 #include "distributed_camera_constants.h"
26 #include "distributed_camera_sink_stub.h"
27 
28 namespace OHOS {
29 namespace DistributedHardware {
30 class DistributedCameraSinkService : public SystemAbility, public DistributedCameraSinkStub {
31 DECLARE_SYSTEM_ABILITY(DistributedCameraSinkService);
32 
33 public:
34     DistributedCameraSinkService(int32_t saId, bool runOnCreate);
35     ~DistributedCameraSinkService() override = default;
36 
37     int32_t InitSink(const std::string& params, const sptr<IDCameraSinkCallback> &sinkCallback) override;
38     int32_t ReleaseSink() override;
39     int32_t SubscribeLocalHardware(const std::string& dhId, const std::string& parameters) override;
40     int32_t UnsubscribeLocalHardware(const std::string& dhId) override;
41     int32_t StopCapture(const std::string& dhId) override;
42     int32_t ChannelNeg(const std::string& dhId, std::string& channelInfo) override;
43     int32_t GetCameraInfo(const std::string& dhId, std::string& cameraInfo) override;
44     int32_t OpenChannel(const std::string& dhId, std::string& openInfo) override;
45     int32_t CloseChannel(const std::string& dhId) override;
46     int Dump(int32_t fd, const std::vector<std::u16string>& args) override;
47     static void GetCamDumpInfo(CameraDumpInfo& camDump);
48     int32_t PauseDistributedHardware(const std::string &networkId) override;
49     int32_t ResumeDistributedHardware(const std::string &networkId) override;
50     int32_t StopDistributedHardware(const std::string &networkId) override;
51 
52 protected:
53     void OnStart() override;
54     void OnStop() override;
55     DISALLOW_COPY_AND_MOVE(DistributedCameraSinkService);
56 
57 private:
58     bool IsCurSinkDev(std::shared_ptr<DCameraSinkDev> sinkDevice);
59 
60     bool Init();
61     void GetCamIds();
62     bool registerToService_ = false;
63     DCameraServiceState state_ = DCameraServiceState::DCAMERA_SRV_STATE_NOT_START;
64 
65     std::string sinkVer_;
66     std::mutex mapMutex_;
67     std::map<std::string, std::shared_ptr<DCameraSinkDev>> camerasMap_;
68     static DistributedCameraSinkService* dcSinkService;
69     const size_t DUMP_MAX_SIZE = 10 * 1024;
70 };
71 } // namespace DistributedHardware
72 } // namespace OHOS
73 #endif // OHOS_DISTRIBUTED_CAMERA_SINK_SERVICE_H