add pulse_disconnect() function and properly send disconnect events when disconnectin...
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Fri, 5 Oct 2012 06:56:13 +0000 (06:56 +0000)
committerMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Fri, 5 Oct 2012 06:56:13 +0000 (06:56 +0000)
SVN revision: 77505

src/modules/mixer/Pulse.h
src/modules/mixer/msg.c
src/modules/mixer/pa.c

index dc6e1a4..bbfabde 100644 (file)
@@ -37,6 +37,7 @@ void pulse_shutdown(void);
 
 Pulse *pulse_new(void);
 Eina_Bool pulse_connect(Pulse *conn);
+void pulse_disconnect(Pulse *conn);
 void pulse_free(Pulse *conn);
 void pulse_cb_set(Pulse *conn, uint32_t tagnum, Pulse_Cb cb);
 void pulse_server_info_free(Pulse_Server_Info *ev);
index 6b6a002..adb6952 100644 (file)
@@ -33,8 +33,7 @@ msg_recv_creds(Pulse *conn, Pulse_Tag *tag)
         if (errno != EAGAIN)
           {
              ERR("%d: %s", errno, strerror(errno));
-             ecore_main_fd_handler_del(conn->fdh);
-             conn->fdh = NULL;
+             pulse_disconnect(conn);
           }
      }
    else
@@ -84,8 +83,7 @@ msg_recv(Pulse *conn, Pulse_Tag *tag)
         if (errno != EAGAIN)
           {
              ERR("%d: %s", errno, strerror(errno));
-             ecore_main_fd_handler_del(conn->fdh);
-             conn->fdh = NULL;
+             pulse_disconnect(conn);
           }
      }
    else
@@ -138,8 +136,7 @@ msg_sendmsg_creds(Pulse *conn, Pulse_Tag *tag)
         if (errno != EAGAIN)
           {
              ERR("%d: %s", errno, strerror(errno));
-             ecore_main_fd_handler_del(conn->fdh);
-             conn->fdh = NULL;
+             pulse_disconnect(conn);
           }
      }
    else
@@ -165,8 +162,7 @@ msg_send_creds(Pulse *conn, Pulse_Tag *tag)
         if (errno != EAGAIN)
           {
              ERR("%d: %s", errno, strerror(errno));
-             ecore_main_fd_handler_del(conn->fdh);
-             conn->fdh = NULL;
+             pulse_disconnect(conn);
           }
      }
    else
@@ -198,8 +194,7 @@ msg_send(Pulse *conn, Pulse_Tag *tag)
         if (errno != EAGAIN)
           {
              ERR("%d: %s", errno, strerror(errno));
-             ecore_main_fd_handler_del(conn->fdh);
-             conn->fdh = NULL;
+             pulse_disconnect(conn);
           }
      }
    else
index ae628d6..497beb8 100644 (file)
@@ -196,11 +196,7 @@ pulse_recv(Pulse *conn, Ecore_Fd_Handler *fdh)
         if (!tag->dsize)
           {
              ERR("Kicked!");
-             conn->state = PA_STATE_INIT;
-             ecore_main_fd_handler_del(conn->fdh);
-             conn->fdh = NULL;
-             close(conn->fd);
-             ecore_event_add(PULSE_EVENT_DISCONNECTED, conn, pulse_fake_free, NULL);
+             pulse_disconnect(conn);
              return NULL;
           }
         tag->data = malloc(tag->dsize);
@@ -274,6 +270,7 @@ fdh_func(Pulse *conn, Ecore_Fd_Handler *fdh)
 
         if (!wprev->auth)
           msg_sendmsg_creds(conn, wprev);
+          
 
         if (wprev->auth && msg_send(conn, wprev))
           {
@@ -354,10 +351,7 @@ con(Pulse *conn, int type __UNUSED__, Ecore_Con_Event_Server_Add *ev)
    fd = ecore_con_server_fd_get(ev->server);
    if (fd == -1)
      {
-        conn->state = PA_STATE_INIT;
-        ecore_con_server_del(ev->server);
-        conn->svr = NULL;
-        ecore_event_add(PULSE_EVENT_DISCONNECTED, conn, pulse_fake_free, NULL);
+        pulse_disconnect(conn);
         return ECORE_CALLBACK_RENEW;
      }
    conn->fd = dup(fd);
@@ -753,6 +747,27 @@ pulse_connect(Pulse *conn)
 }
 
 void
+pulse_disconnect(Pulse *conn)
+{
+   EINA_SAFETY_ON_NULL_RETURN(conn);
+   if (conn->state == PA_STATE_INIT) return;
+   conn->state = PA_STATE_INIT;
+   if (conn->fdh)
+     {
+        ecore_main_fd_handler_del(conn->fdh);
+        conn->fdh = NULL;
+        close(conn->fd);
+        conn->fd = -1;
+     }
+   else if (conn->svr)
+     {
+        ecore_con_server_del(conn->svr);
+        conn->svr = NULL;
+     }
+   ecore_event_add(PULSE_EVENT_DISCONNECTED, conn, pulse_fake_free, NULL);
+}
+
+void
 pulse_server_info_free(Pulse_Server_Info *ev)
 {
    if (!ev) return;