OSDN Git Service

add wakelock control callback
authorDmitry Grinberg <dmitrygr@google.com>
Wed, 21 May 2014 23:27:50 +0000 (16:27 -0700)
committerDmitry Grinberg <dmitrygr@google.com>
Fri, 23 May 2014 17:15:25 +0000 (10:15 -0700)
Change-Id: Iffa8f33767a037fceb4757cdff07f25f30acf453

btif/src/bluetooth.c
gki/ulinux/gki_ulinux.c

index 44644de..f6c2f48 100755 (executable)
@@ -68,6 +68,8 @@ bt_callbacks_t *bt_hal_cbacks = NULL;
 **  Externs
 ************************************************************************************/
 
+extern bt_wakelock_callback config_wakelock_callback;
+
 /* list all extended interfaces here */
 
 /* handsfree profile */
@@ -119,6 +121,7 @@ static int init(bt_callbacks_t* callbacks )
 
     /* store reference to user callbacks */
     bt_hal_cbacks = callbacks;
+    config_wakelock_callback = callbacks->bt_wakelock_cb;
 
     /* add checks for individual callbacks ? */
 
index d03eb05..a66a32f 100755 (executable)
@@ -29,6 +29,7 @@
 #include <stdarg.h>
 #include <errno.h>
 #include <sys/times.h>
+#include <hardware/bluetooth.h>
 
 #include <pthread.h>  /* must be 1st header defined  */
 #include <time.h>
@@ -74,8 +75,6 @@
 #define UNLOCK(m) pthread_mutex_unlock(&m)
 #define INIT(m) pthread_mutex_init(&m, NULL)
 
-#define WAKE_LOCK_ID "brcm_btld"
-#define PARTIAL_WAKE_LOCK 1
 
 #if GKI_DYNAMIC_MEMORY == FALSE
 tGKI_CB   gki_cb;
@@ -113,6 +112,7 @@ typedef struct
 
 int g_GkiTimerWakeLockOn = 0;
 gki_pthread_info_t gki_pthread_info[GKI_MAX_TASKS];
+bt_wakelock_callback config_wakelock_callback = NULL;
 
 /*****************************************************************************
 **  Static functions
@@ -122,13 +122,33 @@ gki_pthread_info_t gki_pthread_info[GKI_MAX_TASKS];
 **  Externs
 ******************************************************************************/
 
-extern int acquire_wake_lock(int lock, const char* id);
-extern int release_wake_lock(const char* id);
+
 
 /*****************************************************************************
 **  Functions
 ******************************************************************************/
 
+/* send a given byte into the wakelock pipe */
+static void wakelock_op_gki(unsigned char op)
+{
+    if (!config_wakelock_callback)
+        GKI_ERROR_LOG("Cannot perform wakelock operation with no callback\n");
+    else
+        config_wakelock_callback(op);
+}
+
+/* release a wakelock by sending a zero down the pipe */
+static void release_wake_lock_gki(void)
+{
+    wakelock_op_gki(0);
+}
+
+/* acquire a wakelock by sending a one down the pipe */
+static void acquire_wake_lock_gki(void)
+{
+    wakelock_op_gki(1);
+}
+
 
 /*****************************************************************************
 **
@@ -527,8 +547,8 @@ void GKI_shutdown(void)
 #endif
     if (g_GkiTimerWakeLockOn)
     {
-        GKI_TRACE("GKI_shutdown :  release_wake_lock(brcm_btld)");
-        release_wake_lock(WAKE_LOCK_ID);
+        GKI_TRACE("GKI_shutdown :  release_wake_lock_gki()");
+        release_wake_lock_gki();
         g_GkiTimerWakeLockOn = 0;
     }
 }
@@ -569,14 +589,14 @@ void gki_system_tick_start_stop_cback(BOOLEAN start)
 
             GKI_TIMER_TRACE(">>> STOP GKI_timer_update(), wake_lock_count:%d", --wake_lock_count);
 
-            release_wake_lock(WAKE_LOCK_ID);
+            release_wake_lock_gki();
             g_GkiTimerWakeLockOn = 0;
         }
     }
     else
     {
         /* restart GKI_timer_update() loop */
-        acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_ID);
+        acquire_wake_lock_gki();
 
         g_GkiTimerWakeLockOn = 1;
         *p_run_cond = GKI_TIMER_TICK_RUN_COND;