From 719b507b9faab1cbe1e77f2bf7151878553ee4e1 Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Thu, 14 Aug 2014 17:48:43 +0200 Subject: [PATCH] Partial implementation of time_t in the Python wrapper. --- tools/python/apixml2python.py | 3 -- .../handwritten_declarations.mustache | 2 ++ .../handwritten_definitions.mustache | 33 +++++++++++++++++++ tools/python/apixml2python/linphone.py | 7 ++++ 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/tools/python/apixml2python.py b/tools/python/apixml2python.py index f4c681fe7..9fe7f214c 100755 --- a/tools/python/apixml2python.py +++ b/tools/python/apixml2python.py @@ -40,11 +40,9 @@ blacklisted_events = [ blacklisted_functions = [ 'linphone_call_log_get_local_stats', # missing rtp_stats_t 'linphone_call_log_get_remote_stats', # missing rtp_stats_t - 'linphone_call_log_get_start_date', # missing time_t 'linphone_call_params_get_privacy', # missing LinphonePrivacyMask 'linphone_call_params_set_privacy', # missing LinphonePrivacyMask 'linphone_chat_message_get_file_transfer_information', # missing LinphoneContent - 'linphone_chat_message_get_time', # missing time_t 'linphone_chat_message_start_file_download', # to be handwritten because of callback 'linphone_chat_message_state_to_string', # There is no use to wrap this function 'linphone_chat_room_create_file_transfer_message', # missing LinphoneContent @@ -70,7 +68,6 @@ blacklisted_functions = [ 'linphone_event_send_subscribe', # missing LinphoneContent 'linphone_event_update_publish', # missing LinphoneContent 'linphone_event_update_subscribe', # missing LinphoneContent - 'linphone_presence_model_get_timestamp', # missing time_t 'linphone_proxy_config_get_privacy', # missing LinphonePrivacyMask 'linphone_proxy_config_normalize_number', # to be handwritten because of result via arguments 'linphone_proxy_config_set_file_transfer_server', # defined but not implemented in linphone core diff --git a/tools/python/apixml2python/handwritten_declarations.mustache b/tools/python/apixml2python/handwritten_declarations.mustache index 4a50a848b..eac0ba4b3 100644 --- a/tools/python/apixml2python/handwritten_declarations.mustache +++ b/tools/python/apixml2python/handwritten_declarations.mustache @@ -10,3 +10,5 @@ typedef struct { int PyLinphoneVideoSize_Check(PyObject *p); MSVideoSize PyLinphoneVideoSize_AsMSVideoSize(PyObject *obj); PyObject * PyLinphoneVideoSize_FromMSVideoSize(MSVideoSize vs); +time_t PyDateTime_As_time_t(PyObject *obj); +PyObject * PyDateTime_From_time_t(time_t t); diff --git a/tools/python/apixml2python/handwritten_definitions.mustache b/tools/python/apixml2python/handwritten_definitions.mustache index 41a563687..5a602d515 100644 --- a/tools/python/apixml2python/handwritten_definitions.mustache +++ b/tools/python/apixml2python/handwritten_definitions.mustache @@ -393,6 +393,39 @@ PyObject * PyLinphoneVideoSize_FromMSVideoSize(MSVideoSize vs) { } +time_t PyDateTime_As_time_t(PyObject *obj) { +} + +PyObject * PyDateTime_From_time_t(time_t t) { + PyObject *pyret = NULL; + PyObject *datetime_module; + PyObject *datetime_class; + if (t == -1) { + Py_RETURN_NONE; + } + datetime_module = PyImport_ImportModule("datetime"); + if (datetime_module != NULL) { + PyObject *datetime_class = PyObject_GetAttrString(datetime_module, "datetime"); + if (datetime_class != NULL) { + PyObject *utcfromtimestamp = PyObject_GetAttrString(datetime_class, "utcfromtimestamp"); + if (utcfromtimestamp != NULL) { + pyret = PyEval_CallObject(utcfromtimestamp, Py_BuildValue("(f)", (float)t)); + if (pyret == NULL) { + PyErr_Print(); + } + Py_DECREF(utcfromtimestamp); + } + Py_DECREF(datetime_class); + } + Py_DECREF(datetime_module); + } + if (pyret == NULL) { + Py_RETURN_NONE; + } + return pyret; +} + + static PyObject * pylinphone_PayloadTypeType_module_method_string(PyObject *self, PyObject *args) { const char *value_str = "[invalid]"; int value; diff --git a/tools/python/apixml2python/linphone.py b/tools/python/apixml2python/linphone.py index 109f6f5b2..a7b1f21b0 100644 --- a/tools/python/apixml2python/linphone.py +++ b/tools/python/apixml2python/linphone.py @@ -139,6 +139,13 @@ class ArgumentType: self.convert_func = 'PyInt_AsLong' self.fmt_str = 'i' self.cfmt_str = '%d' + elif self.basic_type == 'time_t': + self.type_str = 'DateTime' + self.check_func = 'PyDateTime_Check' + self.convert_func = 'PyDateTime_As_time_t' + self.convert_from_func = 'PyDateTime_From_time_t' + self.fmt_str = 'O' + self.cfmt_str = '%p' elif self.basic_type == 'MSList': self.type_str = 'list of linphone.' + self.contained_type self.check_func = 'PyList_Check'