gnokii-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

remove gn_sm_loop from API


From: Ladislav Michl
Subject: remove gn_sm_loop from API
Date: Wed, 9 Apr 2003 15:49:32 +0200
User-agent: Mutt/1.5.4i

Hi,

i'd like to discuss following issue before 0.5

it seems everyone agree that we need some kind of asynchronous library
and it also seems that most people hate threads in libgnokii. so it is
user application which is supposed to call libgnokii functions from
separate (communication) thread. currently there is no mechanism how to
found which incoming frame was actually received (some phones are able
to notify about incoming call, sms, etc...). pseudocode should look like
this:

while (!app_terminated) {
        /* returns GN_OP_Idle when queue is empty */
        op = app_pop_queue();
        error = gn_functions(op, &data, &state);
        /* ... handle error here */
        switch (data.lastop) {
                case GN_OP_IncomingCall:

                ...
                
        }
}

so i killed gn_sm_loop from API and added GN_OP_Idle to gn_functions.
this is only proposal and i'd like to discuss whether it makes sense for
you... patch which implements this interface is bellow, there will be
much more hacking needed to get it fully functional.


Index: common/gsm-statemachine.c
===================================================================
RCS file: /cvsroot/gnokii/gnokii/common/gsm-statemachine.c,v
retrieving revision 1.48
diff -u -r1.48 gsm-statemachine.c
--- common/gsm-statemachine.c   31 Mar 2003 08:46:01 -0000      1.48
+++ common/gsm-statemachine.c   9 Apr 2003 13:22:24 -0000
@@ -57,7 +57,7 @@
        else return GN_ERR_NOTREADY;
 }
 
-API gn_state gn_sm_loop(int timeout, struct gn_statemachine *state)
+gn_state gn_sm_loop(int timeout, struct gn_statemachine *state)
 {
        struct timeval loop_timeout;
        int i;
@@ -293,6 +293,14 @@
        if (!sm->driver.functions) {
                dprintf("Sorry, phone has not yet been converted to new style. 
Phone.Functions == NULL!\n");
                return GN_ERR_INTERNALERROR;
+       }
+       /*
+        * This is ungly hack to remove gn_sm_loop from API before 0.5 release
+        */
+       data->lastop = op;
+       if (op == GN_OP_Idle) {
+               gn_sm_loop(1, sm);
+               return GN_ERR_NONE;
        }
        return sm->driver.functions(op, data, sm);
 }
Index: include/gnokii-internal.h
===================================================================
RCS file: /cvsroot/gnokii/gnokii/include/gnokii-internal.h,v
retrieving revision 1.11
diff -u -r1.11 gnokii-internal.h
--- include/gnokii-internal.h   6 Mar 2003 21:29:04 -0000       1.11
+++ include/gnokii-internal.h   9 Apr 2003 13:22:24 -0000
@@ -49,6 +49,7 @@
 void sm_incoming_function(u8 messagetype, void *message, u16 messagesize, 
struct gn_statemachine *state);
 void sm_incoming_acknowledge(struct gn_statemachine *state);
 void sm_reset(struct gn_statemachine *state);
+gn_state gn_sm_loop(int timeout, struct gn_statemachine *state);
 gn_error sm_error_get(unsigned char messagetype, struct gn_statemachine 
*state);
 gn_error sm_block_timeout(int waitfor, int t, gn_data *data, struct 
gn_statemachine *state);
 gn_error sm_block(int waitfor, gn_data *data, struct gn_statemachine *state);
Index: include/gnokii/data.h.in
===================================================================
RCS file: /cvsroot/gnokii/gnokii/include/gnokii/data.h.in,v
retrieving revision 1.64
diff -u -r1.64 data.h.in
--- include/gnokii/data.h.in    9 Apr 2003 08:35:40 -0000       1.64
+++ include/gnokii/data.h.in    9 Apr 2003 13:22:24 -0000
@@ -39,6 +39,93 @@
 #  include <bluetooth/bluetooth.h>
 #endif
 
+typedef enum {
+       GN_OP_Init,
+       GN_OP_Terminate,
+       GN_OP_GetModel,
+       GN_OP_GetRevision,
+       GN_OP_GetImei,
+       GN_OP_GetManufacturer,
+       GN_OP_Identify,
+       GN_OP_GetBitmap,
+       GN_OP_SetBitmap,
+       GN_OP_GetBatteryLevel,
+       GN_OP_GetRFLevel,
+       GN_OP_DisplayOutput,
+       GN_OP_GetMemoryStatus,
+       GN_OP_ReadPhonebook,
+       GN_OP_WritePhonebook,
+       GN_OP_GetPowersource,
+       GN_OP_GetAlarm,
+       GN_OP_GetSMSStatus,
+       GN_OP_GetIncomingCallNr,
+       GN_OP_GetNetworkInfo,
+       GN_OP_GetSecurityCode,
+       GN_OP_CreateSMSFolder,
+       GN_OP_DeleteSMSFolder,
+       GN_OP_GetSMS,
+       GN_OP_GetSMSnoValidate,
+       GN_OP_GetSMSFolders,
+       GN_OP_GetSMSFolderStatus,
+       GN_OP_GetIncomingSMS,
+       GN_OP_GetUnreadMessages,
+       GN_OP_GetNextSMS,
+       GN_OP_DeleteSMSnoValidate,
+       GN_OP_DeleteSMS,
+       GN_OP_SendSMS,
+       GN_OP_GetSpeedDial,
+       GN_OP_GetSMSCenter,
+       GN_OP_SetSMSCenter,
+       GN_OP_GetDateTime,
+       GN_OP_GetToDo,
+       GN_OP_GetCalendarNote,
+       GN_OP_CallDivert,
+       GN_OP_OnSMS,
+       GN_OP_PollSMS,
+       GN_OP_SetAlarm,
+       GN_OP_SetDateTime,
+       GN_OP_GetProfile,
+       GN_OP_SetProfile,
+       GN_OP_WriteToDo,
+       GN_OP_DeleteAllToDos,
+       GN_OP_WriteCalendarNote,
+       GN_OP_DeleteCalendarNote,
+       GN_OP_SetSpeedDial,
+       GN_OP_GetDisplayStatus,
+       GN_OP_PollDisplay,
+       GN_OP_SaveSMS,
+       GN_OP_SetCellBroadcast,
+       GN_OP_NetMonitor,
+       GN_OP_MakeCall,
+       GN_OP_AnswerCall,
+       GN_OP_CancelCall,
+       GN_OP_SetCallNotification,
+       GN_OP_SendRLPFrame,
+       GN_OP_SetRLPRXCallback,
+       GN_OP_EnterSecurityCode,
+       GN_OP_GetSecurityCodeStatus,
+       GN_OP_ChangeSecurityCode,
+       GN_OP_SendDTMF,
+       GN_OP_Reset,
+       GN_OP_GetRingtone,
+       GN_OP_SetRingtone,
+       GN_OP_GetRawRingtone,
+       GN_OP_SetRawRingtone,
+       GN_OP_PressPhoneKey,
+       GN_OP_ReleasePhoneKey,
+       GN_OP_EnterChar,
+       GN_OP_Subscribe,
+       GN_OP_GetWAPBookmark,
+       GN_OP_WriteWAPBookmark,
+       GN_OP_DeleteWAPBookmark,
+       GN_OP_GetWAPSetting,
+       GN_OP_ActivateWAPSetting,
+       GN_OP_WriteWAPSetting,
+       GN_OP_GetLocksInfo,
+       GN_OP_Idle,
+       GN_OP_Max,      /* don't append anything after this entry */
+} gn_operation;
+
 /* For models table */
 typedef struct {
        char *model;
@@ -48,6 +135,7 @@
 
 /* This is a generic holder for high level information - eg a gn_bmp */
 typedef struct {
+       gn_operation lastop;
        gn_sms_folder *sms_folder;
        gn_sms_folder_list *sms_folder_list;
        gn_sms_raw *raw_sms;         /* This is for phone driver, application 
using libgnokii should not touch this */
@@ -141,92 +229,6 @@
        gn_connection_type type;
        void *device_instance;
 } gn_device;
-
-typedef enum {
-       GN_OP_Init,
-       GN_OP_Terminate,
-       GN_OP_GetModel,
-       GN_OP_GetRevision,
-       GN_OP_GetImei,
-       GN_OP_GetManufacturer,
-       GN_OP_Identify,
-       GN_OP_GetBitmap,
-       GN_OP_SetBitmap,
-       GN_OP_GetBatteryLevel,
-       GN_OP_GetRFLevel,
-       GN_OP_DisplayOutput,
-       GN_OP_GetMemoryStatus,
-       GN_OP_ReadPhonebook,
-       GN_OP_WritePhonebook,
-       GN_OP_GetPowersource,
-       GN_OP_GetAlarm,
-       GN_OP_GetSMSStatus,
-       GN_OP_GetIncomingCallNr,
-       GN_OP_GetNetworkInfo,
-       GN_OP_GetSecurityCode,
-       GN_OP_CreateSMSFolder,
-       GN_OP_DeleteSMSFolder,
-       GN_OP_GetSMS,
-       GN_OP_GetSMSnoValidate,
-       GN_OP_GetSMSFolders,
-       GN_OP_GetSMSFolderStatus,
-       GN_OP_GetIncomingSMS,
-       GN_OP_GetUnreadMessages,
-       GN_OP_GetNextSMS,
-       GN_OP_DeleteSMSnoValidate,
-       GN_OP_DeleteSMS,
-       GN_OP_SendSMS,
-       GN_OP_GetSpeedDial,
-       GN_OP_GetSMSCenter,
-       GN_OP_SetSMSCenter,
-       GN_OP_GetDateTime,
-       GN_OP_GetToDo,
-       GN_OP_GetCalendarNote,
-       GN_OP_CallDivert,
-       GN_OP_OnSMS,
-       GN_OP_PollSMS,
-       GN_OP_SetAlarm,
-       GN_OP_SetDateTime,
-       GN_OP_GetProfile,
-       GN_OP_SetProfile,
-       GN_OP_WriteToDo,
-       GN_OP_DeleteAllToDos,
-       GN_OP_WriteCalendarNote,
-       GN_OP_DeleteCalendarNote,
-       GN_OP_SetSpeedDial,
-       GN_OP_GetDisplayStatus,
-       GN_OP_PollDisplay,
-       GN_OP_SaveSMS,
-       GN_OP_SetCellBroadcast,
-       GN_OP_NetMonitor,
-       GN_OP_MakeCall,
-       GN_OP_AnswerCall,
-       GN_OP_CancelCall,
-       GN_OP_SetCallNotification,
-       GN_OP_SendRLPFrame,
-       GN_OP_SetRLPRXCallback,
-       GN_OP_EnterSecurityCode,
-       GN_OP_GetSecurityCodeStatus,
-       GN_OP_ChangeSecurityCode,
-       GN_OP_SendDTMF,
-       GN_OP_Reset,
-       GN_OP_GetRingtone,
-       GN_OP_SetRingtone,
-       GN_OP_GetRawRingtone,
-       GN_OP_SetRawRingtone,
-       GN_OP_PressPhoneKey,
-       GN_OP_ReleasePhoneKey,
-       GN_OP_EnterChar,
-       GN_OP_Subscribe,
-       GN_OP_GetWAPBookmark,
-       GN_OP_WriteWAPBookmark,
-       GN_OP_DeleteWAPBookmark,
-       GN_OP_GetWAPSetting,
-       GN_OP_ActivateWAPSetting,
-       GN_OP_WriteWAPSetting,
-       GN_OP_GetLocksInfo,
-       GN_OP_Max,      /* don't append anything after this entry */
-} gn_operation;
 
 /* Undefined functions in fbus/mbus files */
 extern gn_error gn_unimplemented(void);
Index: include/gnokii/statemachine.h
===================================================================
RCS file: /cvsroot/gnokii/gnokii/include/gnokii/statemachine.h,v
retrieving revision 1.17
diff -u -r1.17 statemachine.h
--- include/gnokii/statemachine.h       6 Mar 2003 22:32:29 -0000       1.17
+++ include/gnokii/statemachine.h       9 Apr 2003 13:22:24 -0000
@@ -87,7 +87,6 @@
        gn_data *data[GN_SM_WAITINGFOR_MAX_NUMBER];
 };
 
-API gn_state gn_sm_loop(int timeout, struct gn_statemachine *state);
 API gn_error gn_sm_functions(gn_operation op, gn_data *data, struct 
gn_statemachine *sm);
 
 #endif /* _gnokii_statemachine_h */
Index: gnokii/gnokii.c
===================================================================
RCS file: /cvsroot/gnokii/gnokii/gnokii/gnokii.c,v
retrieving revision 1.343
diff -u -r1.343 gnokii.c
--- gnokii/gnokii.c     6 Mar 2003 21:58:00 -0000       1.343
+++ gnokii/gnokii.c     9 Apr 2003 13:22:24 -0000
@@ -2755,7 +2755,7 @@
                                */
                                memset(buf, 0, 102);
                        }
-                       gn_sm_loop(1, &state);
+                       gn_sm_functions(GN_OP_Idle, &data, &state);
                        gn_sm_functions(GN_OP_PollDisplay, &data, &state);
                }
                fprintf (stderr, _("Shutting down\n"));
@@ -4223,7 +4223,7 @@
                fprintf(stderr, _("Entered sms reader mode...\n"));
 
                while (!bshutdown) {
-                       gn_sm_loop(1, &state);
+                       gn_sm_functions(GN_OP_Idle, &data, &state);
                        /* Some phones may not be able to notify us, thus we 
give
                           lowlevel chance to poll them */
                        error = gn_sm_functions(GN_OP_PollSMS, &data, &state);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]