MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / tryRunEventLoop

Function tryRunEventLoop

src/Gui/Application.cpp:2561–2612  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2559}
2560
2561void tryRunEventLoop(GUISingleApplication& mainApp)
2562{
2563 std::stringstream out;
2564 out << App::Application::getUserCachePath() << App::Application::getExecutableName() << "_"
2565 << App::Application::uniqueInstanceId() << ".lock";
2566
2567 // open a lock file with the PID
2568 Base::FileInfo fi(out.str());
2569 Base::ofstream lock(fi);
2570
2571#if !defined(FC_OS_WIN32) || (BOOST_VERSION < 107600)
2572 std::string filename = out.str();
2573#else
2574 std::wstring filename = fi.toStdWString();
2575#endif
2576 try {
2577 boost::interprocess::file_lock flock(filename.c_str());
2578 if (flock.try_lock()) {
2579 Base::Console().log("Init: Executing event loop…\n");
2580 QApplication::exec();
2581
2582 // Qt can't handle exceptions thrown from event handlers, so we need
2583 // to manually rethrow SystemExitExceptions.
2584 if (mainApp.caughtException) {
2585 throw Base::SystemExitException(*mainApp.caughtException.get());
2586 }
2587
2588 // close the lock file, in case of a crash we can see the existing lock file
2589 // on the next restart and try to repair the documents, if needed.
2590 flock.unlock();
2591 lock.close();
2592 fi.deleteFile();
2593 }
2594 else {
2595 Base::Console().error(
2596 "Failed to create a file lock for the IPC.\n"
2597 "The application will be terminated.\n"
2598 "Attempted lock file: %s",
2599 fi.filePath().c_str()
2600 );
2601 }
2602 }
2603 catch (const boost::interprocess::interprocess_exception& e) {
2604 QString msg = QString::fromLocal8Bit(e.what());
2605 Base::Console().error(
2606 "Failed to create a file lock for the IPC: %s\n"
2607 "Attempted lock file: %s\n",
2608 msg.toUtf8().constData(),
2609 fi.filePath().c_str()
2610 );
2611 }
2612}
2613
2614void runEventLoop(GUISingleApplication& mainApp)
2615{

Callers 1

runEventLoopFunction · 0.85

Calls 14

SystemExitExceptionFunction · 0.85
toStdWStringMethod · 0.80
try_lockMethod · 0.80
constDataMethod · 0.80
strMethod · 0.45
c_strMethod · 0.45
logMethod · 0.45
getMethod · 0.45
unlockMethod · 0.45
closeMethod · 0.45
deleteFileMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected