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

Use std::unique_ptr<JavaInfo> in jfw_plugin_getAllJavaInfos

Change-Id: I2beb95c42c666a788a87a45f59bc15ccfcf25aa6
üst 8d475bb1
......@@ -74,13 +74,6 @@ enum class javaPluginError
The JavaInfo structures returned in <code>parJavaInfo</code> should be ordered
according to their version. The one, representing a JRE with the highest
version should be the first in the array. </p>
<p>
The function allocates memory for an array and all the JavaInfo objects returned
in <code>parJavaInfo</code>. The caller must delete each JavaInfo object.
The array is to be
freed by rtl_freeMemory.
In case an error occurred <code>parJavaInfo</code> need not be freed.
</p>
@param sVendor
[in] only JREs from this vendor are examined. This parameter always contains
a vendor string. That is, the string it is not empty.
......@@ -93,10 +86,7 @@ enum class javaPluginError
versions must not be returned by this function.
@param parJavaInfo
[out] if the function runs successfully then <code>parJavaInfo</code> contains
on return an array of pointers to <code>JavaInfo</code> objects.
@param nSizeJavaInfo
[out] the number of <code>JavaInfo</code> pointers contained in
<code>parJavaInfo</code>.
on return a vector of pointers to <code>JavaInfo</code> objects.
@return
javaPluginError::NONE the function ran successfully.</br>
......@@ -112,8 +102,7 @@ javaPluginError jfw_plugin_getAllJavaInfos(
OUString const& sMinVersion,
OUString const& sMaxVersion,
std::vector<OUString> const & arExcludeList,
JavaInfo*** parJavaInfo,
sal_Int32 *nSizeJavaInfo,
std::vector<std::unique_ptr<JavaInfo>> * parJavaInfo,
std::vector<rtl::Reference<jfw_plugin::VendorBase>> & infos);
/** obtains information for a JRE at a given location.
......
......@@ -299,19 +299,15 @@ javaPluginError jfw_plugin_getAllJavaInfos(
OUString const& sMinVersion,
OUString const& sMaxVersion,
std::vector<OUString> const &arExcludeList,
JavaInfo*** parJavaInfo,
sal_Int32 *nLenInfoList,
std::vector<std::unique_ptr<JavaInfo>>* parJavaInfo,
std::vector<rtl::Reference<jfw_plugin::VendorBase>> & infos)
{
assert(parJavaInfo);
assert(nLenInfoList);
OSL_ASSERT(!sVendor.isEmpty());
if (sVendor.isEmpty())
return javaPluginError::InvalidArg;
JavaInfo** arInfo = nullptr;
//Find all JREs
vector<rtl::Reference<VendorBase> > vecInfos =
addAllJREInfos(checkJavaHomeAndPath, infos);
......@@ -337,17 +333,13 @@ javaPluginError jfw_plugin_getAllJavaInfos(
}
//Now vecVerifiedInfos contains all those JREs which meet the version requirements
//Transfer them into the array that is passed out.
arInfo = static_cast<JavaInfo**>(rtl_allocateMemory(vecVerifiedInfos.size() * sizeof (JavaInfo*)));
int j = 0;
parJavaInfo->clear();
typedef vector<rtl::Reference<VendorBase> >::const_iterator cit;
for (cit ii = vecVerifiedInfos.begin(); ii != vecVerifiedInfos.end(); ++ii, ++j)
for (cit ii = vecVerifiedInfos.begin(); ii != vecVerifiedInfos.end(); ++ii)
{
arInfo[j] = createJavaInfo(*ii);
parJavaInfo->push_back(std::unique_ptr<JavaInfo>(createJavaInfo(*ii)));
}
*nLenInfoList = vecVerifiedInfos.size();
*parJavaInfo = arInfo;
return javaPluginError::NONE;
}
......
......@@ -75,8 +75,7 @@ javaFrameworkError jfw_findAllJREs(std::vector<std::unique_ptr<JavaInfo>> *pparI
//get all installations of one vendor according to minVersion,
//maxVersion and excludeVersions
sal_Int32 cInfos = 0;
JavaInfo** arInfos = nullptr;
std::vector<std::unique_ptr<JavaInfo>> arInfos;
std::vector<rtl::Reference<jfw_plugin::VendorBase>> infos;
javaPluginError plerr = jfw_plugin_getAllJavaInfos(
true,
......@@ -85,16 +84,13 @@ javaFrameworkError jfw_findAllJREs(std::vector<std::unique_ptr<JavaInfo>> *pparI
versionInfo.sMaxVersion,
versionInfo.vecExcludeVersions,
& arInfos,
& cInfos,
infos);
if (plerr != javaPluginError::NONE)
return JFW_E_ERROR;
for (int j = 0; j < cInfos; j++)
vecInfo.push_back(std::unique_ptr<JavaInfo>(arInfos[j]));
rtl_freeMemory(arInfos);
for (auto & j: arInfos)
vecInfo.push_back(std::move(j));
//Check if the current plugin can detect JREs at the location
// of the paths added by jfw_addJRELocation
......@@ -423,8 +419,7 @@ javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr<JavaInfo> *pInfo)
//get all installations of one vendor according to minVersion,
//maxVersion and excludeVersions
sal_Int32 cInfos = 0;
JavaInfo** arInfos = nullptr;
std::vector<std::unique_ptr<JavaInfo>> arInfos;
javaPluginError plerr = jfw_plugin_getAllJavaInfos(
false,
vendor,
......@@ -432,22 +427,14 @@ javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr<JavaInfo> *pInfo)
versionInfo.sMaxVersion,
versionInfo.vecExcludeVersions,
& arInfos,
& cInfos,
infos);
if (plerr != javaPluginError::NONE)
continue;
//iterate over all installations to find the best which has
//all features
if (cInfos == 0)
for (auto & pJInfo: arInfos)
{
rtl_freeMemory(arInfos);
continue;
}
for (int ii = 0; ii < cInfos; ii++)
{
JavaInfo* pJInfo = arInfos[ii];
// compare features
// If the user does not require any features (nFeatureFlags = 0)
// then the first installation is used
......@@ -455,8 +442,7 @@ javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr<JavaInfo> *pInfo)
{
//the just found Java implements all required features
//currently there is only accessibility!!!
aCurrentInfo.reset(
jfw::CJavaInfo::copyJavaInfo(pJInfo));
aCurrentInfo = std::move(pJInfo);
bInfoFound = true;
break;
}
......@@ -464,15 +450,9 @@ javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr<JavaInfo> *pInfo)
{
// We remember the first installation in aCurrentInfo if
// no JavaInfo has been found before:
aCurrentInfo.reset(
jfw::CJavaInfo::copyJavaInfo(pJInfo));
aCurrentInfo = std::move(pJInfo);
}
}
//The array returned by jfw_plugin_getAllJavaInfos must be freed as well as
//its contents
for (int j = 0; j < cInfos; j++)
delete arInfos[j];
rtl_freeMemory(arInfos);
if (bInfoFound)
break;
......@@ -928,9 +908,4 @@ void jfw_unlock()
jfw::FwkMutex::get().release();
}
JavaInfo * jfw::CJavaInfo::copyJavaInfo(const JavaInfo * pInfo)
{
return pInfo == nullptr ? nullptr : new JavaInfo(*pInfo);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -27,11 +27,6 @@
namespace jfw
{
namespace CJavaInfo
{
JavaInfo * copyJavaInfo(const JavaInfo * pInfo);
}
class FrameworkException : public std::exception
{
public:
......
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