Changeset 3896


Ignore:
Timestamp:
01/21/08 13:31:52 (5 years ago)
Author:
chris
Message:
  • src/phone-kit/moko-sms.c: (moko_sms_set_property), (moko_sms_dispose), (on_error), (sms_store_opened_cb), (stop_handling_sms), (open_sms_store), (memory_check_idle), (moko_sms_init): Add monitoring of free memory on the root filesystem (hopefully)
Location:
trunk/src/target/OM-2007.2/applications/openmoko-dialer2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/target/OM-2007.2/applications/openmoko-dialer2/ChangeLog

    r3878 r3896  
     12008-01-21  Chris Lord  <chris@openedhand.com> 
     2 
     3        * src/phone-kit/moko-sms.c: (moko_sms_set_property), 
     4        (moko_sms_dispose), (on_error), (sms_store_opened_cb), 
     5        (stop_handling_sms), (open_sms_store), (memory_check_idle), 
     6        (moko_sms_init): 
     7        Add monitoring of free memory on the root filesystem (hopefully) 
     8 
    192008-01-18  Chris Lord  <chris@openedhand.com> 
    210 
  • trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-sms.c

    r3863 r3896  
    2020 
    2121#include <string.h> 
     22#include <sys/vfs.h> 
    2223 
    2324#include <dbus/dbus-glib.h> 
     
    7778   
    7879  gboolean           sim_full; 
     80  gboolean           memory_full; 
     81   
     82  guint              memory_idle; 
    7983}; 
    8084 
    8185static void start_handling_sms (MokoSms *sms); 
     86static void stop_handling_sms (MokoSms *sms); 
     87static void open_sms_store (MokoSms *sms); 
    8288 
    8389static void 
     
    129135    case PROP_NETWORK : 
    130136      if (priv->network) { 
    131         moko_network_remove_listener (priv->network, MOKO_LISTENER (object)); 
     137        stop_handling_sms (sms); 
    132138        g_object_unref (priv->network); 
    133139      } 
     
    141147                        G_CALLBACK (subscriber_number_changed_cb), object);*/ 
    142148      /* moko_network_add_listener happens in start_handling_sms */ 
    143       if (!priv->handling_sms) start_handling_sms (sms); 
     149      if ((!priv->sim_full) && (!priv->memory_full)) start_handling_sms (sms); 
    144150      break; 
    145151    default: 
     
    157163  priv = sms->priv; 
    158164   
     165  if (priv->memory_idle) { 
     166    g_source_remove (priv->memory_idle); 
     167    priv->memory_idle = 0; 
     168  } 
     169 
    159170  while (g_source_remove_by_user_data (object)) moko_notify_stop (priv->notify); 
    160  
     171   
    161172  if (priv->sms_store) { 
    162173    g_object_unref (priv->sms_store); 
     
    428439  if (cms == 322) { 
    429440    priv->sim_full = TRUE; 
    430     g_signal_emit (listener, signals[MEMORY_FULL], 0, TRUE, FALSE); 
     441    g_signal_emit (listener, signals[MEMORY_FULL], 0, TRUE, priv->memory_full); 
    431442  } 
    432443} 
     
    579590  priv->sms_store_open = TRUE; 
    580591 
     592  g_debug ("Sms store opened"); 
     593 
    581594  /* Hook onto added/modified/removed signals for SMS notification */ 
    582595  view = jana_store_get_view (store); 
     
    592605 
    593606static void 
     607stop_handling_sms (MokoSms *sms) 
     608{ 
     609  MokoSmsPrivate *priv = sms->priv; 
     610   
     611  if (!priv->handling_sms) return; 
     612   
     613  g_debug ("Closing sms store"); 
     614   
     615  moko_network_remove_listener (priv->network, MOKO_LISTENER (sms)); 
     616   
     617  g_object_unref (priv->sms_store); 
     618  priv->sms_store = NULL; 
     619   
     620  priv->sms_store_open = FALSE; 
     621  priv->handling_sms = FALSE; 
     622   
     623  g_signal_emit (sms, signals[STATUS_CHANGED], 0, PK_SMS_NOTREADY); 
     624} 
     625 
     626static void 
     627open_sms_store (MokoSms *sms) 
     628{ 
     629  MokoSmsPrivate *priv = sms->priv; 
     630   
     631  if (priv->sms_store) return; 
     632   
     633  g_debug ("Opening sms store"); 
     634 
     635  /* Get the SMS note store */ 
     636  priv->sms_store = jana_ecal_store_new (JANA_COMPONENT_NOTE); 
     637  g_signal_connect (priv->sms_store, "opened", 
     638                    G_CALLBACK (sms_store_opened_cb), sms); 
     639  jana_store_open (priv->sms_store); 
     640} 
     641 
     642static gboolean 
     643memory_check_idle (MokoSms *sms) 
     644{ 
     645  struct statfs buf; 
     646 
     647  MokoSmsPrivate *priv = sms->priv; 
     648   
     649  statfs ("/", &buf); 
     650   
     651  /* TODO: Is it reasonable to expect 4 megs/100 files free? */ 
     652  if (((buf.f_bfree * buf.f_bsize) < (1024*1024*4)) || 
     653      (buf.f_ffree < 100)) { 
     654    if (!priv->memory_full) { 
     655      priv->memory_full = TRUE; 
     656      g_signal_emit (sms, signals[MEMORY_FULL], 0, priv->sim_full, TRUE); 
     657      if (priv->sms_store) { 
     658        stop_handling_sms (sms); 
     659      } 
     660    } 
     661  } else if (priv->memory_full) { 
     662    priv->memory_full = FALSE; 
     663    g_signal_emit (sms, signals[MEMORY_FULL], 0, priv->sim_full, FALSE); 
     664    open_sms_store (sms); 
     665  } 
     666   
     667  return TRUE; 
     668} 
     669 
     670static void 
    594671moko_sms_init (MokoSms *sms) 
    595672{ 
     
    603680  priv->notify = moko_notify_get_default (); 
    604681 
    605   /* Get the SMS note store */ 
    606   priv->sms_store = jana_ecal_store_new (JANA_COMPONENT_NOTE); 
    607   g_signal_connect (priv->sms_store, "opened", 
    608                     G_CALLBACK (sms_store_opened_cb), sms); 
    609   jana_store_open (priv->sms_store); 
     682  memory_check_idle (sms); 
     683  if (!priv->memory_full) open_sms_store (sms); 
     684   
     685  priv->memory_idle = g_timeout_add_seconds (5, (GSourceFunc) 
     686                                             memory_check_idle, sms); 
    610687} 
    611688 
Note: See TracChangeset for help on using the changeset viewer.