//---------------------------------------------------------------------------------- void Monitor::init() { // now scan through all resources, which are already loaded const ResourceManager::ResourceGroupMap& res = mRoot->sResourceManager()->getResourceMap(); ResourceManager::ResourceGroupMap::const_iterator it = res.begin(); for (; it != res.end(); it++) { // for each group do std::list<ResourceHandle>::const_iterator jt = it->second.begin(); for (; jt != it->second.end(); jt++) { // get resource according to the handle IResourcePtr pr = mRoot->sResourceManager()->getByHandle(*jt); // resource is valid, so do if (pr.valid()) { // now get the file name associated with the resource pr.lockResource(); const std::list<std::string>& files = pr.getBase()->getResourceFilenameList(); std::list<std::string>::const_iterator kt = files.begin(); // for each filename add a monitor for (; kt != files.end(); kt ++) { addMonitor(pr, *kt); } pr.unlockResource(); }else{ NR_Log(Log::LOG_PLUGIN, Log::LL_WARNING, "dynamicResources: Resource %s seems to be NULL", pr.getBase()->getResourceName().c_str()); } } } }
void ResourceManager::addResource(IResourcePtr _item) { if (!_item->getResourceName().empty()) mResources[_item->getResourceName()] = _item; if (!_item->getResourceID().empty()) mResourcesID[_item->getResourceID()] = _item; }
void ResourceManager::removeResource(IResourcePtr _item) { if (_item == nullptr) return; if (!_item->getResourceName().empty()) { MapResource::iterator item = mResources.find(_item->getResourceName()); if (item != mResources.end()) mResources.erase(item); } }
void ResourceManager::_load(xml::ElementPtr _node, const std::string& _file, Version _version) { FactoryManager& factory = FactoryManager::getInstance(); VectorGuid vector_guid; // берем детей и крутимся, основной цикл xml::ElementEnumerator root = _node->getElementEnumerator(); while (root.next(XML_TYPE)) { // парсим атрибуты std::string id, type, name; root->findAttribute("type", type); root->findAttribute("name", name); root->findAttribute("id", id); Guid guid(id); if (!guid.empty()) { if (mResourcesID.find(guid) != mResourcesID.end()) { MYGUI_LOG(Warning, "dublicate resource id " << guid.print()); } } if (mResources.find(name) != mResources.end()) { MYGUI_LOG(Warning, "dublicate resource name '" << name << "'"); } vector_guid.push_back(guid); IObject* object = factory.createObject(XML_TYPE, type); if (object == nullptr) { MYGUI_LOG(Error, "resource type '" << type << "' not found"); continue; } IResourcePtr resource = object->castType<IResource>(); resource->deserialization(root.current(), _version); if (!guid.empty()) mResourcesID[guid] = resource; if (!name.empty()) mResources[name] = resource; } if (!vector_guid.empty()) { mListFileGuid[_file] = vector_guid; } }
//---------------------------------------------------------------------------------- bool IResourcePtr::operator==(IResourcePtr& res) const{ // check whenver given one is null if (res.isNull()){ if (isNull()) return true; if (!isNull()) return false; }else{ if (isNull()) return false; } // check for holders ResourceHolder* A = getResourceHolder().get(); ResourceHolder* B = res.getResourceHolder().get(); if (A == B) return true; // At this point, both holders cannot be NULL if (A->getResource()->isResEmpty() || B->getResource()->isResEmpty()) return false; if (A->getResource() == B->getResource()) return true; return false; }
//---------------------------------------------------------------------------------- void Monitor::addMonitor(IResourcePtr res, const std::string& file) { // do only add a watcher if inotify already initialized if (!mInotify || !res.valid() || file.length() < 1) return; // we monitor only non-empty resources res.lockResource(); { // create a watch descriptor try { // first check if such a watcher already exists InotifyWatch* watch = mInotify->FindWatch(file); if (watch == NULL) { watch = new InotifyWatch(file, IN_MODIFY); mInotify->Add(watch); } // add new watcher NR_Log(Log::LOG_PLUGIN, Log::LL_DEBUG, "dynamicResources: Monitor %s --> %s", res.getBase()->getResourceName().c_str(), file.c_str()); // add the watcher into the map WatchData data; data.resource = res; data.watcher = watch; data.resourceName = res.getBase()->getResourceName(); mWatchMap[watch->GetDescriptor()].push_back(data); }catch(InotifyException& e) { NR_Log(Log::LOG_PLUGIN, Log::LL_ERROR, "dynamicResources: Cannot add a monitor %s --> %s", res.getBase()->getResourceName().c_str(), file.c_str()); NR_Log(Log::LOG_PLUGIN, Log::LL_ERROR, "dynamicResources: %s", e.GetMessage().c_str()); return; } } res.unlockResource(); }
Tree::Tree(IResourcePtr res) { static IXMLParserPtr parser = make_xml_parser("schemas/tree.xsd"); parser_state = new ParserState; parser_state->res = res; parser->parse(res->xml_file_name(), *this); model = load_model(res, parser_state->model_file, parser_state->scale); delete parser_state; }
void ResourceManager::loadFromXmlNode(xml::ElementPtr _node, const std::string& _file, Version _version) { FactoryManager& factory = FactoryManager::getInstance(); // берем детей и крутимся, основной цикл xml::ElementEnumerator root = _node->getElementEnumerator(); while (root.next(XML_TYPE)) { // парсим атрибуты std::string type, name; root->findAttribute("type", type); root->findAttribute("name", name); if (name.empty()) continue; MapResource::iterator item = mResources.find(name); if (item != mResources.end()) { MYGUI_LOG(Warning, "dublicate resource name '" << name << "'"); // ресурсами могут пользоваться mRemovedResoures.push_back((*item).second); mResources.erase(item); } IObject* object = factory.createObject(XML_TYPE, type); if (object == nullptr) { MYGUI_LOG(Error, "resource type '" << type << "' not found"); continue; } IResourcePtr resource = object->castType<IResource>(); resource->deserialization(root.current(), _version); mResources[name] = resource; } }
//---------------------------------------------------------------------------------- void Monitor::addMonitor(IResourcePtr res, const std::string& file) { NR_Log(Log::LOG_PLUGIN, Log::LL_WARNING, "dynamicResources: Not valid monitor interface used to monitor %s --> %s", res.getBase()->getResourceName().c_str(), file.c_str()); }
//---------------------------------------------------------------------------------- IResourcePtr::IResourcePtr(const IResourcePtr& resPtr){ mHolder = resPtr.getResourceHolder(); }