summaryrefslogtreecommitdiff
path: root/hald/hald_runner.h
blob: fda9e506dd3bead8e44a8e385c015809fc1c3559 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/***************************************************************************
 *
 * CVSID: $Id$
 *
 * hald_runner.h - Interface to the hal runner helper daemon
 *
 * Copyright (C) 2006 Sjoerd Simons <sjoerd@luon.net>
 * Copyright (C) 2007 Codethink Ltd. Author Rob Taylor <rob.taylor@codethink.co.uk>
 *
 * Licensed under the Academic Free License version 2.1
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 **************************************************************************/

#ifndef HALD_RUNNER_H
#define HALD_RUNNER_H

#include "device.h"

/* Successful run of the program */
#define HALD_RUN_SUCCESS 0x0 
/* Process was killed because of running too long */
#define  HALD_RUN_TIMEOUT 0x1 
/* Failed to start for some reason */
#define HALD_RUN_FAILED 0x2
/* Killed on purpose, e.g. hal_runner_kill_device */   
#define HALD_RUN_KILLED 0x4

/* Default sane timeout */
#define HAL_HELPER_TIMEOUT 20000

typedef void (*HalRunTerminatedCB) (HalDevice *d, guint32 exit_type, 
                                       gint return_code, gchar **error,
                                       gpointer data1, gpointer data2);

/* Start the runner daemon */
gboolean
hald_runner_start_runner(void);

/* Stop the runner daemon */
void
hald_runner_stop_runner(void);

/* Start a helper, returns true on a successfull start. 
 * cb will be called on abnormal or premature termination
 * only 
 */
gboolean
hald_runner_start (HalDevice *device, const gchar *command_line, char **extra_env, 
		   HalRunTerminatedCB cb, gpointer data1, gpointer data2);

gboolean
hald_runner_start_singleton (const gchar * command_line,
			     char **extra_env, HalRunTerminatedCB cb,
			     gpointer data1, gpointer data2);

/* Run a helper program using the commandline, with input as infomation on
 * stdin */
void
hald_runner_run (HalDevice *device,
		 const gchar *command_line, char **extra_env, 
		 guint32 timeout,
		 HalRunTerminatedCB cb,
		 gpointer data1, gpointer data2);

void
hald_runner_run_sync (HalDevice *device,
		      const gchar *command_line, char **extra_env, 
		      guint32 timeout,
		      HalRunTerminatedCB cb,
		      gpointer data1, gpointer data2);

void
hald_runner_run_method(HalDevice *device,                                                              
		       const gchar *command_line, char **extra_env, 
                       gchar *input, gboolean error_on_stderr,
                       guint32 timeout,
                       HalRunTerminatedCB  cb,
                       gpointer data1, gpointer data2);

void hald_runner_kill_device(HalDevice *device);
void hald_runner_kill_all(void);

/* called by the core to tell the runner a device was finalized */
void runner_device_finalized (HalDevice *device);

typedef void (*HaldRunnerRunNotify)(gpointer user_data);
void hald_runner_set_method_run_notify (HaldRunnerRunNotify cb, gpointer user_data);

#endif