MASA-Core
MasaNetCLI.hpp
Go to the documentation of this file.
00001 /*******************************************************************************
00002  *
00003  * Copyright (c) 2010-2015   Edans Sandes
00004  *
00005  * This file is part of MASA-Core.
00006  * 
00007  * MASA-Core is free software: you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation, either version 3 of the License, or
00010  * (at your option) any later version.
00011  * 
00012  * MASA-Core is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with MASA-Core.  If not, see <http://www.gnu.org/licenses/>.
00019  *
00020  ******************************************************************************/
00021 
00022 #ifndef MASANETCLI_HPP_
00023 #define MASANETCLI_HPP_
00024 
00025 
00026 #include "MasaNet.hpp"
00027 
00028 
00029 #define CMD_OK          (0)
00030 #define CMD_ERROR       (1)
00031 #define CMD_ABORT       (-1)
00032 
00033 typedef int (*command_f) (char *arg);
00034 
00035 typedef struct {
00036   char *name;                   /* User printable name of the function. */
00037   command_f func;                       /* Function to call to do the job. */
00038   char *doc;                    /* Documentation for this function.  */
00039 } command_t;
00040 
00041 class MasaNetCLI {
00042 public:
00043         static void initialize();
00044         static void openConsole();
00045 
00046         static int cmd_connect(char* arg);
00047 private:
00048         static MasaNet* masaNet;
00049         static command_t commands[];
00050 
00051         static char * command_generator(const char *text, int state);
00052         static char *strip_whitespaces(char * string);
00053         static command_t * find_command(char *name);
00054         static int execute_line(char *line);
00055         static char** console_completion(const char *text, int start, int end);
00056 
00057         static void printTopology(int type);
00058 
00059         static int cmd_help(char* arg);
00060         static int cmd_status(char* arg);
00061         static int cmd_quit(char* arg);
00062         static int cmd_show_connected(char* arg);
00063         static int cmd_show_connected_remote(char* arg);
00064         static int cmd_show_discovered(char* arg);
00065         static int cmd_show_ring(char* arg);
00066         static int cmd_create_ring(char* arg);
00067         static int cmd_test_ring(char* arg);
00068 };
00069 
00070 #endif /* MASANETCLI_HPP_ */