add code to register for CB message callback 24/111024/2
authorKyeonghun Lee <kh9090.lee@samsung.com>
Thu, 19 Jan 2017 07:40:01 +0000 (16:40 +0900)
committerKyeonghun Lee <kh9090.lee@samsung.com>
Thu, 19 Jan 2017 10:59:37 +0000 (19:59 +0900)
Change-Id: I287eed7965fd1a032d246e36be1ec32da39c398c
Signed-off-by: Kyeonghun Lee <kh9090.lee@samsung.com>
src/messages.c

index 663a585..15e3a1a 100644 (file)
@@ -805,6 +805,30 @@ void _messages_incoming_mediator_cb(msg_handle_t handle, msg_struct_t msg, void
                free(_msg);
        }
 }
+
+void _messages_incoming_cb_mediator_cb(msg_handle_t handle, msg_struct_t msg, void *user_param)
+{
+       messages_message_h _msg = NULL;
+       messages_service_s *_svc = (messages_service_s *) user_param;
+
+       if (NULL == _svc)
+               return;
+
+       int msg_id = 0;
+       msg_get_int_value(msg, MSG_CB_MSG_INTERNAL_MSG_ID_INT, &msg_id);
+
+       if (msg_id > 0 && _svc->incoming_cb_enabled && _svc->incoming_cb != NULL) {
+               messages_search_message_by_id((messages_service_h)_svc, msg_id, &_msg);
+               if (NULL == _msg) {
+                       LOGE("[%s] OUT_OF_MEMORY(0x%08x) fail to create '_msg'.", __FUNCTION__, MESSAGES_ERROR_OUT_OF_MEMORY);
+                       return;
+               }
+
+               ((messages_incoming_cb) _svc->incoming_cb) (_msg, _svc->incoming_cb_user_data);
+
+               messages_destroy_message(_msg);
+       }
+}
 //LCOV_EXCL_STOP
 
 int messages_set_message_incoming_cb(messages_service_h svc, messages_incoming_cb callback, void *user_data)
@@ -824,6 +848,11 @@ int messages_set_message_incoming_cb(messages_service_h svc, messages_incoming_c
                if (MESSAGES_ERROR_NONE != ret)
                        return ret;
 
+               ret = ERROR_CONVERT(msg_reg_cb_message_callback(_svc->service_h, &_messages_incoming_cb_mediator_cb, true, (void *)_svc)
+                       );
+               if (MESSAGES_ERROR_NONE != ret)
+                       return ret;
+
                if (MESSAGES_ERROR_NONE == _messages_check_feature(MESSAGES_TELEPHONY_MMS_FEATURE)) {
                        ret = ERROR_CONVERT(msg_reg_mms_conf_message_callback(_svc->service_h, &_messages_incoming_mediator_cb, NULL, (void *)_svc)
                                );