ndef: Move the action property to a string
authorSamuel Ortiz <sameo@linux.intel.com>
Tue, 27 Sep 2011 11:16:01 +0000 (13:16 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Fri, 21 Oct 2011 06:54:06 +0000 (23:54 -0700)
doc/target-api.txt
src/ndef.c

index 6089954..e4afe11 100644 (file)
@@ -127,13 +127,13 @@ Properties        string Type [readonly]
                        This is not a mandatory field and is only valid for
                        Smart Posters carrying a URI record.
 
-               byte Action [readonly]
+               string Action [readonly]
 
-                       Can exist in SmartPoster(Action) record. It suggests
-                        a course of action that the device should do with the
-                        content.
+                       The suggested course of action.
 
-                        Example:
-                                0 - Do the action.
-                                1 - Save for later.
-                                2 - Open for editing.
+                       This one is only valid for Smart Posters and is a
+                       suggestion only. It can be ignored, and the possible
+                       values are "Do" (for example launch the browser),
+                       "Save" (for example save the URI in the bookmarks folder,
+                       or "Edit" (for example open the URI in an URI editor for
+                       the user to modify it.
index 2e14625..31589ff 100644 (file)
 #define RECORD_TNF_UNKNOWN   0x05
 #define RECORD_TNF_UNCHANGED 0x06
 
+#define RECORD_ACTION_DO   0x00
+#define RECORD_ACTION_SAVE 0x01
+#define RECORD_ACTION_EDIT 0x02
+
 #define RECORD_MB_BIT(val)  ((val & 0x80) >> 7)
 #define RECORD_ME_BIT(val)  ((val & 0x40) >> 6)
 #define RECORD_CF_BIT(val)  ((val & 0x20) >> 5)
@@ -82,8 +86,6 @@ struct near_ndef_uri_record {
 };
 
 struct near_ndef_sp_record {
-       uint8_t action;
-
        struct near_ndef_uri_record *uri;
 
        uint8_t number_of_title_records;
@@ -91,6 +93,7 @@ struct near_ndef_sp_record {
 
        uint32_t size; /* from Size record*/
        char *type;    /* from Type record*/
+       char *action;
        /* TODO add icon and other records fields*/
 };
 
@@ -194,7 +197,8 @@ static void append_smart_poster_record(struct near_ndef_sp_record *sp,
        if (sp == NULL || dict == NULL)
                return;
 
-       near_dbus_dict_append_basic(dict, "Action", DBUS_TYPE_BYTE,
+       if (sp->action != NULL)
+               near_dbus_dict_append_basic(dict, "Action", DBUS_TYPE_STRING,
                                                        &(sp->action));
 
        if (sp->uri != NULL)
@@ -351,6 +355,7 @@ static void free_sp_record(struct near_ndef_sp_record *sp)
 
        g_free(sp->title_records);
        g_free(sp->type);
+       g_free(sp->action);
        g_free(sp);
 
        sp = NULL;
@@ -402,6 +407,21 @@ void __near_ndef_record_free(struct near_ndef_record *record)
        free_ndef_record(record);
 }
 
+static char * action_to_string(uint8_t action)
+{
+       switch (action) {
+       case RECORD_ACTION_DO:
+               return "Do";
+       case RECORD_ACTION_SAVE:
+               return "Save";
+       case RECORD_ACTION_EDIT:
+               return "Edit";
+       default:
+               near_error("Unknown action 0x%x", action);
+               return NULL;
+       }
+}
+
 /**
  * @brief returns record type
  * Validate type name format, type and type length and returns
@@ -860,7 +880,9 @@ static struct near_ndef_sp_record *parse_smart_poster_record(uint8_t *ndef_data,
                        if (payload_length != 1)
                                goto fail;
 
-                       sp_record->action = ndef_data[t_offset];
+                       sp_record->action =
+                               g_strdup(action_to_string(ndef_data[t_offset]));
+
                        break;
                }