Commit | Line | Data |
---|---|---|
d44e3c4f | 1 | /****************************************************************************** |
2 | * Copyright (c) 2000-2016 Ericsson Telecom AB | |
3 | * All rights reserved. This program and the accompanying materials | |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * | |
8 | * Contributors: | |
9 | * Balasko, Jeno | |
10 | * Bene, Tamas | |
11 | * Forstner, Matyas | |
12 | * Gecse, Roland | |
13 | * Lovassy, Arpad | |
14 | * Raduly, Csaba | |
15 | * Szabo, Janos Zoltan – initial implementation | |
16 | * Vilmos Varga - author | |
17 | * | |
18 | ******************************************************************************/ | |
970ed795 EL |
19 | // |
20 | // Description: Header file for Cli | |
970ed795 EL |
21 | // |
22 | #ifndef CLI_CLI_H | |
23 | #define CLI_CLI_H | |
24 | //---------------------------------------------------------------------------- | |
25 | ||
26 | #include <stdio.h> | |
27 | #include <pthread.h> | |
28 | ||
29 | #include "../../core/Types.h" | |
30 | #include "../mctr/UserInterface.h" | |
31 | #include "../mctr/MainController.h" | |
32 | #include "../mctr/config_data.h" | |
33 | ||
34 | //---------------------------------------------------------------------------- | |
35 | ||
36 | namespace cli { | |
37 | ||
38 | //---------------------------------------------------------------------------- | |
39 | ||
40 | /** | |
41 | * User interface cli implementation. | |
42 | */ | |
43 | class Cli : public mctr::UserInterface | |
44 | { | |
45 | public: | |
46 | /** | |
47 | * Constructor, destructor. | |
48 | */ | |
49 | Cli(); | |
50 | ~Cli(); | |
51 | ||
52 | /** | |
53 | * Enters the main loop. | |
54 | */ | |
55 | virtual int enterLoop(int argc, char* argv[]); | |
56 | ||
57 | /** | |
58 | * Status of MC has changed. | |
59 | */ | |
60 | virtual void status_change(); | |
61 | ||
62 | /** | |
63 | * Error message from MC. | |
64 | */ | |
65 | virtual void error(int severity, const char *message); | |
66 | ||
67 | /* | |
68 | * Indicates whether console logging is enabled. | |
69 | */ | |
70 | boolean loggingEnabled; | |
71 | /** | |
72 | * General notification from MC. | |
73 | */ | |
74 | virtual void notify(const struct timeval *timestamp, const char *source, | |
75 | int severity, const char *message); | |
76 | ||
77 | /* | |
78 | * Callback functions for command processing. | |
79 | * (All callback functions MUST be public!!!) | |
80 | */ | |
81 | void cmtcCallback(const char *arguments); | |
82 | void smtcCallback(const char *arguments); | |
83 | void stopCallback(const char *arguments); | |
84 | void pauseCallback(const char *arguments); | |
85 | void continueCallback(const char *arguments); | |
86 | void emtcCallback(const char *arguments); | |
87 | void logCallback(const char *arguments); | |
88 | void infoCallback(const char *arguments); | |
89 | void reconfCallback(const char *arguments); | |
90 | void helpCallback(const char *arguments); | |
91 | void shellCallback(const char *arguments); | |
92 | void exitCallback(const char *arguments); | |
f08ff9ca BB |
93 | |
94 | virtual void executeBatchFile(const char* filename); | |
970ed795 EL |
95 | |
96 | private: | |
97 | /** | |
98 | * Deallocates the memory used by global variables | |
99 | */ | |
100 | static void cleanUp(); | |
101 | ||
102 | /** | |
103 | * Print the welcome text. | |
104 | */ | |
105 | static void printWelcome(); | |
106 | /** | |
107 | * Print program usage information. | |
108 | */ | |
109 | static void printUsage(const char *prg_name); | |
110 | ||
111 | /** | |
112 | * The main cli event loop. | |
113 | */ | |
114 | int interactiveMode(); | |
115 | ||
116 | /** | |
117 | * Execution in batch mode. | |
118 | */ | |
119 | int batchMode(); | |
120 | ||
121 | /** | |
122 | * Process the command to perform the action accordingly. | |
123 | */ | |
124 | void processCommand(char *); | |
125 | ||
126 | /* | |
127 | * Readline command completion function for MC commands. | |
128 | */ | |
129 | static char *completeCommand(const char *, int); | |
130 | ||
131 | /* | |
132 | * Customized character input function for readline. | |
133 | */ | |
134 | static int getcWithShellDetection(FILE *); | |
135 | ||
136 | /** | |
137 | * Remove surrounding LWS, move string content to the beginning of | |
138 | * the buffer and zero the rest of the buffer. | |
139 | */ | |
140 | void stripLWS(char *); | |
141 | ||
142 | /* | |
143 | * Flag for indicating program termination. | |
144 | */ | |
145 | boolean exitFlag; | |
146 | ||
147 | /* | |
148 | * Transforms internal MC state codes to printable strings. | |
149 | */ | |
150 | static const char *verdict2str(verdicttype verdict); | |
151 | ||
152 | /* | |
153 | * Prints information about the current state of MC. | |
154 | */ | |
155 | void printInfo(); | |
156 | ||
157 | /* | |
158 | * Mutex and condition variable for synchronization between threads. | |
159 | */ | |
160 | pthread_mutex_t mutex; | |
161 | pthread_cond_t cond; | |
162 | ||
163 | /* | |
164 | * Primitives for controlling the mutex and the condition variable. | |
165 | */ | |
166 | void lock(); | |
167 | void unlock(); | |
168 | void wait(); | |
169 | void signal(); | |
170 | ||
171 | /* | |
172 | * Functions for waiting until MC reaches the desired state. | |
173 | */ | |
174 | enum waitStateEnum { | |
175 | WAIT_NOTHING, WAIT_HC_CONNECTED, | |
176 | WAIT_ACTIVE, WAIT_MTC_CREATED, WAIT_MTC_READY, | |
177 | WAIT_MTC_TERMINATED, WAIT_SHUTDOWN_COMPLETE, | |
178 | WAIT_EXECUTE_LIST | |
179 | } waitState; | |
180 | boolean conditionHolds(waitStateEnum askedState); | |
181 | void waitMCState(waitStateEnum newWaitState); | |
182 | ||
183 | int getHostIndex(const char*); | |
184 | ||
185 | /* | |
186 | * Executes the index-th element of the execute list | |
187 | */ | |
188 | void executeFromList(int index); | |
189 | /* | |
190 | * Shows which item of the list is currently being executed | |
191 | */ | |
192 | int executeListIndex; | |
193 | ||
b0caada2 | 194 | char* cfg_file_name; |
970ed795 EL |
195 | config_data mycfg; |
196 | }; | |
197 | ||
198 | // pointer to member methods | |
199 | typedef void (Cli::*callback_t)(const char *text); | |
200 | ||
201 | //---------------------------------------------------------------------------- | |
202 | ||
203 | } /* namespace cli */ | |
204 | ||
205 | //---------------------------------------------------------------------------- | |
206 | #endif // CLI_CLI_H | |
207 | ||
208 | // Local Variables: | |
209 | // mode: C++ | |
210 | // indent-tabs-mode: nil | |
211 | // c-basic-offset: 2 | |
212 | // End: |