示例#1
0
bool StMessageBox::QuestionConsole(const StString& theMessage) {
    st::cout << theMessage << stostream_text('\n');
    st::cout << stostream_text("Enter 'y' (yes) or 'n' (no)... ");
    st::cout << stostream_text('\n');
    int aKey = st::getch();
    return aKey == 'y';
}
示例#2
0
void StTestEmbed::nativeLoop() {
#if defined(_WIN32)
    MSG aMsg;
    while(GetMessage(&aMsg, NULL, 0, 0)) {
        TranslateMessage(&aMsg);
        DispatchMessage(&aMsg);
    }
    DestroyWindow(myParent);
#elif defined(__linux__)
    XEvent anEvent;
    for(;;) {
        XNextEvent((Display* )myDisplay, &anEvent);
    }
    XUnmapWindow  ((Display* )myDisplay, (Window )myParent);
    XDestroyWindow((Display* )myDisplay, (Window )myParent);
#else
    st::cout << stostream_text("StTestEmbed::nativeLoop() not implemented on this platform!\n");
#endif
}
示例#3
0
bool StTestImageLib::testLoadSpeed(StImageFile& theLoader) {
    myTimer.restart();
    if(!theLoader.load(myFilePath, myImgType, myDataPtr, myDataSize)) {
        st::cout << stostream_text("  Error! ") << theLoader.getState() << stostream_text("\n");
        return false;
    }

    st::cout << stostream_text("  loaded in:\t")   << myTimer.getElapsedTimeInMilliSec() << stostream_text(" msec\n");
    st::cout << stostream_text("  dimensions:\t")  << theLoader.getSizeX() << stostream_text("x") << theLoader.getSizeY() << stostream_text("\n");
    st::cout << stostream_text("  color model:\t") << theLoader.formatImgColorModel() << stostream_text("\n");

    theLoader.close();
    return true;
}
示例#4
0
void StLogger::write(const StString&       theMessage,
                     const StLogger::Level theLevel,
                     const StLogContext*   ) {
    if(theLevel > myFilter || theMessage.isEmpty()) {
        // just ignore
        return;
    }

    // lock for safety
    if(!myMutex.isNull()) {
        myMutex->lock();
    }

    // log to the file
    if(!myFilePath.isEmpty()) {
    #ifdef _WIN32
        myFileHandle = _wfopen(myFilePath.toCString(), L"ab");
    #elif defined(__linux__)
        myFileHandle =   fopen(myFilePath.toCString(),  "ab");
    #endif
        if(myFileHandle != NULL) {
            switch(theLevel) {
                case ST_PANIC:
                    fwrite("PANIC !! ", 1, 9, myFileHandle);
                    fwrite(theMessage.toCString(), 1, theMessage.getSize(), myFileHandle);
                    break;
                case ST_FATAL:
                    fwrite("FATAL !! ", 1, 9, myFileHandle);
                    fwrite(theMessage.toCString(), 1, theMessage.getSize(), myFileHandle);
                    break;
                case ST_ERROR:
                    fwrite("ERROR !! ", 1, 9, myFileHandle);
                    fwrite(theMessage.toCString(), 1, theMessage.getSize(), myFileHandle);
                    break;
                case ST_WARNING:
                    fwrite("WARN  -- ", 1, 9, myFileHandle);
                    fwrite(theMessage.toCString(), 1, theMessage.getSize(), myFileHandle);
                    break;
                case ST_INFO:
                case ST_VERBOSE:
                    fwrite("INFO  -- ", 1, 9, myFileHandle);
                    fwrite(theMessage.toCString(), 1, theMessage.getSize(), myFileHandle);
                    break;
                case ST_DEBUG:
                    fwrite("DEBUG -- ", 1, 9, myFileHandle);
                    fwrite(theMessage.toCString(), 1, theMessage.getSize(), myFileHandle);
                    break;
                default:
                    fwrite(theMessage.toCString(), 1, theMessage.getSize(), myFileHandle);
                    break;
            }
            fwrite("\n", 1, 1, myFileHandle);
            fclose(myFileHandle);
            myFileHandle = NULL;
        }
    }

    // log to standard output (with colored prefix)
    if(myToLogCout) {
        switch(theLevel) {
            case ST_PANIC:
                ST_LOG_CERR << st::COLOR_FOR_RED      << stostream_text("PANIC !! ") << st::COLOR_FOR_WHITE << theMessage << stostream_text('\n');
                break;
            case ST_FATAL:
                ST_LOG_CERR << st::COLOR_FOR_RED      << stostream_text("FATAL !! ") << st::COLOR_FOR_WHITE << theMessage << stostream_text('\n');
                break;
            case ST_ERROR:
                ST_LOG_CERR << st::COLOR_FOR_RED      << stostream_text("ERROR !! ") << st::COLOR_FOR_WHITE << theMessage << stostream_text('\n');
                break;
            case ST_WARNING:
                ST_LOG_CERR << st::COLOR_FOR_YELLOW_L << stostream_text("WARN  -- ") << st::COLOR_FOR_WHITE << theMessage << stostream_text('\n');
                break;
            case ST_INFO:
            case ST_VERBOSE:
                ST_LOG_CERR << st::COLOR_FOR_YELLOW_L << stostream_text("INFO  -- ") << st::COLOR_FOR_WHITE << theMessage << stostream_text('\n');
                break;
            case ST_DEBUG:
                ST_LOG_CERR << st::COLOR_FOR_YELLOW_L << stostream_text("DEBUG -- ") << st::COLOR_FOR_WHITE << theMessage << stostream_text('\n');
                break;
            default:
                ST_LOG_CERR << theMessage << stostream_text('\n');
                break;
        }
    }

    // log to the system journal(s)
/*#ifdef _WIN32
    // get a handle to the event log
    HANDLE anEventLog = RegisterEventSource(NULL,      // local computer
                                            L"sView"); // event source name
    if(anEventLog != NULL) {
        WORD aLogType = 0;
        switch(theLevel) {
            case ST_PANIC:
            case ST_FATAL:
            case ST_ERROR:
                aLogType = EVENTLOG_ERROR_TYPE;
                break;
            case ST_WARNING:
                aLogType = EVENTLOG_WARNING_TYPE;
                break;
            case ST_INFO:
            case ST_VERBOSE:
            case ST_DEBUG:
            default:
                aLogType = EVENTLOG_INFORMATION_TYPE;
                break;
        }
        ReportEvent(anEventLog, aLogType,
                    0,               // event category
                    0,               // event identifier
                    NULL,            // no user security identifier
                    1,               // number of substitution strings
                    0,               // no data
                    (LPCWSTR* )&theMessage.utfText(), // pointer to strings
                    NULL))           // no binary data
        DeregisterEventSource(anEventLog);
    }
#endif*/

    // unlock mutex
    if(!myMutex.isNull()) {
        myMutex->unlock();
    }
}
示例#5
0
void StMessageBox::ErrorConsole(const StString& theMessage) {
    StLogger::GetDefault().write(theMessage, StLogger::ST_ERROR);
    st::cout << stostream_text("(Error) ") << theMessage << stostream_text('\n');
}
示例#6
0
void StMessageBox::WarnConsole(const StString& theMessage) {
    StLogger::GetDefault().write(theMessage, StLogger::ST_WARNING);
    st::cout << stostream_text("(Warning) ") << theMessage << stostream_text('\n');
}
示例#7
0
void StMessageBox::InfoConsole(const StString& theMessage) {
    StLogger::GetDefault().write(theMessage, StLogger::ST_INFO);
    st::cout << stostream_text("(Info) ") << theMessage << stostream_text('\n');
}
示例#8
0
void StTestImageLib::perform() {
    st::cout << stostream_text("Image library speed tests\n");
    st::cout << stostream_text("  file:   \t'") << myFilePath << stostream_text("'\n");
    if(myImgType == StImageFile::ST_TYPE_NONE) {
        st::cout << stostream_text("  image has unsupported format.\n");
        return;
    }

    myTimer.restart();
    StRawFile aRawFile(myFilePath);
    if(!aRawFile.readFile()) {
        st::cout << stostream_text("  file can not be read.\n");
        return;
    }
    st::cout << stostream_text("  read in:\t") << myTimer.getElapsedTimeInMilliSec() << stostream_text(" msec\n");
    myDataPtr  = (uint8_t* )aRawFile.getBuffer();
    myDataSize = (int )aRawFile.getSize();

    StHandle<StImageFile> aLoader;

    st::cout << stostream_text("FFmpeg:\n");
    if(StAVImage::init()) {
        aLoader = new StAVImage();
        testLoadSpeed(*aLoader);
    } else {
        st::cout << stostream_text("  library is unavailable! Skipped.\n");
    }

    st::cout << stostream_text("FreeImage:\n");
    if(StFreeImage::init()) {
        aLoader = new StFreeImage();
        testLoadSpeed(*aLoader);
    } else {
        st::cout << stostream_text("  library is unavailable! Skipped.\n");
    }

    st::cout << stostream_text("DevIL:\n");
    if(StDevILImage::init()) {
        aLoader = new StDevILImage();
        testLoadSpeed(*aLoader);
    } else {
        st::cout << stostream_text("  library is unavailable! Skipped.\n");
    }

    st::cout << stostream_text("WebP:\n");
    if(StWebPImage::init()) {
        aLoader = new StWebPImage();
        testLoadSpeed(*aLoader);
    } else {
        st::cout << stostream_text("  library is unavailable! Skipped.\n");
    }
}
示例#9
0
文件: main.cpp 项目: KindDragon/sview
int main(int , char** ) { // force console output
#if defined(_WIN32)
    setlocale(LC_ALL, ".OCP"); // we set default locale for console output
#endif

#ifdef __ST_DEBUG__
    // Setup debug environment
    #if defined(_WIN64) || defined(_LP64) || defined(__LP64__)
        const StString ST_ENV_NAME_STCORE_PATH = "StCore64";
    #else
        const StString ST_ENV_NAME_STCORE_PATH = "StCore32";
    #endif
    StProcess::setEnv(ST_ENV_NAME_STCORE_PATH, StProcess::getProcessFolder());
#endif

    st::cout << stostream_text("This application performs some synthetic tests\n");

    StArrayList<StString> anArgs = StProcess::getArguments();
    const StString ST_TEST_MUTICES = "mutex";
    const StString ST_TEST_GLBAND  = "glband";
    const StString ST_TEST_GLHANG  = "glhang";
    const StString ST_TEST_EMBED   = "embed";
    const StString ST_TEST_IMAGE   = "image";
    const StString ST_TEST_ALL     = "all";
    size_t aFound = 0;
    for(size_t anArgId = 0; anArgId < anArgs.size(); ++anArgId) {
        const StString& aParam = anArgs[anArgId];
        if(aParam == ST_TEST_MUTICES) {
            // mutex speed test
            StTestMutex aMutices;
            aMutices.perform();
            ++aFound;
        } else if(aParam == ST_TEST_GLBAND) {
            // gl <-> cpu trasfer speed test
            StTestGlBand aGlBand;
            aGlBand.perform();
            ++aFound;
        } else if(aParam == ST_TEST_GLHANG) {
            // gl stress test
            StTestGlStress aGlHang;
            aGlHang.perform();
            ++aFound;
        } else if(aParam == ST_TEST_EMBED) {
            // StWindow embed to native window
            StTestEmbed anEmbed;
            anEmbed.perform();
            ++aFound;
        } else if(aParam == ST_TEST_IMAGE) {
            // image libraries performance tests
            if(++anArgId >= anArgs.size()) {
                st::cout << stostream_text("Broken syntax - image file awaited!\n");
                break;
            }

            StTestImageLib anImage(anArgs[anArgId]);
            anImage.perform();
            ++aFound;
        } else if(aParam == ST_TEST_ALL) {
            // mutex speed test
            StTestMutex aMutices;
            aMutices.perform();

            // gl <-> cpu trasfer speed test
            StTestGlBand aGlBand;
            aGlBand.perform();

            // StWindow embed to native window
            StTestEmbed anEmbed;
            anEmbed.perform();

            ++aFound;
            break;
        }
    }

    // show help
    if(aFound == 0) {
        st::cout << stostream_text("No test selected. Options:\n")
                 << stostream_text("  all    - execute all available tests\n")
                 << stostream_text("  mutex  - mutex speed test\n")
                 << stostream_text("  glband - gl <-> cpu trasfer speed test\n")
                 << stostream_text("  glhang - gl stress test\n")
                 << stostream_text("  embed  - test window embedding\n")
                 << stostream_text("  image fileName - test image libraries\n");
    }

    st::cout << stostream_text("Press any key to exit...") << st::SYS_PAUSE_EMPTY;
    return 0;
}
示例#10
0
bool StTestEmbed::createNative() {
    myParent = (StNativeWin_t )NULL;
    StRectI_t aRect;
    aRect.top()    = 128;
    aRect.bottom() = 128 + 400;
    aRect.left()   = 128;
    aRect.right()  = 128 + 400;
#if defined(_WIN32)
    WNDCLASSW aWinClass;
    stMemSet(&aWinClass, 0, sizeof(aWinClass));
    HINSTANCE anAppInst = GetModuleHandle(NULL);
    aWinClass.lpfnWndProc   = (WNDPROC )embedWindowProc;
    aWinClass.hInstance     = anAppInst;
    aWinClass.hIcon         = LoadIcon(NULL, IDI_WINLOGO);
    aWinClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
    aWinClass.lpszClassName = L"DummyClass";
    if(!RegisterClassW(&aWinClass)) {
        st::cout << stostream_text("RegisterClass() failed:\nCannot register window class 'DummyClass'.\n");
        return false;
    }
    HWND aWin = CreateWindowW(L"DummyClass", L"DummyWindow",
                              WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
                              aRect.left(), aRect.top(), aRect.width(), aRect.height(), NULL, NULL, anAppInst, NULL);
    ShowWindow(aWin, TRUE);
    myParent = aWin;
    return true;
#elif defined(__linux__)
    // open a connection to the X server
    Display* aDisplay = XOpenDisplay(NULL);
    if(aDisplay == NULL) {
        st::cout << stostream_text("XOpenDisplay() failed!\n");
        return false;
    }

    Window aWin = XCreateSimpleWindow(aDisplay, RootWindow(aDisplay, DefaultScreen(aDisplay)),
                                      aRect.left(), aRect.top(), aRect.width(), aRect.height(),
                                      0, 0, BlackPixel(aDisplay, DefaultScreen(aDisplay)));
    if(aWin == 0) {
        st::cout << stostream_text("XCreateSimpleWindow() failed!\n");
        XCloseDisplay(aDisplay);
        return false;
    }

    XSetStandardProperties(aDisplay, aWin, "DummyWindow", "DummyWindow",
                           None, NULL, 0, NULL);
    XSelectInput(aDisplay, aWin,
                 KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | StructureNotifyMask);

    // handle close window event
    //XSetWMProtocols(aDisplay, aWin, &(stXDisplay->wndDestroyAtom), 1);

    // request the X window to be displayed on the screen
    XMapWindow(aDisplay, aWin);

    // flushes the output buffer
    XFlush(aDisplay);
    myParent = (void* )aWin;
    myDisplay = aDisplay;
    return true;
#else
    st::cout << stostream_text("StTestEmbed::createNative() not implemented on this platform!\n");
    return false;
#endif
}