loplugin:flatten in comphelper

Change-Id: I1a8db4dbd744b87406d1db5609585495f01f4403
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92478
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin
2020-04-18 11:35:04 +02:00
parent ed0097845a
commit 8d4fd34183
16 changed files with 537 additions and 536 deletions

View File

@@ -98,21 +98,21 @@ namespace comphelper
void OContainerListenerAdapter::dispose()
{
if (m_xContainer.is())
if (!m_xContainer.is())
return;
try
{
try
{
Reference< XContainerListener > xPreventDelete(this);
m_xContainer->removeContainerListener(xPreventDelete);
m_pListener->setAdapter(nullptr);
}
catch(const Exception&)
{
OSL_FAIL("Exception caught!");
}
m_xContainer = nullptr;
m_pListener = nullptr;
Reference< XContainerListener > xPreventDelete(this);
m_xContainer->removeContainerListener(xPreventDelete);
m_pListener->setAdapter(nullptr);
}
catch(const Exception&)
{
OSL_FAIL("Exception caught!");
}
m_xContainer = nullptr;
m_pListener = nullptr;
}

View File

@@ -423,42 +423,42 @@ void EmbeddedObjectContainer::AddEmbeddedObject( const css::uno::Reference < css
xChild->setParent( pImpl->m_xModel.get() );
// look for object in temporary container
if ( pImpl->mpTempObjectContainer )
if ( !pImpl->mpTempObjectContainer )
return;
auto& rObjectContainer = pImpl->mpTempObjectContainer->pImpl->maNameToObjectMap;
auto aIter = std::find_if(rObjectContainer.begin(), rObjectContainer.end(),
[&xObj](const EmbeddedObjectContainerNameMap::value_type& rEntry) { return rEntry.second == xObj; });
if (aIter == rObjectContainer.end())
return;
// copy replacement image from temporary container (if there is any)
OUString aTempName = aIter->first;
OUString aMediaType;
uno::Reference < io::XInputStream > xStream = pImpl->mpTempObjectContainer->GetGraphicStream( xObj, &aMediaType );
if ( xStream.is() )
{
auto& rObjectContainer = pImpl->mpTempObjectContainer->pImpl->maNameToObjectMap;
auto aIter = std::find_if(rObjectContainer.begin(), rObjectContainer.end(),
[&xObj](const EmbeddedObjectContainerNameMap::value_type& rEntry) { return rEntry.second == xObj; });
if (aIter != rObjectContainer.end())
InsertGraphicStream( xStream, rName, aMediaType );
xStream = nullptr;
pImpl->mpTempObjectContainer->RemoveGraphicStream( aTempName );
}
// remove object from storage of temporary container
uno::Reference < embed::XEmbedPersist > xPersist( xObj, uno::UNO_QUERY );
if ( xPersist.is() )
{
try
{
pImpl->mpTempObjectContainer->pImpl->mxStorage->removeElement( aTempName );
}
catch (const uno::Exception&)
{
// copy replacement image from temporary container (if there is any)
OUString aTempName = aIter->first;
OUString aMediaType;
uno::Reference < io::XInputStream > xStream = pImpl->mpTempObjectContainer->GetGraphicStream( xObj, &aMediaType );
if ( xStream.is() )
{
InsertGraphicStream( xStream, rName, aMediaType );
xStream = nullptr;
pImpl->mpTempObjectContainer->RemoveGraphicStream( aTempName );
}
// remove object from storage of temporary container
uno::Reference < embed::XEmbedPersist > xPersist( xObj, uno::UNO_QUERY );
if ( xPersist.is() )
{
try
{
pImpl->mpTempObjectContainer->pImpl->mxStorage->removeElement( aTempName );
}
catch (const uno::Exception&)
{
}
}
// temp. container needs to forget the object
pImpl->mpTempObjectContainer->pImpl->maObjectToNameMap.erase( aIter->second );
pImpl->mpTempObjectContainer->pImpl->maNameToObjectMap.erase( aIter );
}
}
// temp. container needs to forget the object
pImpl->mpTempObjectContainer->pImpl->maObjectToNameMap.erase( aIter->second );
pImpl->mpTempObjectContainer->pImpl->maNameToObjectMap.erase( aIter );
}
bool EmbeddedObjectContainer::StoreEmbeddedObject(
@@ -993,20 +993,20 @@ void EmbeddedObjectContainer::CloseEmbeddedObject( const uno::Reference < embed:
auto aIter = std::find_if(pImpl->maNameToObjectMap.begin(), pImpl->maNameToObjectMap.end(),
[&xObj](const EmbeddedObjectContainerNameMap::value_type& rEntry) { return rEntry.second == xObj; });
if (aIter != pImpl->maNameToObjectMap.end())
{
pImpl->maObjectToNameMap.erase( aIter->second );
pImpl->maNameToObjectMap.erase( aIter );
if (aIter == pImpl->maNameToObjectMap.end())
return;
try
{
xObj->close( true );
}
catch (const uno::Exception&)
{
// it is no problem if the object is already closed
// TODO/LATER: what if the object can not be closed?
}
pImpl->maObjectToNameMap.erase( aIter->second );
pImpl->maNameToObjectMap.erase( aIter );
try
{
xObj->close( true );
}
catch (const uno::Exception&)
{
// it is no problem if the object is already closed
// TODO/LATER: what if the object can not be closed?
}
}

View File

@@ -594,26 +594,26 @@ void SAL_CALL ImplEventAttacherManager::detach(sal_Int32 nIndex, const Reference
std::deque< AttacherIndex_Impl >::iterator aCurrentPosition = aIndex.begin() + nIndex;
auto aObjIt = std::find_if(aCurrentPosition->aObjList.begin(), aCurrentPosition->aObjList.end(),
[&xObject](const AttachedObject_Impl& rObj) { return rObj.xTarget == xObject; });
if (aObjIt != aCurrentPosition->aObjList.end())
if (aObjIt == aCurrentPosition->aObjList.end())
return;
sal_Int32 i = 0;
for( const auto& rEvt : aCurrentPosition->aEventList )
{
sal_Int32 i = 0;
for( const auto& rEvt : aCurrentPosition->aEventList )
if( aObjIt->aAttachedListenerSeq[i].is() )
{
if( aObjIt->aAttachedListenerSeq[i].is() )
try
{
xAttacher->removeListener( aObjIt->xTarget, rEvt.ListenerType,
rEvt.AddListenerParam, aObjIt->aAttachedListenerSeq[i] );
}
catch( Exception& )
{
try
{
xAttacher->removeListener( aObjIt->xTarget, rEvt.ListenerType,
rEvt.AddListenerParam, aObjIt->aAttachedListenerSeq[i] );
}
catch( Exception& )
{
}
}
++i;
}
aCurrentPosition->aObjList.erase( aObjIt );
++i;
}
aCurrentPosition->aObjList.erase( aObjIt );
}
void SAL_CALL ImplEventAttacherManager::addScriptListener(const Reference< XScriptListener >& aListener)

View File

@@ -69,41 +69,41 @@ bool DirectoryHelper::dirExists(const OUString& rDirURL)
void DirectoryHelper::scanDirsAndFiles(const OUString& rDirURL, std::set<OUString>& rDirs,
std::set<std::pair<OUString, OUString>>& rFiles)
{
if (!rDirURL.isEmpty())
if (rDirURL.isEmpty())
return;
osl::Directory aDirectory(rDirURL);
if (osl::FileBase::E_None != aDirectory.open())
return;
osl::DirectoryItem aDirectoryItem;
while (osl::FileBase::E_None == aDirectory.getNextItem(aDirectoryItem))
{
osl::Directory aDirectory(rDirURL);
osl::FileStatus aFileStatus(osl_FileStatus_Mask_Type | osl_FileStatus_Mask_FileURL
| osl_FileStatus_Mask_FileName);
if (osl::FileBase::E_None == aDirectory.open())
if (osl::FileBase::E_None == aDirectoryItem.getFileStatus(aFileStatus))
{
osl::DirectoryItem aDirectoryItem;
while (osl::FileBase::E_None == aDirectory.getNextItem(aDirectoryItem))
if (aFileStatus.isDirectory())
{
osl::FileStatus aFileStatus(osl_FileStatus_Mask_Type | osl_FileStatus_Mask_FileURL
| osl_FileStatus_Mask_FileName);
const OUString aFileName(aFileStatus.getFileName());
if (osl::FileBase::E_None == aDirectoryItem.getFileStatus(aFileStatus))
if (!aFileName.isEmpty())
{
if (aFileStatus.isDirectory())
{
const OUString aFileName(aFileStatus.getFileName());
rDirs.insert(aFileName);
}
}
else if (aFileStatus.isRegular())
{
OUString aFileName(aFileStatus.getFileName());
OUString aExtension;
aFileName = splitAtLastToken(aFileName, '.', aExtension);
if (!aFileName.isEmpty())
{
rDirs.insert(aFileName);
}
}
else if (aFileStatus.isRegular())
{
OUString aFileName(aFileStatus.getFileName());
OUString aExtension;
aFileName = splitAtLastToken(aFileName, '.', aExtension);
if (!aFileName.isEmpty())
{
rFiles.insert(std::pair<OUString, OUString>(aFileName, aExtension));
}
}
if (!aFileName.isEmpty())
{
rFiles.insert(std::pair<OUString, OUString>(aFileName, aExtension));
}
}
}

View File

@@ -124,18 +124,18 @@ namespace comphelper
if ( !isAlive() )
return;
if ( _rxListener.is() && m_pImpl->getClientId() )
if ( !(_rxListener.is() && m_pImpl->getClientId()) )
return;
sal_Int32 nListenerCount = AccessibleEventNotifier::removeEventListener( m_pImpl->getClientId( ), _rxListener );
if ( !nListenerCount )
{
sal_Int32 nListenerCount = AccessibleEventNotifier::removeEventListener( m_pImpl->getClientId( ), _rxListener );
if ( !nListenerCount )
{
// no listeners anymore
// -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
// and at least to us not firing any events anymore, in case somebody calls
// NotifyAccessibleEvent, again
AccessibleEventNotifier::revokeClient( m_pImpl->getClientId( ) );
m_pImpl->setClientId( 0 );
}
// no listeners anymore
// -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
// and at least to us not firing any events anymore, in case somebody calls
// NotifyAccessibleEvent, again
AccessibleEventNotifier::revokeClient( m_pImpl->getClientId( ) );
m_pImpl->setClientId( 0 );
}
}

View File

@@ -436,46 +436,46 @@ namespace
private:
void visitNodesXMLRead(const uno::Reference< xml::dom::XElement >& rElement)
{
if (rElement.is())
if (!rElement.is())
return;
const OUString aTagName(rElement->getTagName());
if (aTagName == "extension")
{
const OUString aTagName(rElement->getTagName());
OUString aAttrUrl(rElement->getAttribute("url"));
const OUString aAttrRevoked(rElement->getAttribute("revoked"));
if (aTagName == "extension")
if (!aAttrUrl.isEmpty())
{
OUString aAttrUrl(rElement->getAttribute("url"));
const OUString aAttrRevoked(rElement->getAttribute("revoked"));
const sal_Int32 nIndex(aAttrUrl.lastIndexOf('/'));
if (!aAttrUrl.isEmpty())
if (nIndex > 0 && aAttrUrl.getLength() > nIndex + 1)
{
const sal_Int32 nIndex(aAttrUrl.lastIndexOf('/'));
if (nIndex > 0 && aAttrUrl.getLength() > nIndex + 1)
{
aAttrUrl = aAttrUrl.copy(nIndex + 1);
}
const bool bEnabled(aAttrRevoked.isEmpty() || !aAttrRevoked.toBoolean());
maEntries.emplace_back(
OUStringToOString(aAttrUrl, RTL_TEXTENCODING_ASCII_US),
bEnabled);
aAttrUrl = aAttrUrl.copy(nIndex + 1);
}
const bool bEnabled(aAttrRevoked.isEmpty() || !aAttrRevoked.toBoolean());
maEntries.emplace_back(
OUStringToOString(aAttrUrl, RTL_TEXTENCODING_ASCII_US),
bEnabled);
}
else
}
else
{
uno::Reference< xml::dom::XNodeList > aList = rElement->getChildNodes();
if (aList.is())
{
uno::Reference< xml::dom::XNodeList > aList = rElement->getChildNodes();
const sal_Int32 nLength(aList->getLength());
if (aList.is())
for (sal_Int32 a(0); a < nLength; a++)
{
const sal_Int32 nLength(aList->getLength());
const uno::Reference< xml::dom::XElement > aChild(aList->item(a), uno::UNO_QUERY);
for (sal_Int32 a(0); a < nLength; a++)
if (aChild.is())
{
const uno::Reference< xml::dom::XElement > aChild(aList->item(a), uno::UNO_QUERY);
if (aChild.is())
{
visitNodesXMLRead(aChild);
}
visitNodesXMLRead(aChild);
}
}
}
@@ -605,58 +605,58 @@ namespace
const ExtensionInfoEntryVector& rToBeEnabled,
const ExtensionInfoEntryVector& rToBeDisabled)
{
if (!DirectoryHelper::fileExists(rUnoPackagReg))
return;
uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
uno::Reference< xml::dom::XDocumentBuilder > xBuilder = xml::dom::DocumentBuilder::create(xContext);
uno::Reference< xml::dom::XDocument > aDocument = xBuilder->parseURI(rUnoPackagReg);
if (!aDocument.is())
return;
if (!visitNodesXMLChange(
rTagToSearch,
aDocument->getDocumentElement(),
rToBeEnabled,
rToBeDisabled))
return;
// did change - write back
uno::Reference< xml::sax::XSAXSerializable > xSerializer(aDocument, uno::UNO_QUERY);
if (!xSerializer.is())
return;
// create a SAXWriter
uno::Reference< xml::sax::XWriter > const xSaxWriter = xml::sax::Writer::create(xContext);
uno::Reference< io::XStream > xTempFile = io::TempFile::create(xContext);
uno::Reference< io::XOutputStream > xOutStrm = xTempFile->getOutputStream();
// set output stream and do the serialization
xSaxWriter->setOutputStream(xOutStrm);
xSerializer->serialize(xSaxWriter, uno::Sequence< beans::StringPair >());
// get URL from temp file
uno::Reference < beans::XPropertySet > xTempFileProps(xTempFile, uno::UNO_QUERY);
uno::Any aUrl = xTempFileProps->getPropertyValue("Uri");
OUString aTempURL;
aUrl >>= aTempURL;
// copy back file
if (!(!aTempURL.isEmpty() && DirectoryHelper::fileExists(aTempURL)))
return;
if (DirectoryHelper::fileExists(rUnoPackagReg))
{
uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
uno::Reference< xml::dom::XDocumentBuilder > xBuilder = xml::dom::DocumentBuilder::create(xContext);
uno::Reference< xml::dom::XDocument > aDocument = xBuilder->parseURI(rUnoPackagReg);
if (aDocument.is())
{
if (visitNodesXMLChange(
rTagToSearch,
aDocument->getDocumentElement(),
rToBeEnabled,
rToBeDisabled))
{
// did change - write back
uno::Reference< xml::sax::XSAXSerializable > xSerializer(aDocument, uno::UNO_QUERY);
if (xSerializer.is())
{
// create a SAXWriter
uno::Reference< xml::sax::XWriter > const xSaxWriter = xml::sax::Writer::create(xContext);
uno::Reference< io::XStream > xTempFile = io::TempFile::create(xContext);
uno::Reference< io::XOutputStream > xOutStrm = xTempFile->getOutputStream();
// set output stream and do the serialization
xSaxWriter->setOutputStream(xOutStrm);
xSerializer->serialize(xSaxWriter, uno::Sequence< beans::StringPair >());
// get URL from temp file
uno::Reference < beans::XPropertySet > xTempFileProps(xTempFile, uno::UNO_QUERY);
uno::Any aUrl = xTempFileProps->getPropertyValue("Uri");
OUString aTempURL;
aUrl >>= aTempURL;
// copy back file
if (!aTempURL.isEmpty() && DirectoryHelper::fileExists(aTempURL))
{
if (DirectoryHelper::fileExists(rUnoPackagReg))
{
osl::File::remove(rUnoPackagReg);
}
osl::File::remove(rUnoPackagReg);
}
#if OSL_DEBUG_LEVEL > 1
SAL_WARN_IF(osl::FileBase::E_None != osl::File::move(aTempURL, rUnoPackagReg), "comphelper.backupfilehelper", "could not copy back modified Extension configuration file");
SAL_WARN_IF(osl::FileBase::E_None != osl::File::move(aTempURL, rUnoPackagReg), "comphelper.backupfilehelper", "could not copy back modified Extension configuration file");
#else
osl::File::move(aTempURL, rUnoPackagReg);
osl::File::move(aTempURL, rUnoPackagReg);
#endif
}
}
}
}
}
}
public:
@@ -1602,45 +1602,45 @@ namespace comphelper
// ensure existence of needed paths
getInitialBaseURL();
if (!maUserConfigBaseURL.isEmpty())
if (maUserConfigBaseURL.isEmpty())
return;
if (bSafeMode)
{
if (bSafeMode)
if (!mbSafeModeDirExists)
{
if (!mbSafeModeDirExists)
{
std::set< OUString > aExcludeList;
std::set< OUString > aExcludeList;
// do not move SafeMode directory itself
aExcludeList.insert(getSafeModeName());
// do not move SafeMode directory itself
aExcludeList.insert(getSafeModeName());
// init SafeMode by creating the 'SafeMode' directory and moving
// all stuff there. All repairs will happen there. Both Dirs have to exist.
// extend maUserConfigWorkURL as needed
maUserConfigWorkURL = maUserConfigBaseURL + "/" + getSafeModeName();
// init SafeMode by creating the 'SafeMode' directory and moving
// all stuff there. All repairs will happen there. Both Dirs have to exist.
// extend maUserConfigWorkURL as needed
maUserConfigWorkURL = maUserConfigBaseURL + "/" + getSafeModeName();
osl::Directory::createPath(maUserConfigWorkURL);
DirectoryHelper::moveDirContent(maUserConfigBaseURL, maUserConfigWorkURL, aExcludeList);
osl::Directory::createPath(maUserConfigWorkURL);
DirectoryHelper::moveDirContent(maUserConfigBaseURL, maUserConfigWorkURL, aExcludeList);
// switch local flag, maUserConfigWorkURL is already reset
mbSafeModeDirExists = true;
}
// switch local flag, maUserConfigWorkURL is already reset
mbSafeModeDirExists = true;
}
else
}
else
{
if (mbSafeModeDirExists)
{
if (mbSafeModeDirExists)
{
// SafeMode has ended, return to normal mode by moving all content
// from 'SafeMode' directory back to UserDirectory and deleting it.
// Both Dirs have to exist
std::set< OUString > aExcludeList;
// SafeMode has ended, return to normal mode by moving all content
// from 'SafeMode' directory back to UserDirectory and deleting it.
// Both Dirs have to exist
std::set< OUString > aExcludeList;
DirectoryHelper::moveDirContent(maUserConfigWorkURL, maUserConfigBaseURL, aExcludeList);
osl::Directory::remove(maUserConfigWorkURL);
DirectoryHelper::moveDirContent(maUserConfigWorkURL, maUserConfigBaseURL, aExcludeList);
osl::Directory::remove(maUserConfigWorkURL);
// switch local flag and reset maUserConfigWorkURL
mbSafeModeDirExists = false;
maUserConfigWorkURL = maUserConfigBaseURL;
}
// switch local flag and reset maUserConfigWorkURL
mbSafeModeDirExists = false;
maUserConfigWorkURL = maUserConfigBaseURL;
}
}
}
@@ -1650,22 +1650,22 @@ namespace comphelper
// no push when SafeModeDir exists, it may be Office's exit after SafeMode
// where SafeMode flag is already deleted, but SafeModeDir cleanup is not
// done yet (is done at next startup)
if (mbActive && !mbSafeModeDirExists)
if (!(mbActive && !mbSafeModeDirExists))
return;
const OUString aPackURL(getPackURL());
// ensure dir and file vectors
fillDirFileInfo();
// process all files in question recursively
if (!maDirs.empty() || !maFiles.empty())
{
const OUString aPackURL(getPackURL());
// ensure dir and file vectors
fillDirFileInfo();
// process all files in question recursively
if (!maDirs.empty() || !maFiles.empty())
{
tryPush_Files(
maDirs,
maFiles,
maUserConfigWorkURL,
aPackURL);
}
tryPush_Files(
maDirs,
maFiles,
maUserConfigWorkURL,
aPackURL);
}
}
@@ -1709,29 +1709,29 @@ namespace comphelper
void BackupFileHelper::tryPop()
{
if (mbActive)
if (!mbActive)
return;
bool bDidPop(false);
const OUString aPackURL(getPackURL());
// ensure dir and file vectors
fillDirFileInfo();
// process all files in question recursively
if (!maDirs.empty() || !maFiles.empty())
{
bool bDidPop(false);
const OUString aPackURL(getPackURL());
bDidPop = tryPop_files(
maDirs,
maFiles,
maUserConfigWorkURL,
aPackURL);
}
// ensure dir and file vectors
fillDirFileInfo();
// process all files in question recursively
if (!maDirs.empty() || !maFiles.empty())
{
bDidPop = tryPop_files(
maDirs,
maFiles,
maUserConfigWorkURL,
aPackURL);
}
if (bDidPop)
{
// try removal of evtl. empty directory
osl::Directory::remove(aPackURL);
}
if (bDidPop)
{
// try removal of evtl. empty directory
osl::Directory::remove(aPackURL);
}
}
@@ -1751,18 +1751,18 @@ namespace comphelper
void BackupFileHelper::tryPopExtensionInfo()
{
if (mbActive && mbExtensions)
if (!(mbActive && mbExtensions))
return;
bool bDidPop(false);
const OUString aPackURL(getPackURL());
bDidPop = tryPop_extensionInfo(aPackURL);
if (bDidPop)
{
bool bDidPop(false);
const OUString aPackURL(getPackURL());
bDidPop = tryPop_extensionInfo(aPackURL);
if (bDidPop)
{
// try removal of evtl. empty directory
osl::Directory::remove(aPackURL);
}
// try removal of evtl. empty directory
osl::Directory::remove(aPackURL);
}
}

View File

@@ -256,11 +256,70 @@ void SAL_CALL OLockListener::disposing( const lang::EventObject& aEvent )
osl::ClearableMutexGuard aGuard( m_aMutex );
// object is disposed
if ( aEvent.Source == m_xInstance )
{
// the object does not listen for anything any more
m_nMode = 0;
if ( aEvent.Source != m_xInstance )
return;
// the object does not listen for anything any more
m_nMode = 0;
// dispose the wrapper;
uno::Reference< lang::XComponent > xComponent( m_xWrapper.get(), uno::UNO_QUERY );
aGuard.clear();
if ( xComponent.is() )
{
try { xComponent->dispose(); }
catch( uno::Exception& ){}
}
}
// XCloseListener
void SAL_CALL OLockListener::queryClosing( const lang::EventObject& aEvent, sal_Bool )
{
// GetsOwnership parameter is always ignored, the user of the service must close the object always
osl::ClearableMutexGuard aGuard( m_aMutex );
if ( !(!m_bDisposed && aEvent.Source == m_xInstance && ( m_nMode & embed::Actions::PREVENT_CLOSE )) )
return;
try
{
uno::Reference< embed::XActionsApproval > xApprove = m_xApproval;
// unlock the mutex here
aGuard.clear();
if ( xApprove.is() && xApprove->approveAction( embed::Actions::PREVENT_CLOSE ) )
throw util::CloseVetoException();
}
catch( util::CloseVetoException& )
{
// rethrow this exception
throw;
}
catch( uno::Exception& )
{
// no action should be done
}
}
void SAL_CALL OLockListener::notifyClosing( const lang::EventObject& aEvent )
{
osl::ClearableMutexGuard aGuard( m_aMutex );
// object is closed, no reason to listen
if ( aEvent.Source != m_xInstance )
return;
uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster( aEvent.Source, uno::UNO_QUERY );
if ( !xCloseBroadcaster.is() )
return;
xCloseBroadcaster->removeCloseListener( static_cast< util::XCloseListener* >( this ) );
m_nMode &= ~embed::Actions::PREVENT_CLOSE;
if ( !m_nMode )
{
// dispose the wrapper;
uno::Reference< lang::XComponent > xComponent( m_xWrapper.get(), uno::UNO_QUERY );
aGuard.clear();
@@ -273,91 +332,32 @@ void SAL_CALL OLockListener::disposing( const lang::EventObject& aEvent )
}
// XCloseListener
void SAL_CALL OLockListener::queryClosing( const lang::EventObject& aEvent, sal_Bool )
{
// GetsOwnership parameter is always ignored, the user of the service must close the object always
osl::ClearableMutexGuard aGuard( m_aMutex );
if ( !m_bDisposed && aEvent.Source == m_xInstance && ( m_nMode & embed::Actions::PREVENT_CLOSE ) )
{
try
{
uno::Reference< embed::XActionsApproval > xApprove = m_xApproval;
// unlock the mutex here
aGuard.clear();
if ( xApprove.is() && xApprove->approveAction( embed::Actions::PREVENT_CLOSE ) )
throw util::CloseVetoException();
}
catch( util::CloseVetoException& )
{
// rethrow this exception
throw;
}
catch( uno::Exception& )
{
// no action should be done
}
}
}
void SAL_CALL OLockListener::notifyClosing( const lang::EventObject& aEvent )
{
osl::ClearableMutexGuard aGuard( m_aMutex );
// object is closed, no reason to listen
if ( aEvent.Source == m_xInstance )
{
uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster( aEvent.Source, uno::UNO_QUERY );
if ( xCloseBroadcaster.is() )
{
xCloseBroadcaster->removeCloseListener( static_cast< util::XCloseListener* >( this ) );
m_nMode &= ~embed::Actions::PREVENT_CLOSE;
if ( !m_nMode )
{
// dispose the wrapper;
uno::Reference< lang::XComponent > xComponent( m_xWrapper.get(), uno::UNO_QUERY );
aGuard.clear();
if ( xComponent.is() )
{
try { xComponent->dispose(); }
catch( uno::Exception& ){}
}
}
}
}
}
// XTerminateListener
void SAL_CALL OLockListener::queryTermination( const lang::EventObject& aEvent )
{
osl::ClearableMutexGuard aGuard( m_aMutex );
if ( aEvent.Source == m_xInstance && ( m_nMode & embed::Actions::PREVENT_TERMINATION ) )
if ( !(aEvent.Source == m_xInstance && ( m_nMode & embed::Actions::PREVENT_TERMINATION )) )
return;
try
{
try
{
uno::Reference< embed::XActionsApproval > xApprove = m_xApproval;
uno::Reference< embed::XActionsApproval > xApprove = m_xApproval;
// unlock the mutex here
aGuard.clear();
// unlock the mutex here
aGuard.clear();
if ( xApprove.is() && xApprove->approveAction( embed::Actions::PREVENT_TERMINATION ) )
throw frame::TerminationVetoException();
}
catch( frame::TerminationVetoException& )
{
// rethrow this exception
throw;
}
catch( uno::Exception& )
{
// no action should be done
}
if ( xApprove.is() && xApprove->approveAction( embed::Actions::PREVENT_TERMINATION ) )
throw frame::TerminationVetoException();
}
catch( frame::TerminationVetoException& )
{
// rethrow this exception
throw;
}
catch( uno::Exception& )
{
// no action should be done
}
}
@@ -367,31 +367,31 @@ void SAL_CALL OLockListener::notifyTermination( const lang::EventObject& aEvent
osl::ClearableMutexGuard aGuard( m_aMutex );
// object is terminated, no reason to listen
if ( aEvent.Source == m_xInstance )
if ( aEvent.Source != m_xInstance )
return;
uno::Reference< frame::XDesktop > xDesktop( aEvent.Source, uno::UNO_QUERY );
if ( !xDesktop.is() )
return;
try
{
uno::Reference< frame::XDesktop > xDesktop( aEvent.Source, uno::UNO_QUERY );
if ( xDesktop.is() )
xDesktop->removeTerminateListener( static_cast< frame::XTerminateListener* >( this ) );
m_nMode &= ~embed::Actions::PREVENT_TERMINATION;
if ( !m_nMode )
{
try
// dispose the wrapper;
uno::Reference< lang::XComponent > xComponent( m_xWrapper.get(), uno::UNO_QUERY );
aGuard.clear();
if ( xComponent.is() )
{
xDesktop->removeTerminateListener( static_cast< frame::XTerminateListener* >( this ) );
m_nMode &= ~embed::Actions::PREVENT_TERMINATION;
if ( !m_nMode )
{
// dispose the wrapper;
uno::Reference< lang::XComponent > xComponent( m_xWrapper.get(), uno::UNO_QUERY );
aGuard.clear();
if ( xComponent.is() )
{
try { xComponent->dispose(); }
catch( uno::Exception& ){}
}
}
try { xComponent->dispose(); }
catch( uno::Exception& ){}
}
catch( uno::Exception& )
{}
}
}
catch( uno::Exception& )
{}
}

View File

@@ -208,30 +208,30 @@ OfficeInstallationDirectories::getSupportedServiceNames()
void OfficeInstallationDirectories::initDirs()
{
if ( !m_xOfficeBrandDir)
{
osl::MutexGuard aGuard( m_aMutex );
if ( !m_xOfficeBrandDir )
{
uno::Reference< util::XMacroExpander > xExpander = util::theMacroExpander::get(m_xCtx);
if ( m_xOfficeBrandDir)
return;
m_xOfficeBrandDir = xExpander->expandMacros( "$BRAND_BASE_DIR" );
osl::MutexGuard aGuard( m_aMutex );
if ( m_xOfficeBrandDir )
return;
OSL_ENSURE( !m_xOfficeBrandDir->isEmpty(),
"Unable to obtain office brand installation directory!" );
uno::Reference< util::XMacroExpander > xExpander = util::theMacroExpander::get(m_xCtx);
makeCanonicalFileURL( *m_xOfficeBrandDir );
m_xOfficeBrandDir = xExpander->expandMacros( "$BRAND_BASE_DIR" );
m_xUserDir =
xExpander->expandMacros(
"${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE( "bootstrap" ) ":UserInstallation}" );
OSL_ENSURE( !m_xOfficeBrandDir->isEmpty(),
"Unable to obtain office brand installation directory!" );
OSL_ENSURE( !m_xUserDir->isEmpty(),
"Unable to obtain office user data directory!" );
makeCanonicalFileURL( *m_xOfficeBrandDir );
makeCanonicalFileURL( *m_xUserDir );
}
}
m_xUserDir =
xExpander->expandMacros(
"${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE( "bootstrap" ) ":UserInstallation}" );
OSL_ENSURE( !m_xUserDir->isEmpty(),
"Unable to obtain office user data directory!" );
makeCanonicalFileURL( *m_xUserDir );
}
}

View File

@@ -118,25 +118,25 @@ void SAL_CALL ChainablePropertySet::setPropertyValues(const Sequence< OUString >
if( nCount != rValues.getLength() )
throw IllegalArgumentException();
if( nCount )
if( !nCount )
return;
_preSetValues();
const Any * pAny = rValues.getConstArray();
const OUString * pString = rPropertyNames.getConstArray();
PropertyInfoHash::const_iterator aEnd = mxInfo->maMap.end(), aIter;
for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pAny )
{
_preSetValues();
aIter = mxInfo->maMap.find ( *pString );
if ( aIter == aEnd )
throw RuntimeException( *pString, static_cast< XPropertySet* >( this ) );
const Any * pAny = rValues.getConstArray();
const OUString * pString = rPropertyNames.getConstArray();
PropertyInfoHash::const_iterator aEnd = mxInfo->maMap.end(), aIter;
for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pAny )
{
aIter = mxInfo->maMap.find ( *pString );
if ( aIter == aEnd )
throw RuntimeException( *pString, static_cast< XPropertySet* >( this ) );
_setSingleValue ( *((*aIter).second), *pAny );
}
_postSetValues();
_setSingleValue ( *((*aIter).second), *pAny );
}
_postSetValues();
}
Sequence< Any > SAL_CALL ChainablePropertySet::getPropertyValues(const Sequence< OUString >& rPropertyNames)

View File

@@ -189,53 +189,53 @@ void SAL_CALL MasterPropertySet::setPropertyValues( const Sequence< OUString >&
if( nCount != aValues.getLength() )
throw IllegalArgumentException();
if( nCount )
if( !nCount )
return;
_preSetValues();
const Any * pAny = aValues.getConstArray();
const OUString * pString = aPropertyNames.getConstArray();
PropertyDataHash::const_iterator aEnd = mxInfo->maMap.end(), aIter;
//!! have a unique_ptr to an array of OGuards in order to have the
//!! allocated memory properly freed (exception safe!).
//!! Since the array itself has unique_ptrs as members we have to use a
//!! helper class 'AutoOGuardArray' in order to have
//!! the acquired locks properly released.
AutoOGuardArray aOGuardArray( nCount );
for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pAny )
{
_preSetValues();
aIter = mxInfo->maMap.find ( *pString );
if ( aIter == aEnd )
throw RuntimeException( *pString, static_cast< XPropertySet* >( this ) );
const Any * pAny = aValues.getConstArray();
const OUString * pString = aPropertyNames.getConstArray();
PropertyDataHash::const_iterator aEnd = mxInfo->maMap.end(), aIter;
//!! have a unique_ptr to an array of OGuards in order to have the
//!! allocated memory properly freed (exception safe!).
//!! Since the array itself has unique_ptrs as members we have to use a
//!! helper class 'AutoOGuardArray' in order to have
//!! the acquired locks properly released.
AutoOGuardArray aOGuardArray( nCount );
for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pAny )
if ( (*aIter).second->mnMapId == 0 ) // 0 means it's one of ours !
_setSingleValue( *((*aIter).second->mpInfo), *pAny );
else
{
aIter = mxInfo->maMap.find ( *pString );
if ( aIter == aEnd )
throw RuntimeException( *pString, static_cast< XPropertySet* >( this ) );
if ( (*aIter).second->mnMapId == 0 ) // 0 means it's one of ours !
_setSingleValue( *((*aIter).second->mpInfo), *pAny );
else
SlaveData * pSlave = maSlaveMap [ (*aIter).second->mnMapId ];
if (!pSlave->IsInit())
{
SlaveData * pSlave = maSlaveMap [ (*aIter).second->mnMapId ];
if (!pSlave->IsInit())
{
// acquire mutex in c-tor and releases it in the d-tor (exception safe!).
if (pSlave->mxSlave->mpMutex)
aOGuardArray[i].reset( new osl::Guard< comphelper::SolarMutex >(pSlave->mxSlave->mpMutex) );
// acquire mutex in c-tor and releases it in the d-tor (exception safe!).
if (pSlave->mxSlave->mpMutex)
aOGuardArray[i].reset( new osl::Guard< comphelper::SolarMutex >(pSlave->mxSlave->mpMutex) );
pSlave->mxSlave->_preSetValues();
pSlave->SetInit ( true );
}
pSlave->mxSlave->_setSingleValue( *((*aIter).second->mpInfo), *pAny );
pSlave->mxSlave->_preSetValues();
pSlave->SetInit ( true );
}
pSlave->mxSlave->_setSingleValue( *((*aIter).second->mpInfo), *pAny );
}
}
_postSetValues();
for( const auto& rSlave : maSlaveMap )
_postSetValues();
for( const auto& rSlave : maSlaveMap )
{
if( rSlave.second->IsInit() )
{
if( rSlave.second->IsInit() )
{
rSlave.second->mxSlave->_postSetValues();
rSlave.second->SetInit( false );
}
rSlave.second->mxSlave->_postSetValues();
rSlave.second->SetInit( false );
}
}
}

View File

@@ -99,23 +99,23 @@ GenericPropertySet::GenericPropertySet( PropertySetInfo* pInfo ) throw()
void SAL_CALL GenericPropertySet::addPropertyChangeListener( const OUString& aPropertyName, const Reference< XPropertyChangeListener >& xListener )
{
Reference < XPropertySetInfo > xInfo = getPropertySetInfo( );
if ( xInfo.is() )
if ( !xInfo.is() )
return;
if ( aPropertyName.isEmpty() )
{
if ( aPropertyName.isEmpty() )
Sequence< Property> aSeq = xInfo->getProperties();
const Property* pIter = aSeq.getConstArray();
const Property* pEnd = pIter + aSeq.getLength();
for( ; pIter != pEnd ; ++pIter)
{
Sequence< Property> aSeq = xInfo->getProperties();
const Property* pIter = aSeq.getConstArray();
const Property* pEnd = pIter + aSeq.getLength();
for( ; pIter != pEnd ; ++pIter)
{
m_aListener.addInterface(pIter->Name,xListener);
}
m_aListener.addInterface(pIter->Name,xListener);
}
else if ( xInfo->hasPropertyByName(aPropertyName) )
m_aListener.addInterface(aPropertyName,xListener);
else
throw UnknownPropertyException( aPropertyName, *this );
}
else if ( xInfo->hasPropertyByName(aPropertyName) )
m_aListener.addInterface(aPropertyName,xListener);
else
throw UnknownPropertyException( aPropertyName, *this );
}
void SAL_CALL GenericPropertySet::removePropertyChangeListener( const OUString& aPropertyName, const Reference< XPropertyChangeListener >& xListener )
@@ -123,23 +123,23 @@ void SAL_CALL GenericPropertySet::removePropertyChangeListener( const OUString&
ClearableMutexGuard aGuard( maMutex );
Reference < XPropertySetInfo > xInfo = getPropertySetInfo( );
aGuard.clear();
if ( xInfo.is() )
if ( !xInfo.is() )
return;
if ( aPropertyName.isEmpty() )
{
if ( aPropertyName.isEmpty() )
Sequence< Property> aSeq = xInfo->getProperties();
const Property* pIter = aSeq.getConstArray();
const Property* pEnd = pIter + aSeq.getLength();
for( ; pIter != pEnd ; ++pIter)
{
Sequence< Property> aSeq = xInfo->getProperties();
const Property* pIter = aSeq.getConstArray();
const Property* pEnd = pIter + aSeq.getLength();
for( ; pIter != pEnd ; ++pIter)
{
m_aListener.removeInterface(pIter->Name,xListener);
}
m_aListener.removeInterface(pIter->Name,xListener);
}
else if ( xInfo->hasPropertyByName(aPropertyName) )
m_aListener.removeInterface(aPropertyName,xListener);
else
throw UnknownPropertyException( aPropertyName, *this );
}
else if ( xInfo->hasPropertyByName(aPropertyName) )
m_aListener.removeInterface(aPropertyName,xListener);
else
throw UnknownPropertyException( aPropertyName, *this );
}
void GenericPropertySet::_setPropertyValues( const PropertyMapEntry** ppEntries, const Any* pValues )

View File

@@ -144,19 +144,20 @@ namespace comphelper
::osl::MutexGuard aGuard( m_aMutex );
m_isModified = bModified;
}
if (bModified) {
try {
Reference<XInterface> xThis(*this);
EventObject event(xThis);
m_NotifyListeners.notifyEach(
&XModifyListener::modified, event);
} catch (RuntimeException &) {
if (!bIgnoreRuntimeExceptionsWhileFiring) {
throw;
}
} catch (Exception &) {
// ignore
if (!bModified)
return;
try {
Reference<XInterface> xThis(*this);
EventObject event(xThis);
m_NotifyListeners.notifyEach(
&XModifyListener::modified, event);
} catch (RuntimeException &) {
if (!bIgnoreRuntimeExceptionsWhileFiring) {
throw;
}
} catch (Exception &) {
// ignore
}
}

View File

@@ -298,28 +298,28 @@ namespace internal
void PropertyForwarder::doForward( sal_Int32 _nHandle, const Any& _rValue )
{
OSL_ENSURE( m_rAggregationHelper.m_xAggregateSet.is(), "PropertyForwarder::doForward: no property set!" );
if ( m_rAggregationHelper.m_xAggregateSet.is() )
if ( !m_rAggregationHelper.m_xAggregateSet.is() )
return;
m_rAggregationHelper.forwardingPropertyValue( _nHandle );
OSL_ENSURE( m_nCurrentlyForwarding == -1, "PropertyForwarder::doForward: reentrance?" );
m_nCurrentlyForwarding = _nHandle;
try
{
m_rAggregationHelper.forwardingPropertyValue( _nHandle );
OSL_ENSURE( m_nCurrentlyForwarding == -1, "PropertyForwarder::doForward: reentrance?" );
m_nCurrentlyForwarding = _nHandle;
try
{
m_rAggregationHelper.m_xAggregateSet->setPropertyValue( m_rAggregationHelper.getPropertyName( _nHandle ), _rValue );
// TODO: cache the property name? (it's a O(log n) search)
}
catch( const Exception& )
{
m_rAggregationHelper.forwardedPropertyValue( _nHandle );
throw;
}
m_nCurrentlyForwarding = -1;
m_rAggregationHelper.forwardedPropertyValue( _nHandle );
m_rAggregationHelper.m_xAggregateSet->setPropertyValue( m_rAggregationHelper.getPropertyName( _nHandle ), _rValue );
// TODO: cache the property name? (it's a O(log n) search)
}
catch( const Exception& )
{
m_rAggregationHelper.forwardedPropertyValue( _nHandle );
throw;
}
m_nCurrentlyForwarding = -1;
m_rAggregationHelper.forwardedPropertyValue( _nHandle );
}
}

View File

@@ -129,26 +129,26 @@ void SAL_CALL PropertySetHelper::setPropertyValues( const Sequence< OUString >&
if( nCount != rValues.getLength() )
throw IllegalArgumentException();
if( nCount )
if( !nCount )
return;
std::unique_ptr<PropertyMapEntry const *[]> pEntries(new PropertyMapEntry const *[nCount+1]);
pEntries[nCount] = nullptr;
const OUString* pNames = rPropertyNames.getConstArray();
bool bUnknown = false;
sal_Int32 n;
for( n = 0; !bUnknown && ( n < nCount ); n++, pNames++ )
{
std::unique_ptr<PropertyMapEntry const *[]> pEntries(new PropertyMapEntry const *[nCount+1]);
pEntries[nCount] = nullptr;
const OUString* pNames = rPropertyNames.getConstArray();
bool bUnknown = false;
sal_Int32 n;
for( n = 0; !bUnknown && ( n < nCount ); n++, pNames++ )
{
pEntries[n] = mpImpl->find( *pNames );
bUnknown = nullptr == pEntries[n];
}
if( !bUnknown )
_setPropertyValues( pEntries.get(), rValues.getConstArray() );
if( bUnknown )
throw RuntimeException( *pNames, static_cast< XPropertySet* >( this ) );
pEntries[n] = mpImpl->find( *pNames );
bUnknown = nullptr == pEntries[n];
}
if( !bUnknown )
_setPropertyValues( pEntries.get(), rValues.getConstArray() );
if( bUnknown )
throw RuntimeException( *pNames, static_cast< XPropertySet* >( this ) );
}
Sequence< Any > SAL_CALL PropertySetHelper::getPropertyValues(const Sequence< OUString >& rPropertyNames)

View File

@@ -89,21 +89,21 @@ void OPropertyChangeMultiplexer::unlock()
void OPropertyChangeMultiplexer::dispose()
{
if (m_bListening)
{
Reference< XPropertyChangeListener> xPreventDelete(this);
if (!m_bListening)
return;
for (const OUString& rProp : m_aProperties)
m_xSet->removePropertyChangeListener(rProp, static_cast< XPropertyChangeListener*>(this));
Reference< XPropertyChangeListener> xPreventDelete(this);
m_pListener->setAdapter(nullptr);
for (const OUString& rProp : m_aProperties)
m_xSet->removePropertyChangeListener(rProp, static_cast< XPropertyChangeListener*>(this));
m_pListener = nullptr;
m_bListening = false;
m_pListener->setAdapter(nullptr);
if (m_bAutoSetRelease)
m_xSet = nullptr;
}
m_pListener = nullptr;
m_bListening = false;
if (m_bAutoSetRelease)
m_xSet = nullptr;
}
// XEventListener

View File

@@ -191,24 +191,24 @@ sal_Int64 SAL_CALL UNOMemoryStream::getLength()
void SAL_CALL UNOMemoryStream::writeBytes( const Sequence< sal_Int8 >& aData )
{
const sal_Int32 nBytesToWrite( aData.getLength() );
if( nBytesToWrite )
if( !nBytesToWrite )
return;
sal_Int64 nNewSize = static_cast<sal_Int64>(mnCursor) + nBytesToWrite;
if( nNewSize > SAL_MAX_INT32 )
{
sal_Int64 nNewSize = static_cast<sal_Int64>(mnCursor) + nBytesToWrite;
if( nNewSize > SAL_MAX_INT32 )
{
OSL_ASSERT(false);
throw IOException("this implementation does not support more than 2GB!", static_cast<OWeakObject*>(this) );
}
if( static_cast< sal_Int32 >( nNewSize ) > static_cast< sal_Int32 >( maData.size() ) )
maData.resize( nNewSize );
sal_Int8* pData = &(*maData.begin());
sal_Int8* pCursor = &(pData[mnCursor]);
memcpy( pCursor, aData.getConstArray(), nBytesToWrite );
mnCursor += nBytesToWrite;
OSL_ASSERT(false);
throw IOException("this implementation does not support more than 2GB!", static_cast<OWeakObject*>(this) );
}
if( static_cast< sal_Int32 >( nNewSize ) > static_cast< sal_Int32 >( maData.size() ) )
maData.resize( nNewSize );
sal_Int8* pData = &(*maData.begin());
sal_Int8* pCursor = &(pData[mnCursor]);
memcpy( pCursor, aData.getConstArray(), nBytesToWrite );
mnCursor += nBytesToWrite;
}
void SAL_CALL UNOMemoryStream::flush()