Factorize --list- options handling
This will limit code duplication as more list options will be added. PR #4213 <https://github.com/Genymobile/scrcpy/pull/4213>
This commit is contained in:
parent
a2fb1b40f6
commit
f085765e04
@ -1993,10 +1993,10 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
|||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
case OPT_LIST_ENCODERS:
|
case OPT_LIST_ENCODERS:
|
||||||
opts->list_encoders = true;
|
opts->list |= SC_OPTION_LIST_ENCODERS;
|
||||||
break;
|
break;
|
||||||
case OPT_LIST_DISPLAYS:
|
case OPT_LIST_DISPLAYS:
|
||||||
opts->list_displays = true;
|
opts->list |= SC_OPTION_LIST_DISPLAYS;
|
||||||
break;
|
break;
|
||||||
case OPT_REQUIRE_AUDIO:
|
case OPT_REQUIRE_AUDIO:
|
||||||
opts->require_audio = true;
|
opts->require_audio = true;
|
||||||
|
@ -79,7 +79,6 @@ const struct scrcpy_options scrcpy_options_default = {
|
|||||||
.video = true,
|
.video = true,
|
||||||
.audio = true,
|
.audio = true,
|
||||||
.require_audio = false,
|
.require_audio = false,
|
||||||
.list_encoders = false,
|
|
||||||
.list_displays = false,
|
|
||||||
.kill_adb_on_close = false,
|
.kill_adb_on_close = false,
|
||||||
|
.list = 0,
|
||||||
};
|
};
|
||||||
|
@ -179,9 +179,10 @@ struct scrcpy_options {
|
|||||||
bool video;
|
bool video;
|
||||||
bool audio;
|
bool audio;
|
||||||
bool require_audio;
|
bool require_audio;
|
||||||
bool list_encoders;
|
|
||||||
bool list_displays;
|
|
||||||
bool kill_adb_on_close;
|
bool kill_adb_on_close;
|
||||||
|
#define SC_OPTION_LIST_ENCODERS 0x1
|
||||||
|
#define SC_OPTION_LIST_DISPLAYS 0x2
|
||||||
|
uint8_t list;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const struct scrcpy_options scrcpy_options_default;
|
extern const struct scrcpy_options scrcpy_options_default;
|
||||||
|
@ -379,9 +379,8 @@ scrcpy(struct scrcpy_options *options) {
|
|||||||
.tcpip_dst = options->tcpip_dst,
|
.tcpip_dst = options->tcpip_dst,
|
||||||
.cleanup = options->cleanup,
|
.cleanup = options->cleanup,
|
||||||
.power_on = options->power_on,
|
.power_on = options->power_on,
|
||||||
.list_encoders = options->list_encoders,
|
|
||||||
.list_displays = options->list_displays,
|
|
||||||
.kill_adb_on_close = options->kill_adb_on_close,
|
.kill_adb_on_close = options->kill_adb_on_close,
|
||||||
|
.list = options->list,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct sc_server_callbacks cbs = {
|
static const struct sc_server_callbacks cbs = {
|
||||||
@ -399,7 +398,7 @@ scrcpy(struct scrcpy_options *options) {
|
|||||||
|
|
||||||
server_started = true;
|
server_started = true;
|
||||||
|
|
||||||
if (options->list_encoders || options->list_displays) {
|
if (options->list) {
|
||||||
bool ok = await_for_server(NULL);
|
bool ok = await_for_server(NULL);
|
||||||
ret = ok ? SCRCPY_EXIT_SUCCESS : SCRCPY_EXIT_FAILURE;
|
ret = ok ? SCRCPY_EXIT_SUCCESS : SCRCPY_EXIT_FAILURE;
|
||||||
goto end;
|
goto end;
|
||||||
|
@ -311,10 +311,10 @@ execute_server(struct sc_server *server,
|
|||||||
// By default, power_on is true
|
// By default, power_on is true
|
||||||
ADD_PARAM("power_on=false");
|
ADD_PARAM("power_on=false");
|
||||||
}
|
}
|
||||||
if (params->list_encoders) {
|
if (params->list & SC_OPTION_LIST_ENCODERS) {
|
||||||
ADD_PARAM("list_encoders=true");
|
ADD_PARAM("list_encoders=true");
|
||||||
}
|
}
|
||||||
if (params->list_displays) {
|
if (params->list & SC_OPTION_LIST_DISPLAYS) {
|
||||||
ADD_PARAM("list_displays=true");
|
ADD_PARAM("list_displays=true");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -896,7 +896,7 @@ run_server(void *data) {
|
|||||||
|
|
||||||
// If --list-* is passed, then the server just prints the requested data
|
// If --list-* is passed, then the server just prints the requested data
|
||||||
// then exits.
|
// then exits.
|
||||||
if (params->list_encoders || params->list_displays) {
|
if (params->list) {
|
||||||
sc_pid pid = execute_server(server, params);
|
sc_pid pid = execute_server(server, params);
|
||||||
if (pid == SC_PROCESS_NONE) {
|
if (pid == SC_PROCESS_NONE) {
|
||||||
goto error_connection_failed;
|
goto error_connection_failed;
|
||||||
|
@ -56,9 +56,8 @@ struct sc_server_params {
|
|||||||
bool select_tcpip;
|
bool select_tcpip;
|
||||||
bool cleanup;
|
bool cleanup;
|
||||||
bool power_on;
|
bool power_on;
|
||||||
bool list_encoders;
|
|
||||||
bool list_displays;
|
|
||||||
bool kill_adb_on_close;
|
bool kill_adb_on_close;
|
||||||
|
uint8_t list;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sc_server {
|
struct sc_server {
|
||||||
|
@ -153,6 +153,10 @@ public class Options {
|
|||||||
return powerOn;
|
return powerOn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getList() {
|
||||||
|
return listEncoders || listDisplays;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean getListEncoders() {
|
public boolean getListEncoders() {
|
||||||
return listEncoders;
|
return listEncoders;
|
||||||
}
|
}
|
||||||
|
@ -195,7 +195,7 @@ public final class Server {
|
|||||||
|
|
||||||
Ln.initLogLevel(options.getLogLevel());
|
Ln.initLogLevel(options.getLogLevel());
|
||||||
|
|
||||||
if (options.getListEncoders() || options.getListDisplays()) {
|
if (options.getList()) {
|
||||||
if (options.getCleanup()) {
|
if (options.getCleanup()) {
|
||||||
CleanUp.unlinkSelf();
|
CleanUp.unlinkSelf();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user