mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-16 18:15:17 +00:00
Combine print_texeci and print_execi as much as possible
This commit is contained in:
parent
c010d7cd00
commit
aea8d3ed52
@ -620,23 +620,27 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
|
||||
END OBJ_ARG(execi, 0, "execi needs arguments")
|
||||
scan_execi_arg(obj, arg);
|
||||
obj->parse = false;
|
||||
obj->thread = false;
|
||||
obj->callbacks.print = &print_execi;
|
||||
obj->callbacks.free = &free_execi;
|
||||
END OBJ_ARG(execpi, 0, "execpi needs arguments")
|
||||
scan_execi_arg(obj, arg);
|
||||
obj->verbatim_output = 1;
|
||||
obj->parse = true;
|
||||
obj->thread = false;
|
||||
obj->callbacks.print = &print_execi;
|
||||
obj->callbacks.free = &free_execi;
|
||||
END OBJ_ARG(texeci, 0, "texeci needs arguments")
|
||||
scan_execi_arg(obj, arg);
|
||||
obj->parse = false;
|
||||
obj->callbacks.print = &print_texeci;
|
||||
obj->thread = true;
|
||||
obj->callbacks.print = &print_execi;
|
||||
obj->callbacks.free = &free_execi;
|
||||
END OBJ_ARG(texecpi, 0, "texecpi needs arguments")
|
||||
scan_execi_arg(obj, arg);
|
||||
obj->parse = true;
|
||||
obj->callbacks.print = &print_texeci;
|
||||
obj->thread = true;
|
||||
obj->callbacks.print = &print_execi;
|
||||
obj->callbacks.free = &free_execi;
|
||||
END OBJ(pre_exec, 0)
|
||||
scan_pre_exec_arg(obj, arg);
|
||||
|
45
src/exec.cc
45
src/exec.cc
@ -318,39 +318,34 @@ void print_execp(struct text_object *obj, char *p, int p_max_size)
|
||||
void print_execi(struct text_object *obj, char *p, int p_max_size)
|
||||
{
|
||||
struct execi_data *ed = (struct execi_data *)obj->data.opaque;
|
||||
bool fillbuffer = true;
|
||||
|
||||
if (!ed)
|
||||
return;
|
||||
|
||||
if (time_to_update(ed)) {
|
||||
if (!ed->buffer)
|
||||
ed->buffer = (char*)malloc(text_buffer_size);
|
||||
read_exec(ed->cmd, ed->buffer, text_buffer_size);
|
||||
ed->last_update = current_update_time;
|
||||
}
|
||||
fill_p(ed->buffer, obj, p, p_max_size);
|
||||
}
|
||||
|
||||
void print_texeci(struct text_object *obj, char *p, int p_max_size)
|
||||
{
|
||||
struct execi_data *ed = (struct execi_data *)obj->data.opaque;
|
||||
|
||||
if (!ed)
|
||||
return;
|
||||
|
||||
if (!ed->p_timed_thread) {
|
||||
/*
|
||||
* note that we don't register this thread with the
|
||||
* timed_thread list, because we destroy it manually
|
||||
*/
|
||||
ed->p_timed_thread = timed_thread::create(std::bind(threaded_exec, std::placeholders::_1, obj), ed->interval * 1000000, false);
|
||||
if(obj->thread == true) {
|
||||
if (!ed->p_timed_thread) {
|
||||
NORM_ERR("Error creating texeci timed thread");
|
||||
/*
|
||||
* note that we don't register this thread with the
|
||||
* timed_thread list, because we destroy it manually
|
||||
*/
|
||||
ed->p_timed_thread = timed_thread::create(std::bind(threaded_exec, std::placeholders::_1, obj), ed->interval * 1000000, false);
|
||||
if (!ed->p_timed_thread) {
|
||||
NORM_ERR("Error creating texeci timed thread");
|
||||
}
|
||||
fillbuffer = false;
|
||||
} else {
|
||||
std::lock_guard<std::mutex> lock(ed->p_timed_thread->mutex());
|
||||
}
|
||||
} else {
|
||||
std::lock_guard<std::mutex> lock(ed->p_timed_thread->mutex());
|
||||
fill_p(ed->buffer, obj, p, p_max_size);
|
||||
if (time_to_update(ed)) {
|
||||
if (!ed->buffer)
|
||||
ed->buffer = (char*)malloc(text_buffer_size);
|
||||
read_exec(ed->cmd, ed->buffer, text_buffer_size);
|
||||
ed->last_update = current_update_time;
|
||||
}
|
||||
}
|
||||
if(fillbuffer) fill_p(ed->buffer, obj, p, p_max_size);
|
||||
}
|
||||
|
||||
double execbarval(struct text_object *obj)
|
||||
|
@ -96,6 +96,7 @@ struct text_object {
|
||||
long line;
|
||||
struct obj_cb callbacks;
|
||||
bool parse; //if this true then data.s should still be parsed
|
||||
bool thread; //if this true then data.s should be set by a seperate thread
|
||||
};
|
||||
|
||||
/* text object list helpers */
|
||||
|
Loading…
Reference in New Issue
Block a user