mirror of
https://github.com/openharmony/distributed_camera.git
synced 2026-07-21 04:05:22 -04:00
@@ -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",
|
||||
|
||||
@@ -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 <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "single_instance.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class DCameraSourceDev;
|
||||
enum class HidumpFlag {
|
||||
UNKNOW = 0,
|
||||
GET_HELP,
|
||||
GET_CAMERA_INFO,
|
||||
GET_OPENED_INFO,
|
||||
GET_VERSION_INFO,
|
||||
};
|
||||
|
||||
struct CameraDumpInfo {
|
||||
std::string version;
|
||||
int32_t camNumber;
|
||||
std::string dhOpened;
|
||||
};
|
||||
|
||||
class DcameraSinkHidumper {
|
||||
DECLARE_SINGLE_INSTANCE_BASE(DcameraSinkHidumper);
|
||||
|
||||
public:
|
||||
bool Dump(const std::vector<std::string>& 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
|
||||
+3
@@ -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<std::u16string>& args) override;
|
||||
static void GetCamDumpInfo(CameraDumpInfo& camDump);
|
||||
|
||||
protected:
|
||||
void OnStart() override;
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* 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 <iterator>
|
||||
|
||||
#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<std::string, HidumpFlag> 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<std::string>& args, std::string& result)
|
||||
{
|
||||
DHLOGI("DcameraSinkHidumper Dump args.size():%d.", args.size());
|
||||
result.clear();
|
||||
int32_t argsSize = static_cast<int32_t>(args.size());
|
||||
for (int i = 0; i < argsSize; i++) {
|
||||
DHLOGI("DcameraSinkHidumper Dump args[%d]: %s.", i, args.at(i).c_str());
|
||||
}
|
||||
|
||||
int32_t ret = ProcessDump(args[0], result);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t DcameraSinkHidumper::ProcessDump(const std::string& args, std::string& result)
|
||||
{
|
||||
DHLOGI("ProcessDump Dump.");
|
||||
HidumpFlag hf = HidumpFlag::UNKNOW;
|
||||
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")
|
||||
.append(camDumpInfo_.dhOpened);
|
||||
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 <command> [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("unkown command");
|
||||
return DCAMERA_OK;
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
+32
@@ -33,6 +33,7 @@ namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
REGISTER_SYSTEM_ABILITY_BY_ID(DistributedCameraSinkService, DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID, true);
|
||||
|
||||
static CameraDumpInfo g_camDump;
|
||||
DistributedCameraSinkService::DistributedCameraSinkService(int32_t saId, bool runOnCreate)
|
||||
: SystemAbility(saId, runOnCreate)
|
||||
{
|
||||
@@ -82,6 +83,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 +95,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<DCameraSinkDev> sinkDevice = std::make_shared<DCameraSinkDev>(dhId);
|
||||
ret = sinkDevice->Init();
|
||||
@@ -188,6 +191,7 @@ int32_t DistributedCameraSinkService::ChannelNeg(const std::string& dhId, std::s
|
||||
return DCAMERA_NOT_FOUND;
|
||||
}
|
||||
|
||||
g_camDump.dhOpened = GetAnonyString(dhId);
|
||||
std::shared_ptr<DCameraSinkDev> sinkDevice = iter->second;
|
||||
int32_t ret = sinkDevice->ChannelNeg(channelInfo);
|
||||
if (ret != DCAMERA_OK) {
|
||||
@@ -254,5 +258,33 @@ int32_t DistributedCameraSinkService::CloseChannel(const std::string& dhId)
|
||||
DHLOGI("DistributedCameraSinkService::CloseChannel success");
|
||||
return DCAMERA_OK;
|
||||
}
|
||||
|
||||
int DistributedCameraSinkService::Dump(int32_t fd, const std::vector<std::u16string>& args)
|
||||
{
|
||||
DHLOGI("DistributedCameraSinkService Dump.");
|
||||
std::string result;
|
||||
std::vector<std::string> 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::GetCamDumpInfo(CameraDumpInfo& camDump)
|
||||
{
|
||||
camDump = g_camDump;
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -60,6 +60,7 @@ ohos_shared_library("distributed_camera_source") {
|
||||
"${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_source_hidumper.cpp",
|
||||
"src/distributedcamera/dcamera_service_state_listener.cpp",
|
||||
"src/distributedcamera/dcamera_source_callback_proxy.cpp",
|
||||
"src/distributedcamera/distributed_camera_source_service.cpp",
|
||||
|
||||
+73
@@ -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 <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "single_instance.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class DCameraSourceDev;
|
||||
enum class HidumpFlag {
|
||||
UNKNOW = 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<std::string, int32_t> curState;
|
||||
};
|
||||
|
||||
class DcameraSourceHidumper {
|
||||
DECLARE_SINGLE_INSTANCE_BASE(DcameraSourceHidumper);
|
||||
|
||||
public:
|
||||
bool Dump(const std::vector<std::string>& 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
|
||||
+4
@@ -19,10 +19,12 @@
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#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<std::u16string>& args) override;
|
||||
static void GetDumpInfo(CameraDumpInfo& camDump);
|
||||
|
||||
static std::map<DCameraIndex, std::shared_ptr<DCameraSourceDev>> camerasMap_;
|
||||
|
||||
|
||||
@@ -50,6 +50,8 @@ public:
|
||||
int32_t UpdateCameraSettings(const std::vector<std::shared_ptr<DCameraSettings>>& settings);
|
||||
|
||||
void OnEvent(DCameraSourceEvent& event) override;
|
||||
int32_t GetStateInfo();
|
||||
std::string GetVersion();
|
||||
|
||||
public:
|
||||
virtual int32_t ExecuteRegister(std::shared_ptr<DCameraRegistParam>& param);
|
||||
|
||||
+1
@@ -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<DCameraSourceState> currentState_;
|
||||
|
||||
+172
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
* 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 <iterator>
|
||||
|
||||
#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<std::string, HidumpFlag> 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<int32_t, std::string> 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<std::string>& args, std::string& result)
|
||||
{
|
||||
DHLOGI("DcameraSourceHidumper Dump args.size():%d.", args.size());
|
||||
result.clear();
|
||||
int32_t argsSize = static_cast<int32_t>(args.size());
|
||||
for (int i = 0; i < argsSize; i++) {
|
||||
DHLOGI("DcameraSourceHidumper Dump args[%d]: %s.", i, args.at(i).c_str());
|
||||
}
|
||||
|
||||
int32_t ret = ProcessDump(args[0], result);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t DcameraSourceHidumper::ProcessDump(const std::string& args, std::string& result)
|
||||
{
|
||||
DHLOGI("ProcessDump Dump.");
|
||||
HidumpFlag hf = HidumpFlag::UNKNOW;
|
||||
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<std::string, int32_t> devState = camDumpInfo_.curState;
|
||||
std::string deviceId;
|
||||
int32_t camState;
|
||||
std::map<std::string, int32_t>::iterator it;
|
||||
for (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 <command> [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("--currentState ")
|
||||
.append("dump current state of the camera in the system\n");
|
||||
}
|
||||
|
||||
int32_t DcameraSourceHidumper::ShowIllegalInfomation(std::string& result)
|
||||
{
|
||||
DHLOGI("ShowIllegalInfomation Dump.");
|
||||
result.append("unkown command");
|
||||
return DCAMERA_OK;
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
+44
@@ -15,6 +15,8 @@
|
||||
|
||||
#include "distributed_camera_source_service.h"
|
||||
|
||||
#include <iterator>
|
||||
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "ipc_types.h"
|
||||
@@ -197,5 +199,47 @@ int32_t DistributedCameraSourceService::UnLoadCameraHDF()
|
||||
{
|
||||
return DCAMERA_OK;
|
||||
}
|
||||
|
||||
int DistributedCameraSourceService::Dump(int32_t fd, const std::vector<std::u16string>& args)
|
||||
{
|
||||
DHLOGI("DistributedCameraSourceService Dump.");
|
||||
std::string result;
|
||||
std::vector<std::string> 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();
|
||||
DHLOGI("camDump 111111");
|
||||
std::map<std::string, int32_t> curState;
|
||||
std::map<DCameraIndex, std::shared_ptr<DCameraSourceDev>>::iterator it;
|
||||
for (it = camerasMap_.begin(); it != camerasMap_.end(); it++) {
|
||||
DCameraIndex cam = it->first;
|
||||
std::shared_ptr<DCameraSourceDev> camSourceDev = it->second;
|
||||
camDump.version = camSourceDev->GetVersion();
|
||||
std::string deviceId = GetAnonyString(cam.devId_);
|
||||
deviceId.append(cam.dhId_);
|
||||
int32_t devState = camSourceDev->GetStateInfo();
|
||||
DHLOGI("camDump 111111 devState %d", devState);
|
||||
curState[deviceId] = devState;
|
||||
}
|
||||
camDump.curState = curState;
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -549,5 +549,16 @@ void DCameraSourceDev::NotifyHalResult(DCAMERA_EVENT eventType, DCameraSourceEve
|
||||
ExecuteCameraEventNotify(events);
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t DCameraSourceDev::GetStateInfo()
|
||||
{
|
||||
DHLOGE("GetStateInfo In state %d", stateMachine_->GetCameraState());
|
||||
return stateMachine_->GetCameraState();
|
||||
}
|
||||
|
||||
std::string DCameraSourceDev::GetVersion()
|
||||
{
|
||||
return version_;
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
+6
@@ -59,5 +59,11 @@ void DCameraSourceStateMachine::UpdateState(DCameraStateType stateType)
|
||||
auto stateMachine = std::shared_ptr<DCameraSourceStateMachine>(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
|
||||
|
||||
Reference in New Issue
Block a user