diff --git a/services/cameraservice/sinkservice/BUILD.gn b/services/cameraservice/sinkservice/BUILD.gn index ca6b9c48c36cfd4a6b28d64130e1ff9552ecfc86..c3a5fb7a80659b8e45aa696f662599dbc4e51e4c 100644 --- a/services/cameraservice/sinkservice/BUILD.gn +++ b/services/cameraservice/sinkservice/BUILD.gn @@ -71,6 +71,7 @@ ohos_shared_library("distributed_camera_sink") { "${services_path}/cameraservice/base/src/dcamera_info_cmd.cpp", "${services_path}/cameraservice/base/src/dcamera_metadata_setting_cmd.cpp", "${services_path}/cameraservice/base/src/dcamera_open_info_cmd.cpp", + "src/distributedcamera/dcamera_sink_hidumper.cpp", "src/distributedcamera/distributed_camera_sink_service.cpp", "src/distributedcamera/distributed_camera_sink_stub.cpp", "src/distributedcameramgr/callback/dcamera_sink_controller_state_callback.cpp", diff --git a/services/cameraservice/sinkservice/include/distributedcamera/dcamera_sink_hidumper.h b/services/cameraservice/sinkservice/include/distributedcamera/dcamera_sink_hidumper.h new file mode 100644 index 0000000000000000000000000000000000000000..7622d9c9b03ad492e067ffdeed40bf8fdeaf6607 --- /dev/null +++ b/services/cameraservice/sinkservice/include/distributedcamera/dcamera_sink_hidumper.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DISTRIBUTED_CAMERA_SINK_HIDUMPER_H +#define OHOS_DISTRIBUTED_CAMERA_SINK_HIDUMPER_H + +#include +#include +#include + +#include "single_instance.h" + +namespace OHOS { +namespace DistributedHardware { +class DCameraSourceDev; +enum class HidumpFlag { + UNKNOWN = 0, + GET_HELP, + GET_CAMERA_INFO, + GET_OPENED_INFO, + GET_VERSION_INFO, +}; + +struct CameraDumpInfo { + std::string version; + int32_t camNumber; + std::vector camIds; +}; + +class DcameraSinkHidumper { +DECLARE_SINGLE_INSTANCE_BASE(DcameraSinkHidumper); + +public: + bool Dump(const std::vector& args, std::string& result); + +private: + explicit DcameraSinkHidumper() = default; + ~DcameraSinkHidumper() = default; + void ShowHelp(std::string& result); + int32_t ShowIllegalInfomation(std::string& result); + int32_t ProcessDump(const std::string& args, std::string& result); + void SetSinkDumpInfo(CameraDumpInfo& camDumpInfo_); + + int32_t GetLocalCameraNumber(std::string& result); + int32_t GetOpenedCameraInfo(std::string& result); + int32_t GetVersionInfo(std::string& result); + +private: + CameraDumpInfo camDumpInfo_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DISTRIBUTED_CAMERA_SINK_HIDUMPER_H \ No newline at end of file diff --git a/services/cameraservice/sinkservice/include/distributedcamera/distributed_camera_sink_service.h b/services/cameraservice/sinkservice/include/distributedcamera/distributed_camera_sink_service.h index 48d13d925509eb5874b0ec6a22adc6fb2e449432..40f5d4db88a0965d6bf7dd48fbae47912c2a6432 100644 --- a/services/cameraservice/sinkservice/include/distributedcamera/distributed_camera_sink_service.h +++ b/services/cameraservice/sinkservice/include/distributedcamera/distributed_camera_sink_service.h @@ -20,6 +20,7 @@ #include "ipc_object_stub.h" #include "dcamera_sink_dev.h" +#include "dcamera_sink_hidumper.h" #include "distributed_camera_constants.h" #include "distributed_camera_sink_stub.h" @@ -41,6 +42,8 @@ public: int32_t GetCameraInfo(const std::string& dhId, std::string& cameraInfo) override; int32_t OpenChannel(const std::string& dhId, std::string& openInfo) override; int32_t CloseChannel(const std::string& dhId) override; + int Dump(int32_t fd, const std::vector& args) override; + static void GetCamDumpInfo(CameraDumpInfo& camDump); protected: void OnStart() override; @@ -49,11 +52,13 @@ protected: private: bool Init(); + void GetCamIds(); bool registerToService_ = false; DCameraServiceState state_ = DCameraServiceState::DCAMERA_SRV_STATE_NOT_START; std::string sinkVer_; std::map> camerasMap_; + static DistributedCameraSinkService* dcSinkService; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_dev.h b/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_dev.h index 295e562e8e8318c6141e02033dd2a9fc327fd9d2..79721f537984d6b144ee1fd0b882a0ab106c14b1 100644 --- a/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_dev.h +++ b/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_dev.h @@ -39,6 +39,7 @@ public: int32_t GetCameraInfo(std::string& cameraInfo); int32_t OpenChannel(std::string& openInfo); int32_t CloseChannel(); + std::string GetDhid(); private: bool isInit_; diff --git a/services/cameraservice/sinkservice/src/distributedcamera/dcamera_sink_hidumper.cpp b/services/cameraservice/sinkservice/src/distributedcamera/dcamera_sink_hidumper.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1200678944e72c9a47bdb3734d16e866c63fe5b0 --- /dev/null +++ b/services/cameraservice/sinkservice/src/distributedcamera/dcamera_sink_hidumper.cpp @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "dcamera_sink_hidumper.h" + +#include "distributed_camera_errno.h" +#include "distributed_camera_sink_service.h" +#include "distributed_hardware_log.h" + +namespace OHOS { +namespace DistributedHardware { +IMPLEMENT_SINGLE_INSTANCE(DcameraSinkHidumper); + +namespace { +const std::string ARGS_HELP = "-h"; +const std::string ARGS_VERSION_INFO = "--version"; +const std::string ARGS_CAMERA_INFO = "--camNum"; +const std::string ARGS_OPENED_INFO = "--opened"; + +const std::map ARGS_MAP = { + { ARGS_HELP, HidumpFlag::GET_HELP }, + { ARGS_CAMERA_INFO, HidumpFlag::GET_CAMERA_INFO }, + { ARGS_OPENED_INFO, HidumpFlag::GET_OPENED_INFO }, + { ARGS_VERSION_INFO, HidumpFlag::GET_VERSION_INFO }, +}; +} + +void DcameraSinkHidumper::SetSinkDumpInfo(CameraDumpInfo& camDumpInfo_) +{ + DistributedCameraSinkService::GetCamDumpInfo(camDumpInfo_); +} + +bool DcameraSinkHidumper::Dump(const std::vector& args, std::string& result) +{ + DHLOGI("DcameraSinkHidumper Dump args.size():%d.", args.size()); + result.clear(); + int32_t argsSize = static_cast(args.size()); + for (int32_t i = 0; i < argsSize; i++) { + DHLOGI("DcameraSinkHidumper Dump args[%d]: %s.", i, args.at(i).c_str()); + } + + if (ProcessDump(args[0], result) != DCAMERA_OK) { + return false; + } + return true; +} + +int32_t DcameraSinkHidumper::ProcessDump(const std::string& args, std::string& result) +{ + DHLOGI("ProcessDump Dump."); + HidumpFlag hf = HidumpFlag::UNKNOWN; + auto operatorIter = ARGS_MAP.find(args); + if (operatorIter != ARGS_MAP.end()) { + hf = operatorIter->second; + } + + if (hf == HidumpFlag::GET_HELP) { + ShowHelp(result); + return DCAMERA_OK; + } + result.clear(); + SetSinkDumpInfo(camDumpInfo_); + int32_t ret = DCAMERA_BAD_VALUE; + switch (hf) { + case HidumpFlag::GET_CAMERA_INFO: { + ret = GetLocalCameraNumber(result); + break; + } + case HidumpFlag::GET_OPENED_INFO: { + ret = GetOpenedCameraInfo(result); + break; + } + case HidumpFlag::GET_VERSION_INFO: { + ret = GetVersionInfo(result); + break; + } + default: { + ret = ShowIllegalInfomation(result); + break; + } + } + + return ret; +} + +int32_t DcameraSinkHidumper::GetLocalCameraNumber(std::string& result) +{ + DHLOGI("GetLocalCameraNumber Dump."); + result.append("CameraNumber\n") + .append(std::to_string(camDumpInfo_.camNumber)); + return DCAMERA_OK; +} + +int32_t DcameraSinkHidumper::GetOpenedCameraInfo(std::string& result) +{ + DHLOGI("GetOpenedCameraInfo Dump."); + result.append("OpenedCamera\n"); + std::vector camIds = camDumpInfo_.camIds; + for (size_t i = 0; i < camIds.size(); i++) { + result.append(camIds[i]); + result.append("\n"); + } + return DCAMERA_OK; +} + +int32_t DcameraSinkHidumper::GetVersionInfo(std::string& result) +{ + DHLOGI("GetVersionInfo Dump."); + result.append("CameraVersion\n") + .append(camDumpInfo_.version); + return DCAMERA_OK; +} + +void DcameraSinkHidumper::ShowHelp(std::string& result) +{ + DHLOGI("ShowHelp Dump."); + result.append("Usage:dump [options]\n") + .append("Description:\n") + .append("--version ") + .append("dump camera version in the system\n") + .append("--camNum ") + .append("dump local camera numbers in the system\n") + .append("--opened ") + .append("dump the opened camera in the system\n"); +} + +int32_t DcameraSinkHidumper::ShowIllegalInfomation(std::string& result) +{ + DHLOGI("ShowIllegalInfomation Dump."); + result.append("unknown command"); + return DCAMERA_OK; +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_service.cpp b/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_service.cpp index 41ea35c4f6688d4c5a64ebdd15add4352fd14261..158bb04a72a9ef4f4f6ff80afdc90f24ca7e96c0 100644 --- a/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_service.cpp +++ b/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_service.cpp @@ -33,9 +33,12 @@ namespace OHOS { namespace DistributedHardware { REGISTER_SYSTEM_ABILITY_BY_ID(DistributedCameraSinkService, DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID, true); +static CameraDumpInfo g_camDump; +DistributedCameraSinkService* DistributedCameraSinkService::dcSinkService; DistributedCameraSinkService::DistributedCameraSinkService(int32_t saId, bool runOnCreate) : SystemAbility(saId, runOnCreate) { + dcSinkService = this; } void DistributedCameraSinkService::OnStart() @@ -82,6 +85,7 @@ int32_t DistributedCameraSinkService::InitSink(const std::string& params) { DHLOGI("DistributedCameraSinkService::InitSink"); sinkVer_ = params; + g_camDump.version = sinkVer_; int32_t ret = DCameraHandler::GetInstance().Initialize(); if (ret != DCAMERA_OK) { DHLOGE("DistributedCameraSinkService::InitSink handler initialize failed, ret: %d", ret); @@ -93,6 +97,7 @@ int32_t DistributedCameraSinkService::InitSink(const std::string& params) DHLOGE("DistributedCameraSinkService::InitSink no camera device"); return DCAMERA_BAD_VALUE; } + g_camDump.camNumber = cameras.size(); for (auto& dhId : cameras) { std::shared_ptr sinkDevice = std::make_shared(dhId); ret = sinkDevice->Init(); @@ -254,5 +259,43 @@ int32_t DistributedCameraSinkService::CloseChannel(const std::string& dhId) DHLOGI("DistributedCameraSinkService::CloseChannel success"); return DCAMERA_OK; } + +int DistributedCameraSinkService::Dump(int32_t fd, const std::vector& args) +{ + DHLOGI("DistributedCameraSinkService Dump."); + std::string result; + std::vector argsStr; + for (auto item : args) { + argsStr.emplace_back(Str16ToStr8(item)); + } + + if (!DcameraSinkHidumper::GetInstance().Dump(argsStr, result)) { + DHLOGE("Hidump error"); + return DCAMERA_BAD_VALUE; + } + + int ret = dprintf(fd, "%s\n", result.c_str()); + if (ret < 0) { + DHLOGE("dprintf error"); + return DCAMERA_BAD_VALUE; + } + + return DCAMERA_OK; +} + +void DistributedCameraSinkService::GetCamIds() +{ + std::vector camIds; + for (auto it = camerasMap_.begin(); it != camerasMap_.end(); it++) { + camIds.push_back(it->second->GetDhid()); + } + g_camDump.camIds = camIds; +} + +void DistributedCameraSinkService::GetCamDumpInfo(CameraDumpInfo& camDump) +{ + dcSinkService->GetCamIds(); + camDump = g_camDump; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_dev.cpp b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_dev.cpp index e9db8f9f5fd53956896c5f528b30921796c055ef..02e5a676d82d409687fa37215633eb07868fffe5 100644 --- a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_dev.cpp +++ b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_dev.cpp @@ -156,5 +156,10 @@ int32_t DCameraSinkDev::CloseChannel() DHLOGI("DCameraSinkDev::CloseChannel dhId: %s", GetAnonyString(dhId_).c_str()); return controller_->CloseChannel(); } + +std::string DCameraSinkDev::GetDhid() +{ + return GetAnonyString(dhId_); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/cameraservice/sourceservice/BUILD.gn b/services/cameraservice/sourceservice/BUILD.gn index 8f53c80dc8be0b59c64408fbb07e004dac756646..0558db77a78d136d094519220f535ab23ebc2f25 100644 --- a/services/cameraservice/sourceservice/BUILD.gn +++ b/services/cameraservice/sourceservice/BUILD.gn @@ -62,6 +62,7 @@ ohos_shared_library("distributed_camera_source") { "${services_path}/cameraservice/base/src/dcamera_open_info_cmd.cpp", "src/distributedcamera/dcamera_service_state_listener.cpp", "src/distributedcamera/dcamera_source_callback_proxy.cpp", + "src/distributedcamera/dcamera_source_hidumper.cpp", "src/distributedcamera/distributed_camera_source_service.cpp", "src/distributedcamera/distributed_camera_source_stub.cpp", "src/distributedcameramgr/dcamera_source_dev.cpp", diff --git a/services/cameraservice/sourceservice/include/distributedcamera/dcamera_source_hidumper.h b/services/cameraservice/sourceservice/include/distributedcamera/dcamera_source_hidumper.h new file mode 100644 index 0000000000000000000000000000000000000000..99e97e0b4a884b48fff140267fa549b1a2f1f371 --- /dev/null +++ b/services/cameraservice/sourceservice/include/distributedcamera/dcamera_source_hidumper.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DISTRIBUTED_CAMERA_SOURCE_HIDUMPER_H +#define OHOS_DISTRIBUTED_CAMERA_SOURCE_HIDUMPER_H + +#include +#include +#include + +#include "single_instance.h" + +namespace OHOS { +namespace DistributedHardware { +class DCameraSourceDev; +enum class HidumpFlag { + UNKNOWN = 0, + GET_HELP, + GET_REGISTERED_INFO, + GET_CURRENTSTATE_INFO, + GET_VERSION_INFO, +}; + +typedef enum { + DCAMERA_STATE_INIT_DUMP = 0, + DCAMERA_STATE_REGIST_DUMP = 1, + DCAMERA_STATE_OPENED_DUMP = 2, + DCAMERA_STATE_CONFIG_STREAM_DUMP = 3, + DCAMERA_STATE_CAPTURE_DUMP = 4, +} DCameraState; + +struct CameraDumpInfo { + std::string version; + int32_t regNumber; + std::map curState; +}; + +class DcameraSourceHidumper { +DECLARE_SINGLE_INSTANCE_BASE(DcameraSourceHidumper); + +public: + bool Dump(const std::vector& args, std::string& result); + +private: + explicit DcameraSourceHidumper() = default; + ~DcameraSourceHidumper() = default; + void ShowHelp(std::string& result); + int32_t ShowIllegalInfomation(std::string& result); + int32_t ProcessDump(const std::string& args, std::string& result); + void SetSourceDumpInfo(CameraDumpInfo& camDumpInfo_); + + int32_t GetRegisteredInfo(std::string& result); + int32_t GetCurrentStateInfo(std::string& result); + int32_t GetVersionInfo(std::string& result); + +private: + CameraDumpInfo camDumpInfo_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DISTRIBUTED_CAMERA_SOURCE_HIDUMPER_H \ No newline at end of file diff --git a/services/cameraservice/sourceservice/include/distributedcamera/distributed_camera_source_service.h b/services/cameraservice/sourceservice/include/distributedcamera/distributed_camera_source_service.h index 112030674402abb94e8564b3d72983aa64d18da8..52d6bba9aa53779745c0a7472b97fe368c67cb9d 100644 --- a/services/cameraservice/sourceservice/include/distributedcamera/distributed_camera_source_service.h +++ b/services/cameraservice/sourceservice/include/distributedcamera/distributed_camera_source_service.h @@ -19,10 +19,12 @@ #include #include #include +#include #include "system_ability.h" #include "ipc_object_stub.h" +#include "dcamera_source_hidumper.h" #include "dcamera_index.h" #include "dcamera_service_state_listener.h" #include "dcamera_source_dev.h" @@ -45,6 +47,8 @@ public: int32_t UnregisterDistributedHardware(const std::string& devId, const std::string& dhId, const std::string& reqId) override; int32_t DCameraNotify(const std::string& devId, const std::string& dhId, std::string& events) override; + int Dump(int32_t fd, const std::vector& args) override; + static void GetDumpInfo(CameraDumpInfo& camDump); static std::map> camerasMap_; diff --git a/services/cameraservice/sourceservice/include/distributedcameramgr/dcamera_source_dev.h b/services/cameraservice/sourceservice/include/distributedcameramgr/dcamera_source_dev.h index cb5b41d9985fb868fbcb863cd1e67ea29519e4a5..363f799410ed814bbe9ff182071b1a1f43f7c5c1 100644 --- a/services/cameraservice/sourceservice/include/distributedcameramgr/dcamera_source_dev.h +++ b/services/cameraservice/sourceservice/include/distributedcameramgr/dcamera_source_dev.h @@ -50,6 +50,8 @@ public: int32_t UpdateCameraSettings(const std::vector>& settings); void OnEvent(DCameraSourceEvent& event) override; + int32_t GetStateInfo(); + std::string GetVersion(); public: virtual int32_t ExecuteRegister(std::shared_ptr& param); diff --git a/services/cameraservice/sourceservice/include/distributedcameramgr/dcamerastate/dcamera_source_state_machine.h b/services/cameraservice/sourceservice/include/distributedcameramgr/dcamerastate/dcamera_source_state_machine.h index 8d5d30347e959fa901224af733b5087c33fa361b..e7835e8741065ef181af3d8d078d1be112c10657 100644 --- a/services/cameraservice/sourceservice/include/distributedcameramgr/dcamerastate/dcamera_source_state_machine.h +++ b/services/cameraservice/sourceservice/include/distributedcameramgr/dcamerastate/dcamera_source_state_machine.h @@ -27,6 +27,7 @@ public: ~DCameraSourceStateMachine(); int32_t Execute(DCAMERA_EVENT eventType, DCameraSourceEvent& event); void UpdateState(DCameraStateType stateType); + int32_t GetCameraState(); private: std::shared_ptr currentState_; diff --git a/services/cameraservice/sourceservice/src/distributedcamera/dcamera_source_hidumper.cpp b/services/cameraservice/sourceservice/src/distributedcamera/dcamera_source_hidumper.cpp new file mode 100644 index 0000000000000000000000000000000000000000..991fb84aaec625664f9128d2de7b46934595ee3b --- /dev/null +++ b/services/cameraservice/sourceservice/src/distributedcamera/dcamera_source_hidumper.cpp @@ -0,0 +1,171 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "dcamera_source_hidumper.h" + +#include "distributed_camera_errno.h" +#include "distributed_camera_source_service.h" +#include "distributed_hardware_log.h" + +namespace OHOS { +namespace DistributedHardware { +IMPLEMENT_SINGLE_INSTANCE(DcameraSourceHidumper); + +namespace { +const std::string ARGS_HELP = "-h"; +const std::string ARGS_VERSION_INFO = "--version"; +const std::string ARGS_REGISTERED_INFO = "--registered"; +const std::string ARGS_CURRENTSTATE_INFO = "--curState"; +const std::string STATE_INT = "Init"; +const std::string STATE_REGISTERED = "Registered"; +const std::string STATE_OPENED = "Opened"; +const std::string STATE_CONFIG_STREAM = "ConfigStream"; +const std::string STATE_CAPTURE = "Capture"; + +const std::map ARGS_MAP = { + { ARGS_HELP, HidumpFlag::GET_HELP }, + { ARGS_REGISTERED_INFO, HidumpFlag::GET_REGISTERED_INFO }, + { ARGS_CURRENTSTATE_INFO, HidumpFlag::GET_CURRENTSTATE_INFO }, + { ARGS_VERSION_INFO, HidumpFlag::GET_VERSION_INFO }, +}; + +const std::map STATE_MAP = { + { DCAMERA_STATE_INIT_DUMP, STATE_INT }, + { DCAMERA_STATE_REGIST_DUMP, STATE_REGISTERED }, + { DCAMERA_STATE_OPENED_DUMP, STATE_OPENED }, + { DCAMERA_STATE_CONFIG_STREAM_DUMP, STATE_CONFIG_STREAM }, + { DCAMERA_STATE_CAPTURE_DUMP, STATE_CAPTURE }, +}; +} + +void DcameraSourceHidumper::SetSourceDumpInfo(CameraDumpInfo& camDumpInfo_) +{ + DistributedCameraSourceService::GetDumpInfo(camDumpInfo_); +} + +bool DcameraSourceHidumper::Dump(const std::vector& args, std::string& result) +{ + DHLOGI("DcameraSourceHidumper Dump args.size():%d.", args.size()); + result.clear(); + int32_t argsSize = static_cast(args.size()); + for (int32_t i = 0; i < argsSize; i++) { + DHLOGI("DcameraSourceHidumper Dump args[%d]: %s.", i, args.at(i).c_str()); + } + + if (ProcessDump(args[0], result) != DCAMERA_OK) { + return false; + } + return true; +} + +int32_t DcameraSourceHidumper::ProcessDump(const std::string& args, std::string& result) +{ + DHLOGI("ProcessDump Dump."); + HidumpFlag hf = HidumpFlag::UNKNOWN; + auto operatorIter = ARGS_MAP.find(args); + if (operatorIter != ARGS_MAP.end()) { + hf = operatorIter->second; + } + + if (hf == HidumpFlag::GET_HELP) { + ShowHelp(result); + return DCAMERA_OK; + } + result.clear(); + SetSourceDumpInfo(camDumpInfo_); + int32_t ret = DCAMERA_BAD_VALUE; + switch (hf) { + case HidumpFlag::GET_REGISTERED_INFO: { + ret = GetRegisteredInfo(result); + break; + } + case HidumpFlag::GET_CURRENTSTATE_INFO: { + ret = GetCurrentStateInfo(result); + break; + } + case HidumpFlag::GET_VERSION_INFO: { + ret = GetVersionInfo(result); + break; + } + default: { + ret = ShowIllegalInfomation(result); + break; + } + } + + return ret; +} + +int32_t DcameraSourceHidumper::GetRegisteredInfo(std::string& result) +{ + DHLOGI("GetRegisteredInfo Dump."); + result.append("CameraNumber\n") + .append(std::to_string(camDumpInfo_.regNumber)); + return DCAMERA_OK; +} + +int32_t DcameraSourceHidumper::GetCurrentStateInfo(std::string& result) +{ + DHLOGI("GetCurrentStateInfo Dump."); + std::map devState = camDumpInfo_.curState; + std::string deviceId(""); + int32_t camState = 0; + for (auto it = devState.begin(); it != devState.end(); it++) { + deviceId = it->first; + camState = it->second; + } + DHLOGI("GetCurrentStateInfo camState is %d.", camState); + auto state = STATE_MAP.find(camState); + std::string curState(""); + if (state != STATE_MAP.end()) { + curState = state->second; + } + result.append("CameraId ") + .append("State\n") + .append(deviceId) + .append(" ") + .append(curState); + return DCAMERA_OK; +} + +int32_t DcameraSourceHidumper::GetVersionInfo(std::string& result) +{ + DHLOGI("GetVersionInfo Dump."); + result.append("CameraVersion\n") + .append(camDumpInfo_.version); + return DCAMERA_OK; +} + +void DcameraSourceHidumper::ShowHelp(std::string& result) +{ + DHLOGI("ShowHelp Dump."); + result.append("Usage:dump [options]\n") + .append("Description:\n") + .append("--version ") + .append("dump camera version in the system\n") + .append("--registered ") + .append("dump number of registered cameras in the system\n") + .append("--curState ") + .append("dump current state of the camera in the system\n"); +} + +int32_t DcameraSourceHidumper::ShowIllegalInfomation(std::string& result) +{ + DHLOGI("ShowIllegalInfomation Dump."); + result.append("unknown command"); + return DCAMERA_OK; +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp b/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp index 2aceb73940d33355b99b73a6c5e92125f12e03e1..93f1be29ede8f6101e37e2c0b174c37be831eaf4 100644 --- a/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp +++ b/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp @@ -197,5 +197,44 @@ int32_t DistributedCameraSourceService::UnLoadCameraHDF() { return DCAMERA_OK; } + +int DistributedCameraSourceService::Dump(int32_t fd, const std::vector& args) +{ + DHLOGI("DistributedCameraSourceService Dump."); + std::string result; + std::vector argsStr; + for (auto item : args) { + argsStr.emplace_back(Str16ToStr8(item)); + } + + if (!DcameraSourceHidumper::GetInstance().Dump(argsStr, result)) { + DHLOGE("Hidump error"); + return DCAMERA_BAD_VALUE; + } + + int ret = dprintf(fd, "%s\n", result.c_str()); + if (ret < 0) { + DHLOGE("dprintf error"); + return DCAMERA_BAD_VALUE; + } + + return DCAMERA_OK; +} + +void DistributedCameraSourceService::GetDumpInfo(CameraDumpInfo& camDump) +{ + camDump.regNumber = camerasMap_.size(); + std::map curState; + for (auto it = camerasMap_.begin(); it != camerasMap_.end(); it++) { + DCameraIndex cam = it->first; + std::shared_ptr camSourceDev = it->second; + camDump.version = camSourceDev->GetVersion(); + std::string deviceId = GetAnonyString(cam.devId_); + deviceId.append(cam.dhId_); + int32_t devState = camSourceDev->GetStateInfo(); + curState[deviceId] = devState; + } + camDump.curState = curState; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_dev.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_dev.cpp index 80dd25527a96be3933569341ba6c7effe38e36dc..e9871137e95d930f4e0b852ee26296fd2951b31b 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_dev.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_dev.cpp @@ -549,5 +549,16 @@ void DCameraSourceDev::NotifyHalResult(DCAMERA_EVENT eventType, DCameraSourceEve ExecuteCameraEventNotify(events); return; } + +int32_t DCameraSourceDev::GetStateInfo() +{ + DHLOGI("GetStateInfo In state %d", stateMachine_->GetCameraState()); + return stateMachine_->GetCameraState(); +} + +std::string DCameraSourceDev::GetVersion() +{ + return version_; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerastate/dcamera_source_state_machine.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerastate/dcamera_source_state_machine.cpp index cb7b8a496af45a987139e87848b28f9bb8e908ec..31c851044f1c61b7912f49b546d99e0adba46f2e 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerastate/dcamera_source_state_machine.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerastate/dcamera_source_state_machine.cpp @@ -59,5 +59,11 @@ void DCameraSourceStateMachine::UpdateState(DCameraStateType stateType) auto stateMachine = std::shared_ptr(shared_from_this()); currentState_ = DCameraSourceStateFactory::GetInstance().CreateState(stateType, stateMachine); } + +int32_t DCameraSourceStateMachine::GetCameraState() +{ + DHLOGI("GetCameraState In state %d", currentState_->GetStateType()); + return currentState_->GetStateType(); +} } // namespace DistributedHardware } // namespace OHOS