23 #include "model/ocpn_utils.h"
24 #include "model/logger.h"
28 CmdlineAction LocalClientApi::ParseArgs(
const wxCmdLineParser& parser,
30 return CmdlineAction::Skip;
34 CmdlineAction LocalClientApi::ParseArgs(
const wxCmdLineParser& parser,
36 CmdlineAction result = CmdlineAction::Fail;
38 if (parser.GetParamCount() == 0) {
39 result = CmdlineAction::Raise;
40 }
else if (parser.GetParamCount() == 1) {
41 if (parser.GetParam(0) ==
"raise") {
42 result = CmdlineAction::Raise;
43 }
else if (parser.GetParam(0) ==
"quit") {
44 result = CmdlineAction::Quit;
45 }
else if (parser.GetParam(0) ==
"get_rest_endpoint") {
46 result = CmdlineAction::GetRestEndpoint;
47 }
else if (ocpn::exists(parser.GetParam(0).ToStdString().c_str())) {
48 result = CmdlineAction::Open;
49 arg = parser.GetParam(0).ToStdString();
51 }
else if (parser.GetParamCount() == 2) {
52 if (parser.GetParam(0) ==
"open") {
53 result = CmdlineAction::Open;
54 arg = parser.GetParam(1).ToStdString();
61 LocalApiResult LocalClientApi::HandleCmdline(
const wxCmdLineParser& parser) {
63 auto action = ParseArgs(parser, arg);
64 return HandleCmdline(action, arg);
67 LocalApiResult LocalClientApi::HandleCmdline(CmdlineAction action,
68 const std::string& arg) {
70 case CmdlineAction::Fail:
71 MESSAGE_LOG <<
"IpcClient: Cannot parse command line (ignored)";
72 return LocalApiResult(
false,
"Cannot parse command line");
73 case CmdlineAction::Quit: {
74 auto result = SendQuit();
76 MESSAGE_LOG <<
"Error running remote quit cmd: " << result.second;
81 case CmdlineAction::Raise: {
82 auto result = SendRaise();
84 MESSAGE_LOG <<
"Error running remote raise cmd: " << result.second;
89 case CmdlineAction::Open: {
90 auto result = SendOpen(arg.c_str());
92 MESSAGE_LOG <<
"Error running remote open of file \"" << arg
93 <<
"\": " << result.second;
98 case CmdlineAction::GetRestEndpoint: {
99 auto result = GetRestEndpoint();
101 std::cout << result.second <<
"\n" << std::flush;
103 std::cout <<
"Error getting remote endpoint: " << result.second
104 <<
"\n" << std::flush;
107 case CmdlineAction::Skip:
108 return LocalApiResult(
true,
"Unknown command CmdlineAction::Skip");
110 wxLogMessage(
"Strange code path!");
111 return LocalApiResult(
false,
"Internal error");
The local API has a server side handling commands and a client part issuing commands.