1/*
2 * Copyright 2007, Ingo Weinhold, bonefish@cs.tu-berlin.de.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef _FSSH_FSSH_H
6#define _FSSH_FSSH_H
7
8
9#include "compatibility.h"
10
11#include <map>
12#include <string>
13
14#include "fssh_defs.h"
15
16
17typedef fssh_status_t command_function(int argc, const char* const* argv);
18
19
20namespace FSShell {
21
22
23enum {
24	COMMAND_RESULT_EXIT	= 1,
25};
26
27
28// Command
29class Command {
30public:
31								Command(const char* name,
32									const char* description);
33								Command(command_function* function,
34									const char* name, const char* description);
35	virtual						~Command();
36
37			const char*			Name() const;
38			const char*			Description() const;
39
40	virtual	fssh_status_t		Do(int argc, const char* const* argv);
41
42private:
43			std::string			fName;
44			std::string			fDescription;
45			command_function*	fFunction;
46};
47
48
49// CommandManager
50class CommandManager {
51private:
52								CommandManager();
53
54public:
55	static	CommandManager*		Default();
56
57			void				AddCommand(Command* command);
58			void				AddCommand(command_function* function,
59									const char* name, const char* description);
60			void				AddCommands(command_function* function,
61									const char* name, const char* description,
62									...);
63			Command*			FindCommand(const char* name) const;
64			void				ListCommands() const;
65
66private:
67	typedef std::map<std::string, Command*> CommandMap;
68
69			CommandMap			fCommands;
70
71	static	CommandManager*		sManager;
72};
73
74
75extern void register_additional_commands(void);
76
77
78}	// namespace FSShell
79
80
81#endif	// _FSSH_FSSH_H
82