change 'AsyncCallback<boolean>' to 'AsyncCallback<void>'

Signed-off-by: lu <zhaolu2@huawei.com>
Change-Id: I452460bacb8cdf03cf25246e346edef54c7027ce
This commit is contained in:
lu
2022-05-14 16:30:23 +08:00
parent 44e06aeb35
commit b4e1bbcb50
4 changed files with 44 additions and 66 deletions
+1 -1
View File
@@ -70,7 +70,7 @@ enum class DMError : int32_t {
DM_ERROR_WRITE_DATA_FAILED = 170,
DM_ERROR_RENDER_SERVICE_FAILED = 180,
DM_ERROR_UNREGISTER_AGENT_FAILED = 190,
DM_ERROR_UNKNOWN,
DM_ERROR_UNKNOWN = -1,
};
using DisplayStateCallback = std::function<void(DisplayState)>;
+8 -33
View File
@@ -27,11 +27,6 @@ declare namespace screen {
* @since 9
*/
function getAllScreens(callback: AsyncCallback<Array<Screen>>): void;
/**
* get all screen
* @since 9
*/
function getAllScreens(): Promise<Array<Screen>>;
/**
@@ -52,24 +47,14 @@ declare namespace screen {
* make screens as expand-screen
* @since 9
*/
function makeExpand(options:Array<ExpandOption>, callback: AsyncCallback<number>): void;
/**
* make screens as expand-screen
* @since 9
*/
function makeExpand(options:Array<ExpandOption>, callback: AsyncCallback<number>): void;
function makeExpand(options:Array<ExpandOption>): Promise<number>;
/**
* make screens as mirror-screen
* @since 9
*/
function makeMirror(mainScreen:number, mirrorScreen:Array<number>, callback: AsyncCallback<number>): void;
/**
* make screens as mirror-screen
* @since 9
*/
function makeMirror(mainScreen:number, mirrorScreen:Array<number>, callback: AsyncCallback<number>): void;
function makeMirror(mainScreen:number, mirrorScreen:Array<number>): Promise<number>;
/**
@@ -129,27 +114,17 @@ declare namespace screen {
* set the orientation of the screen
* @since 9
*/
setOrientation(orientation: Orientation, callback: AsyncCallback<boolean>): void;
/**
* set the orientation of the screen
* @since 9
*/
setOrientation(orientation: Orientation): Promise<boolean>;
setOrientation(orientation: Orientation, callback: AsyncCallback<void>): void;
setOrientation(orientation: Orientation): Promise<void>;
/**
* active the mode
*/
setScreenActiveMode(modeIndex: number, callback: AsyncCallback<boolean>): void;
setScreenActiveMode(modeIndex: number, callback: AsyncCallback<void>): void;
setScreenActiveMode(modeIndex: number): Promise<void>;
/**
* active the mode
*/
setScreenActiveMode(modeIndex: number): Promise<boolean>;
setDensityDpi(densityDpi: number, callback: AsyncCallback<boolean>): void;
setDensityDpi(densityDpi: number): Promise<boolean>;
setDensityDpi(densityDpi: number, callback: AsyncCallback<void>): void;
setDensityDpi(densityDpi: number): Promise<void>;
}
/**
@@ -70,10 +70,10 @@ NativeValue* JsScreen::SetOrientation(NativeEngine* engine, NativeCallbackInfo*
NativeValue* JsScreen::OnSetOrientation(NativeEngine& engine, NativeCallbackInfo& info)
{
WLOGFI("JsScreen::OnSetOrientation is called");
WLOGFI("OnSetOrientation is called");
bool paramValidFlag = true;
Orientation orientation = Orientation::UNSPECIFIED;
if (info.argc != ARGC_ONE) {
if (info.argc != ARGC_ONE && info.argc != ARGC_TWO) {
WLOGFE("OnSetOrientation Params not match, info argc: %{public}zu", info.argc);
paramValidFlag = false;
} else {
@@ -86,7 +86,7 @@ NativeValue* JsScreen::OnSetOrientation(NativeEngine& engine, NativeCallbackInfo
AsyncTask::CompleteCallback complete =
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
if (!paramValidFlag) {
WLOGE("JsScreen::OnSetOrientation paramValidFlag error");
WLOGE("OnSetOrientation paramValidFlag error");
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(DMError::DM_ERROR_INVALID_PARAM),
"JsScreen::OnSetOrientation failed."));
return;
@@ -100,11 +100,12 @@ NativeValue* JsScreen::OnSetOrientation(NativeEngine& engine, NativeCallbackInfo
bool res = screen_->SetOrientation(orientation);
if (res) {
task.Resolve(engine, CreateJsValue(engine, true));
WLOGFI("JsScreen::OnSetOrientation success");
task.Resolve(engine, engine.CreateUndefined());
WLOGFI("OnSetOrientation success");
} else {
task.Resolve(engine, CreateJsError(engine, false, "JsScreen::OnSetOrientation failed."));
WLOGFE("JsScreen::OnSetOrientation failed");
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(DMError::DM_ERROR_UNKNOWN),
"JsScreen::OnSetOrientation failed."));
WLOGFE("OnSetOrientation failed");
}
};
NativeValue* lastParam = nullptr;
@@ -120,17 +121,17 @@ NativeValue* JsScreen::OnSetOrientation(NativeEngine& engine, NativeCallbackInfo
NativeValue* JsScreen::SetScreenActiveMode(NativeEngine* engine, NativeCallbackInfo* info)
{
WLOGFI("JsScreen::SetScreenActiveMode is called");
WLOGFI("SetScreenActiveMode is called");
JsScreen* me = CheckParamsAndGetThis<JsScreen>(engine, info);
return (me != nullptr) ? me->OnSetScreenActiveMode(*engine, *info) : nullptr;
}
NativeValue* JsScreen::OnSetScreenActiveMode(NativeEngine& engine, NativeCallbackInfo& info)
{
WLOGFI("JsScreen::OnSetScreenActiveMode is called");
WLOGFI("OnSetScreenActiveMode is called");
bool paramValidFlag = true;
uint32_t modeId = 0;
if (info.argc != ARGC_ONE) {
if (info.argc != ARGC_ONE && info.argc != ARGC_TWO) {
WLOGFE("OnSetScreenActiveMode Params not match %{public}zu", info.argc);
paramValidFlag = false;
} else {
@@ -143,18 +144,19 @@ NativeValue* JsScreen::OnSetScreenActiveMode(NativeEngine& engine, NativeCallbac
AsyncTask::CompleteCallback complete =
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
if (!paramValidFlag) {
WLOGFE("JsScreen::OnSetScreenActiveMode paramValidFlag error");
WLOGFE("OnSetScreenActiveMode paramValidFlag error");
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(DMError::DM_ERROR_INVALID_PARAM),
"JsScreen::OnSetScreenActiveMode failed."));
return;
}
bool res = screen_->SetScreenActiveMode(modeId);
if (res) {
task.Resolve(engine, CreateJsValue(engine, true));
WLOGFI("JsScreen::OnSetScreenActiveMode success");
task.Resolve(engine, engine.CreateUndefined());
WLOGFI("OnSetScreenActiveMode success");
} else {
task.Reject(engine, CreateJsError(engine, false, "JsScreen::OnSetScreenActiveMode failed."));
WLOGFE("JsScreen::OnSetScreenActiveMode failed");
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(DMError::DM_ERROR_UNKNOWN),
"JsScreen::OnSetScreenActiveMode failed."));
WLOGFE("OnSetScreenActiveMode failed");
}
};
NativeValue* lastParam = nullptr;
@@ -169,17 +171,17 @@ NativeValue* JsScreen::OnSetScreenActiveMode(NativeEngine& engine, NativeCallbac
NativeValue* JsScreen::SetDensityDpi(NativeEngine* engine, NativeCallbackInfo* info)
{
WLOGFI("JsScreen::SetDensityDpi is called");
WLOGFI("SetDensityDpi is called");
JsScreen* me = CheckParamsAndGetThis<JsScreen>(engine, info);
return (me != nullptr) ? me->OnSetDensityDpi(*engine, *info) : nullptr;
}
NativeValue* JsScreen::OnSetDensityDpi(NativeEngine& engine, NativeCallbackInfo& info)
{
WLOGFI("JsScreen::OnSetDensityDpi is called");
WLOGFI("OnSetDensityDpi is called");
bool paramValidFlag = true;
uint32_t densityDpi = 0;
if (info.argc != ARGC_ONE) {
if (info.argc != ARGC_ONE && info.argc != ARGC_TWO) {
WLOGFE("OnSetDensityDpi Params not match %{public}zu", info.argc);
paramValidFlag = false;
} else {
@@ -192,18 +194,19 @@ NativeValue* JsScreen::OnSetDensityDpi(NativeEngine& engine, NativeCallbackInfo&
AsyncTask::CompleteCallback complete =
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
if (!paramValidFlag) {
WLOGFE("JsScreen::OnSetDensityDpi paramValidFlag error");
WLOGFE("OnSetDensityDpi paramValidFlag error");
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(DMError::DM_ERROR_INVALID_PARAM),
"JsScreen::OnSetDensityDpi failed."));
return;
}
bool res = screen_->SetDensityDpi(densityDpi);
if (res) {
task.Resolve(engine, CreateJsValue(engine, true));
WLOGFI("JsScreen::OnSetDensityDpi success");
task.Resolve(engine, engine.CreateUndefined());
WLOGFI("OnSetDensityDpi success");
} else {
task.Reject(engine, CreateJsError(engine, false, "JsScreen::OnSetDensityDpi failed."));
WLOGFE("JsScreen::OnSetDensityDpi failed");
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(DMError::DM_ERROR_UNKNOWN),
"JsScreen::OnSetDensityDpi failed."));
WLOGFE("OnSetDensityDpi failed");
}
};
NativeValue* lastParam = nullptr;
@@ -86,7 +86,7 @@ std::mutex mtx_;
NativeValue* OnGetAllScreens(NativeEngine& engine, NativeCallbackInfo& info)
{
WLOGFI("JsScreenManager::OnGetAllScreens is called");
WLOGFI("OnGetAllScreens is called");
AsyncTask::CompleteCallback complete =
[this](NativeEngine& engine, AsyncTask& task, int32_t status) {
std::vector<sptr<Screen>> screens = SingletonContainer::Get<ScreenManager>().GetAllScreens();
@@ -271,8 +271,8 @@ NativeValue* OnUnregisterScreenManagerCallback(NativeEngine& engine, NativeCallb
NativeValue* OnMakeMirror(NativeEngine& engine, NativeCallbackInfo& info)
{
WLOGFI("JsScreenManager::OnMakeMirror is called");
if (info.argc != ARGC_TWO) {
WLOGFI("OnMakeMirror is called");
if (info.argc != ARGC_TWO && info.argc != ARGC_THREE) {
WLOGFE("Params not match");
return engine.CreateUndefined();
}
@@ -304,11 +304,11 @@ NativeValue* OnMakeMirror(NativeEngine& engine, NativeCallbackInfo& info)
ScreenId id = SingletonContainer::Get<ScreenManager>().MakeMirror(mainScreenId, screenIds);
if (id != SCREEN_ID_INVALID) {
task.Resolve(engine, CreateJsValue(engine, static_cast<uint32_t>(id)));
WLOGFI("JsScreenManager::MakeMirror success");
WLOGFI("MakeMirror success");
} else {
task.Reject(engine, CreateJsError(engine,
static_cast<int32_t>(DMError::DM_ERROR_NULLPTR), "JsScreenManager::OnMakeMirror failed."));
WLOGFE("JsScreenManager::MakeMirror failed");
WLOGFE("MakeMirror failed");
}
};
NativeValue* lastParam = nullptr;
@@ -323,8 +323,8 @@ NativeValue* OnMakeMirror(NativeEngine& engine, NativeCallbackInfo& info)
NativeValue* OnMakeExpand(NativeEngine& engine, NativeCallbackInfo& info)
{
WLOGFI("JsScreenManager::OnMakeExpand is called");
if (info.argc != ARGC_ONE) {
WLOGFI("OnMakeExpand is called");
if (info.argc != ARGC_ONE && info.argc != ARGC_TWO) {
WLOGFE("Params not match");
return engine.CreateUndefined();
}
@@ -352,11 +352,11 @@ NativeValue* OnMakeExpand(NativeEngine& engine, NativeCallbackInfo& info)
ScreenId id = SingletonContainer::Get<ScreenManager>().MakeExpand(options);
if (id != SCREEN_ID_INVALID) {
task.Resolve(engine, CreateJsValue(engine, static_cast<uint32_t>(id)));
WLOGFI("JsScreenManager::MakeExpand success");
WLOGFI("MakeExpand success");
} else {
task.Reject(engine, CreateJsError(engine,
static_cast<int32_t>(DMError::DM_ERROR_NULLPTR), "JsScreenManager::OnMakeExpand failed."));
WLOGFE("JsScreenManager::MakeExpand failed");
WLOGFE("MakeExpand failed");
}
};
NativeValue* lastParam = nullptr;