Changeset 3479


Ignore:
Timestamp:
11/22/07 19:47:13 (6 years ago)
Author:
chris
Message:
  • src/phone-kit/Makefile.am:
  • src/phone-kit/dialer-main.c: (main):
  • src/phone-kit/moko-dialer-dbus.xml:
  • src/phone-kit/moko-dialer-sms-dbus.xml:
  • src/phone-kit/moko-dialer-sms.c:
  • src/phone-kit/moko-dialer-sms.h:
  • src/phone-kit/moko-dialer.c: (moko_dialer_dial), (moko_dialer_hang_up), (moko_dialer_hung_up), (moko_dialer_rejected), (on_talking_accept_call), (on_talking_reject_call), (on_talking_cancel_call), (on_network_registered), (on_incoming_call), (on_incoming_clip), (on_pin_requested), (on_call_progress_changed), (moko_dialer_dispose), (moko_dialer_finalize), (status_report_added_cb), (status_report_progress_cb), (store_sms), (gsmd_eventhandler), (sms_msghandler), (net_msghandler), (connection_source_prepare), (connection_source_check), (connection_source_dispatch), (sms_store_opened_cb), (dialer_init_gsmd), (moko_dialer_init), (moko_dialer_send_sms):
  • src/phone-kit/moko-dialer.h: Remove use of libmokogsmd, integrate SMS code with the rest of the dialer code
Location:
trunk/src/target/OM-2007.2/applications/openmoko-dialer2
Files:
3 deleted
6 edited

Legend:

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

    r3466 r3479  
     12007-11-22  Chris Lord  <chris@openedhand.com> 
     2 
     3        * src/phone-kit/Makefile.am: 
     4        * src/phone-kit/dialer-main.c: (main): 
     5        * src/phone-kit/moko-dialer-dbus.xml: 
     6        * src/phone-kit/moko-dialer-sms-dbus.xml: 
     7        * src/phone-kit/moko-dialer-sms.c: 
     8        * src/phone-kit/moko-dialer-sms.h: 
     9        * src/phone-kit/moko-dialer.c: (moko_dialer_dial), 
     10        (moko_dialer_hang_up), (moko_dialer_hung_up), 
     11        (moko_dialer_rejected), (on_talking_accept_call), 
     12        (on_talking_reject_call), (on_talking_cancel_call), 
     13        (on_network_registered), (on_incoming_call), (on_incoming_clip), 
     14        (on_pin_requested), (on_call_progress_changed), 
     15        (moko_dialer_dispose), (moko_dialer_finalize), 
     16        (status_report_added_cb), (status_report_progress_cb), (store_sms), 
     17        (gsmd_eventhandler), (sms_msghandler), (net_msghandler), 
     18        (connection_source_prepare), (connection_source_check), 
     19        (connection_source_dispatch), (sms_store_opened_cb), 
     20        (dialer_init_gsmd), (moko_dialer_init), (moko_dialer_send_sms): 
     21        * src/phone-kit/moko-dialer.h: 
     22        Remove use of libmokogsmd, integrate SMS code with the rest of the 
     23        dialer code 
     24 
    1252007-11-21  Thomas Wood  <thomas@openedhand.com> 
    226 
  • trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/Makefile.am

    r3466 r3479  
    1212        moko-sound.c moko-sound.h \ 
    1313        moko-talking.c moko-talking.h \ 
    14         moko-dialer-sms.c moko-dialer-sms.h \ 
    1514        moko-pin.c \ 
    1615        moko-pin.h 
     
    2221        $(LIBTOOL) --mode=execute $(DBUS_GLIB_BIN)/dbus-binding-tool --prefix=$(subst -,_,$*) --mode=glib-server --output=$@ $< 
    2322         
    24 BUILT_SOURCES = moko-dialer-glue.h moko-dialer-sms-glue.h 
     23BUILT_SOURCES = moko-dialer-glue.h 
    2524 
    26 EXTRA_DIST = moko-dialer-dbus.xml moko-dialer-sms-dbus.xml 
     25EXTRA_DIST = moko-dialer-dbus.xml 
    2726 
  • trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/dialer-main.c

    r3420 r3479  
    2424 
    2525#include "moko-dialer.h" 
    26 #include "moko-dialer-sms.h" 
    2726 
    2827#define DIALER_NAMESPACE "org.openmoko.Dialer" 
    2928#define DIALER_OBJECT "/org/openmoko/Dialer" 
    30 #define SMS_OBJECT "/org/openmoko/Dialer/SMS" 
    3129 
    3230static gchar *number = NULL; 
     
    5856{ 
    5957  MokoDialer *dialer; 
    60   MokoDialerSMS *sms; 
    6158  DBusGConnection *connection; 
    6259  DBusGProxy *proxy; 
     
    111108  moko_stock_register (); 
    112109 
    113    /* Create the MokoDialer/MokoDialerSMS objects */ 
     110   /* Create the MokoDialer object */ 
    114111  dialer = moko_dialer_get_default (); 
    115   sms = moko_dialer_sms_get_default (); 
    116112 
    117113  /* Add the objects onto the bus */ 
     
    119115                                       DIALER_OBJECT, 
    120116                                       G_OBJECT (dialer)); 
    121   dbus_g_connection_register_g_object (connection,  
    122                                        SMS_OBJECT, 
    123                                        G_OBJECT (sms)); 
    124117 
    125118  /* application object */ 
  • trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-dialer-dbus.xml

    r3310 r3479  
    1313  <method name="HangUp"> 
    1414    <arg type="s" name="message" direction="in" /> 
     15  </method> 
     16 
     17  <method name="SendSms"> 
     18    <arg type="s" name="number" /> 
     19    <arg type="s" name="message" /> 
     20    <arg type="s" name="uid" direction="out" /> 
    1521  </method> 
    1622 
  • trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-dialer.c

    r3466 r3479  
    2121#include <string.h> 
    2222#include <stdlib.h> 
     23#include <unistd.h> 
    2324 
    2425#include <dbus/dbus-glib.h> 
    2526#include <dbus/dbus-glib-bindings.h> 
    2627 
    27 #include <moko-gsmd-connection.h> 
    2828#include <moko-journal.h> 
    2929#include <moko-stock.h> 
     30 
     31#include <libgsmd/libgsmd.h> 
     32#include <libgsmd/event.h> 
     33#include <libgsmd/misc.h> 
     34#include <libgsmd/sms.h> 
     35#include <libgsmd/voicecall.h> 
     36 
     37#include <libjana/jana.h> 
     38#include <libjana-ecal/jana-ecal.h> 
    3039 
    3140#include "moko-dialer.h" 
     
    4251        MOKO_TYPE_DIALER, MokoDialerPrivate)) 
    4352 
     53typedef struct { 
     54  GSource source; 
     55  GPollFD pollfd; 
     56  struct lgsm_handle *handle; 
     57} MokoDialerSource; 
     58 
    4459struct _MokoDialerPrivate 
    4560{ 
    46   gint                status; 
    47   gchar               *incoming_clip; 
     61  gint               status; 
     62  gchar              *incoming_clip; 
     63  gchar              *own_number; 
    4864 
    4965  /* handles user interaction */ 
    5066  GtkWidget          *talking; 
    5167 
    52   /* Special objects */ 
    53   MokoGsmdConnection *connection; 
     68  /* gsmd connection variables */ 
     69  struct lgsm_handle *handle; 
     70  MokoDialerSource   *source; 
     71   
     72  /* Storage objects */ 
     73  JanaStore          *sms_store; 
     74  gboolean           sms_store_open; 
     75        JanaNote           *last_msg; 
    5476  MokoJournal        *journal; 
    5577  MokoContacts       *contacts; 
     78   
     79  /* Notification handling object */ 
    5680  MokoNotify         *notify; 
    5781 
     
    6185 
    6286  /* Registration variables */ 
    63   MokoGsmdConnectionNetregType registered; 
    64   MokoGSMLocation     gsm_location; 
     87  enum lgsm_netreg_state registered; 
     88  MokoGSMLocation    gsm_location; 
    6589}; 
    6690 
     
    78102static guint dialer_signals[LAST_SIGNAL] = {0, }; 
    79103 
    80 static MokoGsmdConnection * dialer_init_gsmd (MokoDialer *dialer); 
     104static void dialer_init_gsmd (MokoDialer *dialer); 
    81105 
    82106/* DBus functions */ 
     
    100124 
    101125  MokoDialerPrivate *priv; 
     126  struct lgsm_addr addr; 
    102127  MokoContactEntry *entry = NULL; 
    103128 
     
    109134 
    110135 
    111   if (!priv->connection) 
    112     priv->connection = dialer_init_gsmd (dialer); 
    113    
    114   if (!priv->connection) 
     136  if (!priv->handle) dialer_init_gsmd (dialer); 
     137   
     138  if (!priv->handle) 
    115139  { 
    116140    *error = g_error_new (PHONE_KIT_DIALER_ERROR, PK_DIALER_ERROR_GSMD, "Could not connect to gsmd"); 
     
    137161 
    138162  /* check for network connection */ 
    139   if (priv->registered != MOKO_GSMD_CONNECTION_NETREG_HOME 
    140       && priv->registered != MOKO_GSMD_CONNECTION_NETREG_ROAMING 
    141       && priv->registered != MOKO_GSMD_CONNECTION_NETREG_DENIED) 
     163  if (priv->registered != GSMD_NETREG_REG_HOME 
     164      && priv->registered != GSMD_NETREG_REG_ROAMING 
     165      && priv->registered != GSMD_NETREG_DENIED) 
    142166  { 
    143167 
     
    175199  moko_talking_outgoing_call (MOKO_TALKING (priv->talking), number, entry); 
    176200 
    177   moko_gsmd_connection_voice_dial (MOKO_GSMD_CONNECTION (priv->connection), number); 
     201  /* TODO: No idea where '129' comes from, taken from libmokogsmd - refer to  
     202   * libgsmd.h in gsmd - It says "Refer to GSM 04.08 [8] subclause 10.5.4.7" 
     203   */ 
     204  addr.type = 129; 
     205  g_stpcpy (&addr.addr[0], number); 
     206  lgsm_voice_out_init (priv->handle, &addr); 
    178207 
    179208  return TRUE; 
     
    189218 
    190219  /* check for gsmd connection */ 
    191   if (!priv->connection) 
    192     priv->connection = dialer_init_gsmd (dialer); 
    193    
    194   if (!priv->connection) 
     220  if (!priv->handle) dialer_init_gsmd (dialer); 
     221   
     222  if (!priv->handle) 
    195223  { 
    196224    *error = g_error_new (PHONE_KIT_DIALER_ERROR, PK_DIALER_ERROR_GSMD, "Could not connect to gsmd"); 
     
    232260  priv->status = DIALER_STATUS_NORMAL; 
    233261 
    234   moko_gsmd_connection_voice_hangup (priv->connection);    
     262  lgsm_voice_hangup (priv->handle); 
    235263  g_signal_emit (G_OBJECT (dialer), dialer_signals[HUNG_UP], 0); 
    236264   
     
    250278  moko_notify_stop (priv->notify); 
    251279 
    252   moko_gsmd_connection_voice_hangup (priv->connection); 
     280  lgsm_voice_hangup (priv->handle); 
    253281 
    254282  g_signal_emit (G_OBJECT (dialer), dialer_signals[REJECTED], 0); 
     
    289317    return; 
    290318 
    291   moko_gsmd_connection_voice_accept (priv->connection); 
     319  lgsm_voice_in_accept (priv->handle); 
    292320  priv->status = DIALER_STATUS_TALKING; 
    293321 
     
    307335  priv = dialer->priv; 
    308336 
    309   moko_gsmd_connection_voice_hangup (priv->connection); 
     337  lgsm_voice_hangup (priv->handle); 
    310338  priv->status = DIALER_STATUS_NORMAL; 
    311339 
     
    335363  priv = dialer->priv; 
    336364   
    337   moko_gsmd_connection_voice_hangup (priv->connection); 
     365  lgsm_voice_hangup (priv->handle); 
    338366   
    339367  priv->status = DIALER_STATUS_NORMAL; 
     
    388416} 
    389417#endif 
    390 /* Callbacks for MokoGsmdConnection */ 
    391 static void 
    392 on_network_registered (MokoGsmdConnection *conn,  
     418/* Callbacks for gsmd events */ 
     419static void 
     420on_network_registered (MokoDialer *dialer, 
    393421                       int type,  
    394422                       int lac,   
    395                        int cell, 
    396                        MokoDialer *dialer) 
     423                       int cell) 
    397424{ 
    398425  MokoDialerPrivate *priv; 
     
    403430  switch (type) 
    404431  { 
    405     case MOKO_GSMD_CONNECTION_NETREG_NONE: 
    406     case MOKO_GSMD_CONNECTION_NETREG_SEARCHING: 
     432    case GSMD_NETREG_UNREG: 
     433    case GSMD_NETREG_UNREG_BUSY: 
    407434      /* Do nothing */ 
    408435      g_debug ("Searching for network"); 
    409436      break; 
    410     case MOKO_GSMD_CONNECTION_NETREG_DENIED: 
     437    case GSMD_NETREG_DENIED: 
    411438      /* This may be a pin issue*/ 
    412439      break; 
    413     case MOKO_GSMD_CONNECTION_NETREG_HOME: 
    414     case MOKO_GSMD_CONNECTION_NETREG_ROAMING: 
     440    case GSMD_NETREG_REG_HOME: 
     441    case GSMD_NETREG_REG_ROAMING: 
    415442      g_debug ("Network registered: LocationAreaCode: %x. CellID: %x.", lac, cell); 
    416443      priv->gsm_location.lac = lac; 
     
    425452 
    426453static void 
    427 on_incoming_call (MokoGsmdConnection *conn, int type, MokoDialer *dialer) 
     454on_incoming_call (MokoDialer *dialer, int type) 
    428455{ 
    429456  MokoDialerPrivate *priv; 
     
    463490 
    464491static void 
    465 on_incoming_clip (MokoGsmdConnection *conn, 
    466                   const gchar        *number, 
    467                   MokoDialer         *dialer) 
     492on_incoming_clip (MokoDialer *dialer, const gchar *number) 
    468493{ 
    469494  MokoDialerPrivate *priv; 
     
    496521 
    497522static void 
    498 on_pin_requested (MokoGsmdConnection *conn, int type, MokoDialer *dialer) 
     523on_pin_requested (MokoDialer *dialer, int type) 
    499524{ 
    500525  MokoDialerPrivate *priv; 
     
    508533  if (!pin) 
    509534    return; 
    510   moko_gsmd_connection_send_pin (priv->connection, pin); 
     535   
     536  lgsm_pin (priv->handle, 1, pin, NULL); 
    511537  g_free (pin); 
    512538} 
    513539 
    514540static void 
    515 on_call_progress_changed (MokoGsmdConnection *conn,  
    516                           int type,  
    517                           MokoDialer *dialer) 
     541on_call_progress_changed (MokoDialer *dialer, int type) 
    518542{ 
    519543  MokoDialerPrivate *priv; 
     
    524548  switch (type)  
    525549  { 
    526     case MOKO_GSMD_PROG_DISCONNECT: 
    527     case MOKO_GSMD_PROG_RELEASE: 
     550    case GSMD_CALLPROG_DISCONNECT: 
     551    case GSMD_CALLPROG_RELEASE: 
    528552      /* Finalise and add the journal entry */ 
    529553      if (priv->journal && priv->entry) 
     
    554578      break; 
    555579     
    556     case MOKO_GSMD_PROG_REJECT: 
     580    case GSMD_CALLPROG_REJECT: 
    557581      moko_dialer_rejected (dialer); 
    558582      g_debug ("mokogsmd reject"); 
    559583      break; 
    560584     
    561     case MOKO_GSMD_PROG_CONNECTED: 
     585    case GSMD_CALLPROG_CONNECTED: 
    562586      if (priv->status != DIALER_STATUS_TALKING) 
    563587        moko_dialer_talking (dialer); 
     
    572596      g_debug ("mokogsmd connected"); 
    573597      break; 
    574     case MOKO_GSMD_PROG_SETUP: 
     598    case GSMD_CALLPROG_SETUP: 
    575599      g_debug ("mokogsmd setup"); 
    576600      break; 
    577     case MOKO_GSMD_PROG_ALERT: 
     601    case GSMD_CALLPROG_ALERT: 
    578602      g_debug ("mokogsmd alert"); 
    579603      break; 
    580     case  MOKO_GSMD_PROG_CALL_PROCEED: 
     604    case  GSMD_CALLPROG_CALL_PROCEED: 
    581605      g_debug ("mokogsmd proceed"); 
    582606      break; 
    583     case MOKO_GSMD_PROG_SYNC: 
     607    case GSMD_CALLPROG_SYNC: 
    584608      g_debug ("mokogsmd sync"); 
    585609      break; 
    586     case  MOKO_GSMD_PROG_PROGRESS: 
     610    case GSMD_CALLPROG_PROGRESS: 
    587611      g_debug ("mokogsmd progress"); 
    588612      break; 
    589     case MOKO_GSMD_PROG_UNKNOWN: 
     613    case GSMD_CALLPROG_UNKNOWN: 
    590614    default: 
    591615      g_debug ("mokogsmd unknown"); 
     
    604628  priv = dialer->priv; 
    605629 
     630  if (priv->handle) { 
     631    lgsm_exit (priv->handle); 
     632    priv->handle = NULL; 
     633  } 
     634 
     635  if (priv->source) { 
     636    g_source_destroy ((GSource *)priv->source); 
     637    priv->source = NULL; 
     638  } 
     639 
     640  if (priv->sms_store) { 
     641    g_object_unref (priv->sms_store); 
     642    priv->sms_store = NULL; 
     643  } 
     644 
    606645  /* Close journal */ 
    607646  if (priv->journal) 
     
    609648    moko_journal_write_to_storage (priv->journal); 
    610649    moko_journal_close (priv->journal); 
     650    priv->journal = NULL; 
    611651  } 
    612652  G_OBJECT_CLASS (moko_dialer_parent_class)->dispose (object); 
     
    614654 
    615655static void 
    616 moko_dialer_finalize (GObject *dialer) 
    617 { 
    618   G_OBJECT_CLASS (moko_dialer_parent_class)->finalize (dialer); 
     656moko_dialer_finalize (GObject *object) 
     657{ 
     658  MokoDialer *dialer; 
     659  MokoDialerPrivate *priv; 
     660   
     661  dialer = MOKO_DIALER (object); 
     662  priv = dialer->priv; 
     663 
     664  g_free (priv->own_number); 
     665   
     666  G_OBJECT_CLASS (moko_dialer_parent_class)->finalize (object); 
    619667} 
    620668 
     
    683731 
    684732static void 
    685 dialer_display_error (GError *err) 
    686 { 
    687   if (!err) 
     733status_report_added_cb (JanaStoreView *view, GList *components, gchar *ref) 
     734{ 
     735  MokoDialerPrivate *priv = moko_dialer_get_default ()->priv; 
     736 
     737  for (; components; components = components->next) { 
     738    gchar *compref; 
     739    JanaComponent *comp = JANA_COMPONENT (components->data); 
     740     
     741    compref = jana_component_get_custom_prop ( 
     742      comp, "X-PHONEKIT-SMS-REF"); 
     743    if (compref && (strcmp (compref, ref) == 0)) { 
     744      jana_utils_component_remove_category (comp, "Sending"); 
     745      jana_utils_component_insert_category (comp, "Sent", 0); 
     746      jana_store_modify_component (priv->sms_store, comp); 
     747      g_debug ("Setting message status to confirmed sent"); 
     748    } 
     749    g_free (ref); 
     750  } 
     751} 
     752 
     753static void 
     754status_report_progress_cb (JanaStoreView *view, gint percent, gchar *ref) 
     755{ 
     756  if (percent != 100) return; 
     757   
     758  g_object_unref (view); 
     759  g_free (ref); 
     760} 
     761 
     762static void 
     763store_sms (MokoDialer *dialer, struct gsmd_sms_list *sms) 
     764{ 
     765  gchar *message; 
     766 
     767  MokoDialerPrivate *priv = dialer->priv; 
     768 
     769  /* Return if we haven't opened the journal yet - signals will be re-fired  
     770   * when the journal is opened anyway. 
     771   */ 
     772  if (!priv->sms_store_open) return; 
     773 
     774  /* Ignore voicemail notifications */ 
     775  if (sms->payload.is_voicemail) return; 
     776 
     777  /* TODO: Verify type of message for journal (sent/received) -  
     778   *       Assuming received for now, as messages sent with phone-kit  
     779   *       will be marked already. 
     780   */ 
     781  message = NULL; 
     782  switch (sms->payload.coding_scheme) { 
     783  case ALPHABET_DEFAULT : 
     784    g_debug ("Decoding 7-bit ASCII message"); 
     785    message = g_malloc0 (GSMD_SMS_DATA_MAXLEN); 
     786    unpacking_7bit_character (&sms->payload, message); 
     787    break; 
     788  case ALPHABET_8BIT : 
     789    /* TODO: Verify: Is this encoding just UTF-8? (it is on my Samsung phone) */ 
     790    g_debug ("Decoding UTF-8 message"); 
     791    message = g_strdup (sms->payload.data); 
     792    break; 
     793  case ALPHABET_UCS2 : 
     794    g_debug ("Decoding UCS-2 message"); 
     795    message = g_utf16_to_utf8 ((const gunichar2 *)sms->payload.data, 
     796                               sms->payload.length, NULL, NULL, NULL); 
     797    break; 
     798  } 
     799   
     800  /* Store message in the journal */ 
     801  if (message) { 
     802    struct lgsm_sms_delete sms_del; 
     803    gchar *author; 
     804    JanaNote *note = jana_ecal_note_new (); 
     805     
     806    g_debug ("Moving message to journal:\n\"%s\"", message); 
     807     
     808    author = g_strconcat (((sms->addr.type & __GSMD_TOA_TON_MASK) == 
     809                          GSMD_TOA_TON_INTERNATIONAL) ? "+" : "", 
     810                          sms->addr.number, NULL); 
     811    jana_note_set_author (note, author); 
     812    g_free (author); 
     813     
     814    jana_note_set_recipient (note, priv->own_number); 
     815     
     816    jana_note_set_body (note, message); 
     817     
     818    /* TODO: Set creation time from SMS timestamp */ 
     819     
     820    /* Add SMS to store */ 
     821    jana_store_add_component (priv->sms_store, JANA_COMPONENT (note)); 
     822     
     823    /* Delete SMS from internal storage */ 
     824    sms_del.index = sms->index; 
     825    sms_del.delflg = LGSM_SMS_DELFLG_INDEX; 
     826    lgsm_sms_delete (priv->handle, &sms_del); 
     827     
     828    g_free (message); 
     829  } 
     830} 
     831 
     832static int  
     833gsmd_eventhandler (struct lgsm_handle *lh, int evt_type, 
     834                   struct gsmd_evt_auxdata *aux) 
     835{ 
     836  MokoDialer *dialer = moko_dialer_get_default (); 
     837  MokoDialerPrivate *priv = dialer->priv; 
     838   
     839  switch (evt_type) { 
     840  case GSMD_EVT_IN_CALL : 
     841    on_incoming_call (dialer, aux->u.call.type); 
     842    break; 
     843  case GSMD_EVT_IN_SMS : /* Incoming SMS */ 
     844    /* TODO: Read UDH for multi-part messages */ 
     845    g_debug ("Received incoming SMS"); 
     846    if (aux->u.sms.inlined) { 
     847      struct gsmd_sms_list * sms = (struct gsmd_sms_list *)aux->data; 
     848      g_debug ("Message inline"); 
     849      store_sms (dialer, sms); 
     850    } else { 
     851      g_debug ("Message stored on SIM, reading..."); 
     852      lgsm_sms_read (lh, aux->u.sms.index); 
     853    } 
     854    break; 
     855  case GSMD_EVT_IN_DS : /* SMS status report */ 
     856    if (aux->u.ds.inlined) { 
     857      struct gsmd_sms_list *sms = (struct gsmd_sms_list *) aux->data; 
     858       
     859      /* TODO: I'm not entirely sure of the spec when if  
     860       *       storing an unsent message means it failed? 
     861       */ 
     862      if (sms->payload.coding_scheme == LGSM_SMS_STO_SENT) { 
     863        gchar *ref = g_strdup_printf ("%d", sms->index); 
     864        JanaStoreView *view = jana_store_get_view (priv->sms_store); 
     865         
     866        g_debug ("Received sent SMS status report"); 
     867        jana_store_view_add_match (view, JANA_STORE_VIEW_CATEGORY, "Sending"); 
     868        g_signal_connect (view, "added", 
     869                          G_CALLBACK (status_report_added_cb), ref); 
     870        g_signal_connect (view, "progress", 
     871                          G_CALLBACK (status_report_progress_cb), ref); 
     872      } 
     873    } else { 
     874      g_warning ("Not an in-line event, unhandled"); 
     875    } 
     876    break; 
     877  case GSMD_EVT_IN_CLIP : 
     878    on_incoming_clip (dialer, aux->u.clip.addr.number); 
     879    break; 
     880  case GSMD_EVT_NETREG : 
     881    on_network_registered (dialer, aux->u.netreg.state, 
     882                           aux->u.netreg.lac, aux->u.netreg.ci); 
     883    break; 
     884  case GSMD_EVT_PIN : 
     885    on_pin_requested (dialer, aux->u.pin.type); 
     886    break; 
     887  case GSMD_EVT_OUT_STATUS : 
     888    on_call_progress_changed (dialer, aux->u.call_status.prog); 
     889    break; 
     890  default : 
     891    g_warning ("Unhandled gsmd event (%d)", evt_type); 
     892  } 
     893   
     894  return 0; 
     895} 
     896 
     897static int 
     898sms_msghandler (struct lgsm_handle *lh, struct gsmd_msg_hdr *gmh) 
     899{ 
     900  MokoDialer *dialer = moko_dialer_get_default (); 
     901  MokoDialerPrivate *priv = dialer->priv; 
     902 
     903  /* Store sent messages */ 
     904  if ((gmh->msg_subtype == GSMD_SMS_SEND) && priv->last_msg) { 
     905    int *result = (int *) ((void *) gmh + sizeof(*gmh)); 
     906    gchar *uid = jana_component_get_uid ( 
     907      JANA_COMPONENT (priv->last_msg)); 
     908     
     909    if (*result >= 0) { 
     910      gchar *ref = g_strdup_printf ("%d", *result); 
     911      jana_component_set_custom_prop (JANA_COMPONENT (priv->last_msg), 
     912                                      "X-PHONEKIT-SMS-REF", ref); 
     913      g_free (ref); 
     914      g_debug ("Sent message accepted"); 
     915    } else { 
     916      g_debug ("Sent message rejected"); 
     917      jana_utils_component_remove_category (JANA_COMPONENT(priv->last_msg), 
     918                                            "Sending"); 
     919      jana_utils_component_insert_category (JANA_COMPONENT(priv->last_msg), 
     920                                            "Rejected", 0); 
     921      /* TODO: Add error codes? 42 = congestion? */ 
     922    } 
     923    jana_store_modify_component (priv->sms_store, 
     924                                 JANA_COMPONENT (priv->last_msg)); 
     925     
     926    g_free (uid); 
     927    g_object_unref (priv->last_msg); 
     928    priv->last_msg = NULL; 
     929  } else if ((gmh->msg_subtype == GSMD_SMS_LIST) || 
     930             (gmh->msg_subtype == GSMD_SMS_READ)) { 
     931    struct gsmd_sms_list *sms_list = (struct gsmd_sms_list *) 
     932                                     ((void *) gmh + sizeof(*gmh)); 
     933 
     934    g_debug ("Storing message on SIM"); 
     935    store_sms (dialer, sms_list); 
     936  } else { 
     937    return -EINVAL; 
     938  } 
     939   
     940  return 0; 
     941} 
     942 
     943static int 
     944net_msghandler (struct lgsm_handle *lh, struct gsmd_msg_hdr *gmh) 
     945{ 
     946  MokoDialer *dialer = moko_dialer_get_default (); 
     947  MokoDialerPrivate *priv = dialer->priv; 
     948 
     949  const struct gsmd_own_number *num = (struct gsmd_own_number *) 
     950                                      ((void *) gmh + sizeof(*gmh)); 
     951 
     952  if (gmh->msg_subtype != GSMD_NETWORK_GET_NUMBER) return -EINVAL; 
     953   
     954  g_free (priv->own_number); 
     955   
     956  /* TODO: Normalise number necessary? */ 
     957  priv->own_number = g_strdup (num->addr.number); 
     958  g_debug ("Got phone number: %s", priv->own_number); 
     959   
     960  return 0; 
     961} 
     962 
     963static gboolean  
     964connection_source_prepare (GSource* self, gint* timeout) 
     965{ 
     966    return FALSE; 
     967} 
     968 
     969static gboolean 
     970connection_source_check (GSource* source) 
     971{ 
     972  MokoDialerSource *self = (MokoDialerSource *)source; 
     973  return self->pollfd.revents & G_IO_IN; 
     974} 
     975 
     976static gboolean  
     977connection_source_dispatch (GSource *source, GSourceFunc callback, 
     978                            gpointer data) 
     979{ 
     980  char buf[1025]; 
     981  int size; 
     982 
     983  MokoDialerSource *self = (MokoDialerSource *)source; 
     984 
     985  size = read (self->pollfd.fd, &buf, sizeof(buf)); 
     986  if (size < 0) { 
     987    g_warning ("moko_gsmd_connection_source_dispatch:%s %s", 
     988               "read error from libgsmd:", strerror (errno)); 
     989  } else { 
     990    if (size == 0) /* EOF */ 
     991      return FALSE; 
     992    lgsm_handle_packet (self->handle, buf, size); 
     993  } 
     994 
     995  return TRUE; 
     996} 
     997 
     998static void 
     999sms_store_opened_cb (JanaStore *store, MokoDialer *self) 
     1000{ 
     1001  MokoDialerPrivate *priv = self->priv; 
     1002  priv->sms_store_open = TRUE; 
     1003 
     1004  g_debug ("SMS store opened"); 
     1005   
     1006  if (!priv->handle) return; 
     1007   
     1008  /* Register SMS handling callback */ 
     1009  lgsm_register_handler (priv->handle, GSMD_MSG_SMS, &sms_msghandler); 
     1010 
     1011  /* List all messages to move to journal */ 
     1012  lgsm_sms_list (priv->handle, GSMD_SMS_ALL); 
     1013} 
     1014 
     1015static void 
     1016dialer_init_gsmd (MokoDialer *dialer) 
     1017{ 
     1018  static GSourceFuncs funcs = { 
     1019    connection_source_prepare, 
     1020    connection_source_check, 
     1021    connection_source_dispatch, 
     1022    NULL, 
     1023  }; 
     1024 
     1025  MokoDialerPrivate *priv; 
     1026  priv = dialer->priv; 
     1027 
     1028  /* Get a gsmd handle */ 
     1029  if (!(priv->handle = lgsm_init (LGSMD_DEVICE_GSMD))) { 
     1030    g_warning ("Error connecting to gsmd"); 
    6881031    return; 
    689   g_warning (err->message); 
    690 } 
    691  
    692 static MokoGsmdConnection * 
    693 dialer_init_gsmd (MokoDialer *dialer) 
    694 { 
    695   GError *err = NULL; 
    696   MokoGsmdConnection *conn; 
    697   MokoDialerPrivate *priv; 
    698   priv = dialer->priv = MOKO_DIALER_GET_PRIVATE (dialer); 
    699  
    700   /* Init the gsmd connection, and power it up */ 
    701   conn = moko_gsmd_connection_new (); 
    702   moko_gsmd_connection_set_antenna_power (conn, TRUE, &err); 
    703  
    704   dialer_display_error (err); 
    705   if (err && err->code == MOKO_GSMD_ERROR_CONNECT) 
    706   { 
    707     g_object_unref (conn); 
    708     return NULL; 
    709   } 
    710  
    711   /* Connect to the gsmd signals */ 
    712   g_signal_connect (G_OBJECT (conn), "network-registration",  
    713                     G_CALLBACK (on_network_registered), (gpointer)dialer); 
    714   g_signal_connect (G_OBJECT (conn), "incoming-call",  
    715                     G_CALLBACK (on_incoming_call), (gpointer)dialer); 
    716   g_signal_connect (G_OBJECT (conn), "incoming-clip", 
    717                     G_CALLBACK (on_incoming_clip), (gpointer)dialer); 
    718   g_signal_connect (G_OBJECT (conn), "pin-requested",  
    719                     G_CALLBACK (on_pin_requested), (gpointer)dialer); 
    720   g_signal_connect (G_OBJECT (conn), "call-progress",  
    721                     G_CALLBACK (on_call_progress_changed), (gpointer)dialer); 
    722  
    723   /* FIXME: 
    724    *  moko_gsmd_connection_get_network_status always seems to return 0 here */ 
    725   priv->registered = MOKO_GSMD_CONNECTION_NETREG_SEARCHING; 
    726   moko_gsmd_connection_network_register (conn); 
    727  
    728   return conn; 
     1032  } 
     1033   
     1034  /* Power the gsm modem up */ 
     1035  if (lgsm_phone_power (priv->handle, 1) == -1) { 
     1036    g_warning ("Error powering up gsm modem"); 
     1037    lgsm_exit (priv->handle); 
     1038    priv->handle = NULL; 
     1039    return; 
     1040  } 
     1041   
     1042  /* Add event handlers */ 
     1043  lgsm_evt_handler_register (priv->handle, GSMD_EVT_IN_CALL, gsmd_eventhandler); 
     1044  lgsm_evt_handler_register (priv->handle, GSMD_EVT_IN_CLIP, gsmd_eventhandler); 
     1045  lgsm_evt_handler_register (priv->handle, GSMD_EVT_IN_SMS, gsmd_eventhandler); 
     1046  lgsm_evt_handler_register (priv->handle, GSMD_EVT_IN_DS, gsmd_eventhandler); 
     1047  lgsm_evt_handler_register (priv->handle, GSMD_EVT_NETREG, gsmd_eventhandler); 
     1048  lgsm_evt_handler_register (priv->handle, GSMD_EVT_OUT_STATUS, gsmd_eventhandler); 
     1049  lgsm_register_handler (priv->handle, GSMD_MSG_NETWORK, &net_msghandler); 
     1050 
     1051  /* Register with network */ 
     1052  priv->registered = GSMD_NETREG_UNREG; 
     1053  lgsm_netreg_register (priv->handle, ""); 
     1054 
     1055  /* Get phone number */ 
     1056  lgsm_get_subscriber_num (priv->handle); 
     1057   
     1058  /* Start polling for events */ 
     1059  priv->source = (MokoDialerSource *) 
     1060    g_source_new (&funcs, sizeof (MokoDialerSource)); 
     1061  priv->source->handle = priv->handle; 
     1062  priv->source->pollfd.fd = lgsm_fd (priv->handle); 
     1063  priv->source->pollfd.events = G_IO_IN | G_IO_HUP | G_IO_ERR; 
     1064  priv->source->pollfd.revents = 0; 
     1065  g_source_add_poll ((GSource*)priv->source, &priv->source->pollfd); 
     1066  g_source_attach ((GSource*)priv->source, NULL); 
    7291067} 
    7301068 
     
    7451083  //contact_init_contact_data (&(priv->data->g_contactlist)); 
    7461084 
    747   priv->connection = dialer_init_gsmd (dialer); 
     1085  dialer_init_gsmd (dialer); 
    7481086 
    7491087  /* Set up the journal */ 
     
    7561094  else 
    7571095    g_debug ("Journal Loaded"); 
     1096 
     1097  /* Get the SMS note store */ 
     1098  priv->sms_store = jana_ecal_store_new (JANA_COMPONENT_NOTE); 
     1099  g_signal_connect (priv->sms_store, "opened", 
     1100                    G_CALLBACK (sms_store_opened_cb), dialer); 
     1101  jana_store_open (priv->sms_store); 
    7581102 
    7591103  /* Load the contacts store */ 
     
    7921136  return dialer; 
    7931137} 
     1138 
     1139gboolean 
     1140moko_dialer_send_sms (MokoDialer *self, const gchar *number, 
     1141                      const gchar *message, gchar **uid, GError **error) 
     1142{ 
     1143  MokoDialerPrivate *priv; 
     1144  struct lgsm_sms sms; 
     1145  gint msg_length, c; 
     1146  gboolean ascii; 
     1147  JanaNote *note; 
     1148   
     1149  g_assert (self && number && message); 
     1150 
     1151  priv = self->priv; 
     1152   
     1153  if (!priv->handle) { 
     1154    /* Failed to connect to gsmd earlier */ 
     1155    *error = g_error_new (PHONE_KIT_DIALER_ERROR, PK_DIALER_ERROR_GSMD, 
     1156                          "Failed to connect to gsmd"); 
     1157    return FALSE; 
     1158  } 
     1159   
     1160  if (!priv->sms_store_open) { 
     1161    *error = g_error_new (PHONE_KIT_DIALER_ERROR, PK_DIALER_ERROR_SMS_STORE, 
     1162                          "SMS store not opened"); 
     1163    return FALSE; 
     1164  } 
     1165   
     1166  /* Ask for delivery report */ 
     1167  sms.ask_ds = 1; 
     1168   
     1169  /* Set destination number */ 
     1170  if (strlen (number) > GSMD_ADDR_MAXLEN + 1) { 
     1171    *error = g_error_new (PHONE_KIT_DIALER_ERROR, PK_DIALER_ERROR_NO_TOOLONG, 
     1172                          "Number too long"); 
     1173    return FALSE; 
     1174  } else { 
     1175    strcpy (sms.addr, number); 
     1176  } 
     1177   
     1178  /* Set message */ 
     1179  /* Check if the text is ascii (and pack in 7 bits if so) */ 
     1180  ascii = TRUE; 
     1181  for (c = 0; message[c] != '\0'; c++) { 
     1182    if (((guint8)message[c]) > 0x7F) { 
     1183      ascii = FALSE; 
     1184      break; 
     1185    } 
     1186  } 
     1187   
     1188  /* TODO: Multi-part messages using UDH */ 
     1189  msg_length = strlen (message); 
     1190  if ((ascii && (msg_length > 160)) || (msg_length > 140)) { 
     1191      *error = g_error_new (PHONE_KIT_DIALER_ERROR, PK_DIALER_ERROR_SMS_TOOLONG, 
     1192                            "Message too long"); 
     1193      return FALSE; 
     1194  } 
     1195  if (ascii) { 
     1196    packing_7bit_character (message, &sms); 
     1197  } else { 
     1198    sms.alpha = ALPHABET_8BIT; 
     1199    sms.length = strlen (message); 
     1200    strcpy ((gchar *)sms.data, message); 
     1201  } 
     1202   
     1203  /* Send message */ 
     1204  lgsm_sms_send (priv->handle, &sms); 
     1205   
     1206  /* Store sent message in journal */ 
     1207  note = jana_ecal_note_new (); 
     1208  jana_note_set_recipient (note, number); 
     1209  jana_note_set_author (note, priv->own_number); 
     1210   
     1211  jana_note_set_body (note, message); 
     1212  jana_component_set_categories (JANA_COMPONENT (note), 
     1213    (const gchar *[]){ "Sending", NULL}); 
     1214   
     1215  jana_store_add_component (priv->sms_store, 
     1216    JANA_COMPONENT (note)); 
     1217  if (uid) *uid = jana_component_get_uid (JANA_COMPONENT (note)); 
     1218   
     1219  if (priv->last_msg) { 
     1220    g_warning ("Confirmation not received for last sent SMS, " 
     1221      "delivery report will be lost."); 
     1222    g_object_unref (priv->last_msg); 
     1223    priv->last_msg = NULL; 
     1224  } 
     1225  priv->last_msg = note; 
     1226   
     1227  return TRUE; 
     1228} 
     1229 
  • trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-dialer.h

    r3456 r3479  
    4949  PK_DIALER_ERROR_BUSY, 
    5050  PK_DIALER_ERROR_GSMD, 
    51   PK_DIALER_ERROR_NOT_CONNECTED 
     51  PK_DIALER_ERROR_NOT_CONNECTED, 
     52  PK_DIALER_ERROR_SMS_STORE, 
     53  PK_DIALER_ERROR_SMS_TOOLONG, 
     54  PK_DIALER_ERROR_NO_TOOLONG 
    5255} PhoneKitDialerError; 
    5356 
     
    125128moko_dialer_rejected (MokoDialer *dialer); 
    126129 
     130gboolean 
     131moko_dialer_send_sms (MokoDialer *self, const gchar *number, 
     132                      const gchar *message, gchar **uid, GError **error); 
     133 
    127134G_END_DECLS 
    128135 
Note: See TracChangeset for help on using the changeset viewer.