예제 #1
0
void
IpcClientProxy::send(const IpcMessage& message)
{
    // don't allow other threads to write until we've finished the entire
    // message. stream write is locked, but only for that single write.
    // also, don't allow the dtor to destroy the stream while we're using it.
    ArchMutexLock lock(m_writeMutex);

    LOG((CLOG_DEBUG4 "ipc write: %d", message.type()));

    switch (message.type()) {
    case kIpcLogLine: {
        const IpcLogLineMessage& llm = static_cast<const IpcLogLineMessage&>(message);
        const String logLine = llm.logLine();
        ProtocolUtil::writef(&m_stream, kIpcMsgLogLine, &logLine);
        break;
    }
            
    case kIpcShutdown:
        ProtocolUtil::writef(&m_stream, kIpcMsgShutdown);
        break;

    default:
        LOG((CLOG_ERR "ipc message not supported: %d", message.type()));
        break;
    }
}
예제 #2
0
파일: App.cpp 프로젝트: Coolred/synergy
void
App::handleIpcMessage(const Event& e, void*)
{
	IpcMessage* m = static_cast<IpcMessage*>(e.getDataObject());
	if (m->type() == kIpcShutdown) {
		LOG((CLOG_INFO "got ipc shutdown message"));
		m_events->addEvent(Event(Event::kQuit));
    }
}
예제 #3
0
void
IpcTests::sendMessageToClient_serverHandleClientConnected(const Event& e, void*)
{
    IpcMessage* m = static_cast<IpcMessage*>(e.getDataObject());
    if (m->type() == kIpcHello) {
        LOG((CLOG_DEBUG "client said hello, sending test to client"));
        IpcLogLineMessage m("test");
        m_sendMessageToClient_server->send(m, kIpcClientNode);
    }
}
예제 #4
0
void
IpcTests::sendMessageToClient_clientHandleMessageReceived(const Event& e, void*)
{
    IpcMessage* m = static_cast<IpcMessage*>(e.getDataObject());
    if (m->type() == kIpcLogLine) {
        IpcLogLineMessage* llm = static_cast<IpcLogLineMessage*>(m);
        LOG((CLOG_DEBUG "got ipc log message, %d", llm->logLine().c_str()));
        m_sendMessageToClient_receivedString = llm->logLine();
        m_events.raiseQuitEvent();
    }
}
예제 #5
0
void
IpcTests::connectToServer_handleMessageReceived(const Event& e, void*)
{
    IpcMessage* m = static_cast<IpcMessage*>(e.getDataObject());
    if (m->type() == kIpcHello) {
        m_connectToServer_hasClientNode =
            m_connectToServer_server->hasClients(kIpcClientNode);
        m_connectToServer_helloMessageReceived = true;
        m_events.raiseQuitEvent();
    }
}
예제 #6
0
void
IpcTests::sendMessageToServer_serverHandleMessageReceived(const Event& e, void*)
{
    IpcMessage* m = static_cast<IpcMessage*>(e.getDataObject());
    if (m->type() == kIpcHello) {
        LOG((CLOG_DEBUG "client said hello, sending test to server"));
        IpcCommandMessage m("test", true);
        m_sendMessageToServer_client->send(m);
    }
    else if (m->type() == kIpcCommand) {
        IpcCommandMessage* cm = static_cast<IpcCommandMessage*>(m);
        LOG((CLOG_DEBUG "got ipc command message, %d", cm->command().c_str()));
        m_sendMessageToServer_receivedString = cm->command();
        m_events.raiseQuitEvent();
    }
}
예제 #7
0
void
DaemonApp::handleIpcMessage(const Event& e, void*)
{
	IpcMessage* m = static_cast<IpcMessage*>(e.getDataObject());
	switch (m->type()) {
		case kIpcCommand: {
			IpcCommandMessage* cm = static_cast<IpcCommandMessage*>(m);
			String command = cm->command();

			// if empty quotes, clear.
			if (command == "\"\"") {
				command.clear();
			}

			if (!command.empty()) {
				LOG((CLOG_DEBUG "new command, elevate=%d command=%s", cm->elevate(), command.c_str()));

				std::vector<String> argsArray;
				ArgParser::splitCommandString(command, argsArray);
				ArgParser argParser(NULL);
				const char** argv = argParser.getArgv(argsArray);
				ServerArgs serverArgs;
				ClientArgs clientArgs;
				int argc = static_cast<int>(argsArray.size());
				bool server = argsArray[0].find("synergys") != String::npos ? true : false;
				ArgsBase* argBase = NULL;

				if (server) {
					argParser.parseServerArgs(serverArgs, argc, argv);
					argBase = &serverArgs;
				}
				else {
					argParser.parseClientArgs(clientArgs, argc, argv);
					argBase = &clientArgs;
				}

				delete[] argv;
				
				String logLevel(argBase->m_logFilter);
				if (!logLevel.empty()) {
					try {
						// change log level based on that in the command string
						// and change to that log level now.
						ARCH->setting("LogLevel", logLevel);
						CLOG->setFilter(logLevel.c_str());
					}
					catch (XArch& e) {
						LOG((CLOG_ERR "failed to save LogLevel setting, %s", e.what()));
					}
				}

#if SYSAPI_WIN32
				String logFilename;
				if (argBase->m_logFile != NULL) {
					logFilename = String(argBase->m_logFile);
					ARCH->setting("LogFilename", logFilename);
					m_watchdog->setFileLogOutputter(m_fileLogOutputter);
					command = ArgParser::assembleCommand(argsArray, "--log", 1);
					LOG((CLOG_DEBUG "removed log file argument and filename %s from command ", logFilename.c_str()));
					LOG((CLOG_DEBUG "new command, elevate=%d command=%s", cm->elevate(), command.c_str()));
				}
				else {
					m_watchdog->setFileLogOutputter(NULL);
				}

				m_fileLogOutputter->setLogFilename(logFilename.c_str());
#endif
			}
			else {
				LOG((CLOG_DEBUG "empty command, elevate=%d", cm->elevate()));
			}

			try {
				// store command in system settings. this is used when the daemon
				// next starts.
				ARCH->setting("Command", command);

				// TODO: it would be nice to store bools/ints...
				ARCH->setting("Elevate", String(cm->elevate() ? "1" : "0"));
			}
			catch (XArch& e) {
				LOG((CLOG_ERR "failed to save settings, %s", e.what()));
			}

#if SYSAPI_WIN32
			// tell the relauncher about the new command. this causes the
			// relauncher to stop the existing command and start the new
			// command.
			m_watchdog->setCommand(command, cm->elevate());
#endif
			break;
		}

		case kIpcHello:
			IpcHelloMessage* hm = static_cast<IpcHelloMessage*>(m);
			String type;
			switch (hm->clientType()) {
				case kIpcClientGui: type = "gui"; break;
				case kIpcClientNode: type = "node"; break;
				default: type = "unknown"; break;
			}

			LOG((CLOG_DEBUG "ipc hello, type=%s", type.c_str()));

#if SYSAPI_WIN32
			String watchdogStatus = m_watchdog->isProcessActive() ? "ok" : "error";
			LOG((CLOG_INFO "watchdog status: %s", watchdogStatus.c_str()));
#endif

			m_ipcLogOutputter->notifyBuffer();
			break;
	}
}