mirror of
https://github.com/openharmony/distributed_screen.git
synced 2026-07-19 17:04:08 -04:00
@@ -54,6 +54,7 @@ enum DScreenErrorCode {
|
||||
ERR_DH_SCREEN_SA_UNREGISTER_SCREENLISTENER_FAIL = -500030,
|
||||
ERR_DH_SCREEN_SA_DSCREEN_NEGOTIATE_CODEC_FAIL = -500031,
|
||||
ERR_DH_SCREEN_SA_LOAD_TIMEOUT = -500032,
|
||||
ERR_DH_SCREEN_SA_HIDUMPER_ERROR = -500033,
|
||||
// Transport component error code
|
||||
ERR_DH_SCREEN_TRANS_ERROR = -51000,
|
||||
ERR_DH_SCREEN_TRANS_TIMEOUT = -51001,
|
||||
|
||||
@@ -35,6 +35,7 @@ public:
|
||||
int32_t SubscribeLocalHardware(const std::string &dhId, const std::string ¶m) override;
|
||||
int32_t UnsubscribeLocalHardware(const std::string &dhId) override;
|
||||
void DScreenNotify(const std::string &devId, int32_t eventCode, const std::string &eventContent) override;
|
||||
int Dump(int32_t fd, const std::vector<std::u16string>& args) override;
|
||||
|
||||
protected:
|
||||
void OnStart() override;
|
||||
|
||||
@@ -100,5 +100,19 @@ void DScreenSinkService::DScreenNotify(const std::string &devId, int32_t eventCo
|
||||
eventCode, eventContent.c_str());
|
||||
ScreenRegionManager::GetInstance().HandleDScreenNotify(devId, eventCode, eventContent);
|
||||
}
|
||||
|
||||
int DScreenSinkService::Dump(int32_t fd, const std::vector<std::u16string>& args)
|
||||
{
|
||||
DHLOGI("DScreenSourceService Dump.");
|
||||
std::string result;
|
||||
ScreenRegionManager::GetInstance().GetScreenDumpInfo(result);
|
||||
int ret = dprintf(fd, "%s\n", result.c_str());
|
||||
if (ret < 0) {
|
||||
DHLOGE("dprintf error");
|
||||
return ERR_DH_SCREEN_SA_HIDUMPER_ERROR;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -45,6 +45,8 @@ public:
|
||||
std::string GetRemoteDevId();
|
||||
uint64_t GetScreenId();
|
||||
uint64_t GetDisplayId();
|
||||
std::shared_ptr<VideoParam> GetVideoParam();
|
||||
int32_t GetWindowId();
|
||||
int32_t SetUp();
|
||||
int32_t Start();
|
||||
int32_t Stop();
|
||||
|
||||
@@ -31,12 +31,14 @@ DECLARE_SINGLE_INSTANCE_BASE(ScreenRegionManager);
|
||||
public:
|
||||
int32_t ReleaseAllRegions();
|
||||
void HandleDScreenNotify(const std::string &devId, int32_t eventCode, const std::string &eventContent);
|
||||
void GetScreenDumpInfo(std::string &result);
|
||||
|
||||
private:
|
||||
ScreenRegionManager();
|
||||
~ScreenRegionManager();
|
||||
std::map<std::string, std::shared_ptr<ScreenRegion>> screenRegions_;
|
||||
std::mutex screenRegionsMtx_;
|
||||
std::string localDevId_;
|
||||
|
||||
sptr<IDScreenSource> GetDScreenSourceSA(const std::string &devId);
|
||||
int32_t NotifyRemoteScreenService(const std::string &remoteDevId, const std::string &dhId,
|
||||
|
||||
@@ -73,6 +73,16 @@ std::string ScreenRegion::GetRemoteDevId()
|
||||
return remoteDevId_;
|
||||
}
|
||||
|
||||
std::shared_ptr<VideoParam> ScreenRegion::GetVideoParam()
|
||||
{
|
||||
return videoParam_;
|
||||
}
|
||||
|
||||
int32_t ScreenRegion::GetWindowId()
|
||||
{
|
||||
return windowId_;
|
||||
}
|
||||
|
||||
int32_t ScreenRegion::SetUp()
|
||||
{
|
||||
DHLOGI("ScreenRegion::SetUp, remoteDevId: %s", GetAnonyString(remoteDevId_).c_str());
|
||||
|
||||
@@ -74,6 +74,43 @@ void ScreenRegionManager::HandleDScreenNotify(const std::string &remoteDevId, in
|
||||
DHLOGE("invalid event.");
|
||||
}
|
||||
|
||||
void ScreenRegionManager::GetScreenDumpInfo(std::string &result)
|
||||
{
|
||||
DHLOGI("GetScreenDumpInfo.");
|
||||
result.clear();
|
||||
result.append("screenRegion OnLine:\n[\n");
|
||||
if (screenRegions_.size() == 0) {
|
||||
result.append("]");
|
||||
DHLOGD("no screenRegion");
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto &iter : screenRegions_) {
|
||||
result.append(" {\n");
|
||||
std::shared_ptr<ScreenRegion> screenRegion = iter.second;
|
||||
if (!screenRegion) {
|
||||
continue;
|
||||
}
|
||||
uint64_t screenId = screenRegion->GetScreenId();
|
||||
std::string remoteDevId = screenRegion->GetRemoteDevId();
|
||||
std::shared_ptr<VideoParam> videoParam = screenRegion->GetVideoParam();
|
||||
if (videoParam == nullptr) {
|
||||
continue;
|
||||
}
|
||||
int32_t screenHeight = videoParam->GetScreenHeight();
|
||||
int32_t screenWidth = videoParam->GetScreenWidth();
|
||||
int32_t windowId = screenRegion->GetWindowId();
|
||||
std::string screenInfo = " \"clientWindowId\" : \"" + std::to_string(windowId) + "\",\n" +
|
||||
" \"remoteScreenId\" : \"" + std::to_string(screenId) + "\",\n" +
|
||||
" \"localDevId\" : \"" + GetAnonyString(localDevId_) + "\",\n" +
|
||||
" \"remoteDevId\" : \"" + GetAnonyString(remoteDevId) + "\",\n" +
|
||||
" \"screenWidth\" : \"" + std::to_string(screenWidth) + "\",\n" +
|
||||
" \"screenHeight\" : \"" + std::to_string(screenHeight) + "\"\n";
|
||||
result.append(screenInfo);
|
||||
}
|
||||
result.append(" }\n]");
|
||||
}
|
||||
|
||||
void ScreenRegionManager::HandleNotifySetUp(const std::string &remoteDevId, const std::string &eventContent)
|
||||
{
|
||||
DHLOGI("HandleNotifySetUp, remoteDevId: %s", GetAnonyString(remoteDevId).c_str());
|
||||
@@ -169,6 +206,7 @@ int32_t ScreenRegionManager::NotifyRemoteScreenService(const std::string &remote
|
||||
DHLOGE("notify remote screen service failed, cannot get local device id");
|
||||
return ret;
|
||||
}
|
||||
localDevId_ = localDevId;
|
||||
remoteSourceSA->DScreenNotify(localDevId, eventCode, eventContent);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ public:
|
||||
void RegisterDScreenCallback(const sptr<IDScreenSourceCallback> &callback);
|
||||
void HandleScreenChange(const std::shared_ptr<DScreen> &changedScreen, Rosen::ScreenGroupChangeEvent event);
|
||||
std::shared_ptr<DScreen> FindDScreenByScreenId(uint64_t screenId);
|
||||
void GetScreenDumpInfo(std::string &result);
|
||||
|
||||
private:
|
||||
~DScreenManager();
|
||||
@@ -69,6 +70,7 @@ private:
|
||||
sptr<IDScreenSourceCallback> dScreenSourceCallbackProxy_ = nullptr;
|
||||
sptr<DScreenGroupListener> dScreenGroupListener_ = nullptr;
|
||||
std::shared_ptr<IDScreenCallback> dScreenCallback_ = nullptr;
|
||||
std::string localDevId_;
|
||||
|
||||
sptr<IDScreenSink> GetDScreenSinkSA(const std::string &devId);
|
||||
int32_t NotifyRemoteScreenService(const std::string &devId, int32_t eventCode, const std::string &eventContent);
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
|
||||
#include "dscreen_manager.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
@@ -31,6 +33,17 @@ using json = nlohmann::json;
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
IMPLEMENT_SINGLE_INSTANCE(DScreenManager);
|
||||
|
||||
const std::map<DScreenState, std::string> stateMap = {
|
||||
{ DISABLED, "disabled" },
|
||||
{ ENABLED, "enabled" },
|
||||
{ DISABLING, "disabling" },
|
||||
{ ENABLING, "enabling" },
|
||||
{ CONNECTING, "connecting" },
|
||||
{ CONNECTED, "connected" },
|
||||
{ DISCONNECTING, "disconnecting" }
|
||||
};
|
||||
|
||||
DScreenManager::DScreenManager()
|
||||
{
|
||||
DHLOGI("DScreenMgr construct.");
|
||||
@@ -293,6 +306,45 @@ std::shared_ptr<DScreen> DScreenManager::FindDScreenByScreenId(uint64_t screenId
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void DScreenManager::GetScreenDumpInfo(std::string &result)
|
||||
{
|
||||
DHLOGI("GetScreenDumpInfo.");
|
||||
result.clear();
|
||||
result.append("RemoteScreens OnLine:\n[\n");
|
||||
if (dScreens_.size() == 0) {
|
||||
result.append("]");
|
||||
DHLOGD("no virtualscreen");
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto &iter : dScreens_) {
|
||||
result.append(" {\n");
|
||||
std::shared_ptr<DScreen> dScreen = iter.second;
|
||||
if (!dScreen) {
|
||||
continue;
|
||||
}
|
||||
uint64_t screenId = dScreen->GetScreenId();
|
||||
std::string devId = dScreen->GetDevId();
|
||||
std::shared_ptr<VideoParam> videoParam = dScreen->GetVideoParam();
|
||||
if (videoParam == nullptr) {
|
||||
continue;
|
||||
}
|
||||
int32_t screenHeight = videoParam->GetScreenHeight();
|
||||
int32_t screenWidth = videoParam->GetScreenWidth();
|
||||
DScreenState state = dScreen->GetState();
|
||||
std::string screenState =
|
||||
stateMap.find(state) == stateMap.end() ? "unknown state" : stateMap.find(state)->second;
|
||||
std::string screenInfo = " \"virtualScreenId\" : \"" + std::to_string(screenId) + "\",\n" +
|
||||
" \"localDevId\" : \"" + GetAnonyString(localDevId_) + "\",\n" +
|
||||
" \"remoteDevId\" : \"" + GetAnonyString(devId) + "\",\n" +
|
||||
" \"screenWidth\" : \"" + std::to_string(screenWidth) + "\",\n" +
|
||||
" \"screenHeight\" : \"" + std::to_string(screenHeight) + "\",\n" +
|
||||
" \"state\" : \"" + screenState + "\"\n";
|
||||
result.append(screenInfo);
|
||||
}
|
||||
result.append(" }\n]");
|
||||
}
|
||||
|
||||
void DScreenManager::HandleDScreenNotify(const std::string &devId, int32_t eventCode,
|
||||
const std::string &eventContent)
|
||||
{
|
||||
@@ -321,6 +373,7 @@ int32_t DScreenManager::NotifyRemoteScreenService(const std::string &devId, int3
|
||||
DHLOGE("notify remote screen service failed, cannot get local device id");
|
||||
return ret;
|
||||
}
|
||||
localDevId_ = localDevId;
|
||||
remoteSinkSA->DScreenNotify(localDevId, eventCode, eventContent);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ public:
|
||||
int32_t ConfigDistributedHardware(const std::string &devId, const std::string &dhId, const std::string &key,
|
||||
const std::string &value) override;
|
||||
void DScreenNotify(const std::string &devId, const int32_t eventCode, const std::string &eventContent) override;
|
||||
int Dump(int32_t fd, const std::vector<std::u16string>& args) override;
|
||||
|
||||
protected:
|
||||
void OnStart() override;
|
||||
|
||||
@@ -141,5 +141,19 @@ void DScreenSourceService::DScreenNotify(const std::string &devId, const int32_t
|
||||
DHLOGI("DScreenNotify, devId: %s, eventCode: %d", GetAnonyString(devId).c_str(), eventCode);
|
||||
DScreenManager::GetInstance().HandleDScreenNotify(devId, eventCode, eventContent);
|
||||
}
|
||||
|
||||
int DScreenSourceService::Dump(int32_t fd, const std::vector<std::u16string>& args)
|
||||
{
|
||||
DHLOGI("DScreenSourceService Dump.");
|
||||
std::string result;
|
||||
DScreenManager::GetInstance().GetScreenDumpInfo(result);
|
||||
int ret = dprintf(fd, "%s\n", result.c_str());
|
||||
if (ret < 0) {
|
||||
DHLOGE("dprintf error");
|
||||
return ERR_DH_SCREEN_SA_HIDUMPER_ERROR;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
Reference in New Issue
Block a user