1 /*
2  * Copyright (c)2004 The DragonFly Project.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  *   Redistributions of source code must retain the above copyright
9  *   notice, this list of conditions and the following disclaimer.
10  *
11  *   Redistributions in binary form must reproduce the above copyright
12  *   notice, this list of conditions and the following disclaimer in
13  *   the documentation and/or other materials provided with the
14  *   distribution.
15  *
16  *   Neither the name of the DragonFly Project nor the names of its
17  *   contributors may be used to endorse or promote products derived
18  *   from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31  * OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 /*
35  * commands.h
36  * $Id: commands.h,v 1.14 2005/02/06 21:05:18 cpressey Exp $
37  */
38 
39 #include <stdio.h>
40 
41 #include "libdfui/dfui.h"
42 
43 #ifndef __COMMANDS_H_
44 #define __COMMANDS_H_
45 
46 #include "diskutil.h"
47 
48 /*** TYPES ***/
49 
50 #include "functions.h"
51 
52 struct commands;
53 struct command;
54 
55 #ifdef NEEDS_COMMANDS_STRUCTURE_DEFINITIONS
56 
57 struct commands {
58 	struct command *head;
59 	struct command *tail;
60 };
61 
62 struct command {
63 	struct command *next;
64 	struct command *prev;
65 	char *cmdline;		/* command line to execute */
66 	char *desc;		/* description displayed in progress bar */
67 	int log_mode;		/* use a COMMAND_LOG_* constant here */
68 	int failure_mode;	/* use a COMMAND_FAILURE_* constant here */
69 	char *tag;		/* tag which is recorded on failure */
70 	int result;		/* result code from executing command */
71 	char *output;		/* output of command */
72 };
73 
74 #endif
75 
76 #define	COMMAND_LOG_SILENT	0
77 #define	COMMAND_LOG_QUIET	1
78 #define	COMMAND_LOG_VERBOSE	2
79 
80 #define	COMMAND_FAILURE_IGNORE	0
81 #define	COMMAND_FAILURE_WARN	1
82 #define	COMMAND_FAILURE_ABORT	2
83 
84 #define COMMAND_RESULT_NEVER_EXECUTED	 -1
85 #define COMMAND_RESULT_POPEN_ERR	256
86 #define COMMAND_RESULT_SELECT_ERR	257
87 #define COMMAND_RESULT_CANCELLED	512
88 #define COMMAND_RESULT_SKIPPED		513
89 
90 /*** PROTOTYPES ***/
91 
92 struct commands	*commands_new(void);
93 struct command	*command_add(struct commands *, const char *, ...)
94 		     __printflike(2, 3);
95 
96 void		 command_set_log_mode(struct command *, int);
97 void		 command_set_failure_mode(struct command *, int);
98 void		 command_set_desc(struct command *, const char *, ...)
99 		     __printflike(2, 3);
100 void		 command_set_tag(struct command *, const char *, ...)
101 		     __printflike(2, 3);
102 
103 struct command	*command_get_first(const struct commands *);
104 struct command	*command_get_next(const struct command *);
105 
106 char		*command_get_cmdline(const struct command *);
107 char		*command_get_tag(const struct command *);
108 int		 command_get_result(const struct command *);
109 
110 void		 commands_preview(struct dfui_connection *, const struct commands *);
111 int		 commands_execute(struct i_fn_args *, struct commands *);
112 
113 void		 commands_free(struct commands *);
114 
115 void		 view_command_log(struct i_fn_args *);
116 
117 /* Command Generators */
118 
119 void		 unmount_all_under(struct i_fn_args *, struct commands *,
120 		     const char *, ...) __printflike(3, 4);
121 
122 #endif /* !__COMMANDS_H_ */
123