Ejemplo n.º 1
0
main()
{
	int element , ch ;
	queue q;
	char * mnu[] = {
					"Insertion",
					"Deletion",
					"Display",
					"Exit",

				   };
	q.rear = -1;
	q.front = 0;
	while(1){
		ch = menu(mnu,4,20,10,"****Choices****") ;
		switch(ch){
			case 1:puts("Enter the element to be inserted");
				   scanf("%d",&element);
				   qInsert( &q , element );
				   break;
			case 2:if (!isEmpty(&q) ){
						qDelete( &q , &element );
						printf("The deleted Element is %d\n ",element );
						}
				   else
						printf("Queue Under Flow ");
				   break;
			case 4:exit();
		}
		qDisplay(&q);
		puts("*************** Press any key to continue ********************** ");
		getch();
	}
}
Ejemplo n.º 2
0
bool CMusikLibrary::AddSongDataFromFile( const wxString & filename )
{
	//-----------------------------------------------------//
	//--- we don't need to worry about duplicate files	---//
	//--- because the MusikLibraryFrame will take care	---//
	//--- of any conflicts.								---//
	//-----------------------------------------------------//

	if ( filename.IsEmpty() )
		return true;

	
	CSongMetaData MetaData;
	MetaData.Filename = filename;
	CMetaDataHandler::RetCode rc  = CMetaDataHandler::GetMetaData( MetaData );
	if(rc == CMetaDataHandler::notsupported)
	{
		::wxLogInfo(_("Parsing of file %s not supported. Setting title to filename."),(const wxChar *)MetaData.Filename.GetFullPath());
		rc = CMetaDataHandler::success; // continue as if success
	}
	if(rc == CMetaDataHandler::success )
	{

		//--- run the query ---//
		m_nCachedSongCount = -1;
        MusikDb::QueryString qInsert("insert into songs values (%Q ,%d, %d, %Q, %Q, %Q, %Q, %d, %Q, %Q, %d, %d, %Q, %Q, %d, %d, julianday('now'), %d, %d ,julianday('now'));",
            NULL,	
            (int)MetaData.eFormat,	
            MetaData.bVBR, 
            ( const char* )ConvToUTF8(MetaData.Filename.GetFullPath()) ,
            ( const char* )MetaData.Artist, 
            ( const char* )MetaData.Title, 
            ( const char* )MetaData.Album, 
            MetaData.nTracknum, 
            ( const char* )MetaData.Year, 
            ( const char* )MetaData.Genre, 
            0,//rating 
            MetaData.nBitrate, 
            "",//lastplayed 
            ( const char* )MetaData.Notes,//notes 
            0,//timesplayed 
            MetaData.nDuration_ms, 
            MetaData.nFilesize,
            0); //dirty
        m_pDB->Exec(qInsert);
	}
	else if(rc == CMetaDataHandler::fail)
	{
		::wxLogWarning(_("Parsing of file %s failed."),(const wxChar *)MetaData.Filename.GetFullPath());
	}
	else
	{
		wxASSERT(false);
	}

	return rc != CMetaDataHandler::fail;
}
Ejemplo n.º 3
0
// If a function is registered, it will be enqueued for execution.
// If the funciton cannot be found, an error is printed with the event name
// IMPORTANT NOTE: In the produce loop of the stream, I have to lock
//                                before caling this
void announceEvent( void * handle, const char * eventName, void * info ){

    Handle * hand = ( Handle * ) handle;
    HashTable * tab = hand->registry;
    EventQueue * que = hand->cue;
    hEntry * fin;

    
    if( ( fin = hashFind( tab, ( char * )eventName ) ) != NULL ){
        qInsert( que, fin->func, info );
    }
    else{
        fprintf( stderr, "WARNING: UNHANDLED EVENT: %s\n", eventName );
    }
    
    if( pthread_cond_signal( &hand->cv ) != 0 ){
            fprintf( stderr, "Error in signal.\n" );
            exit( - 1 );
    }
    
}
Ejemplo n.º 4
0
// Starts the event loop. While the event is still running, pop items off the queue and
// execute their functions
void startEventLoop( void * handle, void (*initialFunction )( void * ),
                                                    void * initialArgument ){
    Handle * hand = ( Handle * )handle;
    EventQueue * que = hand->cue;

    qInsert( que, initialFunction, initialArgument );

    if( pthread_mutex_lock( &hand->mu ) != 0 ){
        fprintf( stderr, "Error in mutex lock.\n" );
        exit( -1 );
    }
    
    while( hand->terminated != 1 ){
        while( qIsEmpty( que ) == 1 ){
            if( pthread_cond_wait( &hand->cv, &hand->mu ) != 0 ){
                fprintf( stderr, "Error in cond_wait\n" );
                exit( -1 );
            }
        }
        
        if( qIsEmpty( que ) == 0 ){
            qEntry * popped = qPop( que );
            void ( *f )( void * ) = popped->func;
            void * arg = popped->args;
            free( popped );
            f( arg );
        }
         
    }
    if( pthread_mutex_unlock( &hand->mu ) != 0 ){
        fprintf( stderr, "error in mutex unlock\n" );
        exit( -1 );
    }
    
    
    
}