コード例 #1
0
ファイル: resmgr.cpp プロジェクト: Anehta/kbengine
//-------------------------------------------------------------------------------------
bool Resmgr::initialize()
{
	//if(isInit())
	//	return true;

	// 获取引擎环境配置
	kb_env_.root			= getenv("KBE_ROOT") == NULL ? "" : getenv("KBE_ROOT");
	kb_env_.res_path		= getenv("KBE_RES_PATH") == NULL ? "" : getenv("KBE_RES_PATH"); 
	kb_env_.bin_path		= getenv("KBE_BIN_PATH") == NULL ? "" : getenv("KBE_BIN_PATH"); 

	//kb_env_.root			= "/home/kbengine/";
	//kb_env_.res_path		= "/home/kbengine/kbe/res/;/home/kbengine/demo/;/home/kbengine/demo/scripts/;/home/kbengine/demo/res/"; 
	//kb_env_.bin_path		= "/home/kbengine/kbe/bin/server/"; 
	updatePaths();

	if(kb_env_.root == "" || kb_env_.res_path == "")
		autoSetPaths();

	updatePaths();
	if(getPySysResPath() == "" || getPyUserResPath() == "" || getPyUserScriptsPath() == "")
	{
		printf("[ERROR] Resmgr::initialize: not set environment, (KBE_ROOT, KBE_RES_PATH, KBE_BIN_PATH) invalid!\n");
#if KBE_PLATFORM == PLATFORM_WIN32
		::MessageBox(0, L"Resmgr::initialize: not set environment, (KBE_ROOT, KBE_RES_PATH, KBE_BIN_PATH) invalid!\n", L"ERROR", MB_ICONERROR);
#endif
	}

	isInit_ = true;

	respool_.clear();
	return true;
}
コード例 #2
0
ファイル: aograph.cpp プロジェクト: EmaroLab/endor
//! solve a node, finding it by name
//! @param[in] nameNode    name of the node
void AOgraph::solveByName(string nameNode)
{
    AOnode* solved = findByName(nameNode);
    bool result = solved->setSolved();
    updateNodeFeasibility();
    printGraphInfo();
    
    // report that the graph has been solved if the solved node is the head node
    if (head->nSolved == true)
    {
        cout<<"[REPORT] The graph is solved (head node solved)." <<endl;
        return;
    }
    
    // update the path information (cost) of all paths
    if (result == true)
        updatePaths(*solved);
    cout<<endl <<"Updated paths: " <<endl;
    for(int i=0; i< (int)pUpdate.size(); i++)
        cout<<"Path index: " <<pIndices[i] <<" - Benefit: " <<pUpdate[i] <<endl;
}
コード例 #3
0
void WatcherData::run()
{
    for (;;) {
        if (hasChanged()) {
            slices.clear();
            updatePaths();

            auto where = changes.begin();
            const auto end = changes.end();
            while (where != end) {
                auto to = where + MAXIMUM_WAIT_OBJECTS - 1; // - 1 since we want a wakeup event as well
                if (to > end)
                    to = end;
                slices.push_back(std::unique_ptr<WatcherSlice>(new WatcherSlice(where, to,
                                                                                std::bind(&WatcherData::updated, this,
                                                                                          std::placeholders::_1),
                                                                                handleToPath)));
                where = to;
            }
        }
        const DWORD res = WaitForSingleObject(wakeupHandle, INFINITE);
        if (res == WAIT_FAILED) {
            fprintf(stderr, "Wait failed in WatcherData::run() %lu\n",
                    static_cast<unsigned long>(GetLastError()));
            break;
        }
        assert(res - WAIT_OBJECT_0 == 0);
        // woken up
        //printf("!!!Woken up\n");
        std::lock_guard<std::mutex> changeLocker(changeMutex);
        if (stopped) {
            //printf("!!!! Stopped?\n");
            break;
        }
        std::lock_guard<std::mutex> updateLocker(updateMutex);
        if (!changedPaths.empty()) {
            for (const Path& p : changedPaths) {
                //printf("path was modified... %s\n", p.constData());
                PathData& data = pathData[p];
                p.visit([&data](const Path &pp) {
                        if (pp.isFile()) {
                            //printf("updateDir %s\n", p.constData());
                            const auto modif = data.modified.find(pp);
                            if (modif == data.modified.end()) {
                                //printf("added\n");
                                // new file
                                data.added.insert(pp);
                                return Path::Continue;
                            }
                            data.seen.insert(pp);
                            // possibly modified file
                            if (pp.lastModifiedMs() != modif->second) {
                                //printf("modified\n");
                                // really modified
                                data.changed.insert(pp);
                            }
                            return Path::Continue;
                        }
                        return Path::Recurse;
                    });

                Set<Path> removed;
                // calculate the removed files (modified - seen)
                const auto send = data.seen.end();
                for (const std::pair<Path, uint64_t>& mod : data.modified) {
                    if (data.seen.find(mod.first) == send) {
                        removed.insert(mod.first);
                    } else {
                        // update to our new time
                        data.modified[mod.first] = mod.first.lastModifiedMs();
                    }
                }

                // update the modified structure
                for (const Path& ap : data.added) {
                    data.modified[ap] = ap.lastModifiedMs();
                }
                for (const Path& rp : removed) {
                    data.modified.erase(rp);
                }

                //printf("hei, removed %u, added %u, changed %u\n", removed.size(), data.added.size(), data.changed.size());
                if (!removed.empty())
                    EventLoop::mainEventLoop()->callLaterMove(std::bind(&FileSystemWatcher::pathsRemoved, watcher, std::placeholders::_1), std::move(removed));
                if (!data.added.empty())
                    EventLoop::mainEventLoop()->callLaterMove(std::bind(&FileSystemWatcher::pathsAdded, watcher, std::placeholders::_1), std::move(data.added));
                if (!data.changed.empty())
                    EventLoop::mainEventLoop()->callLaterMove(std::bind(&FileSystemWatcher::pathsModified, watcher, std::placeholders::_1), std::move(data.changed));

                data.added.clear();
                data.changed.clear();
                data.seen.clear();
            }
            changedPaths.clear();
        }
    }
    slices.clear();
}