Parse arg refactoring #4124

Used argParser in DaemonApp.
This commit is contained in:
Xinyu Hou 2014-10-23 12:09:09 +01:00
parent a71ebc78b3
commit a32cb41342

View File

@ -22,6 +22,9 @@
#include "synergy/DaemonApp.h" #include "synergy/DaemonApp.h"
#include "synergy/App.h" #include "synergy/App.h"
#include "synergy/ArgParser.h"
#include "synergy/ServerArgs.h"
#include "synergy/ClientArgs.h"
#include "ipc/IpcClientProxy.h" #include "ipc/IpcClientProxy.h"
#include "ipc/IpcMessage.h" #include "ipc/IpcMessage.h"
#include "ipc/IpcLogOutputter.h" #include "ipc/IpcLogOutputter.h"
@ -301,13 +304,29 @@ CDaemonApp::handleIpcMessage(const CEvent& e, void*)
if (!command.empty()) { if (!command.empty()) {
LOG((CLOG_DEBUG "new command, elevate=%d command=%s", cm->elevate(), command.c_str())); LOG((CLOG_DEBUG "new command, elevate=%d command=%s", cm->elevate(), command.c_str()));
CString debugArg("--debug"); std::vector<CString> argsArray;
UInt32 debugArgPos = static_cast<UInt32>(command.find(debugArg)); CArgParser::splitCommandString(command, argsArray);
if (debugArgPos != CString::npos) { CArgParser argParser(NULL);
UInt32 from = debugArgPos + static_cast<UInt32>(debugArg.size()) + 1; const char** argv = argParser.getArgv(argsArray);
UInt32 nextSpace = static_cast<UInt32>(command.find(" ", from)); CServerArgs serverArgs;
CString logLevel(command.substr(from, nextSpace - from)); CClientArgs clientArgs;
int argc = static_cast<int>(argsArray.size());
bool server = argsArray[0].find("synergys") != CString::npos ? true : false;
CArgsBase* argBase = NULL;
if (server) {
argParser.parseServerArgs(serverArgs, argc, argv);
argBase = &serverArgs;
}
else {
argParser.parseClientArgs(clientArgs, argc, argv);
argBase = &clientArgs;
}
delete[] argv;
CString logLevel(argBase->m_logFilter);
if (!logLevel.empty()) {
try { try {
// change log level based on that in the command string // change log level based on that in the command string
// and change to that log level now. // and change to that log level now.