5 A Linux/Unix GUI for Nokia mobile phones.
6 Copyright (C) 1999 Pavel Janík ml., Hugh Blemings
7 & Ján Derfiòák <ja@mail.upjs.sk>.
9 Released under the terms of the GNU GPL, see file COPYING for more details.
11 Last modification: Sun Dec 17 2000
12 Modified by Jan Derfinak
21 # include <unistd.h> /* for usleep */
25 # include "../win32/winserial.h"
26 # define WRITEPHONE(a, b, c) WriteCommBlock(b, c)
29 # define sleep(x) Sleep((x) * 1000)
30 # define usleep(x) Sleep(((x) < 1000) ? 1 : ((x) / 1000))
37 #include "gsm-common.h"
39 #include "fbus-6110.h"
40 #include "fbus-3810.h"
41 #include "cfgreader.h"
46 #define DB_CONNECT "dbname=sms"
49 /* Hold main configuration data for smsd */
50 SmsdConfig smsdConfig;
52 /* Global variables */
56 static gchar *connect;
58 static pthread_t db_monitor_th;
59 pthread_mutex_t db_monitorMutex;
60 static volatile bool db_monitor;
62 static void Usage (gchar *p)
64 g_print ("\nUsage: %s [options]\n"
65 " -d, --db DBconnectInfo\n"
70 static void ReadConfig (gint argc, gchar *argv[])
72 connect = g_strdup (DB_CONNECT);
77 static struct option longOptions[] =
82 c = getopt_long (argc, argv, "d:h", longOptions, &optionIndex);
89 connect = g_strdup (optarg);
90 memset (optarg, 'x', strlen (optarg));
100 g_print ("getopt returned 0%o\n", c);
104 if ((argc - optind) != 0)
106 g_print ("Wrong argument number!\n");
111 if (readconfig (&smsdConfig.model, &smsdConfig.port, &smsdConfig.initlength,
112 &smsdConfig.connection, &smsdConfig.bindir) < 0)
115 smsdConfig.smsSets = 0;
120 static void *SendSMS (void *a)
122 if (DB_ConnectOutbox (connect))
130 pthread_mutex_lock (&db_monitorMutex);
133 pthread_mutex_unlock (&db_monitorMutex);
137 pthread_mutex_unlock (&db_monitorMutex);
146 gint WriteSMS (GSM_SMSMessage *sms)
149 PhoneEvent *e = (PhoneEvent *) g_malloc (sizeof (PhoneEvent));
150 D_SMSMessage *m = (D_SMSMessage *) g_malloc (sizeof (D_SMSMessage));
153 e->event = Event_SendSMSMessage;
156 pthread_mutex_lock (&sendSMSMutex);
157 pthread_cond_wait (&sendSMSCond, &sendSMSMutex);
158 pthread_mutex_unlock (&sendSMSMutex);
161 g_print ("Address: %s\nText: %s\n",
173 static void ReadSMS (gpointer d, gpointer userData)
175 GSM_SMSMessage *data = (GSM_SMSMessage *) d;
178 if (data->Type == GST_MT || data->Type == GST_DR)
180 if (data->Type == GST_DR)
183 g_print ("Report\n");
185 e = (PhoneEvent *) g_malloc (sizeof (PhoneEvent));
186 e->event = Event_DeleteSMSMessage;
193 g_print ("%d. %s ", data->Location, data->Sender);
194 g_print ("%02d-%02d-%02d %02d:%02d:%02d+%02d %s\n", data->Time.Year + 2000,
195 data->Time.Month, data->Time.Day, data->Time.Hour,
196 data->Time.Minute, data->Time.Second, data->Time.Timezone,
201 e = (PhoneEvent *) g_malloc (sizeof (PhoneEvent));
202 e->event = Event_DeleteSMSMessage;
210 static void GetSMS (void)
214 pthread_mutex_lock (&smsMutex);
215 pthread_cond_wait (&smsCond, &smsMutex);
217 // Waiting for signal
218 pthread_mutex_unlock (&smsMutex);
221 pthread_mutex_lock (&smsMutex);
222 g_slist_foreach (phoneMonitor.sms.messages, ReadSMS, (gpointer) NULL);
223 pthread_mutex_unlock (&smsMutex);
228 static void MainExit (gint sig)
230 PhoneEvent *e = (PhoneEvent *) g_malloc (sizeof (PhoneEvent));
232 e->event = Event_Exit;
236 pthread_mutex_lock (&db_monitorMutex);
238 pthread_mutex_unlock (&db_monitorMutex);
240 pthread_join (monitor_th, NULL);
241 pthread_join (db_monitor_th, NULL);
247 static void Run (void)
249 struct sigaction act;
251 act.sa_handler = MainExit;
252 sigemptyset (&(act.sa_mask));
254 sigaction (SIGQUIT, &act, NULL);
255 sigaction (SIGTERM, &act, NULL);
256 sigaction (SIGINT, &act, NULL);
259 act.sa_handler = SIG_IGN;
260 sigemptyset (&(act.sa_mask));
261 sigaction (SIGALRM, &act, NULL);
265 if (DB_ConnectInbox (connect))
267 pthread_create (&monitor_th, NULL, Connect, NULL);
269 pthread_mutex_init (&db_monitorMutex, NULL);
270 pthread_create (&db_monitor_th, NULL, SendSMS, NULL);
275 int main (int argc, char *argv[])
278 textdomain("gnokii");
281 ReadConfig (argc, argv);
282 TerminateThread = false;