mirror of https://github.com/opencv/opencv.git
Open Source Computer Vision Library
https://opencv.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
230 lines
8.2 KiB
230 lines
8.2 KiB
13 years ago
|
#include "IOpenCVEngine.h"
|
||
|
#include "CommonPackageManager.h"
|
||
|
#include "HardwareDetector.h"
|
||
|
#include <utils/Log.h>
|
||
|
#include <algorithm>
|
||
|
#include <stdio.h>
|
||
|
#include <assert.h>
|
||
|
|
||
|
#undef LOG_TAG
|
||
|
#define LOG_TAG "CommonPackageManager"
|
||
|
|
||
|
using namespace std;
|
||
|
|
||
12 years ago
|
vector<int> CommonPackageManager::GetInstalledVersions()
|
||
13 years ago
|
{
|
||
12 years ago
|
vector<int> result;
|
||
13 years ago
|
vector<PackageInfo> installed_packages = GetInstalledPackages();
|
||
12 years ago
|
|
||
12 years ago
|
result.resize(installed_packages.size());
|
||
|
|
||
|
for (size_t i = 0; i < installed_packages.size(); i++)
|
||
13 years ago
|
{
|
||
12 years ago
|
int version = installed_packages[i].GetVersion();
|
||
|
assert(version);
|
||
|
result[i] = version;
|
||
13 years ago
|
}
|
||
12 years ago
|
|
||
13 years ago
|
return result;
|
||
|
}
|
||
|
|
||
12 years ago
|
bool CommonPackageManager::CheckVersionInstalled(int version, int platform, int cpu_id)
|
||
13 years ago
|
{
|
||
|
bool result = false;
|
||
|
LOGD("CommonPackageManager::CheckVersionInstalled() begin");
|
||
|
PackageInfo target_package(version, platform, cpu_id);
|
||
|
LOGD("GetInstalledPackages() call");
|
||
|
vector<PackageInfo> packages = GetInstalledPackages();
|
||
12 years ago
|
|
||
13 years ago
|
for (vector<PackageInfo>::const_iterator it = packages.begin(); it != packages.end(); ++it)
|
||
|
{
|
||
12 years ago
|
LOGD("Found package: \"%s\"", it->GetFullName().c_str());
|
||
13 years ago
|
}
|
||
12 years ago
|
|
||
13 years ago
|
if (!packages.empty())
|
||
|
{
|
||
12 years ago
|
vector<PackageInfo>::const_iterator it = find(packages.begin(), packages.end(), target_package);
|
||
|
result = (it != packages.end());
|
||
13 years ago
|
}
|
||
|
LOGD("CommonPackageManager::CheckVersionInstalled() end");
|
||
|
return result;
|
||
|
}
|
||
|
|
||
12 years ago
|
bool CommonPackageManager::InstallVersion(int version, int platform, int cpu_id)
|
||
13 years ago
|
{
|
||
|
LOGD("CommonPackageManager::InstallVersion() begin");
|
||
12 years ago
|
PackageInfo package(version, platform, cpu_id);
|
||
13 years ago
|
return InstallPackage(package);
|
||
|
}
|
||
|
|
||
12 years ago
|
string CommonPackageManager::GetPackagePathByVersion(int version, int platform, int cpu_id)
|
||
13 years ago
|
{
|
||
|
string result;
|
||
|
PackageInfo target_package(version, platform, cpu_id);
|
||
|
vector<PackageInfo> all_packages = GetInstalledPackages();
|
||
|
vector<PackageInfo> packages;
|
||
12 years ago
|
|
||
13 years ago
|
for (vector<PackageInfo>::iterator it = all_packages.begin(); it != all_packages.end(); ++it)
|
||
|
{
|
||
12 years ago
|
LOGD("Check version \"%d\" compatibility with \"%d\"\n", version, it->GetVersion());
|
||
12 years ago
|
if (IsVersionCompatible(version, it->GetVersion()))
|
||
12 years ago
|
{
|
||
12 years ago
|
LOGD("Compatible");
|
||
|
packages.push_back(*it);
|
||
12 years ago
|
}
|
||
|
else
|
||
|
{
|
||
12 years ago
|
LOGD("NOT Compatible");
|
||
12 years ago
|
}
|
||
12 years ago
|
}
|
||
12 years ago
|
|
||
12 years ago
|
if (!packages.empty())
|
||
|
{
|
||
12 years ago
|
int platform_group = 0;
|
||
12 years ago
|
|
||
|
if ((cpu_id & ARCH_X86) || (cpu_id & ARCH_X64))
|
||
12 years ago
|
platform_group = 1;
|
||
12 years ago
|
|
||
12 years ago
|
if (cpu_id & ARCH_MIPS)
|
||
|
platform_group = 2;
|
||
12 years ago
|
|
||
12 years ago
|
int opt_rating = -1;
|
||
|
int opt_version = 0;
|
||
|
|
||
|
const int hardware_rating = GetHardwareRating(platform, cpu_id, ArchRatings[platform_group]);
|
||
|
LOGD("Current hardware platform rating %d for (%d,%d)", hardware_rating, platform, cpu_id);
|
||
|
|
||
|
if (-1 == hardware_rating)
|
||
12 years ago
|
{
|
||
12 years ago
|
LOGE("Cannot calculate rating for current hardware platform!");
|
||
12 years ago
|
}
|
||
|
else
|
||
|
{
|
||
12 years ago
|
vector<PackageInfo>::iterator found = packages.end();
|
||
|
for (vector<PackageInfo>::iterator it = packages.begin(); it != packages.end(); ++it)
|
||
12 years ago
|
{
|
||
12 years ago
|
int package_group = 0;
|
||
|
|
||
|
if ((it->GetCpuID() & ARCH_X86) || (it->GetCpuID() & ARCH_X64))
|
||
|
package_group = 1;
|
||
|
|
||
|
if (it->GetCpuID() & ARCH_MIPS)
|
||
|
package_group = 2;
|
||
|
|
||
|
if (package_group != platform_group)
|
||
|
continue;
|
||
|
|
||
|
const int package_rating = GetHardwareRating(it->GetPlatform(), it->GetCpuID(), ArchRatings[package_group]);
|
||
|
|
||
|
LOGD("Package \"%s\" rating %d for (%d,%d)", it->GetFullName().c_str(), package_rating, it->GetPlatform(), it->GetCpuID());
|
||
|
if ((package_rating >= 0) && (package_rating <= hardware_rating))
|
||
12 years ago
|
{
|
||
12 years ago
|
if (((it->GetVersion() >= opt_version) && (package_rating >= opt_rating)) || (it->GetVersion() > opt_version))
|
||
12 years ago
|
{
|
||
12 years ago
|
opt_rating = package_rating;
|
||
|
opt_version = it->GetVersion();
|
||
12 years ago
|
found = it;
|
||
12 years ago
|
}
|
||
|
}
|
||
12 years ago
|
}
|
||
12 years ago
|
|
||
12 years ago
|
if ((-1 != opt_rating) && (packages.end() != found))
|
||
12 years ago
|
{
|
||
|
result = found->GetInstalationPath();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
12 years ago
|
LOGI("No compatible packages found!");
|
||
12 years ago
|
}
|
||
12 years ago
|
}
|
||
|
}
|
||
12 years ago
|
|
||
13 years ago
|
return result;
|
||
|
}
|
||
|
|
||
12 years ago
|
bool CommonPackageManager::IsVersionCompatible(int target_version, int package_version)
|
||
13 years ago
|
{
|
||
12 years ago
|
assert(target_version);
|
||
|
assert(package_version);
|
||
12 years ago
|
|
||
13 years ago
|
// major version is the same and minor package version is above or the same as target.
|
||
12 years ago
|
return ( (package_version/10000 == target_version/10000) && (package_version%10000 >= target_version%10000) );
|
||
13 years ago
|
}
|
||
|
|
||
|
int CommonPackageManager::GetHardwareRating(int platform, int cpu_id, const std::vector<std::pair<int, int> >& group)
|
||
|
{
|
||
|
int result = -1;
|
||
12 years ago
|
|
||
12 years ago
|
if ((cpu_id & ARCH_X86) || (cpu_id & ARCH_X64) || (cpu_id & ARCH_MIPS))
|
||
|
// Note: No raiting for x86, x64 and MIPS
|
||
|
// only one package is used
|
||
|
result = 0;
|
||
|
else
|
||
13 years ago
|
{
|
||
12 years ago
|
// Calculate rating for Arm
|
||
12 years ago
|
LOGD("!!! Calculating rating for ARM\n");
|
||
12 years ago
|
for (size_t i = 0; i < group.size(); i++)
|
||
|
{
|
||
12 years ago
|
LOGD("Checking (%d, %d) against (%d,%d)\n", group[i].first, group[i].second, platform, cpu_id);
|
||
12 years ago
|
if (group[i] == std::pair<int, int>(platform, cpu_id))
|
||
|
{
|
||
12 years ago
|
LOGD("Rating found: %d\n", i);
|
||
12 years ago
|
result = i;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
13 years ago
|
}
|
||
|
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
std::vector<std::pair<int, int> > CommonPackageManager::InitArmRating()
|
||
|
{
|
||
|
std::vector<std::pair<int, int> > result;
|
||
12 years ago
|
|
||
13 years ago
|
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_ARMv5));
|
||
|
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_ARMv6));
|
||
|
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_ARMv6 | FEATURES_HAS_VFPv3d16));
|
||
|
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_ARMv6 | FEATURES_HAS_VFPv3));
|
||
12 years ago
|
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_ARMv6 | FEATURES_HAS_VFPv3 | FEATURES_HAS_VFPv3d16));
|
||
13 years ago
|
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_ARMv7));
|
||
12 years ago
|
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_VFPv3d16));
|
||
12 years ago
|
result.push_back(std::pair<int, int>(PLATFORM_TEGRA2, ARCH_ARMv7 | FEATURES_HAS_VFPv3d16));
|
||
13 years ago
|
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_VFPv3));
|
||
12 years ago
|
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_VFPv3d16 | FEATURES_HAS_VFPv3));
|
||
13 years ago
|
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_NEON));
|
||
12 years ago
|
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_VFPv3d16 | FEATURES_HAS_NEON));
|
||
13 years ago
|
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_VFPv3 | FEATURES_HAS_NEON));
|
||
12 years ago
|
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_VFPv3 | FEATURES_HAS_VFPv3d16 | FEATURES_HAS_NEON));
|
||
12 years ago
|
result.push_back(std::pair<int, int>(PLATFORM_TEGRA3, ARCH_ARMv7 | FEATURES_HAS_VFPv3 | FEATURES_HAS_NEON));
|
||
12 years ago
|
result.push_back(std::pair<int, int>(PLATFORM_TEGRA4, ARCH_ARMv7 | FEATURES_HAS_VFPv3 | FEATURES_HAS_NEON));
|
||
12 years ago
|
|
||
13 years ago
|
return result;
|
||
|
}
|
||
|
|
||
12 years ago
|
// Stub for Intel platforms rating initialization. Common package for all Intel based devices is used now
|
||
13 years ago
|
std::vector<std::pair<int, int> > CommonPackageManager::InitIntelRating()
|
||
|
{
|
||
|
std::vector<std::pair<int, int> > result;
|
||
12 years ago
|
|
||
12 years ago
|
return result;
|
||
|
}
|
||
|
|
||
|
// Stub for MIPS platforms rating initialization. Common package for all MIPS based devices is used now
|
||
|
std::vector<std::pair<int, int> > CommonPackageManager::InitMipsRating()
|
||
|
{
|
||
|
std::vector<std::pair<int, int> > result;
|
||
12 years ago
|
|
||
13 years ago
|
return result;
|
||
|
}
|
||
|
|
||
12 years ago
|
const std::vector<std::pair<int, int> > CommonPackageManager::ArchRatings[] = {
|
||
12 years ago
|
CommonPackageManager::InitArmRating(),
|
||
|
CommonPackageManager::InitIntelRating(),
|
||
12 years ago
|
CommonPackageManager::InitMipsRating()
|
||
|
};
|
||
13 years ago
|
|
||
|
CommonPackageManager::~CommonPackageManager()
|
||
|
{
|
||
|
}
|