blob: ed1f005659cb140c1890b3c7aa841e703d80d956 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _DUMPSTATE_H_
18#define _DUMPSTATE_H_
19
20#include <time.h>
21
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -070022// Commands time out after 60 seconds
23#define TIMEOUT 60
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024
25#define PRINT(s) printf("%s\n", s)
26
27#define DUMP(file) dump_file(file)
28
29#define DUMP_FILES(path) dump_files(path)
30
31#define DUMP_PROMPT(prompt, file) \
32{ \
33 printf(prompt); \
34 dump_file(file); \
35}
36
37#define EXEC(cmd) \
38{ \
39 static struct Command c = { \
40 "/system/bin/" cmd, \
41 { cmd, 0 } \
42 }; \
43 run_command(&c, TIMEOUT); \
44}
45
The Android Open Source Project4df24232009-03-05 14:34:35 -080046#define EXEC_TIMEOUT(cmd, tmout)\
47{ \
48 static struct Command c = { \
49 "/system/bin/" cmd, \
50 { cmd, 0 } \
51 }; \
52 run_command(&c, tmout); \
53}
54
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055#define EXEC_XBIN(cmd) \
56{ \
57 static struct Command c = { \
58 "/system/xbin/" cmd, \
59 { cmd, 0 } \
60 }; \
61 run_command(&c, TIMEOUT); \
62}
63
Evan Millar26a2d822009-10-29 12:41:39 -070064#define EXEC1(cmd, a1) \
65{ \
66 static struct Command c = { \
67 "/system/bin/" cmd, \
68 { cmd, a1, 0 } \
69 }; \
70 run_command(&c, TIMEOUT); \
71}
72
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073#define EXEC2(cmd, a1, a2) \
74{ \
75 static struct Command c = { \
76 "/system/bin/" cmd, \
77 { cmd, a1, a2, 0 } \
78 }; \
79 run_command(&c, TIMEOUT); \
80}
81
Evan Millar26a2d822009-10-29 12:41:39 -070082#define EXEC3(cmd, a1, a2, a3) \
83{ \
84 static struct Command c = { \
85 "/system/bin/" cmd, \
86 { cmd, a1, a2, a3, 0 } \
87 }; \
88 run_command(&c, TIMEOUT); \
89}
90
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091#define EXEC4(cmd, a1, a2, a3, a4) \
92{ \
93 static struct Command c = { \
94 "/system/bin/" cmd, \
95 { cmd, a1, a2, a3, a4, 0 } \
96 }; \
97 run_command(&c, TIMEOUT); \
98}
99
100#define EXEC6(cmd, a1, a2, a3, a4, a5, a6) \
101{ \
102 static struct Command c = { \
103 "/system/bin/" cmd, \
104 { cmd, a1, a2, a3, a4, a5, a6, 0 } \
105 }; \
106 run_command(&c, TIMEOUT); \
107}
108
109#define EXEC7(cmd, a1, a2, a3, a4, a5, a6, a7) \
110{ \
111 static struct Command c = { \
112 "/system/bin/" cmd, \
113 { cmd, a1, a2, a3, a4, a5, a6, a7, 0 } \
114 }; \
115 run_command(&c, TIMEOUT); \
116}
117
118#define EXEC8(cmd, a1, a2, a3, a4, a5, a6, a7, a8) \
119{ \
120 static struct Command c = { \
121 "/system/bin/" cmd, \
122 { cmd, a1, a2, a3, a4, a5, a6, a7, a8, 0 } \
123 }; \
124 run_command(&c, TIMEOUT); \
125}
126
Dmitry Shmidt64bf3d52009-12-16 16:05:08 -0800127#define EXEC_XBIN6(cmd, a1, a2, a3, a4, a5, a6) \
128{ \
129 static struct Command c = { \
130 "/system/xbin/" cmd, \
131 { cmd, a1, a2, a3, a4, a5, a6, 0 } \
132 }; \
133 run_command(&c, TIMEOUT); \
134}
135
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136#define PROPERTY(name) print_property(name)
137
138struct Command {
139 const char* path;
140 char* const args[];
141};
142typedef struct Command Command;
143
144/* prints the contents of a file */
145int dump_file(const char* path);
146
147/* prints the contents of all files in a directory */
148void dump_files(const char* path);
149
150/* forks a command and waits for it to finish */
151int run_command(struct Command* cmd, int timeout);
152
153/* reads the current time into tm */
154void get_time(struct tm *tm);
155
156/* prints the date in tm */
157void print_date(const char* prompt, struct tm *tm);
158
159/* prints the name and value of a system property */
160int print_property(const char* name);
161
162/* prints all the system properties */
163void print_properties();
164
165/* creates directories as needed for the given path */
166void create_directories(char *path);
167
168/* runs the vibrator using the given pattern */
169void vibrate_pattern(int fd, int* pattern);
170
171/* prevents the OOM killer from killing us */
172void protect_from_oom_killer();
173
174#endif /* _DUMPSTATE_H_ */