1 /* Copyright 2013-present Facebook, Inc. 2 * Licensed under the Apache License, Version 2.0 */ 3 4 #ifndef WATCHMAN_CMD_H 5 #define WATCHMAN_CMD_H 6 7 #ifdef __cplusplus 8 extern "C" { 9 #endif 10 11 typedef void (*watchman_command_func)( 12 struct watchman_client *client, 13 json_t *args); 14 15 typedef bool (*watchman_cli_cmd_validate_func)( 16 json_t *args, char **errmsg); 17 18 #define CMD_DAEMON 1 19 #define CMD_CLIENT 2 20 #define CMD_POISON_IMMUNE 4 21 struct watchman_command_handler_def { 22 const char *name; 23 watchman_command_func func; 24 int flags; 25 watchman_cli_cmd_validate_func cli_validate; 26 }; 27 28 // For commands that take the root dir as the second parameter, 29 // realpath's that parameter on the client side and updates the 30 // argument list 31 bool w_cmd_realpath_root(json_t *args, char **errmsg); 32 33 void preprocess_command(json_t *args, enum w_pdu_type output_pdu); 34 bool dispatch_command(struct watchman_client *client, json_t *args, int mode); 35 bool try_client_mode_command(json_t *cmd, bool pretty); 36 void w_register_command(struct watchman_command_handler_def *defs); 37 38 #define W_CMD_REG_1(symbol, name, func, flags, clivalidate) \ 39 static w_ctor_fn_type(symbol) { \ 40 static struct watchman_command_handler_def d = { \ 41 name, func, flags, clivalidate \ 42 }; \ 43 w_register_command(&d); \ 44 } \ 45 w_ctor_fn_reg(symbol) 46 47 #define W_CMD_REG(name, func, flags, clivalidate) \ 48 W_CMD_REG_1(w_gen_symbol(w_cmd_register_), \ 49 name, func, flags, clivalidate) 50 51 #define W_CAP_REG1(symbol, name) \ 52 static w_ctor_fn_type(symbol) { \ 53 w_capability_register(name); \ 54 } \ 55 w_ctor_fn_reg(symbol) 56 57 #define W_CAP_REG(name) \ 58 W_CAP_REG1(w_gen_symbol(w_cap_reg_), name) 59 60 void w_capability_register(const char *name); 61 bool w_capability_supported(const char *name); 62 json_t *w_capability_get_list(void); 63 64 void send_error_response(struct watchman_client *client, 65 const char *fmt, ...); 66 void send_and_dispose_response(struct watchman_client *client, 67 json_t *response); 68 bool enqueue_response(struct watchman_client *client, 69 json_t *json, bool ping); 70 71 w_root_t *resolve_root_or_err( 72 struct watchman_client *client, 73 json_t *args, 74 int root_index, 75 bool create); 76 77 json_t *make_response(void); 78 void annotate_with_clock(w_root_t *root, json_t *resp); 79 void add_root_warnings_to_response(json_t *response, w_root_t *root); 80 81 bool clock_id_string(uint32_t root_number, uint32_t ticks, char *buf, 82 size_t bufsize); 83 84 #ifdef __cplusplus 85 } 86 #endif 87 88 #endif 89 90 /* vim:ts=2:sw=2:et: 91 */ 92