Kaydet (Commit) d0322208 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Combine unoidl::loadProvider and unoidl::Manager::addProvider

Change-Id: I1240656cc2a4d713c838eb80fa90ce3485aad614
üst 8928a4f6
......@@ -423,15 +423,13 @@ SAL_IMPLEMENT_MAIN()
i != extra_registries.end(); ++i)
{
xSet->insert(makeAny(*i));
unoidlMgr->addProvider(unoidl::loadProvider(unoidlMgr, *i));
unoidlMgr->addProvider(*i);
}
for (vector< OUString >::iterator i(mandatory_registries.begin());
i != mandatory_registries.end(); ++i)
{
xSet->insert(makeAny(*i));
rtl::Reference< unoidl::Provider > prov(
unoidl::loadProvider(unoidlMgr, *i));
unoidlMgr->addProvider(prov);
rtl::Reference< unoidl::Provider > prov(unoidlMgr->addProvider(*i));
unoidlMandatoryProvs.push_back(prov);
}
......
......@@ -34,9 +34,7 @@ TypeManager::TypeManager(): manager_(new unoidl::Manager) {}
TypeManager::~TypeManager() {}
void TypeManager::loadProvider(OUString const & uri, bool primary) {
rtl::Reference< unoidl::Provider > prov(
unoidl::loadProvider(manager_, uri));
manager_->addProvider(prov);
rtl::Reference< unoidl::Provider > prov(manager_->addProvider(uri));
if (primary) {
primaryProviders_.push_back(prov);
}
......
......@@ -2142,7 +2142,7 @@ void cppuhelper::TypeManager::readRdbFile(
rtl::OUString const & uri, bool optional)
{
try {
manager_->addProvider(unoidl::loadProvider(manager_, uri));
manager_->addProvider(uri);
} catch (unoidl::NoSuchFileException &) {
if (!optional) {
throw css::uno::DeploymentException(
......
......@@ -684,7 +684,8 @@ class LO_DLLPUBLIC_UNOIDL Manager: public salhelper::SimpleReferenceObject {
public:
Manager() {}
void addProvider(rtl::Reference< Provider > const & provider);
// throws FileFormatException, NoSuchFileException:
rtl::Reference< Provider > addProvider(rtl::OUString const & uri);
// throws FileFormatException:
rtl::Reference< Entity > findEntity(rtl::OUString const & name) const;
......@@ -695,14 +696,13 @@ public:
private:
virtual SAL_DLLPRIVATE ~Manager() throw ();
SAL_DLLPRIVATE rtl::Reference< Provider > loadProvider(
rtl::OUString const & uri);
mutable osl::Mutex mutex_;
std::vector< rtl::Reference< Provider > > providers_;
};
// throws FileFormatException, NoSuchFileException:
LO_DLLPUBLIC_UNOIDL rtl::Reference< Provider > loadProvider(
rtl::Reference< Manager > const & manager, rtl::OUString const & uri);
}
#endif
......
......@@ -14,8 +14,8 @@ for the following registry formats:
(While .idl files still contain #include directives for legacy idlc, the source-
based formats ignore any preprocessing directives starting with "#" in the .idl
files.) unoidl::loadProvider transparently detects the registry format for a
given URI and instantiates the corresponding provider implementation.
files.) unoidl::Manager::addProvider transparently detects the registry format
for a given URI and instantiates the corresponding provider implementation.
Executable_unoidl-write is a helper tool to convert from any of the registry
formats to the UNOIDL format. It is used at build-time to compile UNOIDL format
......
......@@ -1176,13 +1176,12 @@ SAL_IMPLEMENT_MAIN() {
side = 1;
} else {
try {
prov[side] = unoidl::loadProvider(mgr[side], uri);
prov[side] = mgr[side]->addProvider(uri);
} catch (unoidl::NoSuchFileException &) {
std::cerr
<< "Input <" << uri << "> does not exist" << std::endl;
std::exit(EXIT_FAILURE);
}
mgr[side]->addProvider(prov[side]);
}
}
if (side == 0 || !(prov[0].is() && prov[1].is())) {
......
......@@ -1112,13 +1112,12 @@ SAL_IMPLEMENT_MAIN() {
for (sal_uInt32 i = (published ? 1 : 0); i != args; ++i) {
OUString uri(getArgumentUri(i));
try {
prov = unoidl::loadProvider(mgr, uri);
prov = mgr->addProvider(uri);
} catch (unoidl::NoSuchFileException &) {
std::cerr
<< "Input <" << uri << "> does not exist" << std::endl;
std::exit(EXIT_FAILURE);
}
mgr->addProvider(prov);
}
std::map<OUString, Entity> ents;
scanMap(mgr, prov->createRootCursor(), published, "", ents);
......
......@@ -1038,13 +1038,12 @@ SAL_IMPLEMENT_MAIN() {
mapEntities(mgr, uri, map);
} else {
try {
prov = unoidl::loadProvider(mgr, uri);
prov = mgr->addProvider(uri);
} catch (unoidl::NoSuchFileException &) {
std::cerr
<< "Input <" << uri << "> does not exist" << std::endl;
std::exit(EXIT_FAILURE);
}
mgr->addProvider(prov);
}
}
if (!entities) {
......
......@@ -166,36 +166,14 @@ ServiceBasedSingletonEntity::~ServiceBasedSingletonEntity() throw () {}
Provider::~Provider() throw () {}
rtl::Reference< Provider > loadProvider(
rtl::Reference< Manager > const & manager, OUString const & uri)
{
osl::DirectoryItem item;
if (osl::DirectoryItem::get(uri, item) == osl::FileBase::E_None) {
osl::FileStatus status(osl_FileStatus_Mask_Type);
if (item.getFileStatus(status) == osl::FileBase::E_None
&& status.getFileType() == osl::FileStatus::Directory)
{
return new detail::SourceTreeProvider(manager, uri);
}
}
if (uri.endsWith(".idl")) {
return new detail::SourceFileProvider(manager, uri);
}
try {
return new detail::UnoidlProvider(uri);
} catch (FileFormatException & e) {
SAL_INFO(
"unoidl",
"FileFormatException \"" << e.getDetail() << "\", retrying <" << uri
<< "> as legacy format");
return new detail::LegacyProvider(manager, uri);
rtl::Reference< Provider > Manager::addProvider(OUString const & uri) {
rtl::Reference< Provider > p(loadProvider(uri));
assert(p.is());
{
osl::MutexGuard g(mutex_);
providers_.push_back(p);
}
}
void Manager::addProvider(rtl::Reference< Provider > const & provider) {
assert(provider.is());
osl::MutexGuard g(mutex_);
providers_.push_back(provider);
return p;
}
rtl::Reference< Entity > Manager::findEntity(rtl::OUString const & name) const {
......@@ -221,6 +199,30 @@ rtl::Reference< MapCursor > Manager::createCursor(rtl::OUString const & name)
Manager::~Manager() throw () {}
rtl::Reference< Provider > Manager::loadProvider(OUString const & uri) {
osl::DirectoryItem item;
if (osl::DirectoryItem::get(uri, item) == osl::FileBase::E_None) {
osl::FileStatus status(osl_FileStatus_Mask_Type);
if (item.getFileStatus(status) == osl::FileBase::E_None
&& status.getFileType() == osl::FileStatus::Directory)
{
return new detail::SourceTreeProvider(this, uri);
}
}
if (uri.endsWith(".idl")) {
return new detail::SourceFileProvider(this, uri);
}
try {
return new detail::UnoidlProvider(uri);
} catch (FileFormatException & e) {
SAL_INFO(
"unoidl",
"FileFormatException \"" << e.getDetail() << "\", retrying <" << uri
<< "> as legacy format");
return new detail::LegacyProvider(this, uri);
}
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment