void _MESSAGE(const char* fmt, ...) { va_list args; va_start(args, fmt); char formatBuf[1024]; vsprintf_s(formatBuf, fmt, args); va_end(args); gLog << formatBuf << endl; gLog.flush(); }
int main(int argc, char *argv[]) { using namespace boost::interprocess; QGuiApplication app(argc, argv); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); engine.load(QUrl(QStringLiteral("qrc:/Procyon_Toolbox.qml"))); windows_shared_memory shm(open_only, "DBG_LOG_MEM", read_only); mapped_region region(shm, read_only); char *myChar = new char[100]; memcpy(myChar, region.get_address(), 100); DebugLog *dbgLogger = new DebugLog(engine.rootObjects().value(0)); //qmlRegisterType<DebugLog>("debugUtils", 1, 0, "DebugLog"); qRegisterMetaType<DebugLog*>("DebugLog"); QString temp = QString(myChar); temp.insert(0, "[INFO] "); int index = 0; // int test = temp.length(); // int test2 = temp.count(); // int test3 = temp.size(); for (int i = 1; i < temp.length(); ++i) { if (temp[index] == '0') break; ++index; } temp.resize(index); dbgLogger->setText(temp); engine.rootContext()->setContextProperty("dbgLog", QVariant::fromValue(dbgLogger)); qDebug() << "$ERESTES\n"; return app.exec(); }
int PhdApp::OnExit(void) { assert(pMount == NULL); assert(pSecondaryMount == NULL); assert(pCamera == NULL); PhdController::OnAppExit(); Debug.RemoveOldFiles(); GuideLog.RemoveOldFiles(); delete pConfig; pConfig = NULL; delete m_instanceChecker; // OnExit() won't be called if we return false m_instanceChecker = 0; return wxApp::OnExit(); }
bool PhdApp::OnInit() { if (!wxApp::OnInit()) { return false; } m_instanceChecker = new wxSingleInstanceChecker(wxString::Format("%s.%ld", GetAppName(), m_instanceNumber)); if (m_instanceChecker->IsAnotherRunning()) { wxLogError(wxString::Format(_("PHD2 instance %ld is already running. Use the " "-i INSTANCE_NUM command-line option to start a different instance."), m_instanceNumber)); delete m_instanceChecker; // OnExit() won't be called if we return false m_instanceChecker = 0; return false; } #ifndef DEBUG #if (wxMAJOR_VERSION > 2 || wxMINOR_VERSION > 8) wxDisableAsserts(); #endif #endif SetVendorName(_T("StarkLabs")); // use SetAppName() to ensure the local data directory is found even if the name of the executable is changed #ifdef __APPLE__ SetAppName(_T("PHD2")); #else SetAppName(_T("phd2")); #endif pConfig = new PhdConfig(_T("PHDGuidingV2"), m_instanceNumber); Debug.Init("debug", true); Debug.AddLine(wxString::Format("PHD2 version %s begins execution with:", FULLVER)); Debug.AddLine(wxString::Format(" %s", wxVERSION_STRING)); float dummy; Debug.AddLine(wxString::Format(" cfitsio %.2lf", ffvers(&dummy))); #if defined(CV_VERSION) Debug.AddLine(wxString::Format(" opencv %s", CV_VERSION)); #endif #if defined(__WINDOWS__) HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); Debug.AddLine("CoInitializeEx returns %x", hr); #endif DisableOSXAppNap(); if (m_resetConfig) { pConfig->DeleteAll(); } wxString ldir = wxStandardPaths::Get().GetResourcesDir() + PATHSEPSTR "locale"; if (!wxDirExists(ldir)) { // for development environments ldir = _T("locale"); } bool ex = wxDirExists(ldir); Debug.AddLine(wxString::Format("Using Locale Dir %s exists=%d", ldir, ex)); wxLocale::AddCatalogLookupPathPrefix(ldir); m_localeDir = ldir; m_locale.Init(pConfig->Global.GetInt("/wxLanguage", wxLANGUAGE_DEFAULT)); if (!m_locale.AddCatalog(PHD_MESSAGES_CATALOG)) { Debug.AddLine("locale.AddCatalog failed"); } wxSetlocale(LC_NUMERIC, "C"); Debug.RemoveOldFiles(); GuideLog.RemoveOldFiles(); pConfig->InitializeProfile(); PhdController::OnAppInit(); wxImage::AddHandler(new wxJPEGHandler); wxImage::AddHandler(new wxPNGHandler); pFrame = new MyFrame(m_instanceNumber, &m_locale); pFrame->Show(true); if (pConfig->IsNewInstance() || (pConfig->NumProfiles() == 1 && pFrame->pGearDialog->IsEmptyProfile())) { pFrame->pGearDialog->ShowProfileWizard(); // First-light version of profile wizard } return true; }
namespace jackal { //==================== // Local variables //==================== static DebugLog log("logs/engine_log.txt"); // Logging warnings and errors. //==================== // Static variables //==================== Window* Window::m_pMain = nullptr; //==================== // Ctor and dtor //==================== //////////////////////////////////////////////////////////// Window::Window() : m_pWindow(nullptr), m_context(), m_title(), m_position(), m_size(), m_settings(), m_running(false) { } //////////////////////////////////////////////////////////// Window::~Window() { if (m_context) { SDL_GL_DeleteContext(m_context); } if (m_pWindow) { SDL_DestroyWindow(m_pWindow); m_pWindow = nullptr; } } //==================== // Getters and setters //==================== //////////////////////////////////////////////////////////// Window& Window::getMain() { return *m_pMain; } //////////////////////////////////////////////////////////// std::string Window::getTitle() const { return m_title; } //////////////////////////////////////////////////////////// void Window::setTitle(const std::string& title) { SDL_SetWindowTitle(m_pWindow, title.c_str()); m_title = title; } //////////////////////////////////////////////////////////// Vector2i Window::getPosition() const { return m_position; } //////////////////////////////////////////////////////////// void Window::setPosition(const Vector2i& position) { SDL_SetWindowPosition(m_pWindow, position.x, position.y); m_position = position; } //////////////////////////////////////////////////////////// Vector2i Window::getSize() const { return m_size; } //////////////////////////////////////////////////////////// void Window::setSize(const Vector2i& size) { SDL_SetWindowSize(m_pWindow, size.x, size.y); m_size = size; } //////////////////////////////////////////////////////////// const ContextSettings_t& Window::getSettings() const { return m_settings; } //////////////////////////////////////////////////////////// bool Window::isRunning() const { return m_running; } //==================== // Methods //==================== //////////////////////////////////////////////////////////// bool Window::create(const std::string& title, const Vector2i& position, const Vector2i& size, const ContextSettings_t& settings) { m_title = title; m_position = position; m_size = size; if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO)) { log.error(log.function(__FUNCTION__, title, position, size), "SDL failed to initialize:", SDL_GetError()); return false; } if (IMG_Init(IMG_INIT_PNG | IMG_INIT_JPG) == 0) { log.error(log.function(__FUNCTION__, title, position, size), "SDL image failed to initialize:", IMG_GetError()); return false; } m_pWindow = SDL_CreateWindow(m_title.c_str(), m_position.x, m_position.y, m_size.x, m_size.y, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE); if (!m_pWindow) { log.error(log.function(title, position, size), "Failed to create window:", SDL_GetError()); return false; } m_context = SDL_GL_CreateContext(m_pWindow); SDL_GL_SetSwapInterval(1); SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, m_settings.depthBits); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, m_settings.stencilBits); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, m_settings.majorVersion); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, m_settings.minorVersion); m_running = true; if (!m_pMain) { glewExperimental = GL_TRUE; GLenum error = glewInit(); if (error != GLEW_OK) { log.error(log.function(__FUNCTION__, title, position, size), "GLEW failed to initialize:", glewGetErrorString(error)); return false; } glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); log.debug(log.function(__FUNCTION__, title, position, size), "Main window set."); m_pMain = this; } glEnable(GL_DEPTH_TEST); log.debug(log.function(__FUNCTION__, title, position, size), "Created successfully."); return true; } //////////////////////////////////////////////////////////// bool Window::create(const ConfigFile& config) { ContextSettings_t settings; settings.depthBits = config.get<unsigned int>("ContextSettings.depth_bits"); settings.stencilBits = config.get<unsigned int>("ContextSettings.stencil_bits"); settings.majorVersion = config.get<unsigned int>("ContextSettings.major_version"); settings.minorVersion = config.get<unsigned int>("ContextSettings.minor_version"); return this->create(config.get<std::string>("Window.title"), config.get<Vector2i>("Window.position"), config.get<Vector2i>("Window.size"), settings); } //////////////////////////////////////////////////////////// void Window::pollEvents() { SDL_Event e; while (SDL_PollEvent(&e)) { if (e.type == SDL_QUIT) { this->close(); } // TODO(BEN): Poll input events. } } //////////////////////////////////////////////////////////// void Window::close() { m_running = false; } //////////////////////////////////////////////////////////// void Window::clear() const { glClearColor(0.5, 0.5, 0.5, 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } //////////////////////////////////////////////////////////// void Window::swap() const { SDL_GL_SwapWindow(m_pWindow); } } // namespace jackal
//==================== // Methods //==================== //////////////////////////////////////////////////////////// bool Window::create(const std::string& title, const Vector2i& position, const Vector2i& size, const ContextSettings_t& settings) { m_title = title; m_position = position; m_size = size; if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO)) { log.error(log.function(__FUNCTION__, title, position, size), "SDL failed to initialize:", SDL_GetError()); return false; } if (IMG_Init(IMG_INIT_PNG | IMG_INIT_JPG) == 0) { log.error(log.function(__FUNCTION__, title, position, size), "SDL image failed to initialize:", IMG_GetError()); return false; } m_pWindow = SDL_CreateWindow(m_title.c_str(), m_position.x, m_position.y, m_size.x, m_size.y, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE); if (!m_pWindow) { log.error(log.function(title, position, size), "Failed to create window:", SDL_GetError()); return false; } m_context = SDL_GL_CreateContext(m_pWindow); SDL_GL_SetSwapInterval(1); SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, m_settings.depthBits); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, m_settings.stencilBits); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, m_settings.majorVersion); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, m_settings.minorVersion); m_running = true; if (!m_pMain) { glewExperimental = GL_TRUE; GLenum error = glewInit(); if (error != GLEW_OK) { log.error(log.function(__FUNCTION__, title, position, size), "GLEW failed to initialize:", glewGetErrorString(error)); return false; } glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); log.debug(log.function(__FUNCTION__, title, position, size), "Main window set."); m_pMain = this; } glEnable(GL_DEPTH_TEST); log.debug(log.function(__FUNCTION__, title, position, size), "Created successfully."); return true; }