From d0322208bcbb35b9149b508ac2bffa667c38696f Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Fri, 23 May 2014 12:30:00 +0200 Subject: Combine unoidl::loadProvider and unoidl::Manager::addProvider Change-Id: I1240656cc2a4d713c838eb80fa90ce3485aad614 --- cli_ure/source/climaker/climaker_app.cxx | 6 +-- codemaker/source/codemaker/typemanager.cxx | 4 +- cppuhelper/source/typemanager.cxx | 2 +- include/unoidl/unoidl.hxx | 10 ++--- unoidl/README | 4 +- unoidl/source/unoidl-check.cxx | 3 +- unoidl/source/unoidl-read.cxx | 3 +- unoidl/source/unoidl-write.cxx | 3 +- unoidl/source/unoidl.cxx | 60 +++++++++++++++--------------- 9 files changed, 45 insertions(+), 50 deletions(-) diff --git a/cli_ure/source/climaker/climaker_app.cxx b/cli_ure/source/climaker/climaker_app.cxx index 8c416d6090ad..b47be9312774 100644 --- a/cli_ure/source/climaker/climaker_app.cxx +++ b/cli_ure/source/climaker/climaker_app.cxx @@ -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); } diff --git a/codemaker/source/codemaker/typemanager.cxx b/codemaker/source/codemaker/typemanager.cxx index 7779704cef1b..d2e346d6d680 100644 --- a/codemaker/source/codemaker/typemanager.cxx +++ b/codemaker/source/codemaker/typemanager.cxx @@ -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); } diff --git a/cppuhelper/source/typemanager.cxx b/cppuhelper/source/typemanager.cxx index e3e38e5669bd..459671a6235d 100644 --- a/cppuhelper/source/typemanager.cxx +++ b/cppuhelper/source/typemanager.cxx @@ -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( diff --git a/include/unoidl/unoidl.hxx b/include/unoidl/unoidl.hxx index 117ac8710764..9694be73a33d 100644 --- a/include/unoidl/unoidl.hxx +++ b/include/unoidl/unoidl.hxx @@ -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 diff --git a/unoidl/README b/unoidl/README index 3c387e9038d9..9a2f9d263382 100644 --- a/unoidl/README +++ b/unoidl/README @@ -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 diff --git a/unoidl/source/unoidl-check.cxx b/unoidl/source/unoidl-check.cxx index 3a0dd36b8070..688a62ce64ba 100644 --- a/unoidl/source/unoidl-check.cxx +++ b/unoidl/source/unoidl-check.cxx @@ -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())) { diff --git a/unoidl/source/unoidl-read.cxx b/unoidl/source/unoidl-read.cxx index 1a7633535579..1deb4d75f376 100644 --- a/unoidl/source/unoidl-read.cxx +++ b/unoidl/source/unoidl-read.cxx @@ -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 ents; scanMap(mgr, prov->createRootCursor(), published, "", ents); diff --git a/unoidl/source/unoidl-write.cxx b/unoidl/source/unoidl-write.cxx index 8b3b3bf4b287..3ea09d3840a7 100644 --- a/unoidl/source/unoidl-write.cxx +++ b/unoidl/source/unoidl-write.cxx @@ -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) { diff --git a/unoidl/source/unoidl.cxx b/unoidl/source/unoidl.cxx index 3eb36a8990ae..454638312928 100644 --- a/unoidl/source/unoidl.cxx +++ b/unoidl/source/unoidl.cxx @@ -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: */ -- cgit v1.2.3