int main(int argc, char** argv) { #if SYSAPI_WIN32 // record window instance for tray icon, etc ArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL)); #endif Arch arch; arch.init(); Log log; EventQueue events; ClientApp app(&events, createTaskBarReceiver); return app.run(argc, argv); }
int main(int argc, char **argv) { #if SYSAPI_WIN32 // record window instance for tray icon, etc ArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL)); #endif Arch arch; arch.init(); Log log; log.setFilter(kDEBUG2); string lockFile; for (int i = 0; i < argc; i++) { if (string(argv[i]).compare("--lock-file") == 0) { lockFile = argv[i + 1]; } } if (!lockFile.empty()) { lock(lockFile); } testing::InitGoogleTest(&argc, argv); int result = RUN_ALL_TESTS(); if (!lockFile.empty()) { unlock(lockFile); } // gtest seems to randomly finish with error codes (e.g. -1, -1073741819) // even when no tests have failed. not sure what causes this, but it // happens on all platforms and keeps leading to false positives. // according to the documentation, 1 is a failure, so we should be // able to trust that code. return (result == 1) ? 1 : 0; }
int main(int argc, char **argv) { #if SYSAPI_WIN32 // HACK: shouldn't be needed, but logging fails without this. ArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL)); #endif Arch arch; arch.init(); Log log; log.setFilter(kDEBUG4); testing::InitGoogleTest(&argc, argv); // gtest seems to randomly finish with error codes (e.g. -1, -1073741819) // even when no tests have failed. not sure what causes this, but it // happens on all platforms and keeps leading to false positives. // according to the documentation, 1 is a failure, so we should be // able to trust that code. return (RUN_ALL_TESTS() == 1) ? 1 : 0; }
int DaemonApp::run(int argc, char** argv) { #if SYSAPI_WIN32 // win32 instance needed for threading, etc. ArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL)); #endif Arch arch; arch.init(); Log log; EventQueue events; m_events = &events; bool uninstall = false; try { #if SYSAPI_WIN32 // sends debug messages to visual studio console window. log.insert(new MSWindowsDebugOutputter()); #endif // default log level to system setting. string logLevel = arch.setting("LogLevel"); if (logLevel != "") log.setFilter(logLevel.c_str()); bool foreground = false; for (int i = 1; i < argc; ++i) { string arg(argv[i]); if (arg == "/f" || arg == "-f") { foreground = true; } #if SYSAPI_WIN32 else if (arg == "/install") { uninstall = true; arch.installDaemon(); return kExitSuccess; } else if (arg == "/uninstall") { arch.uninstallDaemon(); return kExitSuccess; } #endif else { stringstream ss; ss << "Unrecognized argument: " << arg; foregroundError(ss.str().c_str()); return kExitArgs; } } if (foreground) { // run process in foreground instead of daemonizing. // useful for debugging. mainLoop(false); } else { #if SYSAPI_WIN32 arch.daemonize("Synergy", winMainLoopStatic); #elif SYSAPI_UNIX arch.daemonize("Synergy", unixMainLoopStatic); #endif } return kExitSuccess; } catch (XArch& e) { String message = e.what(); if (uninstall && (message.find("The service has not been started") != String::npos)) { // TODO: if we're keeping this use error code instead (what is it?!). // HACK: this message happens intermittently, not sure where from but // it's quite misleading for the user. they thing something has gone // horribly wrong, but it's just the service manager reporting a false // positive (the service has actually shut down in most cases). } else { foregroundError(message.c_str()); } return kExitFailed; } catch (std::exception& e) { foregroundError(e.what()); return kExitFailed; } catch (...) { foregroundError("Unrecognized error."); return kExitFailed; } }