fixed: ipc client connected event was being wiped out
daemon now communicates graceful shutdown message through new ipc system.
This commit is contained in:
parent
3d6551f708
commit
ddb2d7feeb
|
@ -68,13 +68,12 @@ void IpcClient::read()
|
||||||
stream.readRawData(data, len);
|
stream.readRawData(data, len);
|
||||||
|
|
||||||
readLogLine(QString::fromUtf8(data, len));
|
readLogLine(QString::fromUtf8(data, len));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
|
|
||||||
default: {
|
default:
|
||||||
std::cout << "invalid code: " << codeBuf[0] << std::endl;
|
std::cerr << "message type not supported: " << codeBuf[0] << std::endl;
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,7 +92,7 @@ void IpcClient::error(QAbstractSocket::SocketError error)
|
||||||
QTimer::singleShot(1000, this, SLOT(connectToHost()));
|
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);
|
QDataStream stream(m_Socket);
|
||||||
|
|
||||||
|
@ -102,12 +101,20 @@ void IpcClient::write(unsigned char code, unsigned char length, const char* data
|
||||||
stream.writeRawData(codeBuf, 1);
|
stream.writeRawData(codeBuf, 1);
|
||||||
|
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case kIpcCommand: {
|
case kIpcHello:
|
||||||
char lenBuf[2];
|
stream.writeRawData(data, 1);
|
||||||
intToBytes(length, lenBuf, 2);
|
break;
|
||||||
stream.writeRawData(lenBuf, 2);
|
|
||||||
stream.writeRawData(data, length);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ public:
|
||||||
IpcClient();
|
IpcClient();
|
||||||
virtual ~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:
|
public slots:
|
||||||
void connectToHost();
|
void connectToHost();
|
||||||
|
@ -55,14 +55,14 @@ private:
|
||||||
QTcpSocket* m_Socket;
|
QTcpSocket* m_Socket;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum IpcMessageType {
|
enum qIpcMessageType {
|
||||||
kIpcHello,
|
kIpcHello,
|
||||||
kIpcLogLine,
|
kIpcLogLine,
|
||||||
kIpcCommand,
|
kIpcCommand,
|
||||||
kIpcShutdown,
|
kIpcShutdown,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum IpcClientType {
|
enum qIpcClientType {
|
||||||
kIpcClientUnknown,
|
kIpcClientUnknown,
|
||||||
kIpcClientGui,
|
kIpcClientGui,
|
||||||
kIpcClientNode,
|
kIpcClientNode,
|
||||||
|
|
|
@ -686,7 +686,7 @@ void MainWindow::sendDaemonCommand(const QString& command, bool showErrors)
|
||||||
{
|
{
|
||||||
std::string s = command.toStdString();
|
std::string s = command.toStdString();
|
||||||
const char* data = s.c_str();
|
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()
|
void MainWindow::on_m_pActionWizard_triggered()
|
||||||
|
|
|
@ -69,10 +69,6 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
|
||||||
synergyServer
|
synergyServer
|
||||||
};
|
};
|
||||||
|
|
||||||
enum qIpcMessage {
|
|
||||||
Command = 1
|
|
||||||
};
|
|
||||||
|
|
||||||
enum qLevel {
|
enum qLevel {
|
||||||
Error,
|
Error,
|
||||||
Info
|
Info
|
||||||
|
@ -135,7 +131,7 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
|
||||||
bool serverArgs(QStringList& args, QString& app);
|
bool serverArgs(QStringList& args, QString& app);
|
||||||
void setStatus(const QString& status);
|
void setStatus(const QString& status);
|
||||||
void sendDaemonCommand(const QString& command, bool showErrors);
|
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:
|
private:
|
||||||
QSettings& m_Settings;
|
QSettings& m_Settings;
|
||||||
|
|
|
@ -121,6 +121,14 @@ CEventQueue::adoptBuffer(IEventQueueBuffer* buffer)
|
||||||
{
|
{
|
||||||
CArchMutexLock lock(m_mutex);
|
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
|
// discard old buffer and old events
|
||||||
delete m_buffer;
|
delete m_buffer;
|
||||||
for (CEventTable::iterator i = m_events.begin(); i != m_events.end(); ++i) {
|
for (CEventTable::iterator i = m_events.begin(); i != m_events.end(); ++i) {
|
||||||
|
|
|
@ -30,7 +30,7 @@ m_server(nullptr)
|
||||||
m_serverAddress.resolve();
|
m_serverAddress.resolve();
|
||||||
|
|
||||||
EVENTQUEUE->adoptHandler(
|
EVENTQUEUE->adoptHandler(
|
||||||
m_socket.getConnectedEvent(), &m_socket,
|
m_socket.getConnectedEvent(), m_socket.getEventTarget(),
|
||||||
new TMethodEventJob<CIpcClient>(
|
new TMethodEventJob<CIpcClient>(
|
||||||
this, &CIpcClient::handleConnected));
|
this, &CIpcClient::handleConnected));
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@ CIpcServer::~CIpcServer()
|
||||||
for (it = m_clients.begin(); it != m_clients.end(); it++) {
|
for (it = m_clients.begin(); it != m_clients.end(); it++) {
|
||||||
delete *it;
|
delete *it;
|
||||||
}
|
}
|
||||||
|
m_clients.empty();
|
||||||
|
|
||||||
EVENTQUEUE->removeHandler(m_socket.getConnectingEvent(), &m_socket);
|
EVENTQUEUE->removeHandler(m_socket.getConnectingEvent(), &m_socket);
|
||||||
}
|
}
|
||||||
|
|
|
@ -437,7 +437,8 @@ CMSWindowsRelauncher::shutdownProcess(const PROCESS_INFORMATION& pi, int timeout
|
||||||
{
|
{
|
||||||
GetExitCodeProcess(pi.hProcess, &exitCode);
|
GetExitCodeProcess(pi.hProcess, &exitCode);
|
||||||
if (exitCode != STILL_ACTIVE) {
|
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;
|
break;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -221,6 +221,8 @@ CDaemonApp::mainLoop(bool logToFile)
|
||||||
eventQueue.removeHandler(
|
eventQueue.removeHandler(
|
||||||
CIpcServer::getClientConnectedEvent(), m_ipcServer);
|
CIpcServer::getClientConnectedEvent(), m_ipcServer);
|
||||||
|
|
||||||
|
CLOG->remove(m_ipcLogOutputter);
|
||||||
|
delete m_ipcLogOutputter;
|
||||||
delete m_ipcServer;
|
delete m_ipcServer;
|
||||||
|
|
||||||
DAEMON_RUNNING(false);
|
DAEMON_RUNNING(false);
|
||||||
|
@ -278,8 +280,6 @@ void
|
||||||
CDaemonApp::handleIpcMessage(const CEvent& e, void*)
|
CDaemonApp::handleIpcMessage(const CEvent& e, void*)
|
||||||
{
|
{
|
||||||
CIpcMessage& m = *static_cast<CIpcMessage*>(e.getData());
|
CIpcMessage& m = *static_cast<CIpcMessage*>(e.getData());
|
||||||
LOG((CLOG_DEBUG "ipc message, type=%d", m.m_type));
|
|
||||||
|
|
||||||
switch (m.m_type) {
|
switch (m.m_type) {
|
||||||
case kIpcCommand: {
|
case kIpcCommand: {
|
||||||
CString& command = *static_cast<CString*>(m.m_data);
|
CString& command = *static_cast<CString*>(m.m_data);
|
||||||
|
@ -300,9 +300,5 @@ CDaemonApp::handleIpcMessage(const CEvent& e, void*)
|
||||||
m_relauncher->command(command);
|
m_relauncher->command(command);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
|
||||||
LOG((CLOG_ERR "ipc message not supported, type=%d", m.m_type));
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -760,15 +760,6 @@ CServerApp::mainLoop()
|
||||||
|
|
||||||
// create the event queue
|
// create the event queue
|
||||||
CEventQueue eventQueue;
|
CEventQueue eventQueue;
|
||||||
/*
|
|
||||||
bool a = true;
|
|
||||||
while (a) {
|
|
||||||
ARCH->sleep(1);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
if (argsBase().m_enableIpc) {
|
|
||||||
initIpcClient();
|
|
||||||
}
|
|
||||||
|
|
||||||
// if configuration has no screens then add this system
|
// if configuration has no screens then add this system
|
||||||
// as the default
|
// as the default
|
||||||
|
@ -795,6 +786,12 @@ CServerApp::mainLoop()
|
||||||
|
|
||||||
// start server, etc
|
// start server, etc
|
||||||
appUtil().startNode();
|
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.
|
// load all available plugins.
|
||||||
ARCH->plugin().init(s_serverScreen->getEventTarget());
|
ARCH->plugin().init(s_serverScreen->getEventTarget());
|
||||||
|
|
Loading…
Reference in New Issue