On Mon, Aug 29, 2011 at 5:27 PM, Patrick Ohly <[email protected]> wrote:
> On Mo, 2011-08-29 at 15:12 +0200, Patrick Ohly wrote:
>> > 1) In the case that we have no PnPInformation info we have...
>> >
>> > deviceName = User-modifiable name
>> > peerName = User-modifiable name
>>
>> Better leave the peerName unset. It's semantic will be "we know for sure
>> that this device is a "<vendor>[ <product>]".
>
> You decided to not implement it like this, did you?

That was an oversight. Attached, you'll find updated patch.

>
> From your patch:
>             // This is the user-modifiable device name. Could be shown in 
> GUIs, for example
>             localConfigs.insert(pair<string, string>("peerName", 
> peerTemplate->m_peerName));
>
> +        // 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;
>
> Was it simply easier to implement this way or do you prefer that
> semantic of "peerName" in a template reported by the D-Bus server?
>
> My concern is that if the D-Bus server always reports a value, the D-Bus
> client won't be able to determine whether it has reliable information
> about the manufacturer and model.
>

I agree that there is a need to be able for the client code to know
that they have reliable info or not. Setting peerName to empty is a
good way to do that.

I've also attached a n updated patch for the script. Just adds a
header with copyright and license info.

Cheers,
Chris
From 86e365df27850758fa2480c16e1c298bed172af1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Chris=20K=C3=BChl?= <[email protected]>
Date: Mon, 29 Aug 2011 16:12:46 +0200
Subject: [PATCH 1/2] 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.
---
 src/dbus/server/read-operations.cpp |    7 ++++---
 src/syncevo/SyncConfig.cpp          |   19 +++++++++++--------
 src/syncevo/SyncConfig.h            |   14 ++++++++------
 3 files changed, 23 insertions(+), 17 deletions(-)

diff --git a/src/dbus/server/read-operations.cpp b/src/dbus/server/read-operations.cpp
index be91541..31d9905 100644
--- a/src/dbus/server/read-operations.cpp
+++ b/src/dbus/server/read-operations.cpp
@@ -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));
diff --git a/src/syncevo/SyncConfig.cpp b/src/syncevo/SyncConfig.cpp
index 1ac88b7..3d6b10d 100644
--- a/src/syncevo/SyncConfig.cpp
+++ b/src/syncevo/SyncConfig.cpp
@@ -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) {
diff --git a/src/syncevo/SyncConfig.h b/src/syncevo/SyncConfig.h
index 54d1bab..a07b8d1 100644
--- a/src/syncevo/SyncConfig.h
+++ b/src/syncevo/SyncConfig.h
@@ -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)
-- 
1.7.6

From 1179715e77cb6f3d2815d6f9794580c965ea6845 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Chris=20K=C3=BChl?= <[email protected]>
Date: Mon, 29 Aug 2011 16:37:03 +0200
Subject: [PATCH 2/2] Add script to query for the bluetooth device id

We currently only have a few devices added to our bluetooth product
lookup table.

This script is intended to allow user to query the information from
device they own and instructs them to send it to a syncevolution
devoloper (me for the time being). The goal is to crowd-source sa much
phone data as we can.
---
 test/bluetooth-device-id-inspector.py |  113 +++++++++++++++++++++++++++++++++
 1 files changed, 113 insertions(+), 0 deletions(-)
 create mode 100644 test/bluetooth-device-id-inspector.py

diff --git a/test/bluetooth-device-id-inspector.py b/test/bluetooth-device-id-inspector.py
new file mode 100644
index 0000000..6784ca6
--- /dev/null
+++ b/test/bluetooth-device-id-inspector.py
@@ -0,0 +1,113 @@
+#! /usr/bin/python -u
+
+# * Copyright (C) 2011 Intel Corporation
+
+# This file is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 or 3.0 of the License.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+import dbus
+import string
+import sys
+
+# Defines
+SYNCML_UUID  = "00000002-0000-1000-8000-0002ee000002"
+PNPINFO_UUID = "00001200-0000-1000-8000-00805f9b34fb"
+PNPINFO_ATTRIB = "0x1200"
+SOURCE_ATTRIB  = "0x0205"
+VENDOR_ATTRIB  = "0x0201"
+PRODUCT_ATTRIB = "0x0202"
+
+def extractValueFromServiceRecord(servRec, attribId):
+
+    pos = string.find(servRec, attribId)
+
+    if(pos < 0):
+        return ""
+
+    pos = string.find(servRec, "value", pos + len(attribId))
+    pos = string.find(servRec, '"', pos) + 1
+    endPos = string.find(servRec,'"', pos)
+    return servRec[pos:endPos]
+
+def getVendorAndProductId(pnpInfoServRec):
+    '''Get the vendor and product ids from xml formatted service record.'''
+
+    servRec = pnpInfoServRec.values()[0]
+
+    sourceVal  = extractValueFromServiceRecord(servRec, SOURCE_ATTRIB)
+    vendorVal  = extractValueFromServiceRecord(servRec, VENDOR_ATTRIB)
+    productVal = extractValueFromServiceRecord(servRec, PRODUCT_ATTRIB)
+    return (sourceVal, vendorVal, productVal)
+
+def writeDeviceInfoToFile(ids, vendor, product, hasSyncML):
+
+    filename = "syncevo-phone-info-[%s].txt" % product
+    FILE = open(filename,"w")
+    FILE.write("Thanks, for helping us improve phone syncing on Linux.\n")
+    FILE.write("Please send this file or its contents to blixtra [at] gmail.com\n\n" )
+    FILE.write("SyncML support: %s\n" % hasSyncML)
+    if(len(ids) > 0):
+        FILE.write("Source: %s\n"     % (ids[0]))
+        FILE.write("Vendor: %s=%s\n"  % (ids[1], vendor))
+        FILE.write("product: %s=%s\n\n" % (ids[2], product))
+    else:
+        FILE.write("Vendor: %s\n"  % vendor)
+        FILE.write("product: %s\n\n" % product)
+        FILE.write("This phone doesn't support the bluetooth Device ID profile.\n" )
+
+    FILE.close()
+    return filename
+
+# Start main program
+bus = dbus.SystemBus()
+bluezIface = dbus.Interface(bus.get_object('org.bluez', '/'),
+                            'org.bluez.Manager')
+
+hasSyncmlSupport  = False
+hasPnpInfoSupport = False
+ids = {}
+
+adapters = bluezIface.ListAdapters()
+for adapter in adapters:
+    adapterIface = dbus.Interface(bus.get_object('org.bluez', adapter),
+                                  'org.bluez.Adapter')
+    devices = adapterIface.ListDevices()
+    for device in devices:
+        try:
+            deviceIface = dbus.Interface(bus.get_object('org.bluez', device),
+                                         'org.bluez.Device')
+            props = deviceIface.GetProperties();
+            uuids = props["UUIDs"]
+            print "Device name:", props.get("Name", "???")
+            print "MAC Address:", props.get("Address", "???")
+            for uuid in uuids:
+                if SYNCML_UUID == uuid:
+                    hasSyncmlSupport = True
+                    print "   Supports SyncML."
+                if PNPINFO_UUID == uuid:
+                    hasPnpInfoSupport = True
+                    print "   Looking up device information..."
+                    sys.stdout.flush()
+                    serviceRecord = deviceIface.DiscoverServices(PNPINFO_ATTRIB)
+                    ids = getVendorAndProductId(serviceRecord)
+
+            vendor  = raw_input("   What company makes this phone? (examples: Nokia, Sony Ericsson), empty to skip: ")
+            if vendor:
+                product = raw_input("   What is the model of this phone? (example: N900, K750i), empty to skip: ")
+                if product:
+                    # Write the results to a file
+                    filename = writeDeviceInfoToFile(ids, vendor, product, hasSyncmlSupport)
+                    print "Thanks, please send the file %s to blixtra [at] gmail.com" % filename
+        except dbus.exceptions.DBusException, ex:
+            print "   Failed, skipping device: %s" % ex
-- 
1.7.6

_______________________________________________
SyncEvolution mailing list
[email protected]
http://lists.syncevolution.org/listinfo/syncevolution

Reply via email to