$Id$
$Log$
- Revision 1.1.1.1 2001/11/25 21:59:23 short
- :pserver:cvs@pserver.samba.org:/cvsroot - gnokii - Sun Nov 25 22:56 CET 2001
+ Revision 1.1.1.4 2002/04/03 01:44:15 short
+ Implemented connection type "tcp" (GCT_TCP), use <hostname>:<port> as "port"
+
+ Revision 1.1.1.3 2002/04/03 00:08:22 short
+ Found in "gnokii-working" directory, some November-patches version
Revision 1.4 2001/05/30 14:36:47 pkot
Fix smsd to use StateMachine and let it compile.
static GSM_Error fbusinit(bool enable_monitoring)
{
int count=0;
- static GSM_Error error=GE_NOLINK;
+ GSM_Error error=GE_NOLINK;
GSM_ConnectionType connection=GCT_Serial;
static GSM_Statemachine sm;
if (!strcmp(smsdConfig.connection, "infrared"))
connection = GCT_Infrared;
+ if (!strcmp(smsdConfig.connection, "tcp"))
+ connection = GCT_TCP;
/* Initialise the code for the GSM interface. */
g_print("After usleep. GSM_LinkOK: %d\n", *GSM_LinkOK);
#endif
- if (*GSM_LinkOK == true)
- InitModelInf ();
+ if (*GSM_LinkOK != true) {
+ return (GE_NOLINK);
+ }
- return *GSM_LinkOK;
+ InitModelInf ();
+ return(GE_NONE);
}
phoneMonitor.phone.imei = g_strdup (_("unknown"));
phoneMonitor.supported = 0;
phoneMonitor.working = FALSE;
- phoneMonitor.sms.unRead = phoneMonitor.sms.number = 0;
+ phoneMonitor.sms.unRead = phoneMonitor.sms.used = phoneMonitor.sms.slots = 0;
phoneMonitor.sms.messages = NULL;
pthread_mutex_init (&smsMutex, NULL);
pthread_cond_init (&smsCond, NULL);
}
-static void RefreshSMS (const gint number)
+static void RefreshSMS (const gint slots)
{
GSM_Error error;
GSM_SMSMessage *msg;
register gint i;
+ gint unread = 0;
# ifdef XDEBUG
g_print ("RefreshSMS is running...\n");
pthread_mutex_lock (&smsMutex);
FreeArray (&(phoneMonitor.sms.messages));
- phoneMonitor.sms.number = 0;
+ phoneMonitor.sms.used = 0;
// pthread_mutex_unlock (&smsMutex);
- i = 0;
- while (1)
+ for (i=1; i<=slots; i++)
{
msg = g_malloc (sizeof (GSM_SMSMessage));
msg->MemoryType = GMT_SM;
- msg->Location = ++i;
+ msg->Location = i;
if ((error = GSM->GetSMSMessage (msg)) == GE_NONE)
{
// pthread_mutex_lock (&smsMutex);
phoneMonitor.sms.messages = g_slist_append (phoneMonitor.sms.messages, msg);
- phoneMonitor.sms.number++;
+ phoneMonitor.sms.used++;
+ if (msg->Type == GST_MT && msg->Status == GSS_NOTSENTREAD)
+ unread++;
// pthread_mutex_unlock (&smsMutex);
- if (phoneMonitor.sms.number == number)
- {
- pthread_cond_signal (&smsCond);
- pthread_mutex_unlock (&smsMutex);
- return;
- }
}
else if (error == GE_INVALIDSMSLOCATION) /* All positions are readed */
{
g_free (msg);
- pthread_cond_signal (&smsCond);
- pthread_mutex_unlock (&smsMutex);
break;
}
else
g_free (msg);
- usleep (750000);
+ /* FIXME: Why is any delay here?
+ */
+ /* usleep (750000); */
}
+ /* Update it after the whole run as otherwise "Refreshing SMSes..."
+ * would collide with "Short Message received" message.
+ */
+ phoneMonitor.sms.unRead = unread;
+
+ pthread_cond_signal (&smsCond);
+ pthread_mutex_unlock (&smsMutex);
}
if (d)
{
pthread_mutex_lock (&sendSMSMutex);
- error = d->status = GSM->SendSMSMessage (d->sms, 0);
+ error = d->status = GSM->SendSMSMessage (d->sms);
pthread_cond_signal (&sendSMSCond);
pthread_mutex_unlock (&sendSMSMutex);
}
void *Connect (void *a)
{
- GSM_SMSStatus SMSStatus = {0, 0};
+ GSM_SMSStatus SMSStatus = {0, 0, 0};
PhoneEvent *event;
GSM_Error error;
g_print ("Initializing connection...\n");
# endif
- while (!fbusinit (true))
+ while (fbusinit (true))
sleep (1);
# ifdef XDEBUG
if (GSM->GetSMSStatus (&SMSStatus) == GE_NONE)
{
+ /* Change of "UnRead" shouldn't be interesting - user may have read some of his
+ * SMSes by the phone interface.
+ */
if (phoneMonitor.sms.unRead != SMSStatus.UnRead ||
- phoneMonitor.sms.number != SMSStatus.Number)
+ phoneMonitor.sms.used != SMSStatus.Used ||
+ phoneMonitor.sms.slots != SMSStatus.Slots) /* shouldn't change, just to be sure */
{
+ /* We are primarily interested in SMSStatus.Slots so try to fix it up if it is broken
+ */
+ if (SMSStatus.UnRead > SMSStatus.Used)
+ SMSStatus.Used = SMSStatus.UnRead;
+ if (SMSStatus.Used > SMSStatus.Slots)
+ SMSStatus.Slots = SMSStatus.Used;
+ phoneMonitor.sms.slots = SMSStatus.Slots; /* shouldn't change, just to be sure */
+ /* phoneMonitor.sms.{unRead,used} will be updated by RefreshSMS()
+ */
+
phoneMonitor.working = TRUE;
- RefreshSMS (SMSStatus.Number);
+ RefreshSMS (SMSStatus.Slots);
phoneMonitor.working = FALSE;
}
# endif
phoneMonitor.working = TRUE;
if (event->event <= Event_Exit)
- if ((error = DoAction[event->event] (event->data)) != GE_NONE)
+ if (((error = DoAction[event->event] (event->data)) != GE_NONE) && error != GE_SMSSENDOK)
g_print (_("Event %d failed with return code %d!\n"), event->event, error);
g_free (event);
}