Generic_Extractor::Generic_Extractor(void* z_context, const std::string& z_output_uri, const QString& file_path) : QRunnable()
{
	error.calling_method = "Generic_Extractor::Generic_Extractor";

	if ( z_context == NULL ) {
		error.msg = "z_context is NULL";

		throw error;;
	}

	if ( z_output_uri.empty() == true) {
		error.msg = "z_output_uri is empty";
		throw error;
	}

	if ( file_path.isEmpty() == true ) {
		error.msg = "file_path is empty";
		throw error;
	}

	zmq_context	= (zmq::context_t*) z_context;
	zmq_output_uri = z_output_uri;
	file = file_path;

	setAutoDelete(true);

	if ( autoDelete() == false ) {
		error.msg = "Cannot set autoDelete option";
		throw error;
	}
}
예제 #2
0
//! Destructor
QwtPolarPlot::~QwtPolarPlot()
{
    detachItems( QwtPolarItem::Rtti_PolarItem, autoDelete() );

    delete d_data->layout;
    delete d_data;
}
예제 #3
0
//! Destructor
QwtPlot::~QwtPlot()
{
    detachItems( QwtPlotItem::Rtti_PlotItem, autoDelete() );

    delete d_data->layout;
    deleteAxesData();
    delete d_data;
}
예제 #4
0
IdDecorator::~IdDecorator()
{
    // Do not assert here. IdDecorator can decorate a null pointer. Only assert if a method is called on a decorared
    // null  pointer.
    if (autoDelete()) {
        delete job();
    }
}
void LinkLocal::Stream::autoDelete()
{
	if(!inUse) {
		close();
	} else {
		inUse = false;
		QTimer::singleShot(1000*60*5, this, SLOT(autoDelete()));
	}
}
LinkLocal::Stream::Stream(Jid jidLocal, QString addr, quint16 port) : jidLocal_(jidLocal), root(NULL) {
	state = Idle;
	bs_ = new BSocket;
	inUse = true;
	autoDelete();
	proto = new CoreProtocol();
	proto->reset();
	connect(bs_, SIGNAL(connected()), SLOT(connected()));
	connect(bs_, SIGNAL(error(int)), SLOT(error(int)));
	bs_->connectToHost(addr,port);
}
CoreAttributesList::~CoreAttributesList()
{
    if (autoDelete())
    {
        /* We need to make sure that the CoreAttributes are first removed from
         * the list and then deleted. */
        setAutoDelete(false);
        while (!isEmpty())
        {
            CoreAttributes* tp = getFirst();
            removeRef(tp);
            delete tp;
        }
        setAutoDelete(true);
    }
}
예제 #8
0
CoreAttributesList::~CoreAttributesList()
{
    if (autoDelete()) {
        setAutoDelete(false);
        while (!isEmpty()) {
            delete takeFirst();
        }
        setAutoDelete(true);
    }
//     if (autoDelete())
//     {
//         /* We need to make sure that the CoreAttributes are first removed from
//          * the list and then deleted. */
//         setAutoDelete(false);
//         while (!isEmpty())
//         {
//             CoreAttributes* tp = getFirst();
//             removeRef(tp);
//             delete tp;
//         }
//         setAutoDelete(true);
//     }
}
예제 #9
0
//=========================================================
//=========================================================
void C_GameInstructor::ReadLessonsFromFile( const char *pchFileName )
{
	// Static init function
	CScriptedIconLesson::PreReadLessonsFromFile();
	MEM_ALLOC_CREDIT();
 
	KeyValues *pLessonKeys = new KeyValues("instructor_lessons");
	KeyValues::AutoDelete autoDelete(pLessonKeys);
 
	pLessonKeys->LoadFromFile(g_pFullFileSystem, pchFileName, NULL);
 
	for ( m_pScriptKeys = pLessonKeys->GetFirstTrueSubKey(); m_pScriptKeys; m_pScriptKeys = m_pScriptKeys->GetNextTrueSubKey() )
	{
		if ( Q_stricmp(m_pScriptKeys->GetName(), "GroupConVarToggle") == 0 )
		{
			// Add convar group toggler to the list
			int nLessonGroupConVarToggle							= m_LessonGroupConVarToggles.AddToTail( LessonGroupConVarToggle_t( m_pScriptKeys->GetString( "convar" ) ) );
			LessonGroupConVarToggle_t *pLessonGroupConVarToggle		= &(m_LessonGroupConVarToggles[nLessonGroupConVarToggle]);
 
			Q_strcpy( pLessonGroupConVarToggle->szLessonGroupName, m_pScriptKeys->GetString("group") );
			continue;
		}
 
		// Ensure that lessons aren't added twice
		if ( GetLesson_Internal(m_pScriptKeys->GetName()) )
		{
			DevWarning("Lesson \"%s\" defined twice!\n", m_pScriptKeys->GetName());
			continue;
		}
 
		CScriptedIconLesson *pNewLesson = new CScriptedIconLesson(m_pScriptKeys->GetName(), false, false);
		GetGameInstructor().DefineLesson(pNewLesson);
	}
 
	m_pScriptKeys = NULL;
}
예제 #10
0
gfxFontEntry* 
gfxGDIFontList::MakePlatformFont(const gfxProxyFontEntry *aProxyEntry, 
                                 const PRUint8 *aFontData,
                                 PRUint32 aLength)
{
    // MakePlatformFont is responsible for deleting the font data with NS_Free
    // so we set up a stack object to ensure it is freed even if we take an
    // early exit
    struct FontDataDeleter {
        FontDataDeleter(const PRUint8 *aFontData)
            : mFontData(aFontData) { }
        ~FontDataDeleter() { NS_Free((void*)mFontData); }
        const PRUint8 *mFontData;
    };
    FontDataDeleter autoDelete(aFontData);

    // if calls aren't available, bail
    if (!TTLoadEmbeddedFontPtr || !TTDeleteEmbeddedFontPtr)
        return nsnull;

    PRBool isCFF = gfxFontUtils::IsCffFont(aFontData);
        
    nsresult rv;
    HANDLE fontRef = nsnull;
    PRBool isEmbedded = PR_FALSE;

    nsAutoString uniqueName;
    rv = gfxFontUtils::MakeUniqueUserFontName(uniqueName);
    if (NS_FAILED(rv))
        return nsnull;

    // for TTF fonts, first try using the t2embed library
    if (!isCFF) {
        // TrueType-style glyphs, use EOT library
        AutoFallibleTArray<PRUint8,2048> eotHeader;
        PRUint8 *buffer;
        PRUint32 eotlen;

        isEmbedded = PR_TRUE;
        PRUint32 nameLen = PR_MIN(uniqueName.Length(), LF_FACESIZE - 1);
        nsPromiseFlatString fontName(Substring(uniqueName, 0, nameLen));
        
        FontDataOverlay overlayNameData = {0, 0, 0};

        rv = gfxFontUtils::MakeEOTHeader(aFontData, aLength, &eotHeader, 
                                         &overlayNameData);
        if (NS_SUCCEEDED(rv)) {

            // load in embedded font data
            eotlen = eotHeader.Length();
            buffer = reinterpret_cast<PRUint8*> (eotHeader.Elements());
            
            PRInt32 ret;
            ULONG privStatus, pulStatus;
            EOTFontStreamReader eotReader(aFontData, aLength, buffer, eotlen,
                                          &overlayNameData);

            ret = TTLoadEmbeddedFontPtr(&fontRef, TTLOAD_PRIVATE, &privStatus,
                                       LICENSE_PREVIEWPRINT, &pulStatus,
                                       EOTFontStreamReader::ReadEOTStream,
                                       &eotReader,
                                       (PRUnichar*)(fontName.get()), 0, 0);
            if (ret != E_NONE) {
                fontRef = nsnull;
                char buf[256];
                sprintf(buf, "font (%s) not loaded using TTLoadEmbeddedFont - error %8.8x", NS_ConvertUTF16toUTF8(aProxyEntry->FamilyName()).get(), ret);
                NS_WARNING(buf);
            }
        }
    }

    // load CFF fonts or fonts that failed with t2embed loader
    if (fontRef == nsnull) {
        // Postscript-style glyphs, swizzle name table, load directly
        FallibleTArray<PRUint8> newFontData;

        isEmbedded = PR_FALSE;
        rv = gfxFontUtils::RenameFont(uniqueName, aFontData, aLength, &newFontData);

        if (NS_FAILED(rv))
            return nsnull;
        
        DWORD numFonts = 0;

        PRUint8 *fontData = reinterpret_cast<PRUint8*> (newFontData.Elements());
        PRUint32 fontLength = newFontData.Length();
        NS_ASSERTION(fontData, "null font data after renaming");

        // http://msdn.microsoft.com/en-us/library/ms533942(VS.85).aspx
        // "A font that is added by AddFontMemResourceEx is always private 
        //  to the process that made the call and is not enumerable."
        fontRef = AddFontMemResourceEx(fontData, fontLength, 
                                       0 /* reserved */, &numFonts);
        if (!fontRef)
            return nsnull;

        // only load fonts with a single face contained in the data
        if (fontRef && numFonts != 1) {
            RemoveFontMemResourceEx(fontRef);
            return nsnull;
        }
    }

    // make a new font entry using the unique name
    WinUserFontData *winUserFontData = new WinUserFontData(fontRef, isEmbedded);
    PRUint16 w = (aProxyEntry->mWeight == 0 ? 400 : aProxyEntry->mWeight);

    GDIFontEntry *fe = GDIFontEntry::CreateFontEntry(uniqueName, 
        gfxWindowsFontType(isCFF ? GFX_FONT_TYPE_PS_OPENTYPE : GFX_FONT_TYPE_TRUETYPE) /*type*/, 
        PRUint32(aProxyEntry->mItalic ? FONT_STYLE_ITALIC : FONT_STYLE_NORMAL), 
        w, winUserFontData);

    if (!fe)
        return fe;

    fe->mIsUserFont = PR_TRUE;

    // Uniscribe doesn't place CFF fonts loaded privately 
    // via AddFontMemResourceEx on XP/Vista
    if (isCFF && gfxWindowsPlatform::WindowsOSVersion() 
                 < gfxWindowsPlatform::kWindows7) {
        fe->mForceGDI = PR_TRUE;
    }
 
    return fe;
}
예제 #11
0
void ThreadTask::run()
{
	Q_ASSERT(!autoDelete());
	runTask();
	ThreadTaskCourier::notify(this);
}
예제 #12
0
//=========================================================
//=========================================================
bool C_GameInstructor::WriteSaveData()
{
	if ( engine->IsPlayingDemo() )
		return false;
 
	if ( !m_bDirtySaveData )
		return true;
 
#ifdef _X360
	float flPlatTime = Plat_FloatTime();
 
	static ConVarRef host_write_last_time( "host_write_last_time" );
	if ( host_write_last_time.IsValid() )
	{
		float flTimeSinceLastWrite = flPlatTime - host_write_last_time.GetFloat();
		if ( flTimeSinceLastWrite < 3.5f )
		{
			// Prevent writing to the same storage device twice in less than 3 second succession for TCR success!
			// This happens after leaving a game in splitscreen.
			//DevMsg( "Waiting to write Game Instructor for splitscreen slot %d... (%.1f seconds remain)\n", m_nSplitScreenSlot, 3.5f - flTimeSinceLastWrite );
			return false;
		}
	}
#endif
 
	// Always mark as clean state to avoid re-entry on
	// subsequent frames when storage device might be
	// in a yet-unmounted state.
	m_bDirtySaveData = false;
 
#ifdef _X360
	DevMsg( "Write Game Instructor for splitscreen slot %d at time: %.1f\n", m_nSplitScreenSlot, flPlatTime );
 
	if ( m_nSplitScreenSlot < 0 )
		return false;
 
	if ( m_nSplitScreenSlot >= (int) XBX_GetNumGameUsers() )
		return false;
 
	int iController = XBX_GetUserId( m_nSplitScreenSlot );
 
	if ( iController < 0 || XBX_GetUserIsGuest( iController ) )
	{
		// Can't save data for guests
		return false;
	}
 
	DWORD nStorageDevice = XBX_GetStorageDeviceId( iController );
	if ( !XBX_DescribeStorageDevice( nStorageDevice ) )
		return false;
#endif
 
	// Build key value data to save
	KeyValues *data = new KeyValues( "Game Instructor Counts" );
	KeyValues::AutoDelete autoDelete(data);
 
	for ( int i = 0; i < m_Lessons.Count(); ++i )
	{
		CBaseLesson *pLesson = m_Lessons[i];
 
		int iDisplayCount = pLesson->GetDisplayCount();
		int iSuccessCount = pLesson->GetSuccessCount();
 
		if ( iDisplayCount || iSuccessCount )
		{
			// We've got some data worth saving
			KeyValues *pKVData = new KeyValues( pLesson->GetName() );
 
			if ( iDisplayCount )
				pKVData->SetInt( "display", iDisplayCount );
 
			if ( iSuccessCount )
				pKVData->SetInt( "success", iSuccessCount );
 
			data->AddSubKey( pKVData );
		}
	}
 
	// Save it!
	CUtlBuffer buf( 0, 0, CUtlBuffer::TEXT_BUFFER );
 
	data->RecursiveSaveToFile( buf, 0 );
 
	char	szFilename[_MAX_PATH];
 
#ifdef _X360
	if ( IsX360() )
	{
		XBX_MakeStorageContainerRoot( iController, XBX_USER_SETTINGS_CONTAINER_DRIVE, szFilename, sizeof( szFilename ) );
		int nLen = strlen( szFilename );
		Q_snprintf( szFilename + nLen, sizeof( szFilename ) - nLen, ":\\game_instructor_counts.txt" );
	}
	else
#endif
	{
		Q_snprintf( szFilename, sizeof( szFilename ), "save/game_instructor_counts.txt" );
		filesystem->CreateDirHierarchy( "save", "MOD" );
	}
 
	bool bWriteSuccess = filesystem->WriteFile( szFilename, MOD_DIR, buf );
 
#ifdef _X360
	if ( xboxsystem )
	{
		xboxsystem->FinishContainerWrites( iController );
	}
#endif
 
	return bWriteSuccess;
}
예제 #13
0
//=========================================================
//=========================================================
bool C_GameInstructor::ReadSaveData()
{
	// for external playtests, don't ever read in persisted instructor state, always start fresh
	if ( CommandLine()->FindParm( "-playtest" ) )
		return true;
 
	if ( m_bHasLoadedSaveData )
		return true;
 
	// Always reset state first in case storage device
	// was declined or ends up in faulty state
	ResetDisplaysAndSuccesses();
 
	m_bHasLoadedSaveData = true;
 
#ifdef _X360
	DevMsg( "Read Game Instructor for splitscreen slot %d\n", m_nSplitScreenSlot );
 
	if ( m_nSplitScreenSlot < 0 )
		return false;
 
	if ( m_nSplitScreenSlot >= (int) XBX_GetNumGameUsers() )
		return false;
 
	int iController = XBX_GetUserId( m_nSplitScreenSlot );
 
	if ( iController < 0 || XBX_GetUserIsGuest( iController ) )
	{
		// Can't read data for guests
		return false;
	}
 
	DWORD nStorageDevice = XBX_GetStorageDeviceId( iController );
	if ( !XBX_DescribeStorageDevice( nStorageDevice ) )
		return false;
#endif
 
	char szFilename[_MAX_PATH];
 
#ifdef _X360
	if ( IsX360() )
	{
		XBX_MakeStorageContainerRoot( iController, XBX_USER_SETTINGS_CONTAINER_DRIVE, szFilename, sizeof( szFilename ) );
		int nLen = strlen( szFilename );
		Q_snprintf( szFilename + nLen, sizeof( szFilename ) - nLen, ":\\game_instructor_counts.txt" );
	}
	else
#endif
	{
		Q_snprintf( szFilename, sizeof( szFilename ), "save/game_instructor_counts.txt" );
	}
 
	KeyValues *data = new KeyValues( "Game Instructor Counts" );
	KeyValues::AutoDelete autoDelete(data);
 
	if ( data->LoadFromFile( g_pFullFileSystem, szFilename, NULL ) )
	{
		int nVersion = 0;
 
		for ( KeyValues *pKey = data->GetFirstSubKey(); pKey; pKey = pKey->GetNextTrueSubKey() )
		{
			CBaseLesson *pLesson = GetLesson_Internal( pKey->GetName() );
 
			if ( pLesson )
			{
				pLesson->SetDisplayCount( pKey->GetInt( "display", 0 ) );
				pLesson->SetSuccessCount( pKey->GetInt( "success", 0 ) );
 
				if ( Q_strcmp( pKey->GetName(), "version number" ) == 0 )
				{
					nVersion = pLesson->GetSuccessCount();
				}
			}
		}
 
		CBaseLesson *pLessonVersionNumber = GetLesson_Internal( "version number" );
		if ( pLessonVersionNumber && !pLessonVersionNumber->IsLearned() )
		{
			ResetDisplaysAndSuccesses();
			pLessonVersionNumber->SetSuccessCount( pLessonVersionNumber->GetSuccessLimit() );
			m_bDirtySaveData = true;
		}
 
 
		return true;
	}
 
	// Couldn't read from the file
	return false;
}
예제 #14
0
void Command::tryAutoDelete()
{
    if (autoDelete())
        deleteLater();
}
예제 #15
0
bool XRefDefs::Read(const char* name) {
	Scanner scnr(name);

	if (scnr.InitCheck() == B_OK) {

		BString s; float f;
		bool ok = scnr.ReadName(&s) && scnr.ReadFloat(&f);
		if (!ok || strcmp(s.String(), "CrossReferences") != 0 || f != 1.0) {
			REPORT(kError, 0, "XRefs (line %d, column %d): '%s' not a cross references file or wrong version!", scnr.Line(), scnr.Column(), name);
			return false;
		}
		
		while (!scnr.IsEOF()) {
			XRefDef* def = new XRefDef();
			AutoDelete autoDelete(def);
			BString pattern;

			// Links: Pattern {"," Pattern}.
			do {
				if (!scnr.ReadString(&pattern)) {
					REPORT(kError, 0, "XRefs (line %d, column %d): Could not parse 'link' pattern", scnr.Line(), scnr.Column());
					return false;
				}
				LinkPattern* link = new LinkPattern(pattern.String());
				if (link->InitCheck() == B_OK) {
					def->AddLink(link);
				} else {
					delete link;
					REPORT(kError, 0, "XRefs (line %d, column %d): Invalid RegExp '%s'", pattern.String(), scnr.Line(), scnr.Column());
					return false;
				}
			} while (scnr.NextChar(','));

			// "->"
			if (scnr.NextChar('-') && scnr.NextChar('>')) {

				// Dests: Pattern {"," Pattern}.
				do {
					if (!scnr.ReadString(&pattern)) {
						REPORT(kError, 0, "XRefs (line %d, column %d): Could not parse 'destination' pattern", scnr.Line(), scnr.Column());
						return false;
					}
					DestPattern* dest = new DestPattern(pattern.String());
					if (dest->InitCheck() == B_OK) {
						def->AddDest(dest);
					} else {
						delete dest;
						REPORT(kError, 0, "XRefs (line %d, column %d): Invalid RegExp '%s'", scnr.Line(), scnr.Column(), pattern.String());
						return false;
					}
				} while (scnr.NextChar(','));

				// "."
				if (!scnr.NextChar('.')) {
					REPORT(kError, 0, "XRefs (line %d, column %d): '.' expected at end of definition", scnr.Line(), scnr.Column());
					return false;
				}
			} else {
				REPORT(kError, 0, "XRefs (line %d, column %d): '->' expected", scnr.Line(), scnr.Column());
				return false;
			}

			this->Add(def); 
			autoDelete.Release();
			
			scnr.SkipSpaces();
		}
		return true;
	} else {
		REPORT(kError, 0, "XRefs: Could not open cross references file '%d'", name);
	}	
	return false;	
}
예제 #16
0
void Request::http(const String &prefix, Http::Request &request)
{
	try {
		std::unique_lock<std::mutex> lock(mMutex);	// Request::http() is synced !

		// Cancel autodeletion
		mAutoDeleter.cancel();

		int next = 0;
		if(request.get.contains("next"))
			request.get["next"].extract(next);

		duration timeout = milliseconds(Config::Get("request_timeout").toDouble());
		if(request.get.contains("timeout"))
			timeout = milliseconds(request.get["timeout"].toDouble());

		mCondition.wait_for(lock, timeout, [this, next]() {
			return int(mResults.size()) > next || mFinished;
		});

		// Playlist
		if(request.get.contains("playlist"))
		{
			int start = -1;
			int stop  = -1;

			String startParam;
			if(request.get.get("start", startParam) || request.get.get("t", startParam))
				start = timeParamToSeconds(startParam);

			String stopParam;
			if(request.get.get("stop", stopParam))
				stop = timeParamToSeconds(stopParam);

			Http::Response response(request, 200);
			response.headers["Content-Disposition"] = "attachment; filename=\"playlist.m3u\"";
			response.headers["Content-Type"] = "audio/x-mpegurl";
			response.send();

			String host;
			request.headers.get("Host", host);
			createPlaylist(response.stream, host, start, stop);
		}
		else {
			// JSON
			Http::Response response(request, 200);
			response.headers["Content-Type"] = "application/json";
			response.send();

			std::list<Resource::DirectoryRecord*> tmp;
			if(int(mResults.size()) > next)
				for(int i = next; i < int(mResults.size()); ++i)
					tmp.push_back(&mResults[i]);

			JsonSerializer(response.stream) << tmp;
		}
	}
	catch(...)
	{
		// Reset autodeletion
		autoDelete(mAutoDeleteTimeout);
		throw;
	}

	// Reset autodeletion
	autoDelete(mAutoDeleteTimeout);
}