Make deviceName and peerName more well-defined.

Previously the DeviceDescription deviceName was being stored in the
TemplateDescription peerName.

This patch defines devicename in both DeviceDescription &
TemplateDescription as storing the user-modifiable device name, thus
unifiying the meaning. The peerName is defined to hold the vendor
and/or model information discovered using the Bluetooth Device ID
profile (DIP) or, in the case that DIP is not supported, peerName will
be an empty string. Whether the peerName includes the model of the
device is dependent on whether a matching entry was found in the
product lookup table.
This commit is contained in:
Chris Kühl 2011-08-29 16:12:46 +02:00 committed by Patrick Ohly
parent d4928b4c20
commit d347a548c6
3 changed files with 23 additions and 17 deletions

View File

@ -45,7 +45,7 @@ void ReadOperations::getConfigs(bool getTemplates, std::vector<std::string> &con
std::map<std::string, int> numbers;
BOOST_FOREACH(const boost::shared_ptr<SyncConfig::TemplateDescription> peer, list) {
//if it is not a template for device
if(peer->m_fingerprint.empty()) {
if(peer->m_deviceName.empty()) {
configNames.push_back(peer->m_templateId);
} else {
string templName = "Bluetooth_";
@ -119,8 +119,9 @@ void ReadOperations::getConfig(bool getTemplate,
score << peerTemplate->m_rank;
localConfigs.insert(pair<string, string>("score", score.str()));
// Actually this fingerprint is transferred by getConfigs, which refers to device name
localConfigs.insert(pair<string, string>("deviceName", peerTemplate->m_fingerprint));
// This is the user-modifiable device name. Could be shown in GUIs, for example
localConfigs.insert(pair<string, string>("deviceName", peerTemplate->m_deviceName));
// This is the reliable device info obtained from the bluetooth
// device id profile (DIP) or emtpy if DIP not supported.
localConfigs.insert(pair<string, string>("peerName", peerTemplate->m_peerName));
// This is the fingerprint of the template
localConfigs.insert(pair<string, string>("fingerPrint", peerTemplate->m_matchedModel));

View File

@ -714,16 +714,19 @@ SyncConfig::TemplateList SyncConfig::matchPeerTemplates(const DeviceList &peers,
}
BOOST_FOREACH (const DeviceList::value_type &entry, peers){
std::string fingerprint(entry.getFingerprint());
int rank = templateConf.metaMatch (fingerprint, entry.m_matchMode);
// peerName should be empty if no reliable device info is on hand.
std::string peerName = entry.m_pnpInformation ? fingerprint : "";
int rank = templateConf.metaMatch (entry.getFingerprint(), entry.m_matchMode);
if (fuzzyMatch){
if (rank > TemplateConfig::NO_MATCH) {
result.push_back (boost::shared_ptr<TemplateDescription>(
new TemplateDescription(templateConf.getTemplateId(),
templateConf.getDescription(),
rank,
entry.m_deviceName,
peerName,
entry.m_deviceId,
fingerprint,
entry.m_deviceName,
sDir,
templateConf.getFingerprint(),
templateConf.getTemplateName()
@ -735,9 +738,9 @@ SyncConfig::TemplateList SyncConfig::matchPeerTemplates(const DeviceList &peers,
new TemplateDescription(templateConf.getTemplateId(),
templateConf.getDescription(),
rank,
entry.m_deviceName,
peerName,
entry.m_deviceId,
fingerprint,
entry.m_deviceName,
sDir,
templateConf.getFingerprint(),
templateConf.getTemplateName())
@ -2596,7 +2599,7 @@ SyncConfig::TemplateDescription::TemplateDescription (const std::string &name, c
: m_templateId (name), m_description (description)
{
m_rank = TemplateConfig::LEVEL3_MATCH;
m_fingerprint = "";
m_deviceName = "";
m_path = "";
m_matchedModel = name;
}
@ -2607,8 +2610,8 @@ SyncConfig::TemplateDescription::TemplateDescription (const std::string &name, c
bool SyncConfig::TemplateDescription::compare_op (boost::shared_ptr<SyncConfig::TemplateDescription> &left, boost::shared_ptr<SyncConfig::TemplateDescription> &right)
{
//first sort against the fingerprint string
if (left->m_fingerprint != right->m_fingerprint) {
return (left->m_fingerprint < right->m_fingerprint);
if (left->m_deviceName != right->m_deviceName) {
return (left->m_deviceName < right->m_deviceName);
}
// sort against the rank
if (right->m_rank != left->m_rank) {

View File

@ -1032,22 +1032,24 @@ class SyncConfig {
// The matched percentage of the template, larger the better.
int m_rank;
// A string that can be shown in GUIs. For bluetooth devices
// this is the user-modifiable device name.
// This can be either the user-modifiable device name, vendor
// name, or product name (vendor + model). This depends on
// whether the device supports the Bluetooth Device ID profile
// and, if so, whether we have the model in the lookup table.
std::string m_peerName;
//a unique identity of the device that the template is for, used by caller
std::string m_deviceId;
// A string identify which fingerprint the template is matched with.
std::string m_fingerprint;
// This is always the user-modifiable device name.
std::string m_deviceName;
// A unique string identify the template path, so that a later operation
// fetching this config will be much easier
std::string m_path;
// A string indicates the original fingerprint in the matched template, this
// will not necessarily the same with m_fingerprint
// will not necessarily be the same as m_deviceName
std::string m_matchedModel;
// The template name (device class) presented
@ -1062,7 +1064,7 @@ class SyncConfig {
m_rank (rank),
m_peerName (peerName),
m_deviceId (deviceId),
m_fingerprint (fingerprint),
m_deviceName (fingerprint),
m_path (path),
m_matchedModel(model),
m_templateName (templateName)