|
@@ -1,72 +1,14 @@
|
|
|
-#include <machineiomanager.hpp>
|
|
|
-#include <useriomanager.hpp>
|
|
|
+#include "../include/machineiomanager.hpp"
|
|
|
+#include "../include/useriomanager.hpp"
|
|
|
+#include "../include/commands.hpp"
|
|
|
|
|
|
#include <boost/program_options.hpp>
|
|
|
#include <boost/asio.hpp>
|
|
|
-#include <cctype>
|
|
|
#include <iostream>
|
|
|
#include <string>
|
|
|
|
|
|
-#include <readline/readline.h>
|
|
|
-
|
|
|
-#define COMMANDLEN 10
|
|
|
-#define sizeofarr(a) (sizeof(a) / sizeof(a[0]))
|
|
|
-
|
|
|
namespace bpo = boost::program_options;
|
|
|
|
|
|
-typedef enum {
|
|
|
- CMD_HELP,
|
|
|
- CMD_CONNECT,
|
|
|
- CMD_DISCONNECT,
|
|
|
- CMD_PUT,
|
|
|
- CMD_REMOVE,
|
|
|
- CMD_GET,
|
|
|
- CMD_QUERY,
|
|
|
- CMD_SETUP,
|
|
|
- CMD_LOG,
|
|
|
- CMD_UNKNOWN
|
|
|
-} COMMANDTYPES;
|
|
|
-
|
|
|
-typedef struct {
|
|
|
- COMMANDTYPES cmd;
|
|
|
- const char *name;
|
|
|
- const char *desc;
|
|
|
-} CMD;
|
|
|
-
|
|
|
-CMD commands[]{{CMD_HELP, "help", "show help"},
|
|
|
- {CMD_CONNECT, "connect", "connect to IP"},
|
|
|
- {CMD_DISCONNECT, "disconnect", "disconnect from IP"},
|
|
|
- {CMD_PUT, "put", "upload file to IP and add to queue"},
|
|
|
- {CMD_REMOVE, "remove",
|
|
|
- "remove file from IP and queue (stops xfer if required)"},
|
|
|
- {CMD_GET, "get", "retrieve file from IP"},
|
|
|
- {CMD_QUERY, "query", "query status of IP"},
|
|
|
- {CMD_SETUP, "setup", "configure server at IP"},
|
|
|
- {CMD_LOG, "log", "show log from IP"}};
|
|
|
-
|
|
|
-COMMANDTYPES getCommand(char *str, unsigned int isshort) {
|
|
|
- COMMANDTYPES ret = CMD_UNKNOWN;
|
|
|
- char temp[COMMANDLEN + 1] = {0};
|
|
|
- if (strlen(str) > COMMANDLEN)
|
|
|
- return ret;
|
|
|
- if (isshort)
|
|
|
- temp[0] = std::tolower(str[0]);
|
|
|
- else
|
|
|
- for (int i = 0; i < COMMANDLEN; i++)
|
|
|
- temp[i] = std::tolower(str[i]);
|
|
|
-
|
|
|
- for (int i = 0; i < sizeofarr(commands); i++) {
|
|
|
- if (isshort) {
|
|
|
- if (tolower(str[0]) == commands[i].name[0])
|
|
|
- ret = commands[i].cmd;
|
|
|
- } else {
|
|
|
- if (!strncmp(temp, commands[i].name, COMMANDLEN))
|
|
|
- ret = commands[i].cmd;
|
|
|
- }
|
|
|
- }
|
|
|
- return ret;
|
|
|
-}
|
|
|
-
|
|
|
void show_help(char *exec) {
|
|
|
std::printf("ccats command line interface\n");
|
|
|
std::printf("usage: %s IP [Options]\n", exec);
|
|
@@ -118,9 +60,14 @@ int main(int argc, char **argv) {
|
|
|
std::fprintf(stderr, "%s\n", ex.what());
|
|
|
}
|
|
|
std::printf("ip %s machine mode is %d file is %s\n", argv[1], machine, file?file:"");
|
|
|
- //~ std::printf("read line %s\n", readline("fancprompt "));
|
|
|
|
|
|
- ioman = new UserIoManager(argv[1]);
|
|
|
+ if(machine) {
|
|
|
+ ioman = new MachineIoManager(argv[1]);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ ioman = new UserIoManager(argv[1]);
|
|
|
+ }
|
|
|
+
|
|
|
// ‘MachineIoManager::MachineIoManager(char*&)’
|
|
|
if(ioman->connect()) {
|
|
|
ioman->run();
|