blob: 6c97e55870f21a03a3a4cb289795aa1a70863786 [file] [log] [blame]
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -08001/*
2 * Copyright (C) 2007 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
Doug Zongkerf28c9162009-06-02 15:30:11 -070017#include <stdbool.h>
18
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080019#ifndef AMEND_COMMANDS_H_
20#define AMEND_COMMANDS_H_
21
Doug Zongkerf28c9162009-06-02 15:30:11 -070022/* Invoke a command.
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080023 *
24 * When a boolean command is called, "argc" is the boolean value and
25 * "argv" is NULL.
26 */
27typedef int (*CommandHook)(const char *name, void *cookie,
Doug Zongkerf28c9162009-06-02 15:30:11 -070028 int argc, const char *argv[]);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080029
30int commandInit(void);
31void commandCleanup(void);
32
33/*
34 * Command management
35 */
36
37struct Command;
38typedef struct Command Command;
39
40typedef enum {
41 CMD_ARGS_UNKNOWN = -1,
42 CMD_ARGS_BOOLEAN = 0,
43 CMD_ARGS_WORDS
44} CommandArgumentType;
45
46int registerCommand(const char *name,
47 CommandArgumentType argType, CommandHook hook, void *cookie);
48
49Command *findCommand(const char *name);
50
51CommandArgumentType getCommandArgumentType(Command *cmd);
52
53int callCommand(Command *cmd, int argc, const char *argv[]);
54int callBooleanCommand(Command *cmd, bool arg);
55
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080056/*
57 * Function management
58 */
59
60typedef int (*FunctionHook)(const char *name, void *cookie,
61 int argc, const char *argv[],
Doug Zongkerf28c9162009-06-02 15:30:11 -070062 char **result, size_t *resultLen);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080063
64struct Function;
65typedef struct Function Function;
66
67int registerFunction(const char *name, FunctionHook hook, void *cookie);
68
69Function *findFunction(const char *name);
70
71int callFunction(Function *fn, int argc, const char *argv[],
72 char **result, size_t *resultLen);
73
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080074#endif // AMEND_COMMANDS_H_