gnokii-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Motorola C350 patch 2


From: Ron Yorston
Subject: Re: Motorola C350 patch 2
Date: Fri, 20 Feb 2004 20:15:21 GMT

Pawel Kot wrote:
>On Thu, 19 Feb 2004, Ron Yorston wrote:
>> Should we distinguish between the different causes of an error return
>> from GetMemoryStatus by returning different values?
>
>Yeah, I think so. The 3810 case would be GN_ERR_INVALIDMEMORYTYPE, your
>case whould be GN_ERR_NOTSUPPORTED. Would it make sense? Does it work?

OK, here's a new patch.  GetMemoryStatus in the atgen driver now returns
GN_ERR_NOTSUPPORTED if the phone doesn't report used/total memory.  Since
the atgen driver has information about the range of memory indices we
can at least return a sensible value for the total number of entries.

In xgnokii_contacts.c I've rearranged the checking of error returns after
GetMemoryStatus in a way that seems more natural to me.  I've also made
similar changes in OkImportDialog, which also uses GetMemoryStatus.

I've avoided making any changes to the Nokia code.  This new patch works
for me with the Motorola C350, and I think it should provide the same
behaviour as the current code for the 5110 and 3810 cases.

Ron

---
--- gnokii/common/phones/atgen.c        2004-02-19 14:03:47.000000000 +0000
+++ gnokii.test/common/phones/atgen.c   2004-02-20 20:02:34.000000000 +0000
@@ -516,11 +516,6 @@
                return ret;
        if (sm_message_send(9, GN_OP_GetMemoryStatus, "AT+CPBS?\r", state))
                return GN_ERR_NOTREADY;
-       ret = sm_block_no_retry(GN_OP_GetMemoryStatus, data, state);
-       if (ret != GN_ERR_UNKNOWN)
-               return ret;
-       if (sm_message_send(10, GN_OP_GetMemoryStatus, "AT+CPBR=?\r", state))
-               return GN_ERR_NOTREADY;
        return sm_block_no_retry(GN_OP_GetMemoryStatus, data, state);
 }
 
@@ -1006,7 +1001,7 @@
                } else {
                        data->memory_status->used = drvinst->memorysize;
                        data->memory_status->free = 0;
-                       return GN_ERR_UNKNOWN;
+                       return GN_ERR_NOTSUPPORTED;
                }
                pos = strchr(pos, ',');
                if (pos) {
--- gnokii/xgnokii/xgnokii_contacts.c   2004-02-20 19:52:18.000000000 +0000
+++ gnokii.test/xgnokii/xgnokii_contacts.c      2004-02-20 20:02:34.000000000 
+0000
@@ -82,7 +82,6 @@
 } ExtPbkDialog;
 
 static GtkWidget *GUI_ContactsWindow;
-static bool fbus3810;
 static bool contactsMemoryInitialized;
 static MemoryStatus memoryStatus;
 static ContactsMemory contactsMemory;  /* Hold contacts. */
@@ -2381,10 +2380,6 @@
                pbEntry->status = E_Empty;
        else {
                pbEntry->status = E_Unchanged;
-               if (fbus3810) {
-                       memoryStatus.UsedSM++;
-                       memoryStatus.FreeSM--;
-               }
        }
 
        g_ptr_array_add(contactsMemory, (gpointer) pbEntry);
@@ -2410,8 +2405,7 @@
        D_MemoryLocationAll *mla;
        PhonebookEntry *pbEntry;
        register gint i;
-
-       fbus3810 = FALSE;
+       bool has_memory_stats = true;
 
        if (contactsMemoryInitialized == TRUE) {
                for (i = 0; i < memoryStatus.MaxME + memoryStatus.MaxSM; i++) {
@@ -2438,13 +2432,13 @@
        pthread_cond_wait(&memoryCond, &memoryMutex);
        pthread_mutex_unlock(&memoryMutex);
 
-       if (ms->status != GN_ERR_NONE)
-               /* Phone don't support ME (5110) */
-               memoryStatus.MaxME = memoryStatus.UsedME = memoryStatus.FreeME 
= 0;
-       else {
+       if (ms->status == GN_ERR_NONE || ms->status == GN_ERR_NOTSUPPORTED) {
                memoryStatus.MaxME = ms->memoryStatus.used + 
ms->memoryStatus.free;
                memoryStatus.UsedME = ms->memoryStatus.used;
                memoryStatus.FreeME = ms->memoryStatus.free;
+       } else {
+               /* Phone don't support ME (5110) */
+               memoryStatus.MaxME = memoryStatus.UsedME = memoryStatus.FreeME 
= 0;
        }
 
        ms->memoryStatus.memory_type = GN_MT_SM;
@@ -2456,17 +2450,15 @@
        pthread_cond_wait(&memoryCond, &memoryMutex);
        pthread_mutex_unlock(&memoryMutex);
 
-       if (ms->status != GN_ERR_NONE) {
-               fbus3810 = TRUE;        /* I try to recognize 
memoryStatus.UsedSM while reading */
-               gtk_label_set_text(GTK_LABEL(errorDialog.text), _("Can't get SM 
memory status!\n\n\
-Setting max SIM entries to 100!\n"));
-               memoryStatus.MaxSM = memoryStatus.FreeSM = 100;
-               memoryStatus.UsedSM = 0;
-               gtk_widget_show(errorDialog.dialog);
-       } else {
+       has_memory_stats = ms->status == GN_ERR_NONE;
+       if (ms->status == GN_ERR_NONE || ms->status == GN_ERR_NOTSUPPORTED) {
                memoryStatus.MaxSM = ms->memoryStatus.used + 
ms->memoryStatus.free;
                memoryStatus.UsedSM = ms->memoryStatus.used;
                memoryStatus.FreeSM = ms->memoryStatus.free;
+       } else {
+               /* guess that there are 100 entries and sort out UsedSM later */
+               memoryStatus.MaxSM = memoryStatus.FreeSM = 100;
+               memoryStatus.UsedSM = 0;
        }
        g_free(ms);
 
@@ -2507,6 +2499,19 @@
                        gtk_widget_hide(progressDialog.dialog);
                        return;
                }
+
+               if (!has_memory_stats) {
+                       memoryStatus.FreeME = memoryStatus.UsedME = 0;
+                       for (i = 0; i < memoryStatus.MaxME; i++) {
+                               pbEntry = g_ptr_array_index(contactsMemory, i);
+
+                               if (pbEntry->status == E_Empty)
+                                       memoryStatus.FreeME++;
+                               else
+                                       memoryStatus.UsedME++;
+                       }
+                       RefreshStatusInfo();
+               }
        }
 
        mla->min = 1;
@@ -2530,6 +2535,19 @@
                return;
        }
 
+       if (!has_memory_stats) {
+               memoryStatus.FreeSM = memoryStatus.UsedSM = 0;
+               for (i = memoryStatus.MaxME; i < 
memoryStatus.MaxME+memoryStatus.MaxSM; i++) {
+                       pbEntry = g_ptr_array_index(contactsMemory, i);
+
+                       if (pbEntry->status == E_Empty)
+                               memoryStatus.FreeSM++;
+                       else
+                               memoryStatus.UsedSM++;
+               }
+               RefreshStatusInfo();
+       }
+
        g_free(mla);
 
        gtk_widget_hide(progressDialog.dialog);
@@ -2815,13 +2833,13 @@
        pthread_cond_wait(&memoryCond, &memoryMutex);
        pthread_mutex_unlock(&memoryMutex);
 
-       if (ms->status != GN_ERR_NONE)
-               /* Phone don't support ME (5110) */
-               memoryStatus.MaxME = memoryStatus.UsedME = memoryStatus.FreeME 
= 0;
-       else {
+       if (ms->status == GN_ERR_NONE || ms->status == GN_ERR_NOTSUPPORTED) {
                memoryStatus.MaxME = ms->memoryStatus.used + 
ms->memoryStatus.free;
                memoryStatus.UsedME = 0;
                memoryStatus.FreeME = memoryStatus.MaxME;
+       } else {
+               /* Phone don't support ME (5110) */
+               memoryStatus.MaxME = memoryStatus.UsedME = memoryStatus.FreeME 
= 0;
        }
 
        ms->memoryStatus.memory_type = GN_MT_SM;
@@ -2833,16 +2851,14 @@
        pthread_cond_wait(&memoryCond, &memoryMutex);
        pthread_mutex_unlock(&memoryMutex);
 
-       if (ms->status != GN_ERR_NONE) {
-               gtk_label_set_text(GTK_LABEL(errorDialog.text), _("Can't get SM 
memory status!\n\n\
-Setting max SIM entries set to 100!\n"));
-               memoryStatus.MaxSM = memoryStatus.FreeSM = 100;
-               memoryStatus.UsedSM = 0;
-               gtk_widget_show(errorDialog.dialog);
-       } else {
+       if (ms->status == GN_ERR_NONE || ms->status == GN_ERR_NOTSUPPORTED) {
                memoryStatus.MaxSM = ms->memoryStatus.used + 
ms->memoryStatus.free;
                memoryStatus.UsedSM = 0;
                memoryStatus.FreeSM = memoryStatus.MaxSM;
+       } else {
+               /* guess that there are 100 entries */
+               memoryStatus.MaxSM = memoryStatus.FreeSM = 100;
+               memoryStatus.UsedSM = 0;
        }
        g_free(ms);
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]