fixed: ipc client connected event was being wiped out

daemon now communicates graceful shutdown message through new ipc system.
This commit is contained in:
Nick Bolton 2012-07-05 19:10:04 +00:00
parent 3d6551f708
commit ddb2d7feeb
10 changed files with 44 additions and 38 deletions

View File

@ -68,13 +68,12 @@ void IpcClient::read()
stream.readRawData(data, len);
readLogLine(QString::fromUtf8(data, len));
break;
}
break;
default: {
std::cout << "invalid code: " << codeBuf[0] << std::endl;
}
break;
default:
std::cerr << "message type not supported: " << codeBuf[0] << std::endl;
break;
}
}
}
@ -93,7 +92,7 @@ void IpcClient::error(QAbstractSocket::SocketError error)
QTimer::singleShot(1000, this, SLOT(connectToHost()));
}
void IpcClient::write(unsigned char code, unsigned char length, const char* data)
void IpcClient::write(int code, int length, const char* data)
{
QDataStream stream(m_Socket);
@ -102,12 +101,20 @@ void IpcClient::write(unsigned char code, unsigned char length, const char* data
stream.writeRawData(codeBuf, 1);
switch (code) {
case kIpcCommand: {
char lenBuf[2];
intToBytes(length, lenBuf, 2);
stream.writeRawData(lenBuf, 2);
stream.writeRawData(data, length);
}
case kIpcHello:
stream.writeRawData(data, 1);
break;
case kIpcCommand: {
char lenBuf[2];
intToBytes(length, lenBuf, 2);
stream.writeRawData(lenBuf, 2);
stream.writeRawData(data, length);
break;
}
default:
std::cerr << "message type not supported: " << code << std::endl;
break;
}
}

View File

@ -32,7 +32,7 @@ public:
IpcClient();
virtual ~IpcClient();
void write(unsigned char code, unsigned char length, const char* data);
void write(int code, int length, const char* data);
public slots:
void connectToHost();
@ -55,14 +55,14 @@ private:
QTcpSocket* m_Socket;
};
enum IpcMessageType {
enum qIpcMessageType {
kIpcHello,
kIpcLogLine,
kIpcCommand,
kIpcShutdown,
};
enum IpcClientType {
enum qIpcClientType {
kIpcClientUnknown,
kIpcClientGui,
kIpcClientNode,

View File

@ -686,7 +686,7 @@ void MainWindow::sendDaemonCommand(const QString& command, bool showErrors)
{
std::string s = command.toStdString();
const char* data = s.c_str();
m_IpcClient.write(Command, strlen(data), data);
m_IpcClient.write(kIpcCommand, strlen(data), data);
}
void MainWindow::on_m_pActionWizard_triggered()

View File

@ -69,10 +69,6 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
synergyServer
};
enum qIpcMessage {
Command = 1
};
enum qLevel {
Error,
Info
@ -135,7 +131,7 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
bool serverArgs(QStringList& args, QString& app);
void setStatus(const QString& status);
void sendDaemonCommand(const QString& command, bool showErrors);
void sendIpcMessage(qIpcMessage type, const char* buffer, bool showErrors);
void sendIpcMessage(qIpcMessageType type, const char* buffer, bool showErrors);
private:
QSettings& m_Settings;

View File

@ -121,6 +121,14 @@ CEventQueue::adoptBuffer(IEventQueueBuffer* buffer)
{
CArchMutexLock lock(m_mutex);
LOG((CLOG_DEBUG "adopting new buffer"));
if (m_events.size() != 0) {
// this can come as a nasty surprise to programmers expecting
// their events to be raised, only to have them deleted.
LOG((CLOG_WARN "discarding %d event(s), sorry", m_events.size()));
}
// discard old buffer and old events
delete m_buffer;
for (CEventTable::iterator i = m_events.begin(); i != m_events.end(); ++i) {

View File

@ -30,7 +30,7 @@ m_server(nullptr)
m_serverAddress.resolve();
EVENTQUEUE->adoptHandler(
m_socket.getConnectedEvent(), &m_socket,
m_socket.getConnectedEvent(), m_socket.getEventTarget(),
new TMethodEventJob<CIpcClient>(
this, &CIpcClient::handleConnected));
}

View File

@ -45,6 +45,7 @@ CIpcServer::~CIpcServer()
for (it = m_clients.begin(); it != m_clients.end(); it++) {
delete *it;
}
m_clients.empty();
EVENTQUEUE->removeHandler(m_socket.getConnectingEvent(), &m_socket);
}

View File

@ -437,7 +437,8 @@ CMSWindowsRelauncher::shutdownProcess(const PROCESS_INFORMATION& pi, int timeout
{
GetExitCodeProcess(pi.hProcess, &exitCode);
if (exitCode != STILL_ACTIVE) {
LOG((CLOG_INFO "process %d was shutdown successfully", pi.dwProcessId));
// yay, we got a graceful shutdown. there should be no hook in use errors!
LOG((CLOG_INFO "process %d was shutdown gracefully", pi.dwProcessId));
break;
}
else {

View File

@ -221,6 +221,8 @@ CDaemonApp::mainLoop(bool logToFile)
eventQueue.removeHandler(
CIpcServer::getClientConnectedEvent(), m_ipcServer);
CLOG->remove(m_ipcLogOutputter);
delete m_ipcLogOutputter;
delete m_ipcServer;
DAEMON_RUNNING(false);
@ -278,8 +280,6 @@ void
CDaemonApp::handleIpcMessage(const CEvent& e, void*)
{
CIpcMessage& m = *static_cast<CIpcMessage*>(e.getData());
LOG((CLOG_DEBUG "ipc message, type=%d", m.m_type));
switch (m.m_type) {
case kIpcCommand: {
CString& command = *static_cast<CString*>(m.m_data);
@ -300,9 +300,5 @@ CDaemonApp::handleIpcMessage(const CEvent& e, void*)
m_relauncher->command(command);
}
break;
default:
LOG((CLOG_ERR "ipc message not supported, type=%d", m.m_type));
break;
}
}

View File

@ -760,15 +760,6 @@ CServerApp::mainLoop()
// create the event queue
CEventQueue eventQueue;
/*
bool a = true;
while (a) {
ARCH->sleep(1);
}*/
if (argsBase().m_enableIpc) {
initIpcClient();
}
// if configuration has no screens then add this system
// as the default
@ -795,6 +786,12 @@ CServerApp::mainLoop()
// start server, etc
appUtil().startNode();
// init ipc client after node start, since create a new screen wipes out
// the event queue (the screen ctors call adoptBuffer).
if (argsBase().m_enableIpc) {
initIpcClient();
}
// load all available plugins.
ARCH->plugin().init(s_serverScreen->getEventTarget());