Пример #1
0
LLBC_String LLBC_SockAddr_IN::ToString() const
{
    LLBC_String desc;
    desc.format("%s:%d", GetIpAsString().c_str(), GetPort());

    return desc;
}
Пример #2
0
void TestCase_Com_DataType::StringBaseTest()
{
    LLBC_PrintLine("String base functions test:");

    LLBC_String testStr;
    testStr.format("%s", "hello world!");
    testStr.append_format("%s", "hello world!");
    LLBC_PrintLine("LLBC_String::format/append_format test: %s", testStr.c_str());

    LLBC_String testStr2;
    for(int i = 0; i < 1000; i++)
    {
        testStr.append("hello world!");
    }

    testStr2.append_format("%s", testStr.c_str());
    LLBC_PrintLine("LLBC_String:format large string test: %s", testStr2.c_str());

    // tolower/toupper test.
    testStr = "Hello WoRlD!";
    LLBC_PrintLine("'%s' to lower: '%s'", testStr.c_str(), testStr.tolower().c_str());
    LLBC_PrintLine("'%s' to upper: '%s'", testStr.c_str(), testStr.toupper().c_str());

    LLBC_PrintLine("\n");
}
Пример #3
0
int pyllbc_Service::PreSubscribe(int opcode, PyObject *preHandler, int flags)
{
    if (_started)
    {
        pyllbc_SetError("service already started", LLBC_ERROR_INITED);
        return LLBC_RTN_FAILED;
    }
    else if (_llbcSvcType == LLBC_IService::Raw && opcode != 0)
    {
        pyllbc_SetError("RAW type service could not pre-subscribe opcode != 0's packet", LLBC_ERROR_INVALID);
        return LLBC_RTN_FAILED;
    }

    pyllbc_PacketHandler *wrapHandler = LLBC_New1(pyllbc_PacketHandler, opcode);
    if (wrapHandler->SetHandler(preHandler) != LLBC_RTN_OK)
    {
        LLBC_Delete(wrapHandler);
        return LLBC_RTN_FAILED;
    }

    if (!_preHandlers.insert(std::make_pair(opcode, wrapHandler)).second)
    {
        LLBC_Delete(wrapHandler);

        LLBC_String err;
        pyllbc_SetError(err.format(
            "repeat to pre-subscribe opcode: %d, the opcode already pre-subscribed", opcode), LLBC_ERROR_REPEAT);

        return LLBC_RTN_FAILED;
    }

    _llbcSvc->PreSubscribe(opcode, _cppFacade, &pyllbc_Facade::OnDataPreReceived);

    return LLBC_RTN_OK;
}
Пример #4
0
void TestCase_Com_DataType::StringBaseTest()
{
    LLBC_PrintLine("String base functions test:");

    LLBC_String testStr;
    testStr.format("%s", "hello world!");
    testStr.append_format("%s", "hello world!");
    LLBC_PrintLine("LLBC_String::format/append_format test: %s", testStr.c_str());

    LLBC_String testStr2;
    for(int i = 0; i < 1000; i++)
    {
        testStr.append("hello world!");
    }

    testStr2.append_format("%s", testStr.c_str());
    LLBC_PrintLine("LLBC_String:format large string test: %s", testStr2.c_str());

    // tolower/toupper test.
    testStr = "Hello WoRlD!";
    LLBC_PrintLine("'%s' to lower: '%s'", testStr.c_str(), testStr.tolower().c_str());
    LLBC_PrintLine("'%s' to upper: '%s'", testStr.c_str(), testStr.toupper().c_str());

    // isalpha/isupper/islower.
    LLBC_String str("HELLO");
    LLBC_PrintLine("%s islower?%d, isupper?%d, isalpha?%d", 
        str.c_str(), str.islower(), str.isupper(), str.isalpha());
    str = "hello";
    LLBC_PrintLine("%s islower?%d, isupper?%d, isalpha?%d", 
        str.c_str(), str.islower(), str.isupper(), str.isalpha());
    str = "HeLlO";
    LLBC_PrintLine("%s islower?%d, isupper?%d, isalpha?%d", 
        str.c_str(), str.islower(), str.isupper(), str.isalpha());
    str = "hello123";
    LLBC_PrintLine("%s islower?%d, isupper?%d, isalpha?%d", 
        str.c_str(), str.islower(), str.isupper(), str.isalpha());
    str = "HELLO123";
    LLBC_PrintLine("%s islower?%d, isupper?%d, isalpha?%d", 
        str.c_str(), str.islower(), str.isupper(), str.isalpha());
    str = "Hello123";
    LLBC_PrintLine("%s islower?%d, isupper?%d, isalpha?%d", 
        str.c_str(), str.islower(), str.isupper(), str.isalpha());
    str = "H";
    LLBC_PrintLine("%s islower?%d, isupper?%d, isalpha?%d", 
        str.c_str(), str.islower(), str.isupper(), str.isalpha());
    str = "h";
    LLBC_PrintLine("%s islower?%d, isupper?%d, isalpha?%d", 
        str.c_str(), str.islower(), str.isupper(), str.isalpha());
    str = "3";
    LLBC_PrintLine("%s islower?%d, isupper?%d, isalpha?%d", 
        str.c_str(), str.islower(), str.isupper(), str.isalpha());

    LLBC_PrintLine("\n");
}
Пример #5
0
int pyllbc_PackLemma_Top::Write(pyllbc_Stream *stream, PyObject *values)
{
    if (UNLIKELY(!this->IsDone()))
    {
        pyllbc_SetError("top-lemma not done, could not pack data");
        return LLBC_RTN_FAILED;
    }

    const bool valuesIsNone = pyllbc_TypeDetector::IsNone(values);
    if (valuesIsNone)
    {
        if (!_lemmas.empty())
        {
            pyllbc_SetError("not found any values to pack, but has been specified format character symbol");
            return LLBC_RTN_FAILED;
        }

        return LLBC_RTN_OK;
    }
    else if (!pyllbc_TypeDetector::IsSequence(values))
    {
        pyllbc_SetError("will pack data not iterable");
        return LLBC_RTN_FAILED;
    }
    
    const Py_ssize_t seqSize = PySequence_Size(values);
    if (seqSize != static_cast<Py_ssize_t>(_lemmas.size()))
    {
        LLBC_String errStr;
        pyllbc_SetError(errStr.format(
            "will pack data sequence size[%ld] not equal format character size[%d]", 
            seqSize, _lemmas.size()));

        return LLBC_RTN_FAILED;
    }

    for (Py_ssize_t i = 0; i < seqSize; i++)
    {
        Base *lemma = _lemmas.at(i);
        PyObject *obj = PySequence_GetItem(values, i);
        if (lemma->Write(stream, obj) != LLBC_RTN_OK)
        {
            Py_DECREF(obj);
            return LLBC_RTN_FAILED;
        }

        Py_DECREF(obj);
    }

    return LLBC_RTN_OK;
}
Пример #6
0
int pyllbc_Service::RegisterFacade(PyObject *facade)
{
    if (!_facades.insert(facade).second)
    {
        PyObject *pyFacadeStr = PyObject_Str(facade);
        LLBC_String facadeStr = PyString_AsString(pyFacadeStr);
        Py_DECREF(pyFacadeStr);

        LLBC_String errStr;
        pyllbc_SetError(errStr.format("repeat to register facade: %s", facadeStr.c_str()), LLBC_ERROR_REPEAT);

        return LLBC_RTN_FAILED;
    }

    Py_INCREF(facade);

    return LLBC_RTN_OK;
}
Пример #7
0
LLBC_String LLBC_GetVersionInfo(bool verbose)
{
    LLBC_String desc;
    desc.format("%d.%d.%d_%s", LLBC_majorVersion, 
        LLBC_minorVersion, LLBC_updateNo, LLBC_isDebugVer ? "debug" : "release");

#if LLBC_TARGET_PLATFORM_WIN32
    desc.append_format("(%s", "WIN32");
#elif LLBC_TARGET_PLATFORM_LINUX
    desc.append_format("(%s", "LINUX");
#elif LLBC_TARGET_PLATFORM_IPHONE
    desc.append_format("(%s", "IPHONE");
#elif LLBC_TARGET_PLATFORM_MAC
    desc.append_format("(%s", "MAC");
#elif LLBC_TARGET_PLATFORM_ANDROID
    desc.append_format("(%s", "ANDROID");
#endif

#if LLBC_CUR_COMP == LLBC_COMP_MSVC
    desc.append_format(", compiled with: %s, version: %d)", LLBC_CUR_COMP_DESC, LLBC_COMP_VER);
#elif LLBC_CUR_COMP == LLBC_COMP_GCC
    desc.append_format(", compiled with: %s, version %d.%d.%d)", 
        LLBC_CUR_COMP_DESC, LLBC_COMP_MAJOR_VER, LLBC_COMP_MINOR_VER, LLBC_COMP_PATCH_LEVEL);
#else
    desc.append_format(", compiled with: %s)", LLBC_CUR_COMP_DESC);
#endif

    if (!verbose)
        return desc;

    // Append core info.
    desc.append_format("\n");
    desc.append_format("core info: \n");
    desc.append_format("  thread info: \n");
    desc.append_format("    max thread num: %d\n", LLBC_CFG_THREAD_MAX_THREAD_NUM);
    desc.append_format("    default thread stack size: %d\n", LLBC_CFG_THREAD_DFT_STACK_SIZE);
    desc.append_format("    miximum thread stack size: %d\n", LLBC_CFG_THREAD_MINIMUM_STACK_SIZE);
    desc.append_format("    message block size: %d\n", LLBC_CFG_THREAD_MSG_BLOCK_DFT_SIZE);
    desc.append_format("  logger info: \n");
    desc.append_format("    default level: %d\n", LLBC_CFG_LOG_DEFAULT_LEVEL);
    desc.append_format("    default asynchronous mode: %s\n", (LLBC_CFG_LOG_DEFAULT_ASYNC_MODE) ? "true" : "false");
    desc.append_format("    default log to console: %s\n", (LLBC_CFG_LOG_DEFAULT_LOG_TO_CONSOLE) ? "true" : "false");
    desc.append_format("    default console log pattern: %s\n", LLBC_CFG_LOG_DEFAULT_CONSOLE_LOG_PATTERN);
    desc.append_format("    default log to file: %s\n", (LLBC_CFG_LOG_DEFAULT_LOG_TO_FILE) ? "true" : "false");
    desc.append_format("    default log file name: %s\n", LLBC_CFG_LOG_DEFAULT_LOG_FILE_NAME);
    desc.append_format("    default file log pattern: %s\n", LLBC_CFG_LOG_DEFAULT_FILE_LOG_PATTERN);
    desc.append_format("    default daily mode enabled(available in file log): %s\n", (LLBC_CFG_LOG_DEFAULT_DAILY_MODE) ? "true" : "false");
    desc.append_format("    default max log file size: %d\n", LLBC_CFG_LOG_MAX_FILE_SIZE);
    desc.append_format("    default max backup index: %d\n", LLBC_CFG_LOG_MAX_BACKUP_INDEX);
    desc.append_format("    default flush interval(ms)(only available in asyn mode): %d\n", LLBC_CFG_LOG_DEFAULT_LOG_FLUSH_INTERVAL);
    desc.append_format("    max flush interval(ms)(only available in asyn mode): %d\n", LLBC_CFG_LOG_MAX_LOG_FLUSH_INTERVAL);
    desc.append_format("    default log file buffer size: %d\n", LLBC_CFG_LOG_DEFAULT_LOG_FILE_BUFFER_SIZE);
    desc.append_format("  timer info: \n");
    desc.append_format("    strict timer schedule: %s\n", LLBC_CFG_CORE_TIMER_STRICT_SCHEDULE ? "true" : "false");

    // Append communication info.
    desc.append_format("communication info: \n");
    desc.append_format("  poller model: %s\n", LLBC_CFG_COMM_POLLER_MODEL);
    desc.append_format("  default service FPS: %d\n", LLBC_CFG_COMM_DFT_SERVICE_FPS);
    desc.append_format("  per thread max drive services count: %d\n", LLBC_CFG_COMM_PER_THREAD_DRIVE_MAX_SVC_COUNT);
    desc.append_format("  full protocol-stack support(let your program more efficient): %s\n", LLBC_CFG_COMM_USE_FULL_STACK ? "true" : "false");
    desc.append_format("  enabled register status code handler support: %s\n", LLBC_CFG_COMM_ENABLE_STATUS_HANDLER ? "true" : "false");
    desc.append_format("  enabled register status code describe string support: %s\n", LLBC_CFG_COMM_ENABLE_STATUS_DESC ? "true" : "false");
    desc.append_format("  enabled unify pre-subscribe support: %s\n", LLBC_CFG_COMM_ENABLE_UNIFY_PRESUBSCRIBE ? "true" : "false");
    desc.append_format("  sampler support: %s\n", LLBC_CFG_COMM_ENABLE_SAMPLER_SUPPORT ? "true" : "false");

    // Append third-party info.
    desc.append_format("3rd party info: \n");
    desc.append_format("  zlib version: %s(ver-num:%d)\n", ZLIB_VERSION, ZLIB_VERNUM);

    return desc;
}