Example #1
0
int
CClientApp::mainLoop()
{
    // create socket multiplexer.  this must happen after daemonization
    // on unix because threads evaporate across a fork().
    CSocketMultiplexer multiplexer;

    // create the event queue
    CEventQueue eventQueue;

    // start client, etc
    ARCH->util().startNode();

    // run event loop.  if startClient() failed we're supposed to retry
    // later.  the timer installed by startClient() will take care of
    // that.
    CEvent event;
    DAEMON_RUNNING(true);
    EVENTQUEUE->getEvent(event);
    while (event.getType() != CEvent::kQuit) {
        EVENTQUEUE->dispatchEvent(event);
        CEvent::deleteData(event);
        EVENTQUEUE->getEvent(event);
    }
    DAEMON_RUNNING(false);

    // close down
    LOG((CLOG_DEBUG1 "stopping client"));
    stopClient();
    updateStatus();
    LOG((CLOG_NOTE "stopped client"));

    return kExitSuccess;
}
Example #2
0
static
int
mainLoop()
{
	// logging to files
	CFileLogOutputter* fileLog = NULL;

	if (ARG->m_logFile != NULL) {
		fileLog = new CFileLogOutputter(ARG->m_logFile);

		CLOG->insert(fileLog);

		LOG((CLOG_DEBUG1 "Logging to file (%s) enabled", ARG->m_logFile));
	}

	// create socket multiplexer.  this must happen after daemonization
	// on unix because threads evaporate across a fork().
	CSocketMultiplexer multiplexer;

	// create the event queue
	CEventQueue eventQueue;

	// start the client.  if this return false then we've failed and
	// we shouldn't retry.
	LOG((CLOG_DEBUG1 "starting client"));
	if (!startClient()) {
		return kExitFailed;
	}

	// run event loop.  if startClient() failed we're supposed to retry
	// later.  the timer installed by startClient() will take care of
	// that.
	CEvent event;
	DAEMON_RUNNING(true);
	EVENTQUEUE->getEvent(event);
	while (event.getType() != CEvent::kQuit) {
		EVENTQUEUE->dispatchEvent(event);
		CEvent::deleteData(event);
		EVENTQUEUE->getEvent(event);
	}
	DAEMON_RUNNING(false);

	// close down
	LOG((CLOG_DEBUG1 "stopping client"));
	stopClient();
	updateStatus();
	LOG((CLOG_NOTE "stopped client"));

	if (fileLog) {
		CLOG->remove(fileLog);
		delete fileLog;		
	}

	return kExitSuccess;
}
Example #3
0
int
ClientApp::mainLoop()
{
	// create socket multiplexer.  this must happen after daemonization
	// on unix because threads evaporate across a fork().
	SocketMultiplexer multiplexer;
	setSocketMultiplexer(&multiplexer);

	// start client, 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();
	}

	// run event loop.  if startClient() failed we're supposed to retry
	// later.  the timer installed by startClient() will take care of
	// that.
	DAEMON_RUNNING(true);
	
#if defined(MAC_OS_X_VERSION_10_7)
	
	Thread thread(
		new TMethodJob<ClientApp>(
			this, &ClientApp::runEventsLoop,
			NULL));
	
	// wait until carbon loop is ready
	OSXScreen* screen = dynamic_cast<OSXScreen*>(
		m_clientScreen->getPlatformScreen());
	screen->waitForCarbonLoop();
	
	runCocoaApp();
#else
	m_events->loop();
#endif
	
	DAEMON_RUNNING(false);

	// close down
	LOG((CLOG_DEBUG1 "stopping client"));
	stopClient();
	updateStatus();
	LOG((CLOG_NOTE "stopped client"));

	if (argsBase().m_enableIpc) {
		cleanupIpcClient();
	}

	return kExitSuccess;
}
//! [socketDisconnected]
void RfCommClient::socketDisconnected()
{
    // Note:  it seems that the "disconnected" signal is not emitted by the socket, so this never gets called
    qDebug() << __PRETTY_FUNCTION__ << "Got socketDisconnected";
    emit disconnected();
    stopClient();

    // now reconnect and send text string
    startClient(serviceInfo);
    connect(&lagTimer, SIGNAL(timeout()), this, SLOT(sendText()));
    lagTimer.start();
}
void NetworkManager::startServer() {
	if (state == NetworkStateServer) stopServer();
	if (state == NetworkStateClient) stopClient();

	LOG("Starting server...");
	
	state = NetworkStateServer;

	server = new GameServer(GAME_PORT);
	if (server->start() < 0) {
		LOG("ERROR: SERVER FAILED TO START.");
		return;
	}
}
void NetworkManager::startClient(const char* host) {
	if (state == NetworkStateServer) stopServer();
	if (state == NetworkStateClient) stopClient();

	LOG("Starting client...");

	state = NetworkStateClient;

	client = new GameClient(host, GAME_PORT);
	if (client->connect() < 0) {
		LOG("ERROR: CLIENT FAILED TO CONNECT.");
		return;
	}
}
void RfCommClient::error(QBluetoothSocket::SocketError err)
{
    qDebug() << __PRETTY_FUNCTION__ << "Got socket error" << err;
    // remote side has closed the socket, effectively disconnecting it
    if (state == pendingConnections) {
        state = dataTransfer;
        emit disconnected();
        stopClient();

        // now reconnect and send text string
        MyThread mythread;
        mythread.sleep(5);
        startClient(serviceInfo);
        connect(&lagTimer, SIGNAL(timeout()), this, SLOT(sendText()));
        lagTimer.start();
    } else {
        qDebug() << __PRETTY_FUNCTION__ << "emitting done";
        emit done();
    }
}
Example #8
0
int
CClientApp::mainLoop()
{
	// create socket multiplexer.  this must happen after daemonization
	// on unix because threads evaporate across a fork().
	CSocketMultiplexer multiplexer;

	// start client, 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_clientScreen->getEventTarget());

	// run event loop.  if startClient() failed we're supposed to retry
	// later.  the timer installed by startClient() will take care of
	// that.
	DAEMON_RUNNING(true);
	EVENTQUEUE->loop();
	DAEMON_RUNNING(false);

	// close down
	LOG((CLOG_DEBUG1 "stopping client"));
	stopClient();
	updateStatus();
	LOG((CLOG_NOTE "stopped client"));

	if (argsBase().m_enableIpc) {
		cleanupIpcClient();
	}

	return kExitSuccess;
}
Example #9
0
void AtDrv::startClient(uint8_t sock, const char *host, uint16_t port, uint8_t protMode)
{
	// if we enable CHECK_TCP_STATE feature, always call reConnect(), or we won't get right
	// tcp port status, since we disable tcp auto reconnect.
#ifndef CHECK_TCP_STATE
	bool needReConn = false;
#else
	bool needReConn = true;
#endif
	int curMode;
	char curHostBuf[MAX_HOST_NAME_BUF_SIZE];
	uint8_t curProtocol;
	uint16_t curPort;
	uint16_t curLocalPort;
	uint32_t curTimeout;
	bool curTcpAuto;

	// clear uart buffer first
	stopClient(sock);

	if(!isAtMode()) {
		if(!switchToAtMode()) {
			INFO1("Can't switch to at mode");
			goto end;
		}
	}
	
	if(!getMode(sock, &curMode) || curMode != MODE_CLIENT) {
		needReConn = true;
		INFO1("curMode != MODE_CLIENT");
		if(!setMode(sock, MODE_CLIENT)) {
			INFO1("Can't set mode");
			goto end;			
		}
	}

	if(!getRemoteHost(sock, curHostBuf) || (strcmp(curHostBuf,  host) != 0)) {
		needReConn = true;
		INFO1("curHostBuf != host");
		if(!setRemoteHost(sock, host)) {
			INFO1("Can't set host");
			goto end;	
		}
	}
	
	if(!getProtocol(sock, &curProtocol) || curProtocol != protMode) {
		needReConn = true;
		INFO1("curProtocol != protMode");
		if(!setProtocol(sock, protMode)) {
			INFO1("Can't set protocol");
			goto end;	
		}
	}
	
	if(!getRemotePort(sock, &curPort) || curPort != port) {
		needReConn = true;
		INFO1("curPort != port");
		if(!setPort(sock, port)) {
			INFO1("Can't set port");
			goto end;	
		}
	}
	
	if(!getTcpAuto(sock, &curTcpAuto) || curTcpAuto != false) {
		needReConn = true;
		INFO1("curTcpAuto != false");	
		if(!setTcpAuto(sock, false)) {
			INFO1("Can't set tcp auto");
			goto end;	
		}
	}	
	
	if(!getLocalPort(sock, &curLocalPort) || curLocalPort != localSockPort[sock]) {
		needReConn = true;
		INFO1("curLocalPort != port");
		if(!setLocalPort(sock, localSockPort[sock])) {
			INFO1("Can't set port");
			goto end;	
		}
	}	
	
	if(needReConn) {
		if(!reConnect()) {
			INFO1("Can't reconnect");
			goto end;	
		}
	}	

	sockPort[sock] = localSockPort[sock];
	sockConnected[sock] = true;

end:
	return;
}
Example #10
0
ChatClient::~ChatClient()
{
    stopClient();
}
Example #11
0
RfCommClient::~RfCommClient()
{
    stopClient();
}
Example #12
0
void AudioPlayer::play(const QString &file)/*{{{*/
{
	SNDFILE *sndfile ;
	SF_INFO sndfileinfo ;

	if (file.isEmpty())
	{	
		fprintf (stderr, "no soundfile given\n");
		//TODO: emit error signals
		emit playbackStopped(true);
		return;
	}

	// Open the soundfile.
	sndfileinfo.format = 0 ;
	sndfile = sf_open (file.toUtf8().constData(), SFM_READ, &sndfileinfo) ;
	if (sndfile == NULL)
	{	
		//TODO: emit error signals
		fprintf (stderr, "Could not open soundfile '%s'\n", file.toUtf8().constData()) ;
		emit playbackStopped(true);
		return;
	}

	// Init the thread info struct.
	info.can_process = 0 ;
	info.read_done = 0 ;
	info.play_done = 0 ;
	info.sndfile = sndfile ;
	info.channels = sndfileinfo.channels ;
	info.client = m_client ;
	info.pos = 0 ;
	
	if(info.seek && info.seek < sndfileinfo.frames)
	{
		//qDebug("Preseting seek point");
		sf_seek(sndfile, info.seek, SEEK_CUR);
		info.seek = 0;
	}

	if(!startClient())
		return;
		
	// Start the disk thread. 
	pthread_create (&info.thread_id, NULL, AudioPlayer::read_file, &info);
	info.can_read = 1 ;
	
	m_isPlaying = true;

	emit nowPlaying(QString(file).append("@--,--@").append(calcTimeString((int)sndfileinfo.frames)), sndfileinfo.frames);

	while (!info.play_done)
	{	
		printTime() ;
		usleep (50000) ;
	}
	printTime();
	//memset (ringbuf->buf, 0, ringbuf->size);

	m_isPlaying = false;

	info.can_process = 0;
	
	stopClient();
	sf_close (sndfile) ;
	info.sndfile = 0;
	emit playbackStopped(true);
}/*}}}*/
CClientAmxController::~CClientAmxController()
{
	stopClient();
}
Example #14
0
void AtDrv::startClient(uint8_t sock, uint32_t ipAddress, uint16_t port, uint8_t protMode)
{
	// if we enable CHECK_TCP_STATE feature, always call reConnect(), or we won't get right
	// tcp port status, since we disable tcp auto reconnect.
#ifndef CHECK_TCP_STATE
	bool needReConn = false;
#else
	bool needReConn = true;
#endif
	int curMode;
	uint32_t curIp;
	uint8_t curProtocol;
	uint16_t curPort;
	uint16_t curLocalPort;
	uint32_t curTimeout;
	bool curTcpAuto;

	// clear uart buffer first
	stopClient(sock);
	
	if(!isAtMode()) {
		if(!switchToAtMode()) {
			INFO1("Can't switch to at mode");
			goto end;
		}
	}
	
	if(!getMode(sock, &curMode) || curMode != MODE_CLIENT) {
		needReConn = true;
		INFO1("curMode != MODE_CLIENT");
		if(!setMode(sock, MODE_CLIENT)) {
			INFO1("Can't set mode");
			goto end;			
		}
	}
	
	if(!getRemoteIp(sock, (uint8_t *)&curIp) || curIp != ipAddress) {
		needReConn = true;
		INFO1("curIp != ipAddress");
		if(!setRemoteIp(sock, ipAddress)) {
			INFO1("Can't set ip");
			goto end;	
		}
	}
	
	if(!getProtocol(sock, &curProtocol) || curProtocol != protMode) {
		needReConn = true;
		INFO1("curProtocol != protMode");
		if(!setProtocol(sock, protMode)) {
			INFO1("Can't set protocol");
			goto end;	
		}
	}
	
	if(!getRemotePort(sock, &curPort) || curPort != port) {
		needReConn = true;
		INFO1("curPort != port");
		if(!setPort(sock, port)) {
			INFO1("Can't set port");
			goto end;	
		}
	}

	if(!getTcpAuto(sock, &curTcpAuto) || curTcpAuto != false) {
		needReConn = true;
		INFO1("curTcpAuto != false");	
		if(!setTcpAuto(sock, false)) {
			INFO1("Can't set tcp auto");
			goto end;	
		}
	}
	
	if(!getLocalPort(sock, &curLocalPort) || curLocalPort != localSockPort[sock]) {
		needReConn = true;
		INFO1("curLocalPort != port");
		if(!setLocalPort(sock, localSockPort[sock])) {
			INFO1("Can't set port");
			goto end;	
		}
	}
	
	if(needReConn) {
		if(!reConnect()) {
			INFO1("Can't reconnect");
			goto end;	
		}
	}

	sockPort[sock] = localSockPort[sock];
	sockConnected[sock] = true;

end:
	return;
}
Example #15
0
TennisClient::~TennisClient()
{
    stopClient();
}
Example #16
0
//! [socketDisconnected]
void TennisClient::socketDisconnected()
{
    qDebug() << "Got socketDisconnected";
    stopClient();
}
/*!
  Destructor.
*/
BluetoothClient::~BluetoothClient()
{
    stopClient();
}