dumpstate.h revision ba87e3e6c985e7175152993b5efcc7dd2f0e1c93
1/*
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
22// Commands time out after 60 seconds
23#define TIMEOUT     60
24
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
46#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
55#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
64#define EXEC2(cmd, a1, a2)      \
65{                               \
66    static struct Command c = { \
67        "/system/bin/" cmd,     \
68        { cmd, a1, a2, 0 }      \
69    };                          \
70    run_command(&c, TIMEOUT);   \
71}
72
73#define EXEC4(cmd, a1, a2, a3, a4)  \
74{                                   \
75    static struct Command c = {     \
76        "/system/bin/" cmd,         \
77        { cmd, a1, a2, a3, a4, 0 }  \
78    };                              \
79    run_command(&c, TIMEOUT);       \
80}
81
82#define EXEC6(cmd, a1, a2, a3, a4, a5, a6)  \
83{                                           \
84    static struct Command c = {             \
85        "/system/bin/" cmd,                 \
86        { cmd, a1, a2, a3, a4, a5, a6, 0 }  \
87    };                                      \
88    run_command(&c, TIMEOUT);               \
89}
90
91#define EXEC7(cmd, a1, a2, a3, a4, a5, a6, a7)  \
92{                                               \
93    static struct Command c = {                 \
94        "/system/bin/" cmd,                     \
95        { cmd, a1, a2, a3, a4, a5, a6, a7, 0 }  \
96    };                                          \
97    run_command(&c, TIMEOUT);                   \
98}
99
100#define EXEC8(cmd, a1, a2, a3, a4, a5, a6, a7, a8)  \
101{                                                   \
102    static struct Command c = {                     \
103        "/system/bin/" cmd,                         \
104        { cmd, a1, a2, a3, a4, a5, a6, a7, a8, 0 }  \
105    };                                              \
106    run_command(&c, TIMEOUT);                       \
107}
108
109#define PROPERTY(name) print_property(name)
110
111struct Command {
112    const char* path;
113    char* const args[];
114};
115typedef struct Command Command;
116
117/* prints the contents of a file */
118int dump_file(const char* path);
119
120/* prints the contents of all files in a directory */
121void dump_files(const char* path);
122
123/* forks a command and waits for it to finish */
124int run_command(struct Command* cmd, int timeout);
125
126/* reads the current time into tm */
127void get_time(struct tm *tm);
128
129/* prints the date in tm */
130void print_date(const char* prompt, struct tm *tm);
131
132/* prints the name and value of a system property */
133int print_property(const char* name);
134
135/* prints all the system properties */
136void print_properties();
137
138/* creates directories as needed for the given path */
139void create_directories(char *path);
140
141/* runs the vibrator using the given pattern */
142void vibrate_pattern(int fd, int* pattern);
143
144/* prevents the OOM killer from killing us */
145void protect_from_oom_killer();
146
147#endif /* _DUMPSTATE_H_ */
148