2 * Copyright (C) 2003-2010 The Music Player Daemon Project
3 * http://www.musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "client_internal.h"
27 * Send "idle" response to this client.
30 client_idle_notify(struct client
*client
)
33 const char *const* idle_names
;
35 assert(client
->idle_waiting
);
36 assert(client
->idle_flags
!= 0);
38 flags
= client
->idle_flags
;
39 client
->idle_flags
= 0;
40 client
->idle_waiting
= false;
42 idle_names
= idle_get_names();
43 for (i
= 0; idle_names
[i
]; ++i
) {
44 if (flags
& (1 << i
) & client
->idle_subscriptions
)
45 client_printf(client
, "changed: %s\n",
49 client_puts(client
, "OK\n");
50 g_timer_start(client
->last_activity
);
54 client_idle_callback(gpointer data
, gpointer user_data
)
56 struct client
*client
= data
;
57 unsigned flags
= GPOINTER_TO_UINT(user_data
);
59 if (client_is_expired(client
))
62 client
->idle_flags
|= flags
;
63 if (client
->idle_waiting
64 && (client
->idle_flags
& client
->idle_subscriptions
)) {
65 client_idle_notify(client
);
66 client_write_output(client
);
70 void client_manager_idle_add(unsigned flags
)
74 client_list_foreach(client_idle_callback
, GUINT_TO_POINTER(flags
));
77 bool client_idle_wait(struct client
*client
, unsigned flags
)
79 assert(!client
->idle_waiting
);
81 client
->idle_waiting
= true;
82 client
->idle_subscriptions
= flags
;
84 if (client
->idle_flags
& client
->idle_subscriptions
) {
85 client_idle_notify(client
);