Esempio n. 1
0
void quitter(int ta_socket) {
	//fermeture des connexions
	printf("bye bye...\n");
	close(ta_socket);
	pop_id();
	exit(0);
}
Esempio n. 2
0
int main()
{
    char step[11] = "_mDxcDjg9P4";
    push_id("song 1");
    push_id("song 2");
    push_id("song 3");
    print_queue();

    struct song *s;
    for (int i = 0; i < 4; i++) {
        s = pop_id();
        printf("%11s\n", s ? s->video_id : "(null)");
    }
}
Esempio n. 3
0
/**
	@brief Load a stored query.
	@param state Pointer to the query-building context.
	@param query_id ID of the query in query.stored_query.
	@return A pointer to the newly loaded StoredQ if successful, or NULL if not.

	The calling code is responsible for freeing the StoredQ by calling storedQFree().
*/
StoredQ* getStoredQuery( BuildSQLState* state, int query_id ) {
	if( !state )
		return NULL;

	// Check the stack to see if the current query is nested inside itself.  If it is, then
	// abort in order to avoid infinite recursion.  If it isn't, then add it to the stack.
	// (Make sure to pop it off the stack before returning.)
	if( searchIdStack( state->query_stack, query_id, NULL )) {
		osrfLogWarning( OSRF_LOG_MARK, sqlAddMsg( state,
			"Infinite recursion detected; query # %d is nested within itself", query_id ));
		state->error = 1;
		return NULL;
	} else
		push_id( &state->query_stack, query_id, NULL );

	StoredQ* sq = NULL;
	dbi_result result = dbi_conn_queryf( state->dbhandle,
		"SELECT id, type, use_all, use_distinct, from_clause, where_clause, having_clause "
		"FROM query.stored_query WHERE id = %d;", query_id );
	if( result ) {
		if( dbi_result_first_row( result ) ) {
			sq = constructStoredQ( state, result );
			if( sq ) {
				PRINT( "Got a query row\n" );
				PRINT( "\tid: %d\n", sq->id );
				PRINT( "\ttype: %d\n", (int) sq->type );
				PRINT( "\tuse_all: %s\n", sq->use_all ? "true" : "false" );
				PRINT( "\tuse_distinct: %s\n", sq->use_distinct ? "true" : "false" );
			} else
				osrfLogError( OSRF_LOG_MARK, sqlAddMsg( state,
					"Unable to build a query for id = %d", query_id ));
		} else {
			sqlAddMsg( state, "Stored query not found for id %d", query_id );
		}

		dbi_result_free( result );
	} else {
		const char* msg;
		int errnum = dbi_conn_error( state->dbhandle, &msg );
		osrfLogError( OSRF_LOG_MARK, sqlAddMsg( state, 
			"Unable to query query.stored_query table: #%d %s",
			errnum, msg ? msg : "No description available" ));
	}

	pop_id( &state->query_stack );
	return sq;
}
Esempio n. 4
0
/* main poll for event execution */
void* event_poll( void* _event_handler_p )
{
    event_handler_t* _event_handler = _event_handler_p;
    uint32_t* _frequms = &_event_handler->_frequms;


    while ( _event_handler->_running )
    {

        if ( _event_handler->_events_count ){
            pthread_mutex_lock(&_event_handler->_mutex);

            int i;
            for ( i = 0; i < _event_handler->_events_count; i ++ ){
                _event_handler->_events[i]._event(_event_handler->_events[i]._event_args);

            }
            clear_events(&_event_handler->_events, &_event_handler->_events_count);

            pthread_mutex_unlock(&_event_handler->_mutex);
        }

        if ( _event_handler->_timed_events_count ){
            pthread_mutex_lock(&_event_handler->_mutex);

            uint32_t _time = t_time();

            if ( _event_handler->_timed_events[0]._timeout < _time ) {
                _event_handler->_timed_events[0]._event(_event_handler->_timed_events[0]._event_args);

                pop_id(&_event_handler->_timed_events,
                       &_event_handler->_timed_events_count,
                       _event_handler->_timed_events[0]._id);
            }
            pthread_mutex_unlock(&_event_handler->_mutex);
        }


        usleep(*_frequms);
    }

    _event_handler->_running = -1;
    pthread_exit(NULL);
}
Esempio n. 5
0
static Expression* getExpression( BuildSQLState* state, int id ) {
	
	// Check the stack to see if the current expression is nested inside itself.  If it is,
	// then abort in order to avoid infinite recursion.  If it isn't, then add it to the
	// stack.  (Make sure to pop it off the stack before returning.)
	if( searchIdStack( state->expr_stack, id, NULL )) {
		osrfLogWarning( OSRF_LOG_MARK, sqlAddMsg( state,
			"Infinite recursion detected; expression # %d is nested within itself", id ));
		state->error = 1;
		return NULL;
	} else
		push_id( &state->expr_stack, id, NULL );

		Expression* exp = NULL;
	dbi_result result = dbi_conn_queryf( state->dbhandle,
		"SELECT id, type, parenthesize, parent_expr, seq_no, literal, table_alias, "
		"column_name, left_operand, operator, right_operand, function_id, subquery, cast_type "
		"FROM query.expression WHERE id = %d;", id );
	if( result ) {
		if( dbi_result_first_row( result ) ) {
			exp = constructExpression( state, result );
			if( exp ) {
				PRINT( "Got an expression\n" );
				PRINT( "\tid = %d\n", exp->id );
				PRINT( "\ttype = %d\n", exp->type );
				PRINT( "\tparenthesize = %d\n", exp->parenthesize );
				PRINT( "\tcolumn_name = %s\n", exp->column_name ? exp->column_name : "(none)" );
			} else 
				osrfLogError( OSRF_LOG_MARK, sqlAddMsg( state,
					"Unable to construct an Expression for id = %d", id ));
		}
	} else {
		const char* msg;
		int errnum = dbi_conn_error( state->dbhandle, &msg );
		osrfLogError( OSRF_LOG_MARK, sqlAddMsg( state,
			"Unable to query query.expression table: #%d %s",
			errnum, msg ? msg : "No description available" ));
	}

	pop_id( &state->expr_stack );
	return exp;
}
Esempio n. 6
0
/* main poll for event execution */
void *event_poll( void *arg )
{
    EventHandler *_event_handler = arg;

    while ( _event_handler->running ) {

        LOCK( _event_handler );

        if ( _event_handler->timed_events ) {

            uint32_t _time = ((uint32_t)current_time_monotonic());

            if ( _event_handler->timed_events[0].timeout < _time ) {

                RUN_IN_THREAD ( _event_handler->timed_events[0].func,
                                _event_handler->timed_events[0].func_args );

                pop_id(&_event_handler->timed_events,
                       &_event_handler->timed_events_count,
                       _event_handler->timed_events[0].id);

            }

        }

        UNLOCK( _event_handler );

        usleep(FREQUENCY);
    }

    LOCK( _event_handler );

    clear_events(&_event_handler->timed_events, &_event_handler->timed_events_count);

    UNLOCK( _event_handler );

    _event_handler->running = -1;
    pthread_exit(NULL);
}
Esempio n. 7
0
/* Remove timer from array */
inline__ int cancel_timer_event ( int id )
{
    return pop_id (&event_handler.timed_events, &event_handler.timed_events_count, id );
}
Esempio n. 8
0
int cancel_timer_event ( void* _event_handler_p, int _id )
{
    event_handler_t* _event_handler = _event_handler_p;
    return pop_id(&_event_handler->_timed_events, &_event_handler->_timed_events_count, _id);
}
Esempio n. 9
0
static FromRelation* getFromRelation( BuildSQLState* state, int id ) {
	FromRelation* fr = NULL;
	dbi_result result = dbi_conn_queryf( state->dbhandle,
		"SELECT id, type, table_name, class_name, subquery, function_call, "
		"table_alias, parent_relation, seq_no, join_type, on_clause "
		"FROM query.from_relation WHERE id = %d;", id );
	if( result ) {
		if( dbi_result_first_row( result ) ) {
			fr = constructFromRelation( state, result );
			if( fr ) {
				PRINT( "Got a from_relation row\n" );
				PRINT( "\tid: %d\n", fr->id );
				PRINT( "\ttype: %d\n", (int) fr->type );
				PRINT( "\ttable_name: %s\n", fr->table_name ? fr->table_name : "(none)" );
				PRINT( "\tclass_name: %s\n", fr->class_name ? fr->class_name : "(none)" );
				PRINT( "\tsubquery_id: %d\n", fr->subquery_id );
				PRINT( "\tfunction_call_id: %d\n", fr->function_call_id );
				PRINT( "\ttable_alias: %s\n", fr->table_alias ? fr->table_alias : "(none)" );
				PRINT( "\tparent_relation_id: %d\n", fr->parent_relation_id );
				PRINT( "\tseq_no: %d\n", fr->seq_no );
				PRINT( "\tjoin_type = %d\n", fr->join_type );
				// Check the stack to see if the current from clause is nested inside itself.
				// If it is, then abort in order to avoid infinite recursion.  If it isn't,
				// then add it to the stack.  (Make sure to pop it off the stack before
				// returning.)
				const char* effective_alias = fr->table_alias;
				if( !effective_alias )
					effective_alias = fr->class_name;
				const IdNode* node = searchIdStack( state->from_stack, id, effective_alias );
				if( node ) {
					if( node->id == id )
						osrfLogWarning( OSRF_LOG_MARK, sqlAddMsg( state,
							"Infinite recursion detected; from clause # %d is nested "
							"within itself", id ));
					else
						osrfLogWarning( OSRF_LOG_MARK, sqlAddMsg( state,
							"Conflicting nested table aliases \"%s\" in from clause # %d",
							effective_alias, node->id ));
					state->error = 1;
					return NULL;
				} else
					push_id( &state->from_stack, id, effective_alias );
			} else
				osrfLogError( OSRF_LOG_MARK, sqlAddMsg( state,
					"Unable to build a FromRelation for id = %d", id ));
		} else {
			osrfLogWarning( OSRF_LOG_MARK, sqlAddMsg( state,
				"FROM relation not found for id = %d", id ));
		}
		dbi_result_free( result );
	} else {
		const char* msg;
		int errnum = dbi_conn_error( state->dbhandle, &msg );
		osrfLogError( OSRF_LOG_MARK, sqlAddMsg( state,
			"Unable to query query.from_relation table: #%d %s",
			errnum, msg ? msg : "No description available" ));
	}

	if( fr )
		pop_id( &state->from_stack );

	return fr;
}