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 "phones/nk7110.h"
40 #include "phones/nk6100.h"
41 #include "phones/nk3110.h"
42 #include "phones/nk2110.h"
43 #include "cfgreader.h"
48 #define DB_CONNECT "dbname=sms"
51 /* Hold main configuration data for smsd */
52 SmsdConfig smsdConfig;
54 /* Global variables */
58 static gchar *connect;
60 static pthread_t db_monitor_th;
61 pthread_mutex_t db_monitorMutex;
62 static volatile bool db_monitor;
64 static void Usage (gchar *p)
66 g_print ("\nUsage: %s [options]\n"
67 " -d, --db DBconnectInfo\n"
72 static void ReadConfig (gint argc, gchar *argv[])
74 connect = g_strdup (DB_CONNECT);
79 static struct option longOptions[] =
84 c = getopt_long (argc, argv, "d:h", longOptions, &optionIndex);
91 connect = g_strdup (optarg);
92 memset (optarg, 'x', strlen (optarg));
102 g_print ("getopt returned 0%o\n", c);
106 if ((argc - optind) != 0)
108 g_print ("Wrong argument number!\n");
113 if (readconfig (&smsdConfig.model, &smsdConfig.port, &smsdConfig.initlength,
114 &smsdConfig.connection, &smsdConfig.bindir) < 0)
117 smsdConfig.smsSets = 0;
122 static void *SendSMS (void *a)
124 if (DB_ConnectOutbox (connect))
132 pthread_mutex_lock (&db_monitorMutex);
135 pthread_mutex_unlock (&db_monitorMutex);
139 pthread_mutex_unlock (&db_monitorMutex);
148 gint WriteSMS (GSM_SMSMessage *sms)
151 PhoneEvent *e = (PhoneEvent *) g_malloc (sizeof (PhoneEvent));
152 D_SMSMessage *m = (D_SMSMessage *) g_malloc (sizeof (D_SMSMessage));
155 e->event = Event_SendSMSMessage;
158 pthread_mutex_lock (&sendSMSMutex);
159 pthread_cond_wait (&sendSMSCond, &sendSMSMutex);
160 pthread_mutex_unlock (&sendSMSMutex);
163 g_print ("Address: %s\nText: %s\n",
175 static void ReadSMS (gpointer d, gpointer userData)
177 GSM_SMSMessage *data = (GSM_SMSMessage *) d;
180 if (data->Type == SMS_Deliver || data->Type == SMS_Delivery_Report)
182 if (data->Type == SMS_Delivery_Report)
185 g_print ("Report\n");
187 e = (PhoneEvent *) g_malloc (sizeof (PhoneEvent));
188 e->event = Event_DeleteSMSMessage;
195 g_print ("%d. %s ", data->Location, data->Sender);
196 g_print ("%02d-%02d-%02d %02d:%02d:%02d+%02d %s\n", data->Time.Year + 2000,
197 data->Time.Month, data->Time.Day, data->Time.Hour,
198 data->Time.Minute, data->Time.Second, data->Time.Timezone,
203 e = (PhoneEvent *) g_malloc (sizeof (PhoneEvent));
204 e->event = Event_DeleteSMSMessage;
212 static void GetSMS (void)
216 pthread_mutex_lock (&smsMutex);
217 pthread_cond_wait (&smsCond, &smsMutex);
219 // Waiting for signal
220 pthread_mutex_unlock (&smsMutex);
223 pthread_mutex_lock (&smsMutex);
224 g_slist_foreach (phoneMonitor.sms.messages, ReadSMS, (gpointer) NULL);
225 pthread_mutex_unlock (&smsMutex);
230 static void MainExit (gint sig)
232 PhoneEvent *e = (PhoneEvent *) g_malloc (sizeof (PhoneEvent));
234 e->event = Event_Exit;
238 pthread_mutex_lock (&db_monitorMutex);
240 pthread_mutex_unlock (&db_monitorMutex);
242 pthread_join (monitor_th, NULL);
243 pthread_join (db_monitor_th, NULL);
249 static void Run (void)
251 struct sigaction act;
253 act.sa_handler = MainExit;
254 sigemptyset (&(act.sa_mask));
256 sigaction (SIGQUIT, &act, NULL);
257 sigaction (SIGTERM, &act, NULL);
258 sigaction (SIGINT, &act, NULL);
261 act.sa_handler = SIG_IGN;
262 sigemptyset (&(act.sa_mask));
263 sigaction (SIGALRM, &act, NULL);
267 if (DB_ConnectInbox (connect))
269 pthread_create (&monitor_th, NULL, Connect, NULL);
271 pthread_mutex_init (&db_monitorMutex, NULL);
272 pthread_create (&db_monitor_th, NULL, SendSMS, NULL);
277 int main (int argc, char *argv[])
280 textdomain("gnokii");
283 ReadConfig (argc, argv);
284 TerminateThread = false;