Fix CallStatus signal with libfsointerface
[gsmd2.git] / test / pyfreesmartphonesim.pxi
blob1ebb91bc27809539fb28630323e43a435f130faf
2 # SIM cdefs
4 cdef extern from "../libfreesmartphone/freesmartphone-sim.h":
5     ctypedef void (*FSGSMSIMGetAuthStatusReplyFunc) (gchar *status,
6                                                 GError *error,
7                                                 gpointer userdata )
8     ctypedef void (*FSGSMSIMReplyFunc) (GError *error,
9                                    gpointer userdata )
10     ctypedef void (*FSGSMSIMGetImsiReplyFunc) (gchar *imsi,
11                                           GError *error,
12                                           gpointer userdata )
13     gboolean fso_gsm_sim_get_imsi(FreeSmartphone *fs,
14                               FSGSMSIMGetImsiReplyFunc cb,
15                               gpointer userdata)
16     gboolean fso_gsm_sim_change_auth_code(FreeSmartphone *fs,
17                                       gchar *old_pin,
18                                       gchar *new_pin,
19                                       FSGSMSIMReplyFunc cb,
20                                       gpointer userdata)
21     gboolean fso_gsm_sim_unlock(FreeSmartphone *fs,
22                             gchar *puk,
23                             gchar *new_pin,
24                             FSGSMSIMReplyFunc cb,
25                             gpointer userdata)
26     gboolean fso_gsm_sim_send_auth_code(FreeSmartphone *fs,
27                                     gchar *pin,
28                                     FSGSMSIMReplyFunc cb,
29                                     gpointer userdata)
30     gboolean fso_gsm_sim_get_auth_status(FreeSmartphone *fs,
31                                      FSGSMSIMGetAuthStatusReplyFunc cb,
32                                      gpointer userdata)
33     ctypedef void (*FSGSMSIMAuthStatusSignalFunc) (gchar *status,
34                                               gpointer userdata)
35     gboolean fso_gsm_sim_auth_status_signal_remove(FreeSmartphone *fs,
36                                                FSGSMSIMAuthStatusSignalFunc cb,
37                                                gpointer userdata)
38     gboolean fso_gsm_sim_auth_status_signal(FreeSmartphone *fs,
39                                         FSGSMSIMAuthStatusSignalFunc cb,
40                                         gpointer userdata)
43 # SIM Handlers
46 cdef void auth_status_signal(gchar *status, gpointer userdata) with gil:
47     print "SIM auth status signal"
48     reply = <object>userdata
49     reply_cb = reply.get_cb()
50     reply_data = reply.get_data()
51     status_str = PyString_FromStringAndSize(status, strlen(status))
52     reply_cb(reply_data, id, status_str)
55 # PyFreeSmartPhoneSIM class
58 cdef class PyFreeSmartphoneSIM:
59     cdef FreeSmartphone *fs
61     cdef object auth_status
63     def __new__(self):
64         self.fs = fso_init()
65     def deinitialize(self):
66         fso_free(self.fs)
68     def auth_status_signal(self, cb,data=None):
69         self.auth_status = ReplyData(cb,data)
70         Py_INCREF(self.auth_status)
71         return fso_gsm_sim_auth_status_signal(self.fs, &auth_status_signal, <void*>self.auth_status)
73     def auth_status_signal_remove(self):
74         fso_gsm_sim_auth_status_signal_remove(self.fs, &auth_status_signal, <void*>self.auth_status)
75         Py_DECREF(self.auth_status)