• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_DISTRIBUTED_CAMERA_SOURCE_SERVICE_H
17 #define OHOS_DISTRIBUTED_CAMERA_SOURCE_SERVICE_H
18 
19 #include <memory>
20 #include <mutex>
21 #include <map>
22 #include <vector>
23 
24 #include "system_ability.h"
25 #include "ipc_object_stub.h"
26 
27 #include "dcamera_source_hidumper.h"
28 #include "dcamera_index.h"
29 #include "dcamera_service_state_listener.h"
30 #include "dcamera_source_dev.h"
31 #include "distributed_camera_constants.h"
32 #include "distributed_camera_source_stub.h"
33 
34 namespace OHOS {
35 namespace DistributedHardware {
36 class DistributedCameraSourceService : public SystemAbility, public DistributedCameraSourceStub {
37 DECLARE_SYSTEM_ABILITY(DistributedCameraSourceService);
38 
39 public:
40     DistributedCameraSourceService(int32_t saId, bool runOnCreate);
41     ~DistributedCameraSourceService() = default;
42 
43     int32_t InitSource(const std::string& params, const sptr<IDCameraSourceCallback>& callback) override;
44     int32_t ReleaseSource() override;
45     int32_t RegisterDistributedHardware(const std::string& devId, const std::string& dhId,
46         const std::string& reqId, const EnableParam& param) override;
47     int32_t UnregisterDistributedHardware(const std::string& devId, const std::string& dhId,
48         const std::string& reqId) override;
49     int32_t DCameraNotify(const std::string& devId, const std::string& dhId, std::string& events) override;
50     int Dump(int32_t fd, const std::vector<std::u16string>& args) override;
51     static void GetDumpInfo(CameraDumpInfo& camDump);
52 
53     static void CamDevInsert(DCameraIndex& index, std::shared_ptr<DCameraSourceDev>& camDev);
54     static std::shared_ptr<DCameraSourceDev> GetCamDevByIndex(DCameraIndex& index);
55     static void CamDevErase(DCameraIndex& index);
56     static uint32_t GetCamDevNum();
57 
58 protected:
59     void OnStart() override;
60     void OnStop() override;
61     DISALLOW_COPY_AND_MOVE(DistributedCameraSourceService);
62 
63 private:
64     bool Init();
65     int32_t LoadDCameraHDF();
66     int32_t UnLoadCameraHDF();
67 
68     bool registerToService_ = false;
69     DCameraServiceState state_ = DCameraServiceState::DCAMERA_SRV_STATE_NOT_START;
70 
71     std::shared_ptr<ICameraStateListener> listener_;
72     std::string sourceVer_;
73     const size_t MAX_CAMERAS_NUMBER = 32;
74     const size_t DUMP_MAX_SIZE = 10 * 1024;
75 
76     static std::map<DCameraIndex, std::shared_ptr<DCameraSourceDev>> camerasMap_;
77     static std::mutex camDevMutex_;
78 };
79 } // namespace DistributedHardware
80 } // namespace OHOS
81 #endif // OHOS_DISTRIBUTED_CAMERA_SOURCE_SERVICE_H
82