#include <glib.h>
#include <gdk/gdk.h>
Go to the source code of this file.
Data Structures | |
struct | proc_t |
Defines | |
#define | PS_WAIT_STARTED (1 << 0) |
#define | PS_WAIT_EXIT (1 << 1) |
#define | PS_RESPAWN (1 << 2) |
Enumerations | |
enum | proc_state { STATE_IDLE, STATE_STARTING, STATE_RUNNING, STATE_COMPLETED } |
Functions | |
gboolean | process_add (const char *command, const char *working_dir, GCallback startup_callback, GCallback exit_callback, gint flags) |
Add a process to the queue. The queue is served First In First Out. | |
proc_t * | process_start (const char *command, const char *working_dir, GCallback startup_callback, GCallback exit_callback, gint flags) |
Start a process without queuing. | |
void | process_stop (proc_t *proc) |
Stop a running process. | |
gboolean | process_activate (const char *application) |
Activate a running process (set to top). | |
gboolean | process_activate_ctb (void) |
Activate content browser (set to top). | |
gboolean | process_startup_complete (const char *application, gint pid, gboolean is_multidoc, const char *ipc_service, gint window) |
Call when application has finished starting. | |
proc_t * | process_get_by_name (const char *application) |
proc_t * | process_get_by_pid (GPid pid) |
void | print_process_list () |
#define PS_RESPAWN (1 << 2) |
Definition at line 49 of file process.h.
Referenced by check_respawn(), main(), on_process_exit(), and start_phase_3().
#define PS_WAIT_EXIT (1 << 1) |
Definition at line 48 of file process.h.
Referenced by check_start_next(), start_phase_2(), and start_process().
#define PS_WAIT_STARTED (1 << 0) |
Description: Process handling functions Copyright (C) 2008 iRex Technologies B.V. All rights reserved.
Definition at line 47 of file process.h.
Referenced by check_start_next(), child_new(), main(), start_medium(), start_phase_3(), and start_process().
enum proc_state |
Definition at line 61 of file process.h.
00062 { 00063 STATE_IDLE, 00064 STATE_STARTING, 00065 STATE_RUNNING, 00066 STATE_COMPLETED 00067 };
void print_process_list | ( | ) |
Definition at line 272 of file process.c.
References proc_t::command, g_proclist, proc_t::ipc_service, proc_t::is_multidoc, and proc_t::pid.
Referenced by testing_list_tasks().
00273 { 00274 GSList *proc_ptr = g_proclist; 00275 00276 printf("%s() PROCESS LIST:\n", __func__); 00277 int i = 0; 00278 while (proc_ptr) 00279 { 00280 proc_t *cur = (proc_t *) proc_ptr->data; 00281 printf(" [%d] cmd=%s ipc=%s multi=%d pid=%d\n", i, 00282 cur->command, cur->ipc_service, cur->is_multidoc, cur->pid); 00283 00284 proc_ptr = proc_ptr->next; 00285 i++; 00286 } 00287 }
gboolean process_activate | ( | const char * | application | ) |
Activate a running process (set to top).
---------------------------------------------------------------------------
Name : process_activate
application | Full path of the application |
--------------------------------------------------------------------------
Definition at line 149 of file process.c.
References get_application_window(), LOGPRINTF, WARNPRINTF, and window_activate().
Referenced by cb_menu_item_activated(), and process_activate_ctb().
00150 { 00151 LOGPRINTF("entry"); 00152 00153 gboolean result = FALSE; 00154 Window win_found; 00155 00156 win_found = get_application_window(application); 00157 00158 if (win_found != None) 00159 { 00160 window_activate(win_found); 00161 result = TRUE; 00162 } 00163 else 00164 { 00165 WARNPRINTF("No window found for: %s", application); 00166 } 00167 00168 return result; 00169 }
gboolean process_activate_ctb | ( | void | ) |
Activate content browser (set to top).
---------------------------------------------------------------------------
Name : process_activate_ctb
-- |
--------------------------------------------------------------------------
Definition at line 172 of file process.c.
References display_get_active_window(), LOGPRINTF, process_activate(), STATE_DEVICE_STOPPING, and sys_get_device_state().
Referenced by task_activate_by_xid(), task_cleanup_pid(), and task_cleanup_window().
00173 { 00174 LOGPRINTF("entry"); 00175 00176 gboolean retval = TRUE; 00177 00178 if (sys_get_device_state() == STATE_DEVICE_STOPPING) 00179 { 00180 // don't activate CTB when device is shutting down 00181 return FALSE; 00182 } 00183 00184 // set to top when not already active 00185 gchar *app_active = display_get_active_window(); 00186 if (app_active && strcmp(app_active, "ctb") != 0 ) 00187 { 00188 retval = process_activate("ctb"); 00189 } 00190 00191 return retval; 00192 }
gboolean process_add | ( | const char * | command, | |
const char * | working_dir, | |||
GCallback | startup_callback, | |||
GCallback | exit_callback, | |||
gint | flags | |||
) |
Add a process to the queue. The queue is served First In First Out.
---------------------------------------------------------------------------
Name : process_add
application | Full path of the application | |
working_dir | Working directory, or NULL to inherit parent's | |
startup_callback | Callback function when received startupCopmlete, or NULL | |
exit_callback | Callback function when processes was terminated, or NULL | |
flags | Bit field PS_WAIT_STARTED | PS_WAIT_EXIT | PS_RESPAWN |
--------------------------------------------------------------------------
Definition at line 97 of file process.c.
References check_start_next(), create_process(), and LOGPRINTF.
Referenced by main(), start_phase_2(), and start_phase_3().
00098 { 00099 LOGPRINTF("entry: %s, %d", command, flags); 00100 00101 proc_t *proc = create_process(command, working_dir, startup_callback, exit_callback, flags); 00102 if (proc == NULL) 00103 { 00104 return FALSE; 00105 } 00106 00107 check_start_next(); 00108 00109 return TRUE; 00110 }
proc_t* process_get_by_name | ( | const char * | application | ) |
Definition at line 290 of file process.c.
References proc_t::command, g_proclist, and LOGPRINTF.
Referenced by parse_wm_messages(), and task_start().
00291 { 00292 LOGPRINTF("entry [%s]", application); 00293 00294 GSList *proc_ptr = g_proclist; 00295 00296 while (proc_ptr) 00297 { 00298 proc_t *cur_proc = (proc_t *) proc_ptr->data; 00299 00300 gint argc = 0; 00301 char **argv_ptr = NULL; 00302 if (g_shell_parse_argv(cur_proc->command, &argc, &argv_ptr, NULL)) 00303 { 00304 gchar *proc_app = g_path_get_basename(argv_ptr[0]); 00305 // LOGPRINTF("check [%s]", proc_app); 00306 if (application && proc_app && (strcmp(proc_app, application) == 0)) 00307 { 00308 // LOGPRINTF("match [%s] pid [%d]", proc_app, cur_proc->pid); 00309 g_free(proc_app); 00310 return cur_proc; 00311 } 00312 g_free(proc_app); 00313 g_strfreev(argv_ptr); 00314 } 00315 proc_ptr = proc_ptr->next; 00316 } 00317 00318 return NULL; 00319 }
proc_t* process_get_by_pid | ( | GPid | pid | ) |
Definition at line 248 of file process.c.
References proc_t::command, g_proclist, proc_t::ipc_service, LOGPRINTF, and proc_t::pid.
Referenced by process_startup_complete(), and task_add().
00249 { 00250 LOGPRINTF("entry pid [%d]", pid); 00251 00252 GSList *proc_ptr = g_proclist; 00253 proc_t *cur_proc = NULL; 00254 00255 while (proc_ptr) 00256 { 00257 cur_proc = (proc_t *) proc_ptr->data; 00258 00259 if (cur_proc->pid == pid) 00260 { 00261 LOGPRINTF("found [%p] command [%s] ipc service [%s]", cur_proc, cur_proc->command, cur_proc->ipc_service); 00262 return cur_proc; 00263 } 00264 00265 proc_ptr = proc_ptr->next; 00266 } 00267 00268 return NULL; 00269 }
proc_t* process_start | ( | const char * | command, | |
const char * | working_dir, | |||
GCallback | startup_callback, | |||
GCallback | exit_callback, | |||
gint | flags | |||
) |
Start a process without queuing.
---------------------------------------------------------------------------
Name : process_start
application | Full path of the application | |
working_dir | Working directory, or NULL to inherit parent's | |
startup_callback | Callback function when received startupCopmlete, or NULL | |
exit_callback | Callback function when processes was terminated, or NULL | |
flags | Bit field PS_WAIT_STARTED | PS_RESPAWN |
--------------------------------------------------------------------------
Definition at line 113 of file process.c.
References create_process(), destroy_process(), LOGPRINTF, and start_process().
Referenced by child_new(), and start_medium().
00114 { 00115 LOGPRINTF("entry: %s, %d", command, flags); 00116 00117 gboolean result = FALSE; 00118 00119 proc_t *proc = create_process(command, working_dir, startup_callback, exit_callback, flags); 00120 if (proc == NULL) 00121 { 00122 return NULL; 00123 } 00124 00125 result = start_process(proc); 00126 if (result == FALSE) 00127 { 00128 LOGPRINTF("failed to spawn, remove from list"); 00129 destroy_process(proc); 00130 proc = NULL; 00131 } 00132 00133 return proc; 00134 }
gboolean process_startup_complete | ( | const char * | application, | |
gint | pid, | |||
gboolean | is_multidoc, | |||
const char * | ipc_service, | |||
gint | window | |||
) |
Call when application has finished starting.
---------------------------------------------------------------------------
Name : process_startup_complete
application | Full path of the application | |
pid | Process ud | |
is_multidoc | TRUE if multiple documents are supported, FALSE otherwise | |
ipc_service | IPC service | |
window | Window id |
--------------------------------------------------------------------------
Definition at line 195 of file process.c.
References check_start_next(), display_set_ctb_window(), g_process_pending_source, proc_t::ipc_service, proc_t::is_multidoc, LOGPRINTF, post_process_startup(), process_get_by_pid(), proc_t::startup_callback, proc_t::state, STATE_RUNNING, STATE_STARTING, and WARNPRINTF.
Referenced by cb_startup_complete().
00196 { 00197 LOGPRINTF("entry"); 00198 gboolean retval = FALSE; 00199 00200 // find proc by pid 00201 proc_t *proc = process_get_by_pid(pid); 00202 00203 if (proc == NULL) 00204 { 00205 WARNPRINTF("%s (pid %d) is not started sysd", application, pid); 00206 } 00207 else if (proc->state != STATE_STARTING) 00208 { 00209 WARNPRINTF("unexpected startupComplete received from %s (pid %d), state [%d]", application, pid, proc->state); 00210 } 00211 else 00212 { 00213 // stop pending timeout 00214 if (g_process_pending_source) 00215 { 00216 g_source_remove(g_process_pending_source); 00217 g_process_pending_source = 0; 00218 } 00219 00220 LOGPRINTF("received startupComplete from %s (pid %d, window %d), new state STATE_RUNNING", application, pid, window); 00221 if (strcmp(application, "ctb") == 0) { 00222 display_set_ctb_window(window); 00223 } 00224 00225 // update process info 00226 proc->state = STATE_RUNNING; 00227 proc->is_multidoc = is_multidoc; 00228 proc->ipc_service = g_strdup(ipc_service); 00229 00230 // do post startup actions 00231 post_process_startup(proc, application, window); 00232 00233 // call post startup callback 00234 if (proc->startup_callback) 00235 { 00236 (proc->startup_callback)(); 00237 } 00238 00239 // start next process 00240 check_start_next(); 00241 00242 retval = TRUE; 00243 } 00244 return retval; 00245 }
void process_stop | ( | proc_t * | proc | ) |
Stop a running process.
---------------------------------------------------------------------------
Name : process_stop
process | The process to be stopped |
--------------------------------------------------------------------------
Definition at line 137 of file process.c.
References proc_t::command, LOGPRINTF, and proc_t::pid.
Referenced by stop_medium().
00138 { 00139 g_assert(proc); 00140 LOGPRINTF("entry: %s, %d", proc->command, proc->pid); 00141 00142 if (proc && proc->pid > 0) 00143 { 00144 kill(proc->pid, SIGTERM); 00145 } 00146 }