Changeset 3479
- Timestamp:
- 11/22/07 19:47:13 (6 years ago)
- Location:
- trunk/src/target/OM-2007.2/applications/openmoko-dialer2
- Files:
-
- 3 deleted
- 6 edited
-
ChangeLog (modified) (1 diff)
-
src/phone-kit/Makefile.am (modified) (2 diffs)
-
src/phone-kit/dialer-main.c (modified) (4 diffs)
-
src/phone-kit/moko-dialer-dbus.xml (modified) (1 diff)
-
src/phone-kit/moko-dialer-sms-dbus.xml (deleted)
-
src/phone-kit/moko-dialer-sms.c (deleted)
-
src/phone-kit/moko-dialer-sms.h (deleted)
-
src/phone-kit/moko-dialer.c (modified) (30 diffs)
-
src/phone-kit/moko-dialer.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/target/OM-2007.2/applications/openmoko-dialer2/ChangeLog
r3466 r3479 1 2007-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 1 25 2007-11-21 Thomas Wood <thomas@openedhand.com> 2 26 -
trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/Makefile.am
r3466 r3479 12 12 moko-sound.c moko-sound.h \ 13 13 moko-talking.c moko-talking.h \ 14 moko-dialer-sms.c moko-dialer-sms.h \15 14 moko-pin.c \ 16 15 moko-pin.h … … 22 21 $(LIBTOOL) --mode=execute $(DBUS_GLIB_BIN)/dbus-binding-tool --prefix=$(subst -,_,$*) --mode=glib-server --output=$@ $< 23 22 24 BUILT_SOURCES = moko-dialer-glue.h moko-dialer-sms-glue.h23 BUILT_SOURCES = moko-dialer-glue.h 25 24 26 EXTRA_DIST = moko-dialer-dbus.xml moko-dialer-sms-dbus.xml25 EXTRA_DIST = moko-dialer-dbus.xml 27 26 -
trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/dialer-main.c
r3420 r3479 24 24 25 25 #include "moko-dialer.h" 26 #include "moko-dialer-sms.h"27 26 28 27 #define DIALER_NAMESPACE "org.openmoko.Dialer" 29 28 #define DIALER_OBJECT "/org/openmoko/Dialer" 30 #define SMS_OBJECT "/org/openmoko/Dialer/SMS"31 29 32 30 static gchar *number = NULL; … … 58 56 { 59 57 MokoDialer *dialer; 60 MokoDialerSMS *sms;61 58 DBusGConnection *connection; 62 59 DBusGProxy *proxy; … … 111 108 moko_stock_register (); 112 109 113 /* Create the MokoDialer /MokoDialerSMS objects*/110 /* Create the MokoDialer object */ 114 111 dialer = moko_dialer_get_default (); 115 sms = moko_dialer_sms_get_default ();116 112 117 113 /* Add the objects onto the bus */ … … 119 115 DIALER_OBJECT, 120 116 G_OBJECT (dialer)); 121 dbus_g_connection_register_g_object (connection,122 SMS_OBJECT,123 G_OBJECT (sms));124 117 125 118 /* application object */ -
trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-dialer-dbus.xml
r3310 r3479 13 13 <method name="HangUp"> 14 14 <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" /> 15 21 </method> 16 22 -
trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-dialer.c
r3466 r3479 21 21 #include <string.h> 22 22 #include <stdlib.h> 23 #include <unistd.h> 23 24 24 25 #include <dbus/dbus-glib.h> 25 26 #include <dbus/dbus-glib-bindings.h> 26 27 27 #include <moko-gsmd-connection.h>28 28 #include <moko-journal.h> 29 29 #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> 30 39 31 40 #include "moko-dialer.h" … … 42 51 MOKO_TYPE_DIALER, MokoDialerPrivate)) 43 52 53 typedef struct { 54 GSource source; 55 GPollFD pollfd; 56 struct lgsm_handle *handle; 57 } MokoDialerSource; 58 44 59 struct _MokoDialerPrivate 45 60 { 46 gint status; 47 gchar *incoming_clip; 61 gint status; 62 gchar *incoming_clip; 63 gchar *own_number; 48 64 49 65 /* handles user interaction */ 50 66 GtkWidget *talking; 51 67 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; 54 76 MokoJournal *journal; 55 77 MokoContacts *contacts; 78 79 /* Notification handling object */ 56 80 MokoNotify *notify; 57 81 … … 61 85 62 86 /* Registration variables */ 63 MokoGsmdConnectionNetregType registered;64 MokoGSMLocation gsm_location;87 enum lgsm_netreg_state registered; 88 MokoGSMLocation gsm_location; 65 89 }; 66 90 … … 78 102 static guint dialer_signals[LAST_SIGNAL] = {0, }; 79 103 80 static MokoGsmdConnection *dialer_init_gsmd (MokoDialer *dialer);104 static void dialer_init_gsmd (MokoDialer *dialer); 81 105 82 106 /* DBus functions */ … … 100 124 101 125 MokoDialerPrivate *priv; 126 struct lgsm_addr addr; 102 127 MokoContactEntry *entry = NULL; 103 128 … … 109 134 110 135 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) 115 139 { 116 140 *error = g_error_new (PHONE_KIT_DIALER_ERROR, PK_DIALER_ERROR_GSMD, "Could not connect to gsmd"); … … 137 161 138 162 /* check for network connection */ 139 if (priv->registered != MOKO_GSMD_CONNECTION_NETREG_HOME140 && priv->registered != MOKO_GSMD_CONNECTION_NETREG_ROAMING141 && 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) 142 166 { 143 167 … … 175 199 moko_talking_outgoing_call (MOKO_TALKING (priv->talking), number, entry); 176 200 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); 178 207 179 208 return TRUE; … … 189 218 190 219 /* 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) 195 223 { 196 224 *error = g_error_new (PHONE_KIT_DIALER_ERROR, PK_DIALER_ERROR_GSMD, "Could not connect to gsmd"); … … 232 260 priv->status = DIALER_STATUS_NORMAL; 233 261 234 moko_gsmd_connection_voice_hangup (priv->connection);262 lgsm_voice_hangup (priv->handle); 235 263 g_signal_emit (G_OBJECT (dialer), dialer_signals[HUNG_UP], 0); 236 264 … … 250 278 moko_notify_stop (priv->notify); 251 279 252 moko_gsmd_connection_voice_hangup (priv->connection);280 lgsm_voice_hangup (priv->handle); 253 281 254 282 g_signal_emit (G_OBJECT (dialer), dialer_signals[REJECTED], 0); … … 289 317 return; 290 318 291 moko_gsmd_connection_voice_accept (priv->connection);319 lgsm_voice_in_accept (priv->handle); 292 320 priv->status = DIALER_STATUS_TALKING; 293 321 … … 307 335 priv = dialer->priv; 308 336 309 moko_gsmd_connection_voice_hangup (priv->connection);337 lgsm_voice_hangup (priv->handle); 310 338 priv->status = DIALER_STATUS_NORMAL; 311 339 … … 335 363 priv = dialer->priv; 336 364 337 moko_gsmd_connection_voice_hangup (priv->connection);365 lgsm_voice_hangup (priv->handle); 338 366 339 367 priv->status = DIALER_STATUS_NORMAL; … … 388 416 } 389 417 #endif 390 /* Callbacks for MokoGsmdConnection*/391 static void 392 on_network_registered (Moko GsmdConnection *conn,418 /* Callbacks for gsmd events */ 419 static void 420 on_network_registered (MokoDialer *dialer, 393 421 int type, 394 422 int lac, 395 int cell, 396 MokoDialer *dialer) 423 int cell) 397 424 { 398 425 MokoDialerPrivate *priv; … … 403 430 switch (type) 404 431 { 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: 407 434 /* Do nothing */ 408 435 g_debug ("Searching for network"); 409 436 break; 410 case MOKO_GSMD_CONNECTION_NETREG_DENIED:437 case GSMD_NETREG_DENIED: 411 438 /* This may be a pin issue*/ 412 439 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: 415 442 g_debug ("Network registered: LocationAreaCode: %x. CellID: %x.", lac, cell); 416 443 priv->gsm_location.lac = lac; … … 425 452 426 453 static void 427 on_incoming_call (Moko GsmdConnection *conn, int type, MokoDialer *dialer)454 on_incoming_call (MokoDialer *dialer, int type) 428 455 { 429 456 MokoDialerPrivate *priv; … … 463 490 464 491 static void 465 on_incoming_clip (MokoGsmdConnection *conn, 466 const gchar *number, 467 MokoDialer *dialer) 492 on_incoming_clip (MokoDialer *dialer, const gchar *number) 468 493 { 469 494 MokoDialerPrivate *priv; … … 496 521 497 522 static void 498 on_pin_requested (Moko GsmdConnection *conn, int type, MokoDialer *dialer)523 on_pin_requested (MokoDialer *dialer, int type) 499 524 { 500 525 MokoDialerPrivate *priv; … … 508 533 if (!pin) 509 534 return; 510 moko_gsmd_connection_send_pin (priv->connection, pin); 535 536 lgsm_pin (priv->handle, 1, pin, NULL); 511 537 g_free (pin); 512 538 } 513 539 514 540 static void 515 on_call_progress_changed (MokoGsmdConnection *conn, 516 int type, 517 MokoDialer *dialer) 541 on_call_progress_changed (MokoDialer *dialer, int type) 518 542 { 519 543 MokoDialerPrivate *priv; … … 524 548 switch (type) 525 549 { 526 case MOKO_GSMD_PROG_DISCONNECT:527 case MOKO_GSMD_PROG_RELEASE:550 case GSMD_CALLPROG_DISCONNECT: 551 case GSMD_CALLPROG_RELEASE: 528 552 /* Finalise and add the journal entry */ 529 553 if (priv->journal && priv->entry) … … 554 578 break; 555 579 556 case MOKO_GSMD_PROG_REJECT:580 case GSMD_CALLPROG_REJECT: 557 581 moko_dialer_rejected (dialer); 558 582 g_debug ("mokogsmd reject"); 559 583 break; 560 584 561 case MOKO_GSMD_PROG_CONNECTED:585 case GSMD_CALLPROG_CONNECTED: 562 586 if (priv->status != DIALER_STATUS_TALKING) 563 587 moko_dialer_talking (dialer); … … 572 596 g_debug ("mokogsmd connected"); 573 597 break; 574 case MOKO_GSMD_PROG_SETUP:598 case GSMD_CALLPROG_SETUP: 575 599 g_debug ("mokogsmd setup"); 576 600 break; 577 case MOKO_GSMD_PROG_ALERT:601 case GSMD_CALLPROG_ALERT: 578 602 g_debug ("mokogsmd alert"); 579 603 break; 580 case MOKO_GSMD_PROG_CALL_PROCEED:604 case GSMD_CALLPROG_CALL_PROCEED: 581 605 g_debug ("mokogsmd proceed"); 582 606 break; 583 case MOKO_GSMD_PROG_SYNC:607 case GSMD_CALLPROG_SYNC: 584 608 g_debug ("mokogsmd sync"); 585 609 break; 586 case MOKO_GSMD_PROG_PROGRESS:610 case GSMD_CALLPROG_PROGRESS: 587 611 g_debug ("mokogsmd progress"); 588 612 break; 589 case MOKO_GSMD_PROG_UNKNOWN:613 case GSMD_CALLPROG_UNKNOWN: 590 614 default: 591 615 g_debug ("mokogsmd unknown"); … … 604 628 priv = dialer->priv; 605 629 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 606 645 /* Close journal */ 607 646 if (priv->journal) … … 609 648 moko_journal_write_to_storage (priv->journal); 610 649 moko_journal_close (priv->journal); 650 priv->journal = NULL; 611 651 } 612 652 G_OBJECT_CLASS (moko_dialer_parent_class)->dispose (object); … … 614 654 615 655 static void 616 moko_dialer_finalize (GObject *dialer) 617 { 618 G_OBJECT_CLASS (moko_dialer_parent_class)->finalize (dialer); 656 moko_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); 619 667 } 620 668 … … 683 731 684 732 static void 685 dialer_display_error (GError *err) 686 { 687 if (!err) 733 status_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 753 static void 754 status_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 762 static void 763 store_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 832 static int 833 gsmd_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 897 static int 898 sms_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 943 static int 944 net_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 963 static gboolean 964 connection_source_prepare (GSource* self, gint* timeout) 965 { 966 return FALSE; 967 } 968 969 static gboolean 970 connection_source_check (GSource* source) 971 { 972 MokoDialerSource *self = (MokoDialerSource *)source; 973 return self->pollfd.revents & G_IO_IN; 974 } 975 976 static gboolean 977 connection_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 998 static void 999 sms_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 1015 static void 1016 dialer_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"); 688 1031 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); 729 1067 } 730 1068 … … 745 1083 //contact_init_contact_data (&(priv->data->g_contactlist)); 746 1084 747 priv->connection =dialer_init_gsmd (dialer);1085 dialer_init_gsmd (dialer); 748 1086 749 1087 /* Set up the journal */ … … 756 1094 else 757 1095 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); 758 1102 759 1103 /* Load the contacts store */ … … 792 1136 return dialer; 793 1137 } 1138 1139 gboolean 1140 moko_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 49 49 PK_DIALER_ERROR_BUSY, 50 50 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 52 55 } PhoneKitDialerError; 53 56 … … 125 128 moko_dialer_rejected (MokoDialer *dialer); 126 129 130 gboolean 131 moko_dialer_send_sms (MokoDialer *self, const gchar *number, 132 const gchar *message, gchar **uid, GError **error); 133 127 134 G_END_DECLS 128 135
Note: See TracChangeset
for help on using the changeset viewer.
