Exemplo n.º 1
0
//-------------------------------------------------------------------------------------------------
Console::ModalResult
Console::msgBox(
    std::ctstring_t &a_text,
    std::ctstring_t &a_title,
    cuint_t         &a_type
) const
{
    xUNUSED(a_type);

    ModalResult mrRv;

    std::csize_t width     = 100;
    ctchar_t     cmdAbort  = xT('a');
    ctchar_t     cmdIgnore = xT('i');
    ctchar_t     cmdRetry  = xT('r');

    std::tstring_t title;
    {
        title = _msgBoxLine(a_title, width) + Const::nl();
    }

    std::tstring_t multiText;
    {
    	std::vec_tstring_t text;
		String::split(a_text, Const::nl(), &text);

		xFOR_EACH_CONST(std::vec_tstring_t, it, text) {
			multiText += _msgBoxLine(*it, width) + Const::nl();
		}
    }
Exemplo n.º 2
0
//-------------------------------------------------------------------------------------------------
inline void_t
SmtpClient::connect()
{
    std::tstring_t sRv;

    //-------------------------------------
    //������� �����
    _socket.create(Socket::afInet, Socket::tpStream, Socket::ptIp);

    //-------------------------------------
    //������ �����
    std::tstring_t ip;

    DnsClient::hostAddrByName(_server, &ip);

    //-------------------------------------
    //�����������
    _socket.connect(ip, _port);

    //-------------------------------------
    //[welcome message]
    sRv = _socket.recvAll(0, xT("\r\n"));
    xTEST_MSG_EQ(false, _isError(sRv), sRv);

    //-------------------------------------
    //[HELO\r\n]
    std::ctstring_t helloCmd = xT("HELO HOST\r\n");        //std::ctstring_t helloCmd = "HELO\r\n";

    _command(helloCmd, xT("\r\n"), /*ref*/sRv);

    _isConnected = true;
}
Exemplo n.º 3
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);
    }
Exemplo n.º 4
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);
	}
}
Exemplo n.º 5
0
//-------------------------------------------------------------------------------------------------
void_t
Signal::connectInfo(
    const std::vector<int_t> &a_signalNums,	///<
    const on_info_t           a_onInfo		///<
) const
{
   /**
    * FAQ: set handlers
    *
    * https://gist.github.com/jvranish/4441299
    */

    int_t iRv = 0;

	struct sigaction action;
	{
		// Block other terminal-generated signals while handler runs
		sigset_t blockMask;
		{
			iRv = ::sigemptyset(&blockMask);
			xTEST_DIFF(iRv, - 1);

			xFOR_EACH_CONST(std::vector<int_t>, it, a_signalNums) {
				if (*it == SIGKILL || *it == SIGSTOP) {
					continue;
				}

				iRv = ::sigaddset(&blockMask, *it);
				xTEST_DIFF(iRv, - 1);
			}
		}

		action.sa_sigaction = a_onInfo;
		action.sa_mask      = blockMask;
		action.sa_flags     = SA_RESTART | SA_SIGINFO;
	}

    xFOR_EACH_CONST(std::vector<int_t>, it, a_signalNums) {
        switch (*it) {
        case SIGKILL:
			Trace() << Format::str(xT("xLib: Signal {} ({}) cannot be caught or ignored"),
							xLEX_TO_STR(SIGKILL), SIGKILL);
			continue;
		case SIGSTOP:
			Trace() << Format::str(xT("xLib: Signal {} ({}) cannot be caught or ignored"),
							xLEX_TO_STR(SIGSTOP), SIGSTOP);
            continue;
            break;
        default:
            break;
        }

		iRv = ::sigaction(*it, &action, xPTR_NULL);
		xTEST_DIFF_MSG(iRv, - 1, Format::str(xT("Signal: {}"), decription(*it)));
    }
}
Exemplo n.º 6
0
std::string formatGeoBounds(double l, double r, double t, double b)
#endif
{
#if defined(_UNICODE) || defined(UNICODE)
    std::wostringstream oStream;
#else
    std::ostringstream oStream;
#endif
    oStream << xT("(left top - right bottom) : ") << l << xT(", ") << t << xT(" NE - ") << r << xT(", ") << b << xT(" NE");
    return oStream.str();
}
Exemplo n.º 7
0
void BtCircleTrain::train2DGaussian(BFImage& bfImage, BFImage& bfHist, const BFCircle& circle, BfGaussian2DPixelClassifier& classifier) {

	assert(bfImage.getColorMode() == BF_LAB);

	std::vector<BFCoordinate<int> > innerPoints;
	BFCircle::getInnerPoints(circle, innerPoints);
	int nPoints = innerPoints.size();

	Eigen::MatrixXd xT(nPoints,2);
	cv::Mat histImg = cv::Mat::zeros(histSize,histSize,CV_8U);

	for(int i=0; i<nPoints; i++) {
		BFCoordinate<unsigned int> intPoint(static_cast<int>(innerPoints[i].getX()), static_cast<int>(innerPoints[i].getY()));

		BFColor color = bfImage.getColor(intPoint);

		int aValue = color.getChannel(1);
		int bValue = color.getChannel(2);

		assert(aValue+abRange >= 0 && aValue+abRange < 2*abRange);
		assert(bValue+abRange >= 0 && bValue+abRange < 2*abRange);

		histImg.datastart[(bValue+abRange)*histSize + aValue+abRange]++;

		xT(i,0) = static_cast<double>(aValue);
		xT(i,1) = static_cast<double>(bValue);
	}

	double meanA = xT.col(0).mean();
	double meanB = xT.col(1).mean();

	Eigen::VectorXd meanVecA;
	Eigen::VectorXd meanVecB;
	meanVecA.setConstant(nPoints, meanA);
	meanVecB.setConstant(nPoints, meanB);

	xT.col(0) -= meanVecA;
	xT.col(1) -= meanVecB;

	Eigen::Matrix2d C = xT.transpose()*xT/static_cast<double>(nPoints-1);
	Eigen::Vector2d mu;
	mu << meanA, meanB;

	bfHist.setColorMode(BF_GRAYSCALE);
	cv::Mat& histNorm = bfHist.getImageMat();

	// just for visualization
	cv::normalize(histImg,histNorm,255.0,0.0,cv::NORM_INF,-1);

	classifier.setC(C);
	classifier.setMu(mu);
	classifier.calculateEllipse();
}
Exemplo n.º 8
0
//-------------------------------------------------------------------------------------------------
inline std::tstring_t
BuildInfo::bitsArch() const
{
    std::tstring_t sRv;

#if   xARCH_BITS_32
    sRv = xT("32-bit");
#elif xARCH_BITS_64
    sRv = xT("64-bit");
#endif

    return sRv;
}
Exemplo n.º 9
0
//-------------------------------------------------------------------------------------------------
inline std::tstring_t
CookiePv0::dump() const
{
    std::tstring_t sRv;

    sRv = String::format(
            xT("[CookiePv0 dump]\n\n")
            xT("Name: %s\n")
            xT("Value: %s\n")
            xT("Domain: %s\n")
            xT("Path: %s\n")
            xT("Expires: %s\n")
            xT("Secure: %s\n")
            xT("HttpOnly: %s\n\n"),
            name().c_str(),
            value().c_str(),
            domain().c_str(),
            path().c_str(),
            expires().c_str(),
            String::castBool(secure()).c_str(),
            String::castBool(httpOnly()).c_str()
    );

    return sRv;
}
Exemplo n.º 10
0
//-------------------------------------------------------------------------------------------------
inline std::tstring_t
BuildInfo::binaryType() const
{
    std::tstring_t sRv;

#if   xEXE
    sRv = xT("Executable binary");
#elif xLIB
    sRv = xT("Static library");
#elif xDLL
    sRv = xT("Share (dynamic link) library");
#endif

    return sRv;
}
Exemplo n.º 11
0
//-------------------------------------------------------------------------------------------------
std::ctstring_t &
Const::strUnknown()
{
    static std::ctstring_t sRv(xT("[unknown]"));

    return sRv;
}
Exemplo n.º 12
0
//-------------------------------------------------------------------------------------------------
std::ctstring_t &
Const::hyphen()
{
    static std::ctstring_t sRv(xT("-"));

    return sRv;
}
Exemplo n.º 13
0
//-------------------------------------------------------------------------------------------------
std::ctstring_t &
Const::equal()
{
    static std::ctstring_t sRv(xT("="));

    return sRv;
}
Exemplo n.º 14
0
//-------------------------------------------------------------------------------------------------
std::ctstring_t &
Const::dqm()
{
    static std::ctstring_t sRv(xT("\""));

    return sRv;
}
Exemplo n.º 15
0
//-------------------------------------------------------------------------------------------------
std::ctstring_t &
Const::cr()
{
    static std::ctstring_t sRv(xT("\r"));

    return sRv;
}
Exemplo n.º 16
0
//-------------------------------------------------------------------------------------------------
std::ctstring_t &
Const::ff()
{
    static std::ctstring_t sRv(xT("\f"));

    return sRv;
}
Exemplo n.º 17
0
//-------------------------------------------------------------------------------------------------
std::ctstring_t &
Const::unixSlash()
{
    static std::ctstring_t sRv(xT("/"));

    return sRv;
}
Exemplo n.º 18
0
//-------------------------------------------------------------------------------------------------
std::ctstring_t &
Const::space()
{
    static std::ctstring_t sRv(xT(" "));

    return sRv;
}
Exemplo n.º 19
0
//-------------------------------------------------------------------------------------------------
std::ctstring_t &
Const::vt()
{
    static std::ctstring_t sRv(xT("\v"));

    return sRv;
}
Exemplo n.º 20
0
//-------------------------------------------------------------------------------------------------
std::ctstring_t &
Const::dot3()
{
    static std::ctstring_t sRv(xT("..."));

    return sRv;
}
Exemplo n.º 21
0
//-------------------------------------------------------------------------------------------------
std::ctstring_t &
Const::semicolon()
{
    static std::ctstring_t sRv(xT(";"));

    return sRv;
}
Exemplo n.º 22
0
//-------------------------------------------------------------------------------------------------
std::ctstring_t &
Const::nl()
{
    static std::ctstring_t sRv(xT("\n"));

    return sRv;
}
Exemplo n.º 23
0
//-------------------------------------------------------------------------------------------------
std::ctstring_t &
Const::bs()
{
    static std::ctstring_t sRv(xT("\b"));

    return sRv;
}
Exemplo n.º 24
0
//-------------------------------------------------------------------------------------------------
std::ctstring_t &
Const::maskAll()
{
    static std::ctstring_t sRv(xT("*"));

    return sRv;
}
Exemplo n.º 25
0
//-------------------------------------------------------------------------------------------------
std::ctstring_t &
Const::winSlash()
{
    static std::ctstring_t sRv(xT("\\"));

    return sRv;
}
Exemplo n.º 26
0
//-------------------------------------------------------------------------------------------------
std::ctstring_t &
Const::bell()
{
    static std::ctstring_t sRv(xT("\a"));

    return sRv;
}
Exemplo n.º 27
0
static
void_t *
pvWatch(
    void_t *a_pvParam
)
{
    int_t    iRv  = - 1;
    long_t liId = *(static_cast<long *>( a_pvParam ));
    xUNUSED(liId);

    #if 0
        Tracer() << "Starting pvWatch(): thread " << liId;
    #endif

    /*
    Lock mutex and wait for signal.  Note that the pthread_cond_wait
    routine will automatically and atomically unlock mutex while it waits.
    Also, note that if COUNT_LIMIT is reached before this routine is run by
    the waiting thread, the loop will be skipped to prevent pthread_cond_wait
    from never returning.
    */

    iRv = ::pthread_mutex_lock(&g_mtMutex);
    xTEST_MSG_EQ(0, iRv, NativeError::format(iRv));

    {
        while (g_uiCounter < g_cuiCounterMax) {
            iRv = ::pthread_cond_wait(&g_cndCondition, &g_mtMutex);
            xTEST_MSG_EQ(0, iRv, NativeError::format(iRv));

            #if 0
                Tracer() << xT("pvCountWatch(): thread: ") << liId << xT(" Condition signal received");
            #endif

            g_uiCounter += 125;

            #if 0
                Tracer() << xT("pvCountWatch(): thread: ") << liId << xT(" g_uiCounter: ") << g_uiCounter;
            #endif
        }
    }

    iRv = ::pthread_mutex_unlock(&g_mtMutex);
    xTEST_MSG_EQ(0, iRv, NativeError::format(iRv));

    return xPTR_NULL;
}
Exemplo n.º 28
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);
}
Exemplo n.º 29
0
//-------------------------------------------------------------------------------------------------
inline std::tstring_t
BuildInfo::osEnvironment() const
{
    std::tstring_t sRv;

#if   xENV_WIN
    sRv = xT("Windows");
#elif xENV_LINUX
    sRv = xT("Unix/Linux");
#elif xENV_BSD
    sRv = xT("Unix/BSD");
#elif xENV_APPLE
    sRv = xT("Unix/Apple");
#endif

    return sRv;
}
Exemplo n.º 30
0
//-------------------------------------------------------------------------------------------------
inline std::tstring_t
BuildInfo::stdLibCpp() const
{
    std::tstring_t sRv;
    std::tstring_t stdLibCppName;
    std::tstring_t stdLibCppVersion;

#if   xSTD_LIBCPP_MSVCRT
    stdLibCppName    = xT("Microsoft CRT");
    stdLibCppVersion = xSTD_LIBCPP_MSVCRT_VER_STR;
#elif xSTD_LIBCPP_GNUSTDCPP
    stdLibCppName    = xT("GNU libstdc++");
    stdLibCppVersion = xSTD_LIBCPP_GNUSTDCPP_VER_STR;
#elif XSTD_LIBCPP_DINKUMWARE
    stdLibCppName    = xT("Dinkumware");
    stdLibCppVersion = XSTD_LIBCPP_DINKUMWARE_VER_STR;
#elif xSTD_LIBCPP_GNUSTDCPP
    stdLibCppName    = xT("GNU libstdc++");
    stdLibCppVersion = xSTD_LIBCPP_GNUSTDCPP_VER_STR;
#elif xSTD_LIBCPP_INTEL
    stdLibCppName    = xT("Intel C++ Run-Time Libraries");
    stdLibCppVersion = xSTD_LIBCPP_INTEL_VER_STR;
#elif xSTD_LIBCPP_LIBCPP
    stdLibCppName    = xT("libc++");
    stdLibCppVersion = xSTD_LIBCPP_LIBCPP_VER_STR;
#endif

    sRv = String::format(xT("%s %s"), stdLibCppName.c_str(), stdLibCppVersion.c_str());

    return sRv;
}