rasdaman complete source
rascontrol.hh
Go to the documentation of this file.
1 /*
2 * This file is part of rasdaman community.
3 *
4 * Rasdaman community is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * Rasdaman community is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
18 rasdaman GmbH.
19 *
20 * For more information please see <http://www.rasdaman.org>
21 * or contact Peter Baumann via <baumann@rasdaman.com>.
22 /
36 #ifndef RASCONTROL_H
37 #define RASCONTROL_H
38 
39 #include <stdio.h>
40 #include <errno.h>
41 #include <stdlib.h>
42 #include <unistd.h>
43 #include <sys/types.h>
44 #include <sys/socket.h>
45 #include <netinet/in.h>
46 #include <netdb.h>
47 #include <iostream>
48 #include <string.h>
49 #include <string>
50 
51 #include "commline/cmlparser.hh"
52 
53 #include "../rasmgr/ras_crypto.hh"
54 #include "rasmgr_utils_comm.hh"
55 #include "rasmgr_utils_conf.hh"
56 
57 const int WKMUNKNOWN = 0;
58 const int WKMINTERACTIV = 1;
59 const int WKMBATCH = 2;
60 const int WKMLOGIN = 3;
61 const int WKMTESTLOGIN = 4;
62 const int WKMCREATE = 5;
63 const int WKMTSLANG = 6;
64 
65 const int LGIUNKNOWN = 0;
66 const int LGIINTERACTIV = 1;
67 const int LGIENVIRONM = 2;
68 
69 const int PROMPTSING = 0;
70 const int PROMPTRASC = 1;
71 const int PROMPTFULL = 2;
72 
73 
74 // ----------------
75 // global constants
76 // ----------------
77 
78 #define EOS_CHAR '\0'
79 
80 // rasmgr command words
81 #define RASMGRCMD_EXIT "exit"
82 #define RASMGRCMD_HELLO "Hello"
83 #define RASMGRCMD_LIST_MODUS "list modus"
84 
85 
86 // interim debug solution, should be replaced by std rasdaman mechanism -- now with ../rasmgr/debug.hh
87 // #define TALK(a) cout << a << endl;
88 //#define TALK(a) { /* TALK(a) */ }
89 
90 void printCommandLineHelp();
91 int getCommand();
92 
93 int sendCommandandPrintAnswer(const char*);
94 bool exitbyerror(char*);
95 int createSocket();
96 
97 class EditLine
98 {
99 public:
100  EditLine();
101  ~EditLine();
102 
103  const char *interactiveCommand(const char *prompt);
104  const char *fromStdinCommand(const char *prompt);
105 
106 private:
107  char *rl_gets(const char *prompt);
108  char line[MAXMSG];
109 
110 };
111 
112 class RascontrolConfig:public ConfigurationBase
113 {
114 public:
115  RascontrolConfig();
116 
117  // false means program shouldn't continue
118  bool interpretArguments(int argc, char **argv);
119 
120  int getWorkModus();
121  int getLoginModus();
122  const char* getRasMgrHost();
123  int getRasMgrPort();
124  bool histRequest();
125  const char* getHistFileName();
126  const char* getPrompt();
127  const char* getCommand();
128  bool beQuiet();
129  bool showHelp();
130 
131  void printDebugInfo();
132 
133  void printHelp();
134 private:
135 
136  bool paramError();
137 
138  int workModus;
139  int loginModus;
140 
141  char rasmgrHost[100];
142  int rasmgrPort;
143  bool reqHist;
144  char histFileName[100];
145 
146  int promptType;
147  char prompt[100];
148  char command[100];
149  bool quiet;
150 
151  bool isCommand( const char *command, const char *key );
152 
153  //-- parameters of this program
154  CommandLineParser &cmlInter;
155  CommandLineParameter &cmlHelp, &cmlHost, &cmlPort, &cmlLogin;
156 //#ifdef NO_OFFICIAL_RELEASE
157  CommandLineParameter &cmlHist;
158 //#endif
159  CommandLineParameter &cmlPrompt, &cmlTestLogin;
160  CommandLineParameter &cmlInteractive, &cmlQuiet, &cmlExecute;
161 
162 };
163 
164 #endif
void showHelp()