LLTestCallback(bool verbose_mode, std::ostream *stream) :
	mVerboseMode(verbose_mode),
	mTotalTests(0),
	mPassedTests(0),
	mFailedTests(0),
	mSkippedTests(0),
	// By default, capture a shared_ptr to std::cout, with a no-op "deleter"
	// so that destroying the shared_ptr makes no attempt to delete std::cout.
	mStream(boost::shared_ptr<std::ostream>(&std::cout, boost::lambda::_1))
	{
		if (stream)
		{
			// We want a boost::iostreams::tee_device that will stream to two
			// std::ostreams.
			typedef boost::iostreams::tee_device<std::ostream, std::ostream> TeeDevice;
			// More than that, though, we want an actual stream using that
			// device.
			typedef boost::iostreams::stream<TeeDevice> TeeStream;
			// Allocate and assign in two separate steps, per Herb Sutter.
			// (Until we turn on C++11 support, have to wrap *stream with
			// boost::ref() due to lack of perfect forwarding.)
			boost::shared_ptr<std::ostream> pstream(new TeeStream(std::cout, boost::ref(*stream)));
			mStream = pstream;
		}
	}
Beispiel #2
0
	void Server::main_loop()
	{
		sigset_t sigset_tmpl, sigset;
		pthread_sigmask(0, NULL, &sigset_tmpl);
		sigaddset(&sigset_tmpl, SIGUSR1);
		sigset = sigset_tmpl;
		auto_ptr<DataStream> stream;
		try{
			info_printf(err_cons, "Waiting for connections.");
			while (!shutting_down){
				auto_ptr<DataStream> stream = server.accept(sigset, shutting_down);
				Mutex::Locker l(open_sessions_mutex);
				if (!shutting_down && get_sessions_count() < get_config_max_sessions()){
					try{
						auto_ptr<PackageStream> pstream(new PackageCodec(stream, get_config_max_package_size()));
						shared_ptr<Session> new_session(new Session(*this, pstream));
						open_sessions[new_session->get_id()] = new_session;
						new_session->launch();
					} catch (LoximException &ex) {
						warning_print(err_cons, "Caught exception while creating new session:");
						warning_print(err_cons, ex.to_string());
					} catch (...) {
						warning_print(err_cons, "Caught unknown exception while creating new session");
					}
				}
			}
		} catch (OperationCancelled &ex) {
			//this is a normal way of exiting the server
		} catch (LoximException &ex){
			info_print(err_cons, "Caught exception in server loop, shutting down");
			debug_print(err_cons, ex.to_string());
		} catch (...) {
			info_print(err_cons, "Caught unknown exception in server loop, shutting down");
		}
		{
			Mutex::Locker l(open_sessions_mutex);
			shutting_down = 1;
			info_print(err_cons, "Quitting, telling sessions to shut down");
			for (set<pair<const uint64_t, shared_ptr<Session> > >::iterator i = open_sessions.begin(); i != open_sessions.end(); i++){
				i->second->shutdown(0);
			}
		}
		info_print(err_cons, "Joining threads");
		for (set<pair<const uint64_t, shared_ptr<Session> > >::iterator i = open_sessions.begin(); i != open_sessions.end(); i++){
			pthread_join(i->second->get_thread(), NULL);
		}
		open_sessions.clear();
		info_print(err_cons, "Threads joined");
	}
void FrostbiteConnection::readyRead()
{
    bool exit = false;

    while (!exit) {
        switch (packetReadState) {
        case PacketReadingHeader:
            if (socket->bytesAvailable() >= MIN_PACKET_SIZE) {
                if (socket->read(lastHeader, MIN_PACKET_SIZE) != MIN_PACKET_SIZE) {
                    exit = true;

                    qDebug() << tr("Error while reading header.");
                    break;
                }
            } else {
                exit = true;
                break;
            }
        case PacketReadingData:
            QDataStream hdrstream(QByteArray(lastHeader, MIN_PACKET_SIZE));
            hdrstream.setByteOrder(QDataStream::LittleEndian);

            unsigned int sequence, length, words;
            hdrstream >> sequence;
            hdrstream >> length;
            hdrstream >> words;

            if (socket->bytesAvailable() >= length - MIN_PACKET_SIZE) {
                if (length >= MIN_PACKET_SIZE) {
                    char *data = new char[length];
                    memcpy(data, lastHeader, MIN_PACKET_SIZE);

                    if (socket->read(data + MIN_PACKET_SIZE, length - MIN_PACKET_SIZE) == length - MIN_PACKET_SIZE) {
                        QDataStream pstream(QByteArray(data, length));
                        FrostbiteRconPacket packet;
                        pstream >> packet;
                        handlePacket(packet);
                    } else {
                        qDebug() << tr("Error while reading data.");
                    }

                    delete[] data;
                } else {
Beispiel #4
0
int DisplayVectorGrid( WindowObjectType *wo, MetObjectType *mot )
{
/*
 *	Prepare a horizontal vector Met object for plotting with a 
 *	GEMPAK driver subroutine.
 */
	char			wind[GEMPAKSTRING], title[FILENAMESTRING];
	char			sizestr[GEMPAKSTRING], widthstr[GEMPAKSTRING];
	char			fontstr[GEMPAKSTRING], skipstr[GEMPAKSTRING];
	char			skip[GEMPAKSTRING], skip_x[GEMPAKSTRING],
				skip_y[GEMPAKSTRING];
	int			size, width, font_size, filter;
	int			verbose, iret;

	VectorGridObjectType	*vot;

	vot = (VectorGridObjectType *) mot->metObjectContent;

	assert( vot );

	verbose = GetVerboseLevel();
	if( verbose > VERBOSE_0 )
	    printf ( "DisplayVectorGrid\n" );


/*
 *	Save original FDF settings.
 */
	strcpy ( sizestr, vot->symbol_size );
	strcpy ( widthstr, vot->symbol_width );
	strcpy ( fontstr, vot->text );
	strcpy ( skip, vot->skip_contour );
	strcpy ( skip_x, vot->skip_plot_x );
	strcpy ( skip_y, vot->skip_plot_y );

/*
 *	Set plotting parameters according to generalized values.
 */
	GetDepictableValue ( "SYMBOLSIZE", &size );
	GetDepictableValue ( "SYMBOLWIDTH", &width );
	GetDepictableValue ( "FONTSIZE", &font_size );
	GetDepictableValue ( "SYMBOLPACKING", &filter );

	SetGemText ( VECTORGRIDOBJECT, fontstr, "FONTSIZE", font_size );
	SetGemFloatVar ( VECTORGRIDOBJECT, sizestr, "SYMBOLSIZE", size );
	SetGemFloatVar ( VECTORGRIDOBJECT, widthstr, "SYMBOLWIDTH", width );
	SetGemIntVar ( VECTORGRIDOBJECT, skip, "SYMBOLPACKING", filter );
	SetGemIntVar ( VECTORGRIDOBJECT, skip_x, "SYMBOLPACKING", filter );
	SetGemIntVar ( VECTORGRIDOBJECT, skip_y, "SYMBOLPACKING", filter );

	sprintf ( skipstr, "%s/%s;%s", skip, skip_x, skip_y );
	sprintf ( wind, "%s%s/%s/%s/%s/%s",
			vot->wind_symbol, vot->symbol_color,
		 	sizestr         , widthstr         ,
			vot->symbol_type, vot->symbol_headsize );
	strcpy ( title, mot->titleString );
	SetGemTitle ( wind, mot->titleIndex, title );

/*
 *	Gempak driver.
 */
	if (  strcasecmp ( vot->wind_symbol, "st" ) == 0 )

	    pstream(
		mot->filename,		vot->gdatim,
 	        vot->glevel,		vot->gvcord,
		vot->gvect,		vot->symbol_color,
	        wind,			vot->refvec,
	        skipstr,		title,
		fontstr,		&(vot->nfunction),
		&(mot->titleIndex),
		&verbose,		&iret, 
	        strlen(mot->filename),	strlen(vot->gdatim),
		strlen(vot->glevel),	strlen(vot->gvcord),
	        strlen(vot->gvect),	strlen(vot->symbol_color),
	        strlen(wind),		strlen(vot->refvec),
	        strlen(skipstr),	strlen(title),
		strlen(fontstr) );

	else
	    pvgrid(
		mot->filename,		vot->gdatim,
 	        vot->glevel,		vot->gvcord,
		vot->gvect,		vot->gridtype,
		wind,			vot->refvec,
		vot->scale,		skipstr,
		title,			fontstr,
		&(vot->nfunction),	&(mot->titleIndex),
		&verbose,		&iret, 
	        strlen(mot->filename),	strlen(vot->gdatim),
		strlen(vot->glevel),	strlen(vot->gvcord),
	        strlen(vot->gvect),	strlen(vot->gridtype),
		strlen(wind),		strlen(vot->refvec),
		strlen(vot->scale),	strlen(skipstr),
		strlen(title),		strlen(fontstr) );

	SetMetObjectDrawnFlag( mot, True );

	return(0);

}