/*
Bacula® - The Network Backup Solution
- Copyright (C) 2007-2009 Free Software Foundation Europe e.V.
+ Copyright (C) 2007-2010 Free Software Foundation Europe e.V.
The main author of Bacula is Kern Sibbald, with contributions from
many others, a complete list can be found in the file AUTHORS.
Switzerland, email:ftf@fsfeurope.org.
*/
/*
- * Version $Id$
- *
* Console Class
*
* Kern Sibbald, January MMVII
#include "select.h"
#include "run/run.h"
-Console::Console(QStackedWidget *parent)
+Console::Console(QTabWidget *parent)
{
QFont font;
+ m_name = tr("Console");
m_messages_pending = false;
m_parent = parent;
m_closeable = false;
m_console = this;
+ m_warningPrevent = false;
m_dircommCounter = 0;
+
+ /*
+ * Create a connection to the Director and put it in a hash table
+ */
m_dircommHash.insert(m_dircommCounter, new DirComm(this, m_dircommCounter));
setupUi(this);
void Console::poll_messages()
{
int conn;
- if (!availableDirComm(conn))
+ if (!availableDirComm(conn)) {
return;
+ }
DirComm *dircomm = m_dircommHash.value(conn);
- if (mainWin->m_checkMessages && dircomm->m_at_main_prompt && hasFocus()){
+ if (mainWin->m_checkMessages && dircomm->m_at_main_prompt && hasFocus() && !mainWin->getWaitState()){
messagesPending(true);
dircomm->write(".messages");
displayToPrompt(conn);
if (dircomm->connect_dir()) {
if (mainWin->m_connDebug)
- Pmsg0(000, "DirComm 0 Seems to have Connected\n");
+ Pmsg1(000, "DirComm 0 Seems to have Connected %s\n", m_dir->name());
beginNewCommand(0);
}
- populateLists(true);
mainWin->set_status(_("Connected"));
startTimer(); /* start message timer */
* A function created to separate out the population of the lists
* from the Console::connect_dir function
*/
-void Console::populateLists(bool forcenew)
+void Console::populateLists(bool /*forcenew*/)
{
int conn;
- if (forcenew)
- if (!newDirComm(conn)) {
- Pmsg0(000, "newDirComm Seems to Failed to create a connection for populateLists\n");
- return;
- }
- else
- if(!availableDirComm(conn)) {
- Pmsg0(000, "availableDirComm Seems to Failed to find a connection for populateLists\n");
- return;
- }
- populateLists(conn);
+ if (!availableDirComm(conn) && !newDirComm(conn)) {
+ Emsg1(M_ABORT, 0, "Failed to connect to %s for populateLists.\n", m_dir->name());
+ return;
+ }
+ populateLists(conn);
}
void Console::populateLists(int conn)
job_list.clear();
client_list.clear();
fileset_list.clear();
- fileset_list.clear();
messages_list.clear();
pool_list.clear();
storage_list.clear();
type_list.clear();
level_list.clear();
+ volstatus_list.clear();
+ mediatype_list.clear();
dir_cmd(conn, ".jobs", job_list);
dir_cmd(conn, ".clients", client_list);
dir_cmd(conn, ".filesets", fileset_list);
dir_cmd(conn, ".storage", storage_list);
dir_cmd(conn, ".types", type_list);
dir_cmd(conn, ".levels", level_list);
+ dir_cmd(conn, ".volstatus", volstatus_list);
+ dir_cmd(conn, ".mediatypes", mediatype_list);
+ dir_cmd(conn, ".locations", location_list);
if (mainWin->m_connDebug) {
- QString dbgmsg = QString("jobs=%1 clients=%2 filesets=%3 msgs=%4 pools=%5 storage=%6 types=%7 levels=%8\n")
+ QString dbgmsg = QString("jobs=%1 clients=%2 filesets=%3 msgs=%4 pools=%5 storage=%6 types=%7 levels=%8 conn=%9 %10\n")
.arg(job_list.count()).arg(client_list.count()).arg(fileset_list.count()).arg(messages_list.count())
- .arg(pool_list.count()).arg(storage_list.count()).arg(type_list.count()).arg(level_list.count());
- Pmsg1(000, "%s\n", dbgmsg.toUtf8().data());
+ .arg(pool_list.count()).arg(storage_list.count()).arg(type_list.count()).arg(level_list.count())
+ .arg(conn).arg(m_dir->name());
+ Pmsg1(000, "%s", dbgmsg.toUtf8().data());
}
+ job_list.sort();
+ client_list.sort();
+ fileset_list.sort();
+ messages_list.sort();
+ pool_list.sort();
+ storage_list.sort();
+ type_list.sort();
+ level_list.sort();
}
/*
bool Console::dir_cmd(const char *cmd, QStringList &results)
{
int conn;
- if(availableDirComm(conn)) {
+ if (availableDirComm(conn)) {
dir_cmd(conn, cmd, results);
return true;
} else {
- Pmsg0(000, "dir_cmd Seems to Failed to find a connection\n");
+ Pmsg1(000, "dir_cmd failed to connect to %s\n", m_dir->name());
return false;
}
}
DirComm *dircomm = m_dircommHash.value(conn);
int stat;
- if (mainWin->m_connDebug)
- Pmsg2(000, "dir_cmd conn %i %s\n", conn, cmd);
+ if (mainWin->m_connDebug) {
+ QString dbgmsg = QString("dir_cmd conn %1 %2 %3\n").arg(conn).arg(m_dir->name()).arg(cmd);
+ Pmsg1(000, "%s", dbgmsg.toUtf8().data());
+ }
notify(conn, false);
dircomm->write(cmd);
while ((stat = dircomm->read()) > 0 && dircomm->is_in_command()) {
bool Console::sql_cmd(QString &query, QStringList &results)
{
int conn;
- if (!availableDirComm(conn))
+ if (!availableDirComm(conn)) {
return false;
+ }
return sql_cmd(conn, query.toUtf8().data(), results, true);
}
bool Console::sql_cmd(const char *query, QStringList &results)
{
int conn;
- if (!availableDirComm(conn))
+ if (!availableDirComm(conn)) {
return false;
+ }
return sql_cmd(conn, query, results, true);
}
return true; /* ***FIXME*** return any command error */
}
-/* Send a command to the Director */
+/*
+ * Overloads for
+ * Sending a command to the Director
+ */
int Console::write_dir(const char *msg)
{
int conn;
- if(availableDirComm(conn))
+ if (availableDirComm(conn)) {
write_dir(conn, msg);
+ }
+ return conn;
+}
+
+int Console::write_dir(const char *msg, bool dowait)
+{
+ int conn;
+ if (availableDirComm(conn)) {
+ write_dir(conn, msg, dowait);
+ }
return conn;
}
-/* Send a command to the Director */
void Console::write_dir(int conn, const char *msg)
+{
+ write_dir(conn, msg, true);
+}
+
+/*
+ * Send a command to the Director
+ */
+void Console::write_dir(int conn, const char *msg, bool dowait)
{
DirComm *dircomm = m_dircommHash.value(conn);
if (dircomm->m_sock) {
mainWin->set_status(_("Processing command ..."));
- mainWin->waitEnter();
+ if (dowait)
+ mainWin->waitEnter();
dircomm->write(msg);
- mainWin->waitExit();
+ if (dowait)
+ mainWin->waitExit();
} else {
mainWin->set_status( tr(" Director not connected. Click on connect button."));
mainWin->actionConnect->setIcon(QIcon(":images/disconnected.png"));
conn = notifyOff();
beginNewCommand(conn);
DirComm *dircomm = m_dircommHash.value(conn);
+ bool prevWaitState = mainWin->getWaitState();
+ if (!prevWaitState)
+ mainWin->waitEnter();
if (mainWin->m_connDebug)
- Pmsg1(000, "job_defaults conn %i\n", conn);
+ Pmsg2(000, "job_defaults conn %i %s\n", conn, m_dir->name());
scmd = QString(".defaults job=\"%1\"").arg(job_defs.job_name);
dircomm->write(scmd);
while ((stat = dircomm->read()) > 0) {
if (donotify)
notify(conn, true);
+ if (!prevWaitState)
+ mainWin->waitExit();
return true;
bail_out:
if (donotify)
notify(conn, true);
+ if (!prevWaitState)
+ mainWin->waitExit();
return false;
}
/* Position cursor to end of screen */
void Console::update_cursor()
{
- QApplication::restoreOverrideCursor();
m_textEdit->moveCursor(QTextCursor::End);
m_textEdit->ensureCursorVisible();
}
for (int i=0; i < 3; i++) {
dircomm->write(".");
while (dircomm->read() > 0) {
+ Pmsg2(000, "begin new command loop %i %s\n", i, m_dir->name());
if (mainWin->m_displayAll) display_text(dircomm->msg());
}
if (dircomm->m_at_main_prompt) {
int stat = 0;
QString buf;
- if (mainWin->m_commDebug) Pmsg0(000, "DisplaytoPrompt\n");
+ if (mainWin->m_commDebug) Pmsg1(000, "DisplaytoPrompt %s\n", m_dir->name());
while (!dircomm->m_at_prompt) {
if ((stat=dircomm->read()) > 0) {
buf += dircomm->msg();
}
}
display_text(buf);
- if (mainWin->m_commDebug) Pmsg1(000, "endDisplaytoPrompt=%d\n", stat);
+ if (mainWin->m_commDebug) Pmsg2(000, "endDisplaytoPrompt=%d %s\n", stat, m_dir->name());
}
void Console::discardToPrompt(int conn)
DirComm *dircomm = m_dircommHash.value(conn);
int stat = 0;
- if (mainWin->m_commDebug) Pmsg0(000, "discardToPrompt\n");
+ if (mainWin->m_commDebug) Pmsg1(000, "discardToPrompt %s\n", m_dir->name());
if (mainWin->m_displayAll) {
displayToPrompt(conn);
} else {
while (!dircomm->m_at_prompt) {
- stat=dircomm->read();
+ stat = dircomm->read();
+ if (stat < 0) {
+ break;
+ }
}
}
- if (mainWin->m_commDebug) Pmsg1(000, "endDiscardToPrompt=%d\n", stat);
+ if (mainWin->m_commDebug) Pmsg2(000, "endDiscardToPrompt=%d %s\n", stat, m_dir->name());
+}
+
+QString Console::returnFromPrompt(int conn)
+{
+ DirComm *dircomm = m_dircommHash.value(conn);
+ QString text("");
+
+ int stat = 0;
+ text = "";
+ if (mainWin->m_commDebug) Pmsg1(000, "returnFromPrompt %s\n", m_dir->name());
+ while (!dircomm->m_at_prompt) {
+ if ((stat=dircomm->read()) > 0) {
+ text += dircomm->msg();
+ }
+ }
+ if (mainWin->m_commDebug) Pmsg2(000, "endreturnFromPrompt=%d %s\n", stat, m_dir->name());
+ return text;
}
/*
* When the notifier is enabled, read_dir() will automatically be
* called by the Qt event loop when ever there is any output
- * from the Directory, and read_dir() will then display it on
+ * from the Director, and read_dir() will then display it on
* the console.
*
* When we are in a bat dialog, we want to control *all* output
- * from the Directory, so we set notify to off.
+ * from the Director, so we set notify to off.
* m_console->notifiy(false);
*/
int Console::notifyOff()
{
int conn = 0;
- if(availableDirComm(conn))
+ if (availableDirComm(conn)) {
notify(conn, false);
+ }
return conn;
}
* This may be rendered not needed if the multiple connections feature gets working */
bool Console::hasFocus()
{
- if (mainWin->stackedWidget->currentIndex() == mainWin->stackedWidget->indexOf(this))
+ if (mainWin->tabWidget->currentIndex() == mainWin->tabWidget->indexOf(this))
return true;
else
return false;
*/
bool Console::availableDirComm(int &conn)
{
+ if (currentDirComm(conn)) {
+ return true;
+ }
+ return newDirComm(conn);
+}
+
+
+/*
+ * Need current connection.
+ */
+bool Console::currentDirComm(int &conn)
+{
+ int i = 1;
QHash<int, DirComm*>::const_iterator iter = m_dircommHash.constBegin();
while (iter != m_dircommHash.constEnd()) {
DirComm *dircomm = iter.value();
conn = dircomm->m_conn;
return true;
}
+ if (mainWin->m_connDebug) {
+ Pmsg4(000, "currentDirComm=%d at_prompt=%d at_main=%d && notify=%d\n",
+ i, dircomm->m_at_prompt, dircomm->m_at_main_prompt, dircomm->is_notify_enabled());
+ i++;
+ }
++iter;
}
- if (newDirComm(conn))
- return true;
- else
- return false;
+ return false;
}
/*
*/
bool Console::newDirComm(int &conn)
{
- m_dircommCounter += 1;
- conn = m_dircommCounter;
- if (mainWin->m_connDebug)
- Pmsg1(000, "DirComm %i About to Create and Connect\n", m_dircommCounter);
+ m_dircommCounter++;
+ if (mainWin->m_connDebug) {
+ Pmsg2(000, "newDirComm=%i to: %s\n", m_dircommCounter, m_dir->name());
+ }
DirComm *dircomm = new DirComm(this, m_dircommCounter);
m_dircommHash.insert(m_dircommCounter, dircomm);
bool success = dircomm->connect_dir();
- if (mainWin->m_connDebug)
- if (success)
- Pmsg1(000, "DirComm %i Connected\n", conn);
- else
- Pmsg1(000, "DirComm %i NOT Connected\n", conn);
+ if (mainWin->m_connDebug) {
+ if (success) {
+ Pmsg2(000, "newDirComm=%i Connected %s\n", m_dircommCounter, m_dir->name());
+ } else {
+ Emsg2(M_ERROR, 0, "DirComm=%i. Unable to connect to %s\n",
+ m_dircommCounter, m_dir->name());
+ }
+ }
+ if (!success) {
+ m_dircommHash.remove(m_dircommCounter);
+ delete dircomm;
+ m_dircommCounter--;
+ }
+ conn = m_dircommCounter;
return success;
}