The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1 | /* |
| 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 Zongker | f28c916 | 2009-06-02 15:30:11 -0700 | [diff] [blame] | 17 | #include <stdbool.h> |
| 18 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 19 | #ifndef AMEND_COMMANDS_H_ |
| 20 | #define AMEND_COMMANDS_H_ |
| 21 | |
Doug Zongker | f28c916 | 2009-06-02 15:30:11 -0700 | [diff] [blame] | 22 | /* Invoke a command. |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 23 | * |
| 24 | * When a boolean command is called, "argc" is the boolean value and |
| 25 | * "argv" is NULL. |
| 26 | */ |
| 27 | typedef int (*CommandHook)(const char *name, void *cookie, |
Doug Zongker | f28c916 | 2009-06-02 15:30:11 -0700 | [diff] [blame] | 28 | int argc, const char *argv[]); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 29 | |
| 30 | int commandInit(void); |
| 31 | void commandCleanup(void); |
| 32 | |
| 33 | /* |
| 34 | * Command management |
| 35 | */ |
| 36 | |
| 37 | struct Command; |
| 38 | typedef struct Command Command; |
| 39 | |
| 40 | typedef enum { |
| 41 | CMD_ARGS_UNKNOWN = -1, |
| 42 | CMD_ARGS_BOOLEAN = 0, |
| 43 | CMD_ARGS_WORDS |
| 44 | } CommandArgumentType; |
| 45 | |
| 46 | int registerCommand(const char *name, |
| 47 | CommandArgumentType argType, CommandHook hook, void *cookie); |
| 48 | |
| 49 | Command *findCommand(const char *name); |
| 50 | |
| 51 | CommandArgumentType getCommandArgumentType(Command *cmd); |
| 52 | |
| 53 | int callCommand(Command *cmd, int argc, const char *argv[]); |
| 54 | int callBooleanCommand(Command *cmd, bool arg); |
| 55 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 56 | /* |
| 57 | * Function management |
| 58 | */ |
| 59 | |
| 60 | typedef int (*FunctionHook)(const char *name, void *cookie, |
| 61 | int argc, const char *argv[], |
Doug Zongker | f28c916 | 2009-06-02 15:30:11 -0700 | [diff] [blame] | 62 | char **result, size_t *resultLen); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 63 | |
| 64 | struct Function; |
| 65 | typedef struct Function Function; |
| 66 | |
| 67 | int registerFunction(const char *name, FunctionHook hook, void *cookie); |
| 68 | |
| 69 | Function *findFunction(const char *name); |
| 70 | |
| 71 | int callFunction(Function *fn, int argc, const char *argv[], |
| 72 | char **result, size_t *resultLen); |
| 73 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 74 | #endif // AMEND_COMMANDS_H_ |