UINT MBBigRealCalculator::run() { setPoolState(CALC_RUNNING); MBContainer &mbc = getMBContainer(); const UINT maxCount = mbc.getMaxCount(); const bool useEdgeDetection = mbc.useEdgeDetection(); CellCountAccessor *cca = mbc.getCCA(); PUSHPHASE("RUN") m_digits = mbc.getDigits(); initStartTime(); try { while(mbc.getJobToDo(m_currentRect)) { // DLOG(_T("calc(%d) got rect (%d,%d,%d,%d)\n"), getId(), m_currentRect.left,m_currentRect.top,m_currentRect.right,m_currentRect.bottom); enableEdgeTracing(false); CPoint p; for(p.y = m_currentRect.top; p.y < m_currentRect.bottom; p.y++) { CHECKPENDING(); updateThreadTime(); const BigReal &yt = s_yValue[p.y]; for(p.x = m_currentRect.left; p.x < m_currentRect.right; p.x++) { if(!cca->isEmptyCell(p)) continue; const BigReal &xt = s_xValue[p.x]; const UINT count = FINDCOUNT(xt, yt, maxCount); if((count == maxCount) && useEdgeDetection) { // DLOG(_T("calc(%d) found black point (%d,%d)\n"), getId(), p.x,p.y); enableEdgeTracing(true); cca = followBlackEdge(p, cca, maxCount); enableEdgeTracing(false); } else { cca->setCount(p, count); m_doneCount++; } } } } DLOG(_T("calc(%d) done\n"), getId()); } catch(bool) { #ifdef SAVE_CALCULATORINFO DLOG(_T("calc(%d) killed in phase %s\n"), getId(), m_phase); #else DLOG(_T("calc(%d) killed\n"), getId()); #endif } catch(Exception e) { DLOG(_T("calc(%d) caught Exception:%s\n"), getId(), e.what()); } catch(...) { DLOG(_T("calc(%d) caught unknown Exception\n"), getId()); } POPPHASE(); setPoolState(CALC_TERMINATED); return 0; }
int main (int argc, const char **argv) { printLicense(); if (argc < 2) { printUsage(); return 0; } initStartTime(); // parse input cmdArguments args = parseInput (argc, argv); // init random seed initRand(); // go run (&args); }
int main(int argc, char **argv) { struct aXInfo xinfo; struct aOpts opts; #if HAVE_XF86MISC int xf86misc_major = -1; int xf86misc_minor = -1; #endif int arg = 0; const char* cursor_args = NULL; const char* background_args = NULL; opts.auth = NULL; opts.cursor = alock_cursors[0]; opts.background = alock_backgrounds[0]; /* parse options */ if (argc != 1) { for(arg = 1; arg <= argc; arg++) { if (!strcmp(argv[arg - 1], "-bg")) { if (arg < argc) { char* char_tmp; struct aBackground* bg_tmp = NULL; struct aBackground** i; if (strcmp(argv[arg], "list") == 0) { for(i = alock_backgrounds; *i; ++i) { printf("%s\n", (*i)->name); } exit(EXIT_SUCCESS); } for(i = alock_backgrounds; *i; ++i) { char_tmp = strstr(argv[arg], (*i)->name); if(char_tmp && char_tmp == argv[arg]) { background_args = char_tmp; bg_tmp = *i; opts.background = bg_tmp; ++arg; break; } } if (bg_tmp == NULL) { printf("%s", "alock: error, couldnt find the bg-module you specified.\n"); exit(EXIT_FAILURE); } } else { printf("%s", "alock, error, missing argument\n"); displayUsage(); exit(EXIT_FAILURE); } } else if (!strcmp(argv[arg - 1], "-auth")) { if (arg < argc) { char* char_tmp; struct aAuth* auth_tmp = NULL; struct aAuth** i; if (!strcmp(argv[arg], "list")) { for(i = alock_authmodules; *i; ++i) { printf("%s\n", (*i)->name); } exit(EXIT_SUCCESS); } for(i = alock_authmodules; *i; ++i) { char_tmp = strstr(argv[arg], (*i)->name); if(char_tmp && char_tmp == argv[arg]) { auth_tmp = (*i); if (auth_tmp->init(argv[arg]) == 0) { printf("alock: error, failed init of [%s].\n", auth_tmp->name); exit(EXIT_FAILURE); } opts.auth = auth_tmp; ++arg; break; } } if (auth_tmp == NULL) { printf("%s", "alock: error, couldnt find the auth-module you specified.\n"); exit(EXIT_FAILURE); } } else { printf("%s", "alock, error, missing argument\n"); displayUsage(); exit(EXIT_FAILURE); } } else if (strcmp(argv[arg - 1], "-cursor") == 0) { if (arg < argc) { char* char_tmp; struct aCursor* cursor_tmp = NULL; struct aCursor** i; if (strcmp(argv[arg], "list") == 0) { for(i = alock_cursors; *i; ++i) { printf("%s\n", (*i)->name); } exit(EXIT_SUCCESS); } for(i = alock_cursors; *i; ++i) { char_tmp = strstr(argv[arg], (*i)->name); if(char_tmp && char_tmp == argv[arg]) { cursor_args = char_tmp; cursor_tmp = *i; opts.cursor= cursor_tmp; ++arg; break; } } if (!cursor_tmp) { printf("%s", "alock: error, couldnt find the cursor-module you specified.\n"); exit(EXIT_FAILURE); } } else { printf("%s", "alock, error, missing argument\n"); displayUsage(); exit(EXIT_FAILURE); } } else if (strcmp(argv[arg - 1], "-h") == 0) { displayUsage(); exit(EXIT_SUCCESS); } else if (strcmp(argv[arg - 1], "-v") == 0) { printf("alock-%s by m.gumz 2005 - 2006\n", VERSION); exit(EXIT_SUCCESS); } } } initStartTime(); initXInfo(&xinfo); if (detectOtherInstance(&xinfo)) { printf("%s", "alock: error, another instance seems to be running\n"); exit(EXIT_FAILURE); } if (!opts.auth) { printf("%s", "alock: error, no auth-method specified.\n"); displayUsage(); exit(EXIT_FAILURE); } if (opts.background->init(background_args, &xinfo) == 0) { printf("alock: error, couldnt init [%s] with [%s].\n", opts.background->name, background_args); exit(EXIT_FAILURE); } if (opts.cursor->init(cursor_args, &xinfo) == 0) { printf("alock: error, couldnt init [%s] with [%s].\n", opts.cursor->name, cursor_args); exit(EXIT_FAILURE); } { int scr; for (scr = 0; scr < xinfo.nr_screens; scr++) { XSelectInput(xinfo.display, xinfo.window[scr], KeyPressMask|KeyReleaseMask); XMapWindow(xinfo.display, xinfo.window[scr]); XRaiseWindow(xinfo.display, xinfo.window[scr]); } } /* try to grab 2 times, another process (windowmanager) may have grabbed * the keyboard already */ if ((XGrabKeyboard(xinfo.display, xinfo.window[0], True, GrabModeAsync, GrabModeAsync, CurrentTime)) != GrabSuccess) { sleep(1); if ((XGrabKeyboard(xinfo.display, xinfo.window[0], True, GrabModeAsync, GrabModeAsync, CurrentTime)) != GrabSuccess) { printf("%s", "alock: couldnt grab the keyboard.\n"); exit(EXIT_FAILURE); } } #if HAVE_XF86MISC { if (XF86MiscQueryVersion(xinfo.display, &xf86misc_major, &xf86misc_minor) == True) { if (xf86misc_major >= 0 && xf86misc_minor >= 5 && XF86MiscSetGrabKeysState(xinfo.display, False) == MiscExtGrabStateLocked) { printf("%s", "alock: cant disable xserver hotkeys to remove grabs.\n"); exit(EXIT_FAILURE); } printf("%s", "disabled AllowDeactivateGrabs and AllowClosedownGrabs\n."); } } #endif /* TODO: think about it: do we really need NR_SCREEN cursors ? we grab the * pointer on :*.0 anyway ... */ if (XGrabPointer(xinfo.display, xinfo.window[0], False, None, GrabModeAsync, GrabModeAsync, None, xinfo.cursor[0], CurrentTime) != GrabSuccess) { XUngrabKeyboard(xinfo.display, CurrentTime); printf("%s", "alock: couldnt grab the pointer.\n"); exit(EXIT_FAILURE); } registerInstance(&xinfo); eventLoop(&opts, &xinfo); unregisterInstance(&xinfo); opts.auth->deinit(); opts.cursor->deinit(&xinfo); opts.background->deinit(&xinfo); #if HAVE_XF86MISC if (xf86misc_major >= 0 && xf86misc_minor >= 5) { XF86MiscSetGrabKeysState(xinfo.display, True); XFlush(xinfo.display); } #endif XCloseDisplay(xinfo.display); return EXIT_SUCCESS; }
int main(int argc, char **argv) { struct aXInfo xinfo; struct aOpts opts; int arg = 0; const char* cursor_args = NULL; const char* background_args = NULL; int precheck = 0; opts.auth = NULL; opts.cursor = tlock_cursors[0]; opts.background = tlock_backgrounds[0]; opts.flash = 0; opts.gids = 0; /* parse options */ if (argc != 1) { for (arg = 1; arg <= argc; arg++) { /** * Background options. */ if (!strcmp(argv[arg - 1], "-bg")) { if (arg < argc) { char* char_tmp; struct aBackground* bg_tmp = NULL; struct aBackground** i; /* * List all the available backgrounds. */ if (strcmp(argv[arg], "list") == 0) { for (i = tlock_backgrounds; *i; ++i) { printf("%s\n", (*i)->name); } exit(EXIT_SUCCESS); } /* * Assigning the backgrounds to the option array. */ for (i = tlock_backgrounds; *i; ++i) { char_tmp = strstr(argv[arg], (*i)->name); if (char_tmp && char_tmp == argv[arg]) { background_args = char_tmp; bg_tmp = *i; opts.background = bg_tmp; ++arg; break; } } /** * Abort when background is not found. */ if (bg_tmp == NULL) { printf("%s", "tlock: error, couldn't find the bg-module you specified.\n"); exit(EXIT_FAILURE); } } else { printf("%s", "tlock, error, missing argument\n"); displayUsage(); exit(EXIT_FAILURE); } } else if (!strcmp(argv[arg - 1], "-auth")) { if (arg < argc) { char* char_tmp; struct aAuth* auth_tmp = NULL; struct aAuth** i; if (!strcmp(argv[arg], "list")) { for (i = tlock_authmodules; *i; ++i) { printf("%s\n", (*i)->name); } exit(EXIT_SUCCESS); } for (i = tlock_authmodules; *i; ++i) { char_tmp = strstr(argv[arg], (*i)->name); if (char_tmp && char_tmp == argv[arg]) { auth_tmp = (*i); if (auth_tmp->init(argv[arg]) == 0) { printf("%s.%s: error, failed init of [%s] with arguments [%s].\n", __FILE__, __FUNCTION__, auth_tmp->name, argv[arg]); exit(EXIT_FAILURE); } else { printf("%s.%s: initialized [%s] with arguments [%s].\n", __FILE__, __FUNCTION__, auth_tmp->name, argv[arg]); } opts.auth = auth_tmp; ++arg; break; } } if (auth_tmp == NULL) { printf("%s", "tlock: error, couldnt find the auth-module you specified.\n"); exit(EXIT_FAILURE); } } else { printf("%s", "tlock, error, missing argument\n"); displayUsage(); exit(EXIT_FAILURE); } } else if (strcmp(argv[arg - 1], "-cursor") == 0) { if (arg < argc) { char* char_tmp; struct aCursor* cursor_tmp = NULL; struct aCursor** i; if (strcmp(argv[arg], "list") == 0) { for (i = tlock_cursors; *i; ++i) { printf("%s\n", (*i)->name); } exit(EXIT_SUCCESS); } for (i = tlock_cursors; *i; ++i) { char_tmp = strstr(argv[arg], (*i)->name); if (char_tmp && char_tmp == argv[arg]) { cursor_args = char_tmp; cursor_tmp = *i; opts.cursor = cursor_tmp; ++arg; break; } } if (!cursor_tmp) { printf("%s", "tlock: error, couldn't find the cursor-module you specified.\n"); exit(EXIT_FAILURE); } } else { printf("%s", "tlock, error, missing argument\n"); displayUsage(); exit(EXIT_FAILURE); } } else { if (strcmp(argv[arg - 1], "-h") == 0) { displayUsage(); exit(EXIT_SUCCESS); } else if (strcmp(argv[arg - 1], "-v") == 0) { printf("tlock-%s by André 'Bananaman' Kaan\n", VERSION); exit(EXIT_SUCCESS); } else if (strcmp(argv[arg - 1], "-pre") == 0) { precheck = 1; } else if (strcmp(argv[arg - 1], "-flash") == 0) { opts.flash = 1; } else if (strcmp(argv[arg - 1], "-gids") == 0) { opts.gids = 1; } } } } /** * */ initStartTime(); /* * */ initXInfo(&xinfo); if (detectOtherInstance(&xinfo)) { printf("%s", "tlock: error, another instance seems to be running\n"); exit(EXIT_FAILURE); } /* * List the usage of the authentication. */ if (!opts.auth) { printf("%s", "tlock: error, no auth-method specified.\n"); displayUsage(); exit(EXIT_FAILURE); } /* * */ if (opts.background->init(background_args, &xinfo) == 0) { printf("tlock: error, couldn't init [%s] with [%s].\n", opts.background->name, background_args); exit(EXIT_FAILURE); } if (opts.cursor->init(cursor_args, &xinfo) == 0) { printf("tlock: error, couldn't init [%s] with [%s].\n", opts.cursor->name, cursor_args); exit(EXIT_FAILURE); } LOG("initializing screens"); { int scr; for (scr = 0; scr < xinfo.nr_screens; scr++) { XSelectInput(xinfo.display, xinfo.window[scr], ButtonReleaseMask | ButtonPressMask); XMapWindow(xinfo.display, xinfo.window[scr]); XRaiseWindow(xinfo.display, xinfo.window[scr]); } } LOG("initializing keyboard control"); /* try to grab 2 times, another process (windowmanager) may have grabbed * the keyboard already */ if ((XGrabKeyboard(xinfo.display, xinfo.window[0], True, GrabModeAsync, GrabModeAsync, CurrentTime)) != GrabSuccess) { sleep(1); if ((XGrabKeyboard(xinfo.display, xinfo.window[0], True, GrabModeAsync, GrabModeAsync, CurrentTime)) != GrabSuccess) { printf("%s", "tlock: couldn't grab the keyboard.\n"); exit(EXIT_FAILURE); } } /* TODO: think about it: do we really need NR_SCREEN cursors ? we grab the * pointer on :*.0 anyway ... */ LOG("initializing mouse control"); if (XGrabPointer(xinfo.display, xinfo.window[0], False, ButtonPressMask | ButtonReleaseMask, // needed for the propagation of the pointer events on window[0] GrabModeAsync, GrabModeAsync, None, xinfo.cursor[0], CurrentTime) != GrabSuccess) { XUngrabKeyboard(xinfo.display, CurrentTime); printf("%s", "tlock: couldn't grab the pointer.\n"); exit(EXIT_FAILURE); } openlog("tlock", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1); syslog(LOG_NOTICE, "program started by user %d(%s), accepting groups as '%s' only.", getuid(), getenv("USER"), opts.gids ? "id" : "names" ); // pre authorization check if (precheck == 1) { if (opts.auth != NULL) { int ret = opts.auth->auth(NULL, NULL, 0); syslog( LOG_NOTICE, "%s: %s[exit=%d]\n", __FILE__, __FUNCTION__, ret); if (ret != 1) { registerInstance(&xinfo); eventLoop(&opts, &xinfo); LOG("exiting eventloop, and unregister"); unregisterInstance(&xinfo); } } } else { registerInstance(&xinfo); eventLoop(&opts, &xinfo); LOG("exiting eventloop, and unregister"); unregisterInstance(&xinfo); } closelog(); opts.auth->deinit(); opts.cursor->deinit(&xinfo); opts.background->deinit(&xinfo); XCloseDisplay(xinfo.display); return EXIT_SUCCESS; }