}\r
catch (XMLException& e) {\r
auto_ptr_char msg(e.getMessage());\r
- log.errorStream() << "Xerces error while loading resource (" << m_source << "): "\r
+ log.critStream() << "Xerces error while loading resource (" << m_source << "): "\r
<< msg.get() << CategoryStream::ENDLINE;\r
throw XMLParserException(msg.get());\r
}\r
- catch (XMLToolingException& e) {\r
- log.errorStream() << "error while loading configuration from ("\r
+ catch (exception& e) {\r
+ log.critStream() << "error while loading configuration from ("\r
<< (m_source.empty() ? "inline" : m_source) << "): " << e.what() << CategoryStream::ENDLINE;\r
throw;\r
}\r
\r
// Update the timestamp regardless. No point in repeatedly trying.\r
m_filestamp=stat_buf.st_mtime;\r
+ Category::getInstance(XMLTOOLING_LOGCAT".ReloadableXMLFile").info("change detected, reloading local resource...");\r
}\r
else {\r
if (isValid())\r
m_lock->rdlock();\r
return this;\r
}\r
+ Category::getInstance(XMLTOOLING_LOGCAT".ReloadableXMLFile").info("local copy invalid, reloading remote resource...");\r
}\r
\r
// Do this once...\r
- do {\r
+ try {\r
// At this point we're holding the write lock, so make sure we pop it.\r
SharedLock lockwrap(m_lock,false);\r
pair<bool,DOMElement*> ret=load();\r
if (ret.first)\r
ret.second->getOwnerDocument()->release();\r
- } while(0);\r
+ } catch (exception& ex) {\r
+ Category::getInstance(XMLTOOLING_LOGCAT".ReloadableXMLFile").crit(\r
+ "maintaining existing configuration, error reloading resource (%s): %s", m_source.c_str(), ex.what()\r
+ );\r
+ }\r
\r
// If we made it here, the swap may or may not have worked, but we need to relock.\r
m_lock->rdlock();\r
delete m_lock;
}
- public:
- Lockable* lock();
-
- void unlock() {
- if (m_lock)
- m_lock->unlock();
- }
-
/**
* Loads configuration material.
*
return true;
}
- private:
+ /** Root of the original DOM element passed into constructor. */
const DOMElement* m_root;
- bool m_local, m_validate;
+
+ /** Indicates whether resources is local or remote. */
+ bool m_local;
+
+ /** Use a validating parser when parsing XML. */
+ bool m_validate;
+
+ /** Resource location, may be a local path or a URI. */
std::string m_source;
+
+ /** Last modification of local resource. */
time_t m_filestamp;
+
+ /** Shared lock for guarding reloads. */
RWLock* m_lock;
+
+ public:
+ Lockable* lock();
+
+ void unlock() {
+ if (m_lock)
+ m_lock->unlock();
+ }
};
};