Changeset 3422


Ignore:
Timestamp:
11/14/07 15:20:26 (6 years ago)
Author:
chris
Message:
  • src/phone-kit/moko-dialer-sms-dbus.xml: Remove signals, handled by the storage (jana/eds), return the UID of a sent message
  • src/phone-kit/moko-dialer-sms.c: (gsmd_eventhandler), (sms_msghandler), (moko_dialer_sms_init), (moko_dialer_sms_new), (moko_dialer_sms_get_default), (moko_dialer_sms_send):
  • src/phone-kit/moko-dialer-sms.h: Add status reports, sending confirmation and synchronisation with storage
Location:
trunk/src/target/OM-2007.2/applications/openmoko-dialer2
Files:
4 edited

Legend:

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

    r3420 r3422  
     12007-11-14  Chris Lord  <chris@openedhand.com> 
     2 
     3        * src/phone-kit/moko-dialer-sms-dbus.xml: 
     4        Remove signals, handled by the storage (jana/eds), return the UID of a 
     5        sent message 
     6 
     7        * src/phone-kit/moko-dialer-sms.c: (gsmd_eventhandler), 
     8        (sms_msghandler), (moko_dialer_sms_init), (moko_dialer_sms_new), 
     9        (moko_dialer_sms_get_default), (moko_dialer_sms_send): 
     10        * src/phone-kit/moko-dialer-sms.h: 
     11        Add status reports, sending confirmation and synchronisation with 
     12        storage 
     13 
    1142007-11-14  Chris Lord  <chris@openedhand.com> 
    215 
  • trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-dialer-sms-dbus.xml

    r3420 r3422  
    66    <arg type="s" name="number" /> 
    77    <arg type="s" name="message" /> 
     8    <arg type="s" name="uid" direction="out" /> 
    89  </method> 
    9  
    10   <signal name="Sending"> 
    11   </signal> 
    12  
    13   <signal name="Sent"> 
    14   </signal> 
    15  
    16   <signal name="Rejected"> 
    17     <arg type="s" name="message" /> 
    18   </signal> 
    19  
    2010</interface> 
    2111</node> 
  • trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-dialer-sms.c

    r3420 r3422  
    2323        struct lgsm_handle *handle; 
    2424        JanaStore *note_store; 
     25        JanaNote *last_msg; 
    2526}; 
    26  
    27 enum { 
    28   SENDING, 
    29   SENT, 
    30   REJECTED, 
    31   LAST_SIGNAL 
    32 }; 
    33  
    34 static guint signals[LAST_SIGNAL]; 
    3527 
    3628static void 
     
    7870        object_class->dispose = moko_dialer_sms_dispose; 
    7971        object_class->finalize = moko_dialer_sms_finalize; 
    80          
    81         signals[SENDING] = g_signal_new ("sending",  
    82                 G_TYPE_FROM_CLASS (object_class), 
    83                 G_SIGNAL_RUN_LAST, 
    84                 G_STRUCT_OFFSET (MokoDialerSMSClass, sending), 
    85                 NULL, NULL, 
    86                 g_cclosure_marshal_VOID__VOID, 
    87                 G_TYPE_NONE, 0); 
    88  
    89         signals[SENT] = g_signal_new ("sent",  
    90                 G_TYPE_FROM_CLASS (object_class), 
    91                 G_SIGNAL_RUN_LAST, 
    92                 G_STRUCT_OFFSET (MokoDialerSMSClass, sent), 
    93                 NULL, NULL, 
    94                 g_cclosure_marshal_VOID__VOID, 
    95                 G_TYPE_NONE, 0); 
    96  
    97         signals[REJECTED] = g_signal_new ("rejected",  
    98                 G_TYPE_FROM_CLASS (object_class), 
    99                 G_SIGNAL_RUN_LAST, 
    100                 G_STRUCT_OFFSET (MokoDialerSMSClass, rejected), 
    101                 NULL, NULL, 
    102                 g_cclosure_marshal_VOID__STRING, 
    103                 G_TYPE_NONE, 1, G_TYPE_STRING); 
     72} 
     73 
     74static void 
     75status_report_added_cb (JanaStoreView *view, GList *components, gchar *ref) 
     76{ 
     77        MokoDialerSMSPrivate *priv = SMS_PRIVATE ( 
     78                moko_dialer_sms_get_default ()); 
     79 
     80        for (; components; components = components->next) { 
     81                gchar *compref; 
     82                JanaComponent *comp = JANA_COMPONENT (components->data); 
     83                 
     84                compref = jana_component_get_custom_prop ( 
     85                        comp, "X-PHONEKIT-SMS-REF"); 
     86                if (compref && (strcmp (compref, ref) == 0)) { 
     87                        jana_utils_component_remove_category (comp, "Sending"); 
     88                        jana_utils_component_insert_category (comp, "Sent", 0); 
     89                        jana_store_modify_component (priv->note_store, comp); 
     90                } 
     91                g_free (ref); 
     92        } 
     93} 
     94 
     95static void 
     96status_report_progress_cb (JanaStoreView *view, gint percent, gchar *ref) 
     97{ 
     98        if (percent != 100) return; 
     99         
     100        g_object_unref (view); 
     101        g_free (ref); 
    104102} 
    105103 
     
    111109                moko_dialer_sms_get_default ()); 
    112110         
     111        /* TODO: Handle events that aren't in-line */ 
     112         
    113113        switch (evt_type) { 
    114114            case GSMD_EVT_IN_SMS : /* Incoming SMS */ 
     115                /* TODO: Read UDH for multi-part messages */ 
    115116                if (aux->u.sms.inlined) { 
    116117                        gchar *message; 
     
    173174                        } 
    174175                } else { 
     176                        g_warning ("Not an in-line event, unhandled"); 
    175177                } 
    176178                break; 
    177179            case GSMD_EVT_IN_DS : /* SMS status report */ 
     180                if (aux->u.ds.inlined) { 
     181                        struct gsmd_sms_list *sms = 
     182                                (struct gsmd_sms_list *) aux->data; 
     183                         
     184                        /* TODO: I'm not entirely sure of the spec when if  
     185                         *       storing an unsent message means it failed? 
     186                         */ 
     187                        if (sms->payload.coding_scheme == LGSM_SMS_STO_SENT) { 
     188                                gchar *ref = g_strdup_printf ("%d", sms->index); 
     189                                JanaStoreView *view = jana_store_get_view ( 
     190                                        priv->note_store); 
     191                                jana_store_view_add_match (view, 
     192                                        JANA_STORE_VIEW_CATEGORY, "Sending"); 
     193                                g_signal_connect (view, "added", G_CALLBACK ( 
     194                                        status_report_added_cb), ref); 
     195                                g_signal_connect (view, "progress", G_CALLBACK ( 
     196                                        status_report_progress_cb), ref); 
     197                        } 
     198                } else { 
     199                        g_warning ("Not an in-line event, unhandled"); 
     200                } 
    178201                break; 
    179202            default : 
    180203                g_warning ("Unhandled gsmd event (%d)", evt_type); 
     204        } 
     205         
     206        return 0; 
     207} 
     208 
     209static int 
     210sms_msghandler (struct lgsm_handle *lh, struct gsmd_msg_hdr *gmh) 
     211{ 
     212        MokoDialerSMS *sms = moko_dialer_sms_get_default (); 
     213        MokoDialerSMSPrivate *priv = SMS_PRIVATE (sms); 
     214 
     215        /* Store sent messages */ 
     216        if ((gmh->msg_subtype == GSMD_SMS_SEND) && priv->last_msg) { 
     217                int *result = (int *) ((void *) gmh + sizeof(*gmh)); 
     218                gchar *uid = jana_component_get_uid ( 
     219                        JANA_COMPONENT (priv->last_msg)); 
     220                 
     221                if (*result >= 0) { 
     222                        gchar *ref = g_strdup_printf ("%d", *result); 
     223                        jana_component_set_custom_prop ( 
     224                                JANA_COMPONENT (priv->last_msg), 
     225                                "X-PHONEKIT-SMS-REF", ref); 
     226                        g_free (ref); 
     227                } else { 
     228                        jana_utils_component_remove_category ( 
     229                                JANA_COMPONENT(priv->last_msg), "Sending"); 
     230                        jana_utils_component_insert_category ( 
     231                                JANA_COMPONENT(priv->last_msg), "Rejected", 0); 
     232                        /* TODO: Add error codes? 42 = congestion? */ 
     233                } 
     234                jana_store_modify_component (priv->note_store, 
     235                        JANA_COMPONENT (priv->last_msg)); 
     236                 
     237                g_free (uid); 
     238                g_object_unref (priv->last_msg); 
     239                priv->last_msg = NULL; 
    181240        } 
    182241         
     
    202261        /* Initialise gsmd and connect event handler */ 
    203262        if (!(priv->handle = lgsm_init (LGSMD_DEVICE_GSMD))) { 
    204                 g_warning ("Failed to connect to gsmd, signals won't work"); 
     263                g_error ("Failed to connect to gsmd"); 
    205264        } else { 
    206265                lgsm_evt_handler_register (priv->handle, GSMD_EVT_IN_SMS, 
     
    209268                        gsmd_eventhandler); 
    210269        } 
     270         
     271        /* Connect SMS message handler (to get sent message references) */ 
     272        lgsm_register_handler (priv->handle, GSMD_MSG_SMS, &sms_msghandler); 
     273         
     274        /* TODO: Move any existing SMS messages off of sim and to journal */ 
    211275} 
    212276 
     
    231295gboolean 
    232296moko_dialer_sms_send (MokoDialerSMS *self, const gchar *number, 
    233                       const gchar *message, GError **error) 
     297                      const gchar *message, gchar **uid, GError **error) 
    234298{ 
    235299        MokoDialerSMSPrivate *priv; 
     
    237301        gint msg_length, c; 
    238302        gboolean ascii; 
     303        JanaNote *note; 
     304        gchar *author; 
    239305         
    240306        g_assert (self && number && message); 
     
    242308        priv = SMS_PRIVATE (self); 
    243309         
    244         /* TODO: Delivery report */ 
    245         sms.ask_ds = 0; 
     310        /* Ask for delivery report */ 
     311        sms.ask_ds = 1; 
    246312         
    247313        /* Set destination number */ 
     
    263329                } 
    264330        } 
     331         
     332        /* TODO: Multi-part messages using UDH */ 
    265333        msg_length = strlen (message); 
    266334        if ((ascii && (msg_length > 160)) || (msg_length > 140)) { 
     
    280348        lgsm_sms_send (priv->handle, &sms); 
    281349         
     350        /* Store sent message in journal */ 
     351        note = jana_ecal_note_new (); 
     352        jana_note_set_recipient (note, number); 
     353         
     354        /* TODO: Normalise number necessary? */ 
     355        author = g_strdup_printf ("%d", 
     356                lgsm_get_subscriber_num (priv->handle)); 
     357        jana_note_set_author (note, author); 
     358        g_free (author); 
     359         
     360        jana_note_set_body (note, message); 
     361        jana_component_set_categories (JANA_COMPONENT (note), 
     362                (const gchar *[]){ "Sending", NULL}); 
     363         
     364        jana_store_add_component (priv->note_store, 
     365                JANA_COMPONENT (note)); 
     366        if (uid) *uid = jana_component_get_uid (JANA_COMPONENT (note)); 
     367         
     368        if (priv->last_msg) { 
     369                g_warning ("Confirmation not received for last sent SMS, " 
     370                        "delivery report will be lost."); 
     371                g_object_unref (priv->last_msg); 
     372                priv->last_msg = NULL; 
     373        } 
     374        priv->last_msg = note; 
     375         
    282376        return TRUE; 
    283377} 
    284  
    285 void 
    286 moko_dialer_sms_sending (MokoDialerSMS *sms) 
    287 { 
    288         g_signal_emit (sms, signals[SENDING], 0); 
    289 } 
    290  
    291 void 
    292 moko_dialer_sms_sent (MokoDialerSMS *sms) 
    293 { 
    294         g_signal_emit (sms, signals[SENT], 0); 
    295 } 
    296  
    297 void 
    298 moko_dialer_sms_rejected (MokoDialerSMS *sms, const gchar *message) 
    299 { 
    300         g_signal_emit (sms, signals[REJECTED], 0, message); 
    301 } 
    302  
  • trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-dialer-sms.h

    r3420 r3422  
    4141typedef struct { 
    4242        GObjectClass parent_class; 
    43          
    44         void    (*sending)      (MokoDialerSMS *sms); 
    45         void    (*sent)         (MokoDialerSMS *sms); 
    46         void    (*rejected)     (MokoDialerSMS *sms, const gchar *message); 
    4743} MokoDialerSMSClass; 
    4844 
     
    5450 
    5551gboolean moko_dialer_sms_send (MokoDialerSMS *sms, const gchar *number, 
    56                                const gchar *message, GError **error); 
    57  
    58 void moko_dialer_sms_sending (MokoDialerSMS *sms); 
    59 void moko_dialer_sms_sent (MokoDialerSMS *sms); 
    60 void moko_dialer_sms_rejected (MokoDialerSMS *sms, const gchar *message); 
     52                               const gchar *message, gchar **uid, 
     53                               GError **error); 
    6154 
    6255G_END_DECLS 
Note: See TracChangeset for help on using the changeset viewer.