Fix indent
[platform/upstream/pulseaudio.git] / src / modules / module-suspend-on-idle.c
index 8350917..886fcd1 100644 (file)
 #include <errno.h>
 #include <linux/limits.h>
 
-#define SOCK_PATH                      "/tmp/pm_sock"
-#define SHIFT_UNLOCK                   4
-#define SHIFT_UNLOCK_PARAMETER         12
-#define SHIFT_CHANGE_STATE             8
-#define SHIFT_HOLD_KEY_BLOCK           16
-#define SHIFT_CHANGE_TIMEOUT           20
-#define TIMEOUT_RESET_BIT              0x80
+#define SOCK_PATH               "/tmp/pm_sock"
+#define SHIFT_UNLOCK            4
+#define SHIFT_UNLOCK_PARAMETER  12
+#define SHIFT_CHANGE_STATE      8
+#define SHIFT_HOLD_KEY_BLOCK    16
+#define SHIFT_CHANGE_TIMEOUT    20
+#define TIMEOUT_RESET_BIT       0x80
 
 #define LCD_NORMAL      0x1   /**< NORMAL state */
 #define LCD_DIM         0x2  /**< LCD dimming state */
 #define PM_KEEP_TIMER   0x2     /**< keep timer for unlock */
 
 struct pwr_msg {
-       pid_t pid;
-       unsigned int cond;
-       unsigned int timeout;
-       unsigned int timeout2;
+    pid_t pid;
+    unsigned int cond;
+    unsigned int timeout;
+    unsigned int timeout2;
 };
 
 #endif /* USE_PM_LOCK */
@@ -94,11 +94,11 @@ static const char* const valid_modargs[] = {
 };
 
 #ifdef USE_PM_LOCK
-#define PM_TYPE_SINK   0x01
-#define PM_TYPE_SOURCE 0x02
+#define PM_TYPE_SINK    0x01
+#define PM_TYPE_SOURCE  0x02
 
-#define UPDATE_PM_LOCK(current,type)   (current |= type)
-#define UPDATE_PM_UNLOCK(current,type) (current &= ~type)
+#define UPDATE_PM_LOCK(current,type)    (current |= type)
+#define UPDATE_PM_UNLOCK(current,type)  (current &= ~type)
 #endif /* USE_PM_LOCK */
 struct userdata {
     pa_core *core;
@@ -140,68 +140,68 @@ struct device_info {
 
 static int send_msg(unsigned int s_bits, unsigned int timeout, unsigned int timeout2)
 {
-       int rc = 0;
-       int sock;
-       struct pwr_msg p;
-       struct sockaddr_un remote;
-
-       p.pid = getpid();
-       p.cond = s_bits;
-       p.timeout = timeout;
-       p.timeout2 = timeout2;
-
-       sock = socket(AF_UNIX, SOCK_DGRAM, 0);
-       if (sock == -1) {
-               return -1;
-       }
-
-       remote.sun_family = AF_UNIX;
-       if(strlen(SOCK_PATH) >= sizeof(remote.sun_path)) {
-               return -1;
-       }
-       strncpy(remote.sun_path, SOCK_PATH, sizeof(remote.sun_path));
-
-       rc = sendto(sock, (void *)&p, sizeof(p), 0, (struct sockaddr *)&remote,
-                   sizeof(struct sockaddr_un));
-
-       close(sock);
-       return rc;
+    int rc = 0;
+    int sock;
+    struct pwr_msg p;
+    struct sockaddr_un remote;
+
+    p.pid = getpid();
+    p.cond = s_bits;
+    p.timeout = timeout;
+    p.timeout2 = timeout2;
+
+    sock = socket(AF_UNIX, SOCK_DGRAM, 0);
+    if (sock == -1) {
+        return -1;
+    }
+
+    remote.sun_family = AF_UNIX;
+    if(strlen(SOCK_PATH) >= sizeof(remote.sun_path)) {
+        return -1;
+    }
+    strncpy(remote.sun_path, SOCK_PATH, sizeof(remote.sun_path));
+
+    rc = sendto(sock, (void *)&p, sizeof(p), 0, (struct sockaddr *)&remote,
+            sizeof(struct sockaddr_un));
+
+    close(sock);
+    return rc;
 }
 
 static int pm_lock_state(unsigned int s_bits, unsigned int flag,
-                     unsigned int timeout)
+                unsigned int timeout)
 {
-       switch (s_bits) {
-       case LCD_NORMAL:
-       case LCD_DIM:
-       case LCD_OFF:
-               break;
-       default:
-               return -1;
-       }
-       if (flag & GOTO_STATE_NOW)
-               /* if the flag is true, go to the locking state directly */
-               s_bits = s_bits | (s_bits << SHIFT_CHANGE_STATE);
-       if (flag & HOLD_KEY_BLOCK)
-               s_bits = s_bits | (1 << SHIFT_HOLD_KEY_BLOCK);
-
-       return send_msg(s_bits, timeout, 0);
+    switch (s_bits) {
+    case LCD_NORMAL:
+    case LCD_DIM:
+    case LCD_OFF:
+        break;
+    default:
+        return -1;
+    }
+    if (flag & GOTO_STATE_NOW)
+        /* if the flag is true, go to the locking state directly */
+        s_bits = s_bits | (s_bits << SHIFT_CHANGE_STATE);
+    if (flag & HOLD_KEY_BLOCK)
+        s_bits = s_bits | (1 << SHIFT_HOLD_KEY_BLOCK);
+
+    return send_msg(s_bits, timeout, 0);
 }
 
 static int pm_unlock_state(unsigned int s_bits, unsigned int flag)
 {
-       switch (s_bits) {
-       case LCD_NORMAL:
-       case LCD_DIM:
-       case LCD_OFF:
-               break;
-       default:
-               return -1;
-       }
-
-       s_bits = (s_bits << SHIFT_UNLOCK);
-       s_bits = (s_bits | (flag << SHIFT_UNLOCK_PARAMETER));
-       return send_msg(s_bits, 0, 0);
+    switch (s_bits) {
+    case LCD_NORMAL:
+    case LCD_DIM:
+    case LCD_OFF:
+        break;
+    default:
+        return -1;
+    }
+
+    s_bits = (s_bits << SHIFT_UNLOCK);
+    s_bits = (s_bits | (flag << SHIFT_UNLOCK_PARAMETER));
+    return send_msg(s_bits, 0, 0);
 }
 
 #endif
@@ -222,14 +222,14 @@ static void timeout_cb(pa_mainloop_api*a, pa_time_event* e, const struct timeval
         pa_sink_suspend(d->sink, true, PA_SUSPEND_IDLE);
         pa_core_maybe_vacuum(d->userdata->core);
 #ifdef USE_PM_LOCK
-               UPDATE_PM_UNLOCK(d->userdata->pm_state, PM_TYPE_SINK);
-               if(!(d->userdata->pm_state)) {
-                       ret = pm_unlock_state(LCD_OFF, PM_SLEEP_MARGIN);
-                       if(ret != -1)
-                               pa_log_info("sink pm_unlock_state success [%d]", ret);
-                       else
-                               pa_log_error("sink pm_unlock_state failed [%d]", ret);
-               }
+        UPDATE_PM_UNLOCK(d->userdata->pm_state, PM_TYPE_SINK);
+        if(!(d->userdata->pm_state)) {
+            ret = pm_unlock_state(LCD_OFF, PM_SLEEP_MARGIN);
+            if(ret != -1)
+                pa_log_info("sink pm_unlock_state success [%d]", ret);
+            else
+                pa_log_error("sink pm_unlock_state failed [%d]", ret);
+        }
 #endif /* USE_PM_LOCK */
     }
 
@@ -241,12 +241,12 @@ static void timeout_cb(pa_mainloop_api*a, pa_time_event* e, const struct timeval
 
         UPDATE_PM_UNLOCK(d->userdata->pm_state, PM_TYPE_SOURCE);
         if(!(d->userdata->pm_state)) {
-                       ret = pm_unlock_state(LCD_OFF, PM_SLEEP_MARGIN);
-                       if(ret != -1)
-                               pa_log_info("source pm_unlock_state success [%d]", ret);
-                       else
-                               pa_log_error("source pm_unlock_state failed [%d]", ret);
-               }
+            ret = pm_unlock_state(LCD_OFF, PM_SLEEP_MARGIN);
+            if(ret != -1)
+                pa_log_info("source pm_unlock_state success [%d]", ret);
+            else
+                pa_log_error("source pm_unlock_state failed [%d]", ret);
+        }
 #endif /* USE_PM_LOCK */
     }
 }
@@ -277,13 +277,13 @@ static void resume(struct device_info *d) {
 
     if (d->sink) {
 #ifdef USE_PM_LOCK
-               UPDATE_PM_LOCK(d->userdata->pm_state, PM_TYPE_SINK);
-               ret = pm_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
-               if(ret != -1) {
-                       pa_log_info("sink pm_lock_state success [%d]", ret);
-               } else {
-                       pa_log_error("sink pm_lock_state failed [%d]", ret);
-               }
+        UPDATE_PM_LOCK(d->userdata->pm_state, PM_TYPE_SINK);
+        ret = pm_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
+        if(ret != -1) {
+            pa_log_info("sink pm_lock_state success [%d]", ret);
+        } else {
+            pa_log_error("sink pm_lock_state failed [%d]", ret);
+        }
 #endif /* USE_PM_LOCK */
         pa_log_debug("Sink %s becomes busy.", d->sink->name);
         pa_sink_suspend(d->sink, false, PA_SUSPEND_IDLE);
@@ -291,13 +291,13 @@ static void resume(struct device_info *d) {
 
     if (d->source) {
 #ifdef USE_PM_LOCK
-               UPDATE_PM_LOCK(d->userdata->pm_state, PM_TYPE_SOURCE);
-               ret = pm_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
-               if(ret != -1) {
-                       pa_log_info("source pm_lock_state success [%d]", ret);
-               } else {
-                       pa_log_error("source pm_lock_state failed [%d]", ret);
-               }
+        UPDATE_PM_LOCK(d->userdata->pm_state, PM_TYPE_SOURCE);
+        ret = pm_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
+        if(ret != -1) {
+            pa_log_info("source pm_lock_state success [%d]", ret);
+        } else {
+            pa_log_error("source pm_lock_state failed [%d]", ret);
+        }
 #endif /* USE_PM_LOCK */
         pa_log_debug("Source %s becomes busy.", d->source->name);
         pa_source_suspend(d->source, false, PA_SUSPEND_IDLE);