Newer
Older
Gigg, Martyn Anthony
committed
newSearchString.append(*it);
newSearchString.append(";");
}
newSearchString.append(path);
setString("datasearch.directories", newSearchString);
}
}
/**
* Return the list of user search paths
* @returns A vector of strings containing the defined search directories
*/
const std::vector<std::string>& ConfigServiceImpl::getUserSearchDirs() const
{
return m_UserSearchDirs;
}
/**
* Return the search directory for XML instrument definition files (IDFs)
* @returns Full path of instrument search directory
*/
const std::string ConfigServiceImpl::getInstrumentDirectory() const
Campbell, Stuart
committed
{
// Determine the search directory for XML instrument definition files (IDFs)
std::string directoryName = getString("instrumentDefinition.directory");
if (directoryName.empty())
Campbell, Stuart
committed
// This is the assumed deployment directory for IDFs, where we need to be relative to the
// directory of the executable, not the current working directory.
directoryName = Poco::Path(getPropertiesDir()).resolve("../instrument").toString();
Janik Zikovsky
committed
if (!Poco::File(directoryName).isDirectory())
g_log.error("Unable to locate instrument search directory at: " + directoryName);
return directoryName;
Campbell, Stuart
committed
}
/**
* Load facility information from instrumentDir/Facilities.xml file if fName parameter
* is not set
Janik Zikovsky
committed
* @param fName :: An alternative file name for loading facilities information.
Campbell, Stuart
committed
*/
void ConfigServiceImpl::updateFacilities(const std::string& fName)
{
m_facilities.clear();
Campbell, Stuart
committed
std::string instrDir = getString("instrumentDefinition.directory");
std::string fileName = fName.empty() ? instrDir + "Facilities.xml" : fName;
// Set up the DOM parser and parse xml file
Poco::XML::DOMParser pParser;
Poco::XML::Document* pDoc;
Roman Tolchenov
committed
Campbell, Stuart
committed
try
Roman Tolchenov
committed
try
{
pDoc = pParser.parse(fileName);
} catch (...)
{
throw Kernel::Exception::FileError("Unable to parse file:", fileName);
}
// Get pointer to root element
Poco::XML::Element* pRootElem = pDoc->documentElement();
if (!pRootElem->hasChildNodes())
{
pDoc->release();
throw std::runtime_error("No root element in Facilities.xml file");
}
Roman Tolchenov
committed
Poco::XML::NodeList* pNL_facility = pRootElem->getElementsByTagName("facility");
unsigned int n = pNL_facility->length();
Campbell, Stuart
committed
Roman Tolchenov
committed
for (unsigned int i = 0; i < n; ++i)
{
Poco::XML::Element* elem = dynamic_cast<Poco::XML::Element*> (pNL_facility->item(i));
if (elem)
{
m_facilities.push_back(new FacilityInfo(elem));
}
}
if (m_facilities.empty())
Roman Tolchenov
committed
pNL_facility->release();
pDoc->release();
throw std::runtime_error("The facility definition file " + fileName + " defines no facilities");
Janik Zikovsky
committed
Roman Tolchenov
committed
pNL_facility->release();
pDoc->release();
Janik Zikovsky
committed
} catch (std::exception& e)
Roman Tolchenov
committed
{
Roman Tolchenov
committed
g_log.error(e.what());
Roman Tolchenov
committed
}
Campbell, Stuart
committed
}
Alex Buts
committed
/** Get the default `
* @return the facility information object
Campbell, Stuart
committed
*/
const FacilityInfo& ConfigServiceImpl::Facility() const
{
std::string defFacility = getString("default.facility");
if (defFacility.empty())
Roman Tolchenov
committed
{
Campbell, Stuart
committed
defFacility = "ISIS";
Roman Tolchenov
committed
}
Campbell, Stuart
committed
return Facility(defFacility);
}
Michael Whitty
committed
/** Add an observer to a notification
Janik Zikovsky
committed
@param observer :: Reference to the observer to add
Michael Whitty
committed
*/
Janik Zikovsky
committed
void ConfigServiceImpl::addObserver(const Poco::AbstractObserver& observer) const
Michael Whitty
committed
{
Janik Zikovsky
committed
m_notificationCenter.addObserver(observer);
Michael Whitty
committed
}
/** Remove an observer
Janik Zikovsky
committed
@param observer :: Reference to the observer to remove
Michael Whitty
committed
*/
Janik Zikovsky
committed
void ConfigServiceImpl::removeObserver(const Poco::AbstractObserver& observer) const
Michael Whitty
committed
{
Janik Zikovsky
committed
m_notificationCenter.removeObserver(observer);
Michael Whitty
committed
}
Campbell, Stuart
committed
/**
* Get a facility
Janik Zikovsky
committed
* @param fName :: Facility name
* @return the facility information object
Janik Zikovsky
committed
* @throw NotFoundException if the facility is not found
Campbell, Stuart
committed
*/
const FacilityInfo& ConfigServiceImpl::Facility(const std::string& fName) const
{
std::vector<FacilityInfo*>::const_iterator it = m_facilities.begin();
for (; it != m_facilities.end(); ++it)
Roman Tolchenov
committed
{
Campbell, Stuart
committed
if ((**it).name() == fName)
Roman Tolchenov
committed
{
Campbell, Stuart
committed
return **it;
Roman Tolchenov
committed
}
}
Campbell, Stuart
committed
g_log.error("Facility " + fName + " not found");
throw Exception::NotFoundError("Facilities", fName);
}
/// \cond TEMPLATE
template DLLExport int ConfigServiceImpl::getValue(const std::string&, double&);
template DLLExport int ConfigServiceImpl::getValue(const std::string&, std::string&);
template DLLExport int ConfigServiceImpl::getValue(const std::string&, int&);
/// \endcond TEMPLATE
} // namespace Kernel
} // namespace Mantid