mtypes
[oweals/gnunet.git] / src / include / gnunet_os_lib.h
1 /*
2      This file is part of GNUnet.
3      (C) 2001, 2002, 2003, 2004, 2005, 2006 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 2, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file include/gnunet_os_lib.h
23  * @brief low level process routines
24  * @author Christian Grothoff
25  * @author Krista Bennett
26  * @author Gerd Knorr <kraxel@bytesex.org>
27  * @author Ioana Patrascu
28  * @author Tzvetan Horozov
29  * @author Milan
30  */
31
32 #ifndef GNUNET_OS_LIB_H
33 #define GNUNET_OS_LIB_H
34
35 #ifdef __cplusplus
36 extern "C"
37 {
38 #if 0                           /* keep Emacsens' auto-indent happy */
39 }
40 #endif
41 #endif
42
43 #include "gnunet_common.h"
44 #include "gnunet_configuration_lib.h"
45 #include "gnunet_scheduler_lib.h"
46
47
48 /**
49  * Possible installation paths to request
50  */
51 enum GNUNET_OS_InstallationPathKind
52 {
53   GNUNET_OS_IPK_PREFIX,
54   GNUNET_OS_IPK_BINDIR,
55   GNUNET_OS_IPK_LIBDIR,
56   GNUNET_OS_IPK_DATADIR,
57   GNUNET_OS_IPK_LOCALEDIR,
58   GNUNET_OS_IPK_SELF_PREFIX
59 };
60
61
62 /**
63  * Process status types
64  */
65 enum GNUNET_OS_ProcessStatusType
66 {
67   GNUNET_OS_PROCESS_UNKNOWN,
68   GNUNET_OS_PROCESS_RUNNING,
69   GNUNET_OS_PROCESS_STOPPED,
70   GNUNET_OS_PROCESS_EXITED,
71   GNUNET_OS_PROCESS_SIGNALED
72 };
73
74
75 /**
76  * Get the path to a specific GNUnet installation directory or, with
77  * GNUNET_OS_IPK_SELF_PREFIX, the current running apps installation
78  * directory.
79  *
80  * @param dirkind what kind of directory is desired?
81  * @return a pointer to the dir path (to be freed by the caller)
82  */
83 char *GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind
84                                        dirkind);
85
86
87 /**
88  * Callback function invoked for each interface found.
89  *
90  * @param cls closure
91  * @param name name of the interface (can be NULL for unknown)
92  * @param isDefault is this presumably the default interface
93  * @param addr address of this interface (can be NULL for unknown or unassigned)
94  * @param addrlen length of the address
95  * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
96  */
97 typedef int (*GNUNET_OS_NetworkInterfaceProcessor) (void *cls,
98                                                     const char *name,
99                                                     int isDefault,
100                                                     const struct sockaddr *
101                                                     addr, socklen_t addrlen);
102
103
104 /**
105  * @brief Enumerate all network interfaces
106  * @param callback the callback function
107  */
108 void GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor
109                                         proc, void *cls);
110
111 /**
112  * Get the current CPU load.
113  *
114  * @param cfg to determine acceptable load level (LOAD::MAXCPULOAD)
115  * @return -1 on error, otherwise load value (between 0 and 100,
116  *        (100 is equivalent to full load for one CPU)
117  */
118 int GNUNET_OS_load_cpu_get (struct GNUNET_CONFIGURATION_Handle *cfg);
119
120 /**
121  * Get the current IO load.
122  *
123  * @param cfg to determine acceptable load level (LOAD::MAXIOLOAD)
124  * @return -1 on error, otherwise load value (between 0 and 100,
125  *       100 means that we spend all of our cycles waiting for
126  *       the disk)
127  */
128 int GNUNET_OS_load_disk_get (struct GNUNET_CONFIGURATION_Handle *cfg);
129
130
131 /**
132  * Set process priority
133  *
134  * @param proc id of the process
135  * @param prio priority value
136  * @return GNUNET_OK on success, GNUNET_SYSERR on error
137  */
138 int GNUNET_OS_set_process_priority (pid_t proc,
139                                     enum GNUNET_SCHEDULER_Priority prio);
140
141
142 /**
143  * Start a process.
144  *
145  * @param filename name of the binary
146  * @param ... NULL-terminated list of arguments to the process
147  * @return process ID of the new process, -1 on error
148  */
149 pid_t GNUNET_OS_start_process (const char *filename, ...);
150
151 /**
152  * Start a process.
153  *
154  * @param filename name of the binary
155  * @param argv NULL-terminated list of arguments to the process,
156  *             including the process name as the first argument
157  * @return process ID of the new process, -1 on error
158  */
159 pid_t GNUNET_OS_start_process_v (const char *filename, char *const argv[]);
160
161 /**
162  * Retrieve the status of a process
163  * @param proc process ID
164  * @param type status type
165  * @param code return code/signal number
166  * @return GNUNET_OK on success, GNUNET_NO if the process is still running, GNUNET_SYSERR otherwise
167  */
168 int GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType *type,
169     unsigned long *code);
170
171 /**
172  * Wait for a process
173  * @param proc process ID to wait for
174  * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
175  */
176 int GNUNET_OS_process_wait (pid_t proc);
177
178 #if 0                           /* keep Emacsens' auto-indent happy */
179 {
180 #endif
181 #ifdef __cplusplus
182 }
183 #endif
184
185
186 /* ifndef GNUNET_OS_LIB_H */
187 #endif
188 /* end of gnunet_os_lib.h */