#include <liberipc/eripc.h>
#include <X11/Xlib.h>
#include "process.h"
Go to the source code of this file.
Functions | |
G_BEGIN_DECLS gboolean | task_start (const char *command_line, const char *working_dir, const char *label, const char *image, eripc_context_t *context, const char *message_id) |
Start a task. | |
gboolean | task_activate (const char *command_line) |
Activate a running task. | |
void | task_activate_by_xid (int xid) |
const gchar * | task_service_by_window (Window xid) |
Get service of task with given window. | |
gboolean | task_stop (const char *command_line, eripc_context_t *context, const char *message_id) |
Stop a running task. | |
gboolean | task_rename (int xid, const char *new_document, const char *new_label) |
gboolean | task_add (const char *application, const char *document, const char *label, const char *image, const char *ipc_service, gint pid, Window xid) |
Add a task which is already running. | |
gboolean | task_cleanup_pid (GPid pid) |
Cleanup tasks for process. | |
gboolean | task_cleanup_window (Window xid) |
Cleanup tasks for window. | |
gboolean | task_startup_completed (proc_t *proc, Window xid) |
Call when a task has finished starting. | |
char * | testing_task_get_list () |
void | print_task_list () |
void print_task_list | ( | ) |
Definition at line 363 of file tasks.c.
References task_t::application, task_t::document, g_tasklist, proc_t::pid, task_t::proc, and task_t::window.
Referenced by testing_list_tasks().
00364 { 00365 GSList *task_ptr = g_tasklist; 00366 00367 int i = 0; 00368 printf("%s() TASKS\n", __func__); 00369 while (task_ptr) 00370 { 00371 task_t *task = (task_t *) task_ptr->data; 00372 int pid = (task->proc) ? task->proc->pid : 0; 00373 printf(" [%d] proc_pid=%d window=%d app=%s doc=%s\n", i, pid, 00374 (guint)task->window, task->application, task->document); 00375 00376 task_ptr = task_ptr->next; 00377 i++; 00378 } 00379 }
gboolean task_activate | ( | const char * | command_line | ) |
Activate a running task.
---------------------------------------------------------------------------
Name : task_activate
command_line | Full command line of task, quoted as g_shell_quote |
--------------------------------------------------------------------------
Definition at line 331 of file tasks.c.
References child_activate(), get_task(), LOGPRINTF, parse_commandline(), WARNPRINTF, and task_t::window.
Referenced by cb_menu_item_activated(), and cb_status_item_activated().
00332 { 00333 LOGPRINTF("entry: `%s`", command_line); 00334 00335 gboolean retval = FALSE; 00336 gchar *application = NULL; 00337 gchar *document = NULL; 00338 00339 parse_commandline(command_line, &application, &document, NULL); 00340 00341 task_t *task = get_task(application, document); 00342 if (task) 00343 { 00344 LOGPRINTF("found task, activate window %d", (gint) task->window); 00345 retval = child_activate(task); 00346 } 00347 else 00348 { 00349 WARNPRINTF("task not found cmdline='%s'", command_line); 00350 } 00351 00352 // free allocated memory 00353 g_free(application); 00354 g_free(document); 00355 00356 LOGPRINTF("leave: retval %d", retval); 00357 00358 return retval; 00359 }
void task_activate_by_xid | ( | int | xid | ) |
Definition at line 310 of file tasks.c.
References child_activate(), FOLDER_XID, get_task_by_xid(), LOGPRINTF, process_activate_ctb(), WARNPRINTF, and task_t::window.
Referenced by cb_task_activate().
00311 { 00312 LOGPRINTF("entry xid=%d", xid); 00313 if (xid == FOLDER_XID) 00314 { 00315 process_activate_ctb(); 00316 return; 00317 } 00318 task_t *task = get_task_by_xid(xid); 00319 if (task) 00320 { 00321 LOGPRINTF("found task, activate window %d", (gint) task->window); 00322 child_activate(task); 00323 } 00324 else 00325 { 00326 WARNPRINTF("task not found, xid=%d", xid); 00327 } 00328 }
gboolean task_add | ( | const char * | application, | |
const char * | document, | |||
const char * | label, | |||
const char * | image, | |||
const char * | ipc_service, | |||
gint | pid, | |||
Window | xid | |||
) |
Add a task which is already running.
---------------------------------------------------------------------------
Name : task_add
application | Basename of the application | |
document | Full path of the document | |
label | Text label shown under icon in popup menu | |
image | Full path to icon shown in popup menu | |
ipc_service | IPC service name of the application | |
pid | Process ID | |
xid | Window ID |
--------------------------------------------------------------------------
Definition at line 396 of file tasks.c.
References get_task(), LOGPRINTF, process_get_by_pid(), and tasklist_add().
Referenced by cb_opened_window().
00403 { 00404 LOGPRINTF("entry"); 00405 00406 gboolean retval = FALSE; 00407 00408 task_t *task = get_task(application, document); 00409 proc_t *proc = process_get_by_pid(pid); 00410 if (proc && !task) 00411 { 00412 LOGPRINTF("task %s, %s, not found, add it...", application, document); 00413 task = tasklist_add(proc, application, document, label, image, xid); 00414 if (task) 00415 { 00416 retval = TRUE; 00417 } 00418 } 00419 00420 return retval; 00421 }
gboolean task_cleanup_pid | ( | GPid | pid | ) |
Cleanup tasks for process.
---------------------------------------------------------------------------
Name : task_cleanup_pid
pid | Process that has exited |
--------------------------------------------------------------------------
Definition at line 424 of file tasks.c.
References g_forced_close, LOGPRINTF, process_activate_ctb(), and tasklist_remove_pid().
Referenced by on_process_exit().
00425 { 00426 LOGPRINTF("entry: forced %d", g_forced_close); 00427 00428 gboolean result = tasklist_remove_pid(pid); 00429 00430 if (result && !g_forced_close) 00431 { 00432 #if MACHINE_IS_DR800SG || MACHINE_IS_DR800S || MACHINE_IS_DR800SW 00433 // automatically return to application that was on top in the stack 00434 #elif MACHINE_IS_DR1000S || MACHINE_IS_DR1000SW 00435 // return to folder in content browser 00436 process_activate_ctb(); 00437 #endif 00438 } 00439 00440 g_forced_close = FALSE; 00441 00442 return result; 00443 }
gboolean task_cleanup_window | ( | Window | xid | ) |
Cleanup tasks for window.
---------------------------------------------------------------------------
Name : task_cleanup_window
xid | Window that was closed |
--------------------------------------------------------------------------
Definition at line 446 of file tasks.c.
References g_forced_close, LOGPRINTF, process_activate_ctb(), and tasklist_remove_window().
Referenced by cb_closed_window().
00447 { 00448 LOGPRINTF("entry: xid %d, forced %d", (int) xid, g_forced_close); 00449 00450 gboolean result = tasklist_remove_window(xid); 00451 00452 if (result && !g_forced_close) 00453 { 00454 #if MACHINE_IS_DR800SG || MACHINE_IS_DR800S || MACHINE_IS_DR800SW 00455 // automatically return to application that was on top in the stack 00456 #elif MACHINE_IS_DR1000S || MACHINE_IS_DR1000SW 00457 // return to folder in content browser 00458 process_activate_ctb(); 00459 #endif 00460 } 00461 00462 g_forced_close = FALSE; 00463 00464 return result; 00465 }
gboolean task_rename | ( | int | xid, | |
const char * | new_document, | |||
const char * | new_label | |||
) |
Definition at line 293 of file tasks.c.
References task_t::document, ERRORPRINTF, get_task_by_xid(), ipc_menu_rename_task(), task_t::label, and LOGPRINTF.
Referenced by cb_task_rename().
00294 { 00295 LOGPRINTF("[%d] %s '%s'", xid, new_document, new_label); 00296 task_t *task = get_task_by_xid(xid); 00297 if (task == NULL) { 00298 ERRORPRINTF("unknown task: xid=%d", xid); 00299 return FALSE; 00300 } 00301 g_free(task->document); 00302 task->document = g_strdup(new_document); 00303 g_free(task->label); 00304 task->label = g_strdup(new_label); 00305 ipc_menu_rename_task(xid, task->label); 00306 return TRUE; 00307 }
const gchar* task_service_by_window | ( | Window | xid | ) |
Get service of task with given window.
---------------------------------------------------------------------------
Name : task_service_by_window
xid | Window ID |
--------------------------------------------------------------------------
Definition at line 383 of file tasks.c.
References get_task_by_xid(), proc_t::ipc_service, LOGPRINTF, and task_t::proc.
Referenced by parse_wm_messages().
00384 { 00385 LOGPRINTF("entry: %d", (gint) xid); 00386 00387 task_t *task = get_task_by_xid(xid); 00388 if (task && task->proc && task->proc->ipc_service) 00389 { 00390 return task->proc->ipc_service; 00391 } 00392 return NULL; 00393 }
G_BEGIN_DECLS gboolean task_start | ( | const char * | command_line, | |
const char * | working_dir, | |||
const char * | label, | |||
const char * | image, | |||
eripc_context_t * | context, | |||
const char * | message_id | |||
) |
Start a task.
Description: Task list handling functions Copyright (C) 2008 iRex Technologies B.V. All rights reserved.---------------------------------------------------------------------------
Name : task_start
command_line | Full command line to spawn, quoted as g_shell_quote | |
working_dir | Working directory or NULL to inherit from sysd | |
label | Text label shown under icon in popup menu | |
image | Full path to icon shown in popup menu |
--------------------------------------------------------------------------
Definition at line 168 of file tasks.c.
References child_activate(), child_new(), child_window_open(), get_task(), ipc_send_reply_task_start(), proc_t::ipc_service, proc_t::is_multidoc, LOGPRINTF, new_request(), parse_commandline(), task_t::proc, process_get_by_name(), and tasklist_add().
Referenced by cb_open_url(), cb_status_item_activated(), cb_task_start(), and start_demo_mode().
00174 { 00175 LOGPRINTF("entry: `%s`", command_line); 00176 00177 gboolean retval = FALSE; 00178 gchar *application = NULL; 00179 gchar *document = NULL; 00180 00181 parse_commandline(command_line, &application, &document, NULL); 00182 00183 LOGPRINTF("app [%s] wd [%s] doc [%s] label [%s] image [%s]", application, working_dir, document, label, image); 00184 00185 task_t *task = get_task(application, document); 00186 if (task) 00187 { 00188 LOGPRINTF("task exists, reopen or activate"); 00189 // task already exists, reopen or activate 00190 // 00191 if (task->proc && task->proc->ipc_service && task->proc->is_multidoc) 00192 { 00193 request_t *request = new_request(task, context, message_id); 00194 retval = child_window_open(task, request); 00195 } 00196 else 00197 { 00198 retval = child_activate(task); 00199 if (context && message_id) 00200 { 00201 // return result to caller 00202 ipc_send_reply_task_start(context, message_id, 0, NULL); 00203 } 00204 } 00205 } 00206 else 00207 { 00208 proc_t *proc = process_get_by_name(application); 00209 if (proc) 00210 { 00211 // process is running but no task yet, create new 00212 // 00213 if (proc->ipc_service && proc->is_multidoc) 00214 { 00215 LOGPRINTF("task %s, %s not found, create it...", application, document); 00216 task_t *task = tasklist_add(proc, application, document, label, image, 0); 00217 request_t *request = new_request(task, context, message_id); 00218 retval = child_window_open(task, request); 00219 } 00220 else 00221 { 00222 if (proc->is_multidoc) { 00223 LOGPRINTF("%s, %s is currently running but is not a task, ignored.", application, document); 00224 // process running, singledoc and no task found for it 00225 // this is either a window-less process or a system process 00226 // in either case; we ignore this start command. 00227 } else { 00228 // TODO REFACTOR (common code) 00229 // process not running, create new 00230 LOGPRINTF("process %s running, but not for current doc, start new", application); 00231 retval = child_new(command_line, working_dir, application, document, label, image, context, message_id); 00232 } 00233 } 00234 } 00235 else 00236 { 00237 // process not running, create new 00238 // 00239 LOGPRINTF("process %s, not currently running start new", application); 00240 retval = child_new(command_line, working_dir, application, document, label, image, context, message_id); 00241 } 00242 } 00243 00244 // free allocated memory 00245 g_free(application); 00246 g_free(document); 00247 00248 LOGPRINTF("leave: retval %d", retval); 00249 00250 return retval; 00251 }
gboolean task_startup_completed | ( | proc_t * | proc, | |
Window | xid | |||
) |
Call when a task has finished starting.
---------------------------------------------------------------------------
Name : task_startup_completed
proc | Process | |
xid | Window id |
--------------------------------------------------------------------------
Definition at line 468 of file tasks.c.
References task_t::application, task_t::document, g_tasklist, ipc_menu_add_task(), task_t::label, LOGPRINTF, task_t::proc, and task_t::window.
Referenced by post_process_startup().
00469 { 00470 LOGPRINTF("entry"); 00471 00472 GSList *task_ptr = g_tasklist; 00473 while (task_ptr) 00474 { 00475 task_t *task = (task_t *) task_ptr->data; 00476 00477 if (task->proc == proc) 00478 { 00479 if (window != 0) 00480 { 00481 task->window = window; 00482 LOGPRINTF("assigned window %d to %s, %s", (gint) task->window, task->application, task->document); 00483 } 00484 00485 // add to task manager 00486 ipc_menu_add_task((gint)task->window, task->label); 00487 00488 return TRUE; 00489 } 00490 task_ptr = task_ptr->next; 00491 } 00492 return FALSE; 00493 }
gboolean task_stop | ( | const char * | command_line, | |
eripc_context_t * | context, | |||
const char * | message_id | |||
) |
Stop a running task.
---------------------------------------------------------------------------
Name : task_stop
command_line | Full command line of task, quoted as g_shell_quote |
--------------------------------------------------------------------------
Definition at line 254 of file tasks.c.
References child_close(), child_window_close(), get_task(), ipc_send_reply(), proc_t::ipc_service, proc_t::is_multidoc, LOGPRINTF, new_request(), parse_commandline(), and task_t::proc.
Referenced by cb_task_stop().
00257 { 00258 LOGPRINTF("entry: `%s`", command_line); 00259 00260 gboolean retval = FALSE; 00261 gchar *application = NULL; 00262 gchar *document = NULL; 00263 00264 parse_commandline(command_line, &application, &document, NULL); 00265 00266 task_t *task = get_task(application, document); 00267 if (task) 00268 { 00269 if (task->proc && task->proc->ipc_service && task->proc->is_multidoc) 00270 { 00271 request_t *request = new_request(task, context, message_id); 00272 LOGPRINTF("found multidoc window, close child window"); 00273 retval = child_window_close(task, request); 00274 } 00275 else 00276 { 00277 LOGPRINTF("found singledoc window, close child"); 00278 retval = child_close(task); 00279 ipc_send_reply(context, message_id, retval); 00280 } 00281 } 00282 00283 // free allocated memory 00284 g_free(application); 00285 g_free(document); 00286 00287 LOGPRINTF("leave: retval %d", retval); 00288 00289 return retval; 00290 }
char* testing_task_get_list | ( | ) |
Definition at line 496 of file tasks.c.
References task_t::application, buffer, cp, task_t::document, and g_tasklist.
Referenced by testing_list_tasks().
00497 { 00498 #if (TESTING_ON) 00499 char buffer[1000]; 00500 char* cp = buffer; 00501 GSList *iter = g_tasklist; 00502 while (iter) 00503 { 00504 task_t* task = (task_t*) iter->data; 00505 strcpy(cp, task->application); 00506 cp += strlen(task->application); 00507 *cp++ = '|'; 00508 strcpy(cp, task->document); 00509 cp += strlen(task->document); 00510 *cp++ = '\n'; 00511 00512 iter = g_slist_next(iter); 00513 } 00514 *cp = 0; 00515 char* result = g_strdup(buffer); 00516 return result; 00517 #endif 00518 return g_strdup("no debug"); 00519 }