Add the status check logic for BT enable / disable method
[platform/core/connectivity/bluetooth-frwk.git] / bt-api / bt-rfcomm-client.c
index 4c0b4c9..99ad52a 100644 (file)
@@ -323,7 +323,7 @@ static gboolean __client_data_received_cb(GIOChannel *chan, GIOCondition cond,
        GIOStatus status = G_IO_STATUS_NORMAL;
        GError *err = NULL;
        int fd;
-       BT_DBG("");
+       BT_DBG("+");
 
        retv_if(info == NULL, FALSE);
        fd = g_io_channel_unix_get_fd(chan);
@@ -391,7 +391,14 @@ static gboolean __client_data_received_cb(GIOChannel *chan, GIOCondition cond,
                        result, &data_r,
                        event_info->cb, event_info->user_data);
 
+       if (bluetooth_get_battery_monitor_state()) {
+               int ret = _bt_common_send_rfcomm_rx_details(&data_r);
+               if (ret != BLUETOOTH_ERROR_NONE)
+                       BT_ERR("RFCOMM received data details not sent to battery monitor frwk");
+       }
+
        g_free(buffer);
+       BT_DBG("-");
        return TRUE;
 }
 
@@ -1287,7 +1294,7 @@ BT_EXPORT_API int bluetooth_rfcomm_disconnect(int socket_fd)
 #else
 static int __write_all(int fd, const char *buf, int len)
 {
-       int sent = 0;
+       int sent = 0, try = 0;
 
        BT_DBG("+");
        while (len > 0) {
@@ -1296,8 +1303,11 @@ static int __write_all(int fd, const char *buf, int len)
                written = write(fd, buf, len);
                BT_DBG("written: %d", written);
                if (written < 0) {
-                       if (errno == EINTR || errno == EAGAIN)
-                               continue;
+                       if (errno == EINTR || errno == EAGAIN) {
+                               try++;
+                               if (try <= 49)
+                                       continue;
+                       }
                        return -1;
                }
 
@@ -1307,6 +1317,7 @@ static int __write_all(int fd, const char *buf, int len)
                len -= written;
                buf += written;
                sent += written;
+               try = 0;
        }
 
        BT_DBG("-");
@@ -1358,6 +1369,12 @@ BT_EXPORT_API int bluetooth_rfcomm_write(int fd, const char *buf, int length)
                return BLUETOOTH_ERROR_INTERNAL;
        }
 
+       if (bluetooth_get_battery_monitor_state()) {
+               int ret = _bt_common_send_rfcomm_tx_details(length);
+               if (ret != BLUETOOTH_ERROR_NONE)
+                       BT_ERR("RFCOMM tx data could not be sent");
+       }
+
 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
        written = write(fd, buf, length);
        /*BT_DBG("Length %d, written = %d, balance(%d)",