1 /* vim:tw=78:ts=8:sw=4:set ft=c: */
3 Copyright (C) 2006-2009 Ben Kibbey <bjk@luxsci.net>
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
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02110-1301 USA
24 #include "pwmd_error.h"
26 static void *write_status_cb(void *arg
)
28 struct assuan_cmd_s
*data
= arg
;
31 rc
= assuan_write_status(data
->ctx
, data
->line
, data
->line2
);
36 gpg_error_t
send_status(assuan_context_t ctx
, status_msg_t which
,
37 const gchar
*fmt
, ...)
39 const gchar
*line
= NULL
;
40 gchar buf
[ASSUAN_LINELENGTH
+1];
44 struct assuan_cmd_s data
;
48 g_vsnprintf(buf
, sizeof(buf
), fmt
, ap
);
58 CACHE_LOCK(client
->ctx
);
59 line
= print_fmt(buf
, sizeof(buf
), "%i", cache_file_count());
64 MUTEX_LOCK(&cn_mutex
);
65 line
= print_fmt(buf
, sizeof(buf
), "%i", g_slist_length(cn_thread_list
));
66 MUTEX_UNLOCK(&cn_mutex
);
72 case STATUS_KEEPALIVE
:
77 line
= N_("Waiting for lock");
85 case STATUS_DECOMPRESS
:
86 status
= "DECOMPRESS";
94 log_write("%s %s", status
, line
);
101 rc
= do_assuan_command(ctx
, write_status_cb
, &data
);
105 void *client_msg_thread(void *arg
)
107 struct client_thread_s
*thd
= arg
;
109 pth_attr_t attr
= pth_attr_of(pth_self());
111 pth_attr_set(attr
, PTH_ATTR_NAME
, __FUNCTION__
);
112 pth_attr_destroy(attr
);
114 pth_cond_init(&thd
->msg_cond
);
115 pth_mutex_acquire(&m
, FALSE
, NULL
);
118 pth_cond_await(&thd
->msg_cond
, &m
, NULL
);
125 MUTEX_LOCK(&thd
->msg_list_mutex
);
126 msg
= g_slist_nth_data(thd
->msg_list
, 0);
129 thd
->msg_list
= g_slist_remove(thd
->msg_list
, msg
);
131 MUTEX_UNLOCK(&thd
->msg_list_mutex
);
136 rc
= send_status(thd
->cl
->ctx
, *msg
, NULL
);
141 log_write("%s(%i): %s", __FILE__
, __LINE__
, pwmd_strerror(rc
));
142 pth_cancel(thd
->tid
);
151 static gboolean
msg_list_dup(GSList
*list
, status_msg_t which
)
155 for (t
= g_slist_length(list
), i
= 0; i
< t
; i
++) {
156 status_msg_t
*m
= g_slist_nth_data(list
, i
);
165 void send_status_all(status_msg_t which
)
169 MUTEX_LOCK(&cn_mutex
);
171 for (t
= g_slist_length(cn_thread_list
), i
= 0; i
< t
; i
++) {
172 struct client_thread_s
*cn
= g_slist_nth_data(cn_thread_list
, i
);
175 if (msg_list_dup(cn
->msg_list
, which
))
178 m
= g_malloc(sizeof(status_msg_t
));
181 log_write("%s(%i): %s", __FILE__
, __LINE__
, strerror(ENOMEM
));
186 MUTEX_LOCK(&cn
->msg_list_mutex
);
187 cn
->msg_list
= g_slist_append(cn
->msg_list
, m
);
188 MUTEX_UNLOCK(&cn
->msg_list_mutex
);
189 pth_cond_notify(&cn
->msg_cond
, FALSE
);
192 MUTEX_UNLOCK(&cn_mutex
);