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
15 * Szabo, Janos Zoltan – initial implementation
16 * Vilmos Varga - author
18 ******************************************************************************/
20 // Description: Header file for Cli
24 //----------------------------------------------------------------------------
29 #include "../../core/Types.h"
30 #include "../mctr/UserInterface.h"
31 #include "../mctr/MainController.h"
32 #include "../mctr/config_data.h"
34 //----------------------------------------------------------------------------
38 //----------------------------------------------------------------------------
41 * User interface cli implementation.
43 class Cli
: public mctr::UserInterface
47 * Constructor, destructor.
53 * Enters the main loop.
55 virtual int enterLoop(int argc
, char* argv
[]);
58 * Status of MC has changed.
60 virtual void status_change();
63 * Error message from MC.
65 virtual void error(int severity
, const char *message
);
68 * Indicates whether console logging is enabled.
70 boolean loggingEnabled
;
72 * General notification from MC.
74 virtual void notify(const struct timeval
*timestamp
, const char *source
,
75 int severity
, const char *message
);
78 * Callback functions for command processing.
79 * (All callback functions MUST be public!!!)
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
);
94 virtual void executeBatchFile(const char* filename
);
98 * Deallocates the memory used by global variables
100 static void cleanUp();
103 * Print the welcome text.
105 static void printWelcome();
107 * Print program usage information.
109 static void printUsage(const char *prg_name
);
112 * The main cli event loop.
114 int interactiveMode();
117 * Execution in batch mode.
122 * Process the command to perform the action accordingly.
124 void processCommand(char *);
127 * Readline command completion function for MC commands.
129 static char *completeCommand(const char *, int);
132 * Customized character input function for readline.
134 static int getcWithShellDetection(FILE *);
137 * Remove surrounding LWS, move string content to the beginning of
138 * the buffer and zero the rest of the buffer.
140 void stripLWS(char *);
143 * Flag for indicating program termination.
148 * Transforms internal MC state codes to printable strings.
150 static const char *verdict2str(verdicttype verdict
);
153 * Prints information about the current state of MC.
158 * Mutex and condition variable for synchronization between threads.
160 pthread_mutex_t mutex
;
164 * Primitives for controlling the mutex and the condition variable.
172 * Functions for waiting until MC reaches the desired state.
175 WAIT_NOTHING
, WAIT_HC_CONNECTED
,
176 WAIT_ACTIVE
, WAIT_MTC_CREATED
, WAIT_MTC_READY
,
177 WAIT_MTC_TERMINATED
, WAIT_SHUTDOWN_COMPLETE
,
180 boolean
conditionHolds(waitStateEnum askedState
);
181 void waitMCState(waitStateEnum newWaitState
);
183 int getHostIndex(const char*);
186 * Executes the index-th element of the execute list
188 void executeFromList(int index
);
190 * Shows which item of the list is currently being executed
192 int executeListIndex
;
197 // pointer to member methods
198 typedef void (Cli::*callback_t
)(const char *text
);
200 //----------------------------------------------------------------------------
202 } /* namespace cli */
204 //----------------------------------------------------------------------------
209 // indent-tabs-mode: nil