예제 #1
0
//-------------------------------------------------------------------------------------------------
inline void_t
Console::pause(
    culong_t &a_timeoutMsec
) const
{
#if xENV_WIN
    xTEST_DIFF(_wnd, xWND_NATIVE_HANDLE_NULL);
    xTEST_EQ(_stdIn.isValid(), true);
    xTEST_EQ(_stdOut.isValid(), true);
#endif

    std::tstring_t msg;

	if (a_timeoutMsec == xTIMEOUT_INFINITE) {
        msg = xT("Pause, press [ENTER] to continue...");

        writeLine(msg);

        std::cin.clear();
        std::cin.ignore();
	} else {
        msg = String::format(xT("Pause, wait for %lu msec to continue..."), a_timeoutMsec);

        writeLine(msg);

		Thread::currentSleep(a_timeoutMsec);
	}
}
예제 #2
0
//-------------------------------------------------------------------------------------------------
inline std::ctstring_t &
File::path() const
{
    xTEST_EQ(_filePath.empty(), false);
    xTEST_EQ(isExists(_filePath), true);

    return _filePath;
}
예제 #3
0
//-------------------------------------------------------------------------------------------------
inline Console::ExModalResult
Console::msgBox(
    std::ctstring_t &a_text,
    std::ctstring_t &a_title,
    cuint_t         &a_type
) const
{
    xUNUSED(a_type);

#if xENV_WIN
    xTEST_DIFF(_wnd, xWND_NATIVE_HANDLE_NULL);
    xTEST_EQ(_stdIn.isValid(), true);
    xTEST_EQ(_stdOut.isValid(), true);
#endif

    ExModalResult mrRv;

    enum EConsoleCmd {
        cmAbort  = xT('a'),
        cmIgnore = xT('i'),
        cmRetry  = xT('r')
    };

    writeLine();
    writeLine(xT("################################################################################"));
    writeLine(xT("#  ") + a_title);
    writeLine(xT("#"));
    writeLine(xT("#  ") + a_text);
    writeLine(xT("#"));
    writeLine(xT("################################################################################"));
    writeLine();
    write(String::format(xT("\nAbort (%c), Ignore (%c), Retry (%c): "), cmAbort, cmIgnore, cmRetry));

    EConsoleCmd cmRv = static_cast<EConsoleCmd>( std::tcin.get() );   std::tcin.ignore();
    switch (cmRv) {
    case cmAbort:
        mrRv = mrAbort;
        writeLine(xT("Abort..."));
        break;
    case cmIgnore:
        mrRv = mrIgnore;
        writeLine(xT("Ignore..."));
        break;
    case cmRetry:
        mrRv = mrRetry;
        writeLine(xT("Retry..."));
        break;
    default:
        mrRv = mrRetry;
        writeLine(xT("Retry..."));
        break;
    }

    return mrRv;
}
예제 #4
0
//-------------------------------------------------------------------------------------------------
inline std::tstring_t
Console::read() const
{
#if xENV_WIN
    xTEST_DIFF(_wnd, xWND_NATIVE_HANDLE_NULL);
    xTEST_EQ(_stdIn.isValid(), true);
    xTEST_EQ(_stdOut.isValid(), true);
#endif

    return _read_impl();
}
예제 #5
0
//-------------------------------------------------------------------------------------------------
inline void_t
Console::clear() const
{
#if xENV_WIN
    xTEST_DIFF(_wnd, xWND_NATIVE_HANDLE_NULL);
    xTEST_EQ(_stdIn.isValid(), true);
    xTEST_EQ(_stdOut.isValid(), true);
#endif

    _clear_impl();
}
예제 #6
0
//-------------------------------------------------------------------------------------------------
void_t
IpcSemaphore::create(
    clong_t         &a_initialValue,
    std::ctstring_t &a_name
)
{
    xTEST_EQ(_isValid(), false);
    xTEST_GR(Path::maxSize(), a_name.size());
    xTEST_EQ(0L <= a_initialValue && a_initialValue <= valueMax(), true);

    _create_impl(a_initialValue, a_name);
}
예제 #7
0
//-------------------------------------------------------------------------------------------------
inline std::tstring_t
Console::setAttributesDef() const
{
#if xENV_WIN
    xTEST_DIFF(_wnd, xWND_NATIVE_HANDLE_NULL);
    xTEST_EQ(_stdIn.isValid(), true);
    xTEST_EQ(_stdOut.isValid(), true);
#endif
    // n/a

    return _setAttributesDef_impl();
}
예제 #8
0
//-------------------------------------------------------------------------------------------------
inline void_t
Console::writeLine(
    std::ctstring_t &a_str /* = xT("") */
) const
{
#if xENV_WIN
    xTEST_DIFF(_wnd, xWND_NATIVE_HANDLE_NULL);
    xTEST_EQ(_stdIn.isValid(), true);
    xTEST_EQ(_stdOut.isValid(), true);
#endif

    write(a_str + Const::nl());
}
예제 #9
0
//-------------------------------------------------------------------------------------------------
inline void_t
Console::setTitle(
    std::ctstring_t &a_title
) const
{
#if xENV_WIN
    xTEST_NA(_wnd);
    xTEST_EQ(_stdIn.isValid(), true);
    xTEST_EQ(_stdOut.isValid(), true);
#endif

    _setTitle_impl(a_title);
}
예제 #10
0
//-------------------------------------------------------------------------------------------------
inline
Config::Config() :
    _separator(Const::equal()),
    _fileExt  ( Path::fileExt(Path::seConfig) ),
    _filePath (),
    _config   ()
{
    xTEST_EQ(_separator.empty(), false);
    xTEST_EQ(_fileExt.empty(), false);
    xTEST_EQ(_filePath.empty(), true);

    setPath( Path( Path::exe() ).setExt(_fileExt) );
}
예제 #11
0
//-------------------------------------------------------------------------------------------------
inline void_t
Console::write(
    std::ctstring_t &a_str
) const
{
#if xENV_WIN
    xTEST_DIFF(_wnd, xWND_NATIVE_HANDLE_NULL);
    xTEST_EQ(_stdIn.isValid(), true);
    xTEST_EQ(_stdOut.isValid(), true);
#endif

    _write_impl(a_str);

    std::tcout.flush();
}
예제 #12
0
//-------------------------------------------------------------------------------------------------
inline void_t
Console::writeErrLine(
    std::ctstring_t &a_str
) const
{
#if xENV_WIN
    xTEST_DIFF(_wnd, xWND_NATIVE_HANDLE_NULL);
    xTEST_EQ(_stdIn.isValid(), true);
    xTEST_EQ(_stdOut.isValid(), true);
#endif

    writeLine(xT("Error: ") + a_str);

    pause(xTIMEOUT_INFINITE);
}
예제 #13
0
//-------------------------------------------------------------------------------------------------
inline std::ctstring_t &
Dir::dirPath() const
{
    xTEST_EQ(_dirPath.empty(), false);

    return _dirPath;
}
예제 #14
0
//-------------------------------------------------------------------------------------------------
inline std::ctstring_t &
Config::path() const
{
    xTEST_EQ(_filePath.empty(), false);

    return _filePath;
}
예제 #15
0
    xNO_INLINE static void_t
    onInfo(int_t a_signal, siginfo_t *a_info, void_t *a_context)
    {
        xTEST_EQ(a_signal, a_info->si_signo);
        xUNUSED((ucontext_t *)a_context);

        xTRACE_FUNC;

        Trace() << Signal::infoDescription(*a_info) << "\n";
        Trace() << Signal::decription(0) << "\n";

        FileLog log(FileLog::lsDefaultMb);
        log.setFilePath(xT("crash.log"));

        std::ctstring_t msg = Format::str(
            xT("Crash info:\n\n")
            xT("Signal:\n{}\n\n")
            xT("StackTrace:\n{}"),
            Signal::infoDescription(*a_info),
            StackTrace().toString());

        log.write(xT("%s\n"), msg.c_str());

        std::tcout << StackTrace().toString() << std::endl;

        Application::exit(EXIT_FAILURE);
    }
예제 #16
0
//-------------------------------------------------------------------------------------------------
inline std::FILE *
File::get() const
{
    xTEST_EQ(isValid(), true);

    return _handle;
}
예제 #17
0
//-------------------------------------------------------------------------------------------------
const IpcSemaphore::handle_t &
IpcSemaphore::handle() const
{
    xTEST_EQ(_isValid(), true);

    return _handle;
}
예제 #18
0
//-------------------------------------------------------------------------------------------------
long_t
IpcSemaphore::value() const
{
    xTEST_EQ(_isValid(), true);

    return _value_impl();
}
예제 #19
0
//-------------------------------------------------------------------------------------------------
inline void_t
File::reopen(
    std::ctstring_t  &a_filePath,
    const ExOpenMode &a_mode,
    cbool_t          &a_isUseBuffering
)
{
    xTEST_EQ(a_filePath.empty(), false);
    xTEST_NA(a_mode);
    xTEST_NA(a_isUseBuffering);

    // create dir
    Dir( Path(a_filePath).dir() ).pathCreate();

    // create, reopen file
    {
        std::FILE *file = xTFREOPEN(a_filePath.c_str(), _openMode(a_mode).c_str(), get());
        xTEST_PTR(file);

        _handle   = file;
        _filePath = a_filePath;
    }

    // buffering
    if (!a_isUseBuffering) {
        setVBuff(xPTR_NULL, bmNo,   0);
    } else {
        setVBuff(xPTR_NULL, bmFull, BUFSIZ);
    }
}
예제 #20
0
//-------------------------------------------------------------------------------------------------
void_t
IpcSemaphore::post() const
{
    xTEST_EQ(_isValid(), true);

    _post_impl();
}
예제 #21
0
//-------------------------------------------------------------------------------------------------
inline std::tstring_t
Console::setAttributes(
    const ExForeground &a_foreground,
    const ExBackground &a_background,
    cint_t             &a_attributes
) const
{
#if xENV_WIN
    xTEST_DIFF(_wnd, xWND_NATIVE_HANDLE_NULL);
    xTEST_EQ(_stdIn.isValid(), true);
    xTEST_EQ(_stdOut.isValid(), true);
#endif
    // n/a

    return _setAttributes_impl(a_foreground, a_background, a_attributes);
}
예제 #22
0
//-------------------------------------------------------------------------------------------------
inline void_t
SmtpClient::_command(
    std::ctstring_t &a_command,
    std::ctstring_t &a_replyDelimiter,
    std::tstring_t  &a_reply
)
{
    xTEST_EQ(a_command.empty(), false);
    xTEST_EQ(a_replyDelimiter.empty(), false);

    std::tstring_t sRv;

    _socket.sendAll(a_command, 0);
    sRv = _socket.recvAll(0, a_replyDelimiter);

    a_reply.swap(sRv);
}
예제 #23
0
//-------------------------------------------------------------------------------------------------
inline void_t
File::resize(
    clonglong_t &a_size
) const
{
    xTEST_NA(a_size);

#if   xENV_WIN
    clonglong_t _size = a_size;
#elif xENV_UNIX
    const off_t _size = static_cast<off_t>( a_size );
#endif

    int_t iRv = xCHSIZE(_nativeHandle( get() ), _size);
    xTEST_EQ(iRv, 0);
    xTEST_EQ(a_size, size());
}
예제 #24
0
//-------------------------------------------------------------------------------------------------
inline void_t
SmtpClient::sendRaw
(
    std::ctstring_t &a_filePath,
    std::ctstring_t &a_from,
    std::ctstring_t &a_to
)
{
    // TODO: xTEST_DIFF(xSOCKET_HANDLE_INVALID, _socket,   false);
    xTEST_EQ(a_from.empty(), false);
    xTEST_EQ(a_to.empty(), false);

    std::tstring_t sRv;

    /////////std::ctstring_t helloCmd = "HELO HOST\r\n"; // std::ctstring_t helloCmd = "HELO\r\n";
    std::ctstring_t fromCmd = xT("MAIL FROM: <") + a_from + xT(">\r\n");
    std::ctstring_t toCmd   = xT("RCPT TO: <")   + a_to   + xT(">\r\n");
    std::ctstring_t dataCmd = xT("DATA\r\n");
    std::ctstring_t endCmd  = xT("\r\n.\r\n");

    //////////-------------------------------------
    //////////[HELO\r\n]
    ////////////bRv = _bCommand(helloCmd, "\r\n", /*ref*/sRv);
    ////////////xCHECK_RET(!bRv, false);

    //-------------------------------------
    //[MAIL FROM:<*****@*****.**>\r\n]
    _command(fromCmd, xT("\r\n"), /*ref*/sRv);

    //-------------------------------------
    //[RCPT TO:<*****@*****.**>\r\n]
    _command(toCmd, xT("\r\n"), /*ref*/sRv);

    //-------------------------------------
    //[DATA\r\n]
    _command(dataCmd, xT("\r\n"), /*ref*/sRv);

    //-------------------------------------
    std::tstring_t text;

    File::textRead(a_filePath, &text);

    //-------------------------------------
    //[DataText\r\n.\r\n]
    _command(text + endCmd, xT("\r\n"), /*ref*/sRv);
}
예제 #25
0
//-------------------------------------------------------------------------------------------------
inline
Dir::Dir(
    std::ctstring_t &a_dirPath
) :
    _dirPath(a_dirPath)
{
    xTEST_EQ(a_dirPath.empty(), false);
}
예제 #26
0
파일: Profiler.cpp 프로젝트: skynowa/xLib
//-------------------------------------------------------------------------------------------------
void_t
Profiler::setLogPath(
    std::ctstring_t &a_logPath
)
{
    xTEST_EQ(Path::isValid(a_logPath, xPTR_NULL), true);

    _log.setFilePath(a_logPath);
}
예제 #27
0
//-------------------------------------------------------------------------------------------------
inline void_t
Config::keyClear(
    std::ctstring_t &a_key
)
{
    xTEST_EQ(a_key.empty(), false);

    keyWriteString(a_key, std::tstring_t());
}
예제 #28
0
//-------------------------------------------------------------------------------------------------
inline void_t
Dir::create() const
{
    bool_t bRv = isExists();
    xCHECK_DO(bRv, return);

    _create_impl();
    xTEST_EQ(isExists(), true);
}
예제 #29
0
//-------------------------------------------------------------------------------------------------
inline void_t
SmtpClient::send(
    std::ctstring_t &a_text,
    std::ctstring_t &a_from,
    std::ctstring_t &a_to
)
{
    // TODO: xTEST_DIFF(xSOCKET_HANDLE_INVALID, _socket);
    xTEST_EQ(a_from.empty(), false);
    xTEST_EQ(a_to.empty(), false);

    std::tstring_t sRv;

    std::ctstring_t helloCmd = xT("HELO HOST\r\n");
    std::ctstring_t fromCmd  = xT("MAIL FROM: <") + a_from + xT(">\r\n");
    std::ctstring_t toCmd    = xT("RCPT TO: <")   + a_to   + xT(">\r\n");
    std::ctstring_t dataCmd  = xT("DATA\r\n");
    std::ctstring_t endCmd   = xT("\r\n.\r\n");

    //////-------------------------------------
    //////[HELO DrWEB\r\n]
    ////bRv = _bCommand(helloCmd, "\r\n", /*ref*/sRv);
    ////xCHECK_RET(!bRv, false);

    //-------------------------------------
    //[MAIL FROM:<*****@*****.**>\r\n]
    _command(fromCmd, xT("\r\n"), /*ref*/sRv);

    //-------------------------------------
    //[RCPT TO:<*****@*****.**>\r\n]
    _command(toCmd, xT("\r\n"), /*ref*/sRv);

    //-------------------------------------
    //[DATA\r\n]
    _command(dataCmd, xT("\r\n"), /*ref*/sRv);

    //-------------------------------------
    //�������� �����
    _socket.sendAll(a_text, 0);

    //-------------------------------------
    //[\r\n.\r\n]
    _command(endCmd, xT("\r\n"), /*ref*/sRv);
}
예제 #30
0
//-------------------------------------------------------------------------------------------------
inline std::tstring_t
BuildInfo::os() const
{
    std::tstring_t sRv;

    std::tstring_t osName;
    {
    #if   xOS_WIN
        osName = xT("Windows");
    #elif xOS_ANDROID
        osName = xT("Andriod");
    #elif xOS_LINUX
        osName = xT("Linux");
    #elif xOS_FREEBSD
        osName = xT("FreeBSD");
    #elif xOS_MACOSX
        osName = xT("MacOSX");
    #endif
    }

    std::tstring_t osVersion;
    {
    #if   xOS_WIN
        #if   (xOS_WIN_VER == xOS_WIN_NT4)
            osVersion = xT("NT 4.0");
        #elif (xOS_WIN_VER == xOS_WIN_2K)
            osVersion = xT("2000");
        #elif (xOS_WIN_VER == xOS_WIN_XP)
            osVersion = xT("Server 2003, Windows XP");
        #elif (xOS_WIN_VER == xOS_WIN_S03)
            osVersion = xT("Server 2003 SP1, Windows XP SP2");
        #elif (xOS_WIN_VER == xOS_WIN_VISTA)
            osVersion = xT("Vista, Windows Server 2008");
        #elif (xOS_WIN_VER == xOS_WIN_7)
            osVersion = xT("7, Windows Server 2008 R2");
        #endif
    #elif (xOS_ANDROID || xOS_LINUX)
        cint_t versionMajor = (xOS_LINUX_VER & 0x00FF0000) >> 16;
        cint_t versionMinor = (xOS_LINUX_VER & 0x0000FF00) >> 8;
        cint_t versionPatch = (xOS_LINUX_VER & 0x000000FF) >> 0;

        osVersion = String::format(xT("%d.%d.%d"), versionMajor, versionMinor, versionPatch);
        xTEST_EQ(LINUX_VERSION_CODE, xLINUX_KERNEL_VER(versionMajor, versionMinor, versionPatch));
    #elif xOS_FREEBSD
        osVersion = String::cast(xOS_FREEBSD_VER);
    #elif xOS_MACOSX
        // TODO: BuildInfo::os() - OS version
        osVersion = Const::strUnknown();
    #endif
    }

    sRv = String::format(xT("%s %s"), osName.c_str(), osVersion.c_str());
    sRv = String::trimRightChars(sRv, Const::space());

    return sRv;
}