Exemplo n.º 1
0
TEST_F(TestIronBeeModuleRulesLua, new_state)
{
    int res = 0;
    ib_tx_t tx;
    tx.ib = ib_engine;

    ib_rule_exec_t rule_exec;
    memset(&rule_exec, 0, sizeof(rule_exec));
    rule_exec.ib = ib_engine;
    rule_exec.tx = &tx;
    rule_exec.rule = rule;

    ib_tx_generate_id(&tx, ib_engine->mp);
    lua_State *L = luaL_newstate();
    luaL_openlibs(L);
    setSearchPath(L);
    ASSERT_EQ(IB_OK, ib_lua_require(ib_engine, L, "ffi", "ffi"));
    ASSERT_EQ(IB_OK, ib_lua_require(ib_engine, L, "ibapi", "ironbee/api"));
    ASSERT_NE(static_cast<lua_State*>(NULL), L);

    lua_State *L2;

    ASSERT_EQ(IB_OK, ib_lua_new_thread(ib_engine, L, &L2));
    ASSERT_NE(static_cast<lua_State*>(NULL), L2);
    ASSERT_EQ(IB_OK, ib_lua_load_func(ib_engine, L2, luafile, "f1"));
    ASSERT_EQ(IB_OK, ib_lua_func_eval_int(ib_engine, &tx, L2, "f1", &res));
    ASSERT_EQ(IB_OK, ib_lua_join_thread(ib_engine, L, &L2));
    ASSERT_EQ(5, res);
}
KDvoid AssetsManager::update ( KDvoid )
{
    // 1. Urls of package and version should be valid;
    // 2. Package should be a zip file.
    if ( m_sVersionFileUrl.size ( ) == 0 ||
         m_sPackageUrl.size ( ) == 0 ||
         std::string::npos == m_sPackageUrl.find ( ".zip" ) )
    {
        CCLOG ( "no version file url, or no package url, or the package is not a zip file" );
        return;
    }
    
    // Check if there is a new version.
    if ( !checkUpdate ( ) )
	{
		return;
	}
    
    // Is package already downloaded?
	std::string  sDownloadedVersion = CCUserDefault::sharedUserDefault ( )->getStringForKey ( KEY_OF_DOWNLOADED_VERSION );
    if ( sDownloadedVersion != m_sVersion )
    {
        if ( !downLoad ( ) )
		{
			return;
		}
        
        // Record downloaded version.
        CCUserDefault::sharedUserDefault ( )->setStringForKey ( KEY_OF_DOWNLOADED_VERSION, m_sVersion.c_str ( ) );
        CCUserDefault::sharedUserDefault ( )->flush ( );
    }
    
    // Uncompress zip file.
    if ( !uncompress_ ( ) )
	{
		return;
	}
    
    // Record new version code.
    CCUserDefault::sharedUserDefault ( )->setStringForKey ( KEY_OF_VERSION, m_sVersion.c_str ( ) );
    
    // Unrecord downloaded version code.
    CCUserDefault::sharedUserDefault ( )->setStringForKey ( KEY_OF_DOWNLOADED_VERSION, "" );
    
    CCUserDefault::sharedUserDefault ( )->flush ( );
    
    // Set resource search path.
    setSearchPath ( );
    
    // Delete unloaded zip file.
	std::string  sZipfileName = m_sStoragePath + TEMP_PACKAGE_FILE_NAME;
    if ( kdRemove ( sZipfileName.c_str ( ) ) != 0 )
    {
        CCLOG ( "can not remove downloaded zip file" );
    }
}
Exemplo n.º 3
0
TEST_F(TestIronBeeModuleRulesLua, load_eval)
{
    lua_State *L = luaL_newstate();

    luaL_openlibs(L);

    setSearchPath(L);

    ASSERT_NE(static_cast<lua_State*>(NULL), L);
    ASSERT_EQ(IB_OK, ib_lua_require(ib_engine, L, "ffi", "ffi"));
    ASSERT_EQ(IB_OK, ib_lua_require(ib_engine, L, "ibapi", "ironbee/api"));
    ASSERT_EQ(IB_OK, ib_lua_load_eval(ib_engine, L, luafile));

}
KDbool AssetsManager::checkUpdate ( KDvoid )
{
    if ( m_sVersionFileUrl.size ( ) == 0 )
	{
		return KD_FALSE;
	}
    
    m_pCurl = curl_easy_init ( );
    if ( !m_pCurl )
    {
        CCLOG ( "can not init curl" );
        return KD_FALSE;
    }
    
    // Clear m_sVersion before assign new value.
    m_sVersion.clear ( );
    
    CURLcode  eRes;
    curl_easy_setopt ( m_pCurl, CURLOPT_URL, m_sVersionFileUrl.c_str ( ) );
    curl_easy_setopt ( m_pCurl, CURLOPT_SSL_VERIFYPEER, 0L );
    curl_easy_setopt ( m_pCurl, CURLOPT_WRITEFUNCTION, getVersionCode );
    curl_easy_setopt ( m_pCurl, CURLOPT_WRITEDATA, &m_sVersion );
    eRes = curl_easy_perform ( m_pCurl );
    
    if ( eRes != 0 )
    {
        CCLOG ( "can not get version file content, error code is %d", eRes );
        curl_easy_cleanup ( m_pCurl );
        return KD_FALSE;
    }
    
	std::string  sRecordedVersion = CCUserDefault::sharedUserDefault ( )->getStringForKey ( KEY_OF_VERSION );
    if ( sRecordedVersion == m_sVersion )
    {
        CCLOG ( "there is not new version" );
        // Set resource search path.
        setSearchPath ( );
        return KD_FALSE;
    }
    
    CCLOG ( "there is a new version: %s", m_sVersion.c_str ( ) );
    
    return KD_TRUE;
}
Exemplo n.º 5
0
TEST_F(TestIronBeeModuleRulesLua, load_func_eval)
{
    int res = 0;
    ib_tx_t tx;
    tx.ib = ib_engine;
    tx.id = "tx_id.TestIronBeeModuleRulesLua.load_func_eval";
    ASSERT_EQ(IB_OK, ib_conn_create(ib_engine, &tx.conn, NULL));

    ib_rule_exec_t rule_exec;
    memset(&rule_exec, 0, sizeof(rule_exec));
    rule_exec.ib = ib_engine;
    rule_exec.tx = &tx;
    rule_exec.rule = rule;

    lua_State *L = luaL_newstate();
    ASSERT_NE(static_cast<lua_State*>(NULL), L);
    luaL_openlibs(L);
    setSearchPath(L);
    ASSERT_EQ(IB_OK, ib_lua_require(ib_engine, L, "ffi", "ffi"));
    ASSERT_EQ(IB_OK, ib_lua_require(ib_engine, L, "ibapi", "ironbee/api"));
    ASSERT_EQ(IB_OK, ib_lua_load_func(ib_engine, L, luafile, "f1"));
    ASSERT_EQ(IB_OK, ib_lua_func_eval_int(ib_engine, &tx, L, "f1", &res));
    ASSERT_EQ(5, res);
}
Exemplo n.º 6
0
void ProjectConfig::parseCommandLine(const vector<string> &args)
{
    auto it = args.begin();
    while (it != args.end())
    {
        string arg = *it;

        if (arg.compare("-workdir") == 0)
        {
            ++it;
            if (it == args.end()) break;
            setProjectDir(*it);
            if (_writablePath.length() == 0) setWritablePath(*it);
        }
        else if (arg.compare("-writable-path") == 0)
        {
            ++it;
            if (it == args.end()) break;
            setWritablePath(*it);
        }
        else if (arg.compare("-entry") == 0)
        {
            ++it;
            if (it == args.end()) break;
            setScriptFile(*it);
        }
        else if (arg.compare("-landscape") == 0)
        {
            setFrameSize(cocos2d::Size(DEFAULT_HEIGHT, DEFAULT_WIDTH));
        }
        else if (arg.compare("-portrait") == 0)
        {
            setFrameSize(cocos2d::Size(DEFAULT_WIDTH, DEFAULT_HEIGHT));
        }
        else if (arg.compare("-resolution") == 0)
        {
            ++it;
            if (it == args.end()) break;
            const string& sizeStr(*it);
            size_t pos = sizeStr.find('x');
            int width = 0;
            int height = 0;
            if (pos != sizeStr.npos && pos > 0)
            {
                string widthStr, heightStr;
                widthStr.assign(sizeStr, 0, pos);
                heightStr.assign(sizeStr, pos + 1, sizeStr.length() - pos);
                width = atoi(widthStr.c_str());
                height = atoi(heightStr.c_str());
                setFrameSize(cocos2d::Size(width, height));
            }
        }
        else if (arg.compare("-scale") == 0)
        {
            ++it;
            if (it == args.end()) break;
            float scale = atof((*it).c_str());
            setFrameScale(scale);
        }
        else if (arg.compare("-write-debug-log") == 0)
        {
            ++it;
            if (it == args.end()) break;
            setDebugLogFilePath((*it));
            setWriteDebugLogToFile(true);
        }
        else if (arg.compare("-console") == 0)
        {
            ++it;
            if (it == args.end()) break;
            if ((*it).compare("enable") == 0)
            {
                setShowConsole(true);
            }
            else
            {
                setShowConsole(false);
            }
        }
        else if (arg.compare("-position") == 0)
        {
            ++it;
            if (it == args.end()) break;
            const string& posStr(*it);
            size_t pos = posStr.find(',');
            int x = 0;
            int y = 0;
            if (pos != posStr.npos && pos > 0)
            {
                string xStr, yStr;
                xStr.assign(posStr, 0, pos);
                yStr.assign(posStr, pos + 1, posStr.length() - pos);
                x = atoi(xStr.c_str());
                y = atoi(yStr.c_str());
                setWindowOffset(cocos2d::Vec2(x, y));
            }
        }
        else if (arg.compare("-debugger") == 0)
        {
            ++it;
            if (it == args.end()) break;
            if ((*it).compare("codeide") == 0)
            {
                setDebuggerType(kCCRuntimeDebuggerCodeIDE);
            }
            else if ((*it).compare("studio") == 0)
            {
                setDebuggerType(kCCRuntimeDebuggerStudio);
            }
        }
        else if (arg.compare("-app-menu") == 0)
        {
            _isAppMenu = true;
        }
        else if (arg.compare("-resize-window") == 0)
        {
            _isResizeWindow = true;
        }
        else if (arg.compare("-retina-display") == 0)
        {
            _isRetinaDisplay = true;
        }
        else if (arg.compare("-port") == 0)
        {
            CCLOG("TODO:");
        }
        else if (arg.compare("-listen") == 0)
        {
            ++it;
            setBindAddress((*it));
        }
        else if (arg.compare("-search-path") == 0)
        {
            ++it;
            vector<string> pathes = split((*it), ';');
            setSearchPath(pathes);
        }
        else if (arg.compare("-first-search-path") == 0)
        {
            ++it;
            vector<string> pathes = split((*it), ';');
            setFirstSearchPath(pathes);
        }
        else if (arg.compare("-language-data-path") == 0)
        {
            ++it;
            if (it == args.end()) break;
            setLanguageDataPath(*it);
        }
        ++it;
    }
}