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() && !mainWin->getWaitState()){
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);
}
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))
+ if (availableDirComm(conn)) {
write_dir(conn, msg, dowait);
+ }
return conn;
}
int Console::notifyOff()
{
int conn = 0;
- if (availableDirComm(conn))
+ if (availableDirComm(conn)) {
notify(conn, false);
+ }
return conn;
}
*/
bool Console::availableDirComm(int &conn)
{
- QHash<int, DirComm*>::const_iterator iter = m_dircommHash.constBegin();
- while (iter != m_dircommHash.constEnd()) {
- DirComm *dircomm = iter.value();
- if (dircomm->m_at_prompt && dircomm->m_at_main_prompt && dircomm->is_notify_enabled()) {
- conn = dircomm->m_conn;
- return true;
- }
- ++iter;
- }
- if (newDirComm(conn))
+ if (currentDirComm(conn)) {
return true;
- else
- return false;
+ }
+ return newDirComm(conn);
}
*/
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();
- if (dircomm->m_at_prompt && !dircomm->m_at_main_prompt && dircomm->is_notify_enabled()) {
+ if (dircomm->m_at_prompt && dircomm->m_at_main_prompt && dircomm->is_notify_enabled()) {
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;
}
return false;
*/
bool Console::newDirComm(int &conn)
{
- m_dircommCounter += 1;
- conn = m_dircommCounter;
- if (mainWin->m_connDebug)
- Pmsg2(000, "DirComm %i About to Create and Connect %s\n", m_dircommCounter, m_dir->name());
+ 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)
- Pmsg2(000, "DirComm %i Connected %s\n", conn, m_dir->name());
- else
- Pmsg2(000, "DirComm %i NOT Connected %s\n", conn, m_dir->name());
+ 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;
}