On Mon, Aug 29, 2011 at 3:12 PM, Patrick Ohly <[email protected]> wrote:
> On Mo, 2011-08-29 at 14:03 +0200, Chris Kühl wrote:
>> On Mon, Aug 29, 2011 at 12:25 PM, Patrick Ohly <[email protected]> 
>> wrote:
>> > On Mo, 2011-08-29 at 11:50 +0200, Chris Kühl wrote:
>> >> 2011/8/26 Patrick Ohly <[email protected]>:
>> > But see my later email: after some more thinking I came to the
>> > conclusion that "deviceName" should stay as it is (name chosen by the
>> > user) and the new information should go into "templateName".
>>
>> Did you mean peerName instead of templateName?
>
> Yes.
>
>> Patrick Ohly <[email protected]> wrote:
>> >> The UI should be adapted to use peerName instead of deviceName, if
>> >> peerName is available. That way the user would see his chosen name
>> >> instead of the vendor/model name, which will not be unique in the
>> >> (unlikely) case that the user has more than one. Not a big deal.
>> >>
>> >> We might have the inverse situation, too: multiple different devices all
>> >> called "My Phone". I think users should (and can) avoid this, so we
>> >> should continue to display only the chosen name instead of adding the
>> >> vendor/model information - right?
>> >
>> > Given that the UI should only display the chosen name, and expects it in
>> > "deviceName", perhaps we should keep the traditional D-Bus API semantic
>> > unchanged and put the Device ID profile information into the "peerName"?
>> >
>> > That is a bit backwards (peerName is used for user-configurable strings
>> > elsewhere), but has the advantage that no changes will be needed in the
>> > D-Bus clients to get the desired behavior.
>> >
>>
>> ... I understand the following.
>>
>> 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>]".
>
>> 2) In the case that we have PnPInformation info but no product match
>> in the lookup table  we have...
>>
>> deviceName = User-modifiable name
>> peerName = Vendor found in Lookup table
>
> Correct.
>
>> 3) In the case that we have PnPInformation info and a product match in
>> the lookup table we have...
>>
>> deviceName = User-modifiable name
>> peerName = Vendor + " " + Product found in Lookup table
>>
>> Is this right?
>
> Yes.
>
>> Also, the templateName was and is simply the "templateName" field from
>> the template. The code is...
>>
>> string TemplateConfig::getTemplateName() {
>>     return m_metaProps["templateName"];
>> }
>
> Correct.
>
>> Should this be different? We could create a different template for
>> each class of phone.
>
> I don't think anything around templateName needs to be changed.
>

I believe the first patch I've attached takes care of the deviceName
and peerName meanings. The second patch just adds the bluetooth
inspector script to the "test" directory.

Cheers,
Chris
From dec4d34c0b1297b5ed7b39d60df2c58b395eb5b6 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 now used to hold the value used
as the template fingerprint. This value can be the same as deviceName,
in the case where the device does not support the Device ID
profile. In the case that the Device ID profile is supported, it will
be either the vendor or vendor + model depending on whether the device
model is found in the lookup table.
---
 src/dbus/server/read-operations.cpp |    4 ++--
 src/syncevo/SyncConfig.cpp          |   14 +++++++-------
 src/syncevo/SyncConfig.h            |   14 ++++++++------
 3 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/src/dbus/server/read-operations.cpp b/src/dbus/server/read-operations.cpp
index be91541..c6bb6e4 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,7 +119,7 @@ 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));
+            localConfigs.insert(pair<string, string>("deviceName", peerTemplate->m_deviceName));
             // This is the user-modifiable device name. Could be shown in GUIs, for example
             localConfigs.insert(pair<string, string>("peerName", peerTemplate->m_peerName));
             // This is the fingerprint of the template
diff --git a/src/syncevo/SyncConfig.cpp b/src/syncevo/SyncConfig.cpp
index 1ac88b7..fd364c8 100644
--- a/src/syncevo/SyncConfig.cpp
+++ b/src/syncevo/SyncConfig.cpp
@@ -721,9 +721,9 @@ SyncConfig::TemplateList SyncConfig::matchPeerTemplates(const DeviceList &peers,
                                     new TemplateDescription(templateConf.getTemplateId(),
                                                             templateConf.getDescription(),
                                                             rank,
-                                                            entry.m_deviceName,
-                                                            entry.m_deviceId,
                                                             fingerprint,
+                                                            entry.m_deviceId,
+                                                            entry.m_deviceName,
                                                             sDir,
                                                             templateConf.getFingerprint(),
                                                             templateConf.getTemplateName()
@@ -735,9 +735,9 @@ SyncConfig::TemplateList SyncConfig::matchPeerTemplates(const DeviceList &peers,
                                 new TemplateDescription(templateConf.getTemplateId(),
                                                         templateConf.getDescription(),
                                                         rank,
-                                                        entry.m_deviceName,
-                                                        entry.m_deviceId,
                                                         fingerprint,
+                                                        entry.m_deviceId,
+                                                        entry.m_deviceName,
                                                         sDir,
                                                         templateConf.getFingerprint(),
                                                         templateConf.getTemplateName())
@@ -2596,7 +2596,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 +2607,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 cb0b2a35ba989266403c2486f6cd020be932c8c1 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 |   97 +++++++++++++++++++++++++++++++++
 1 files changed, 97 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..54ea167
--- /dev/null
+++ b/test/bluetooth-device-id-inspector.py
@@ -0,0 +1,97 @@
+#! /usr/bin/python -u
+
+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