Esempio n. 1
0
GameState events_menu_sim_menu(GameVars *game_vars) {
    SDL_Event ev;
    while (SDL_PollEvent(&ev)) {
        GameEvent gameev = events_parse(&ev);
        switch (gameev) {
        case EV_EXIT:
            return STATE_EXIT;
        case EV_KEY_Q:
            if (game_vars->grid != NULL) {
                grid_free(game_vars->grid);
                game_vars->grid = NULL;
            }
            return STATE_MAIN_MENU;
        case EV_KEY_ESC:
            return STATE_SIM_PAUSED;
        case EV_KEY_DOWN:
            return STATE_SIM_SAVE;
        case EV_KEY_UP:
            return STATE_SIM_SETTINGS;
        case EV_RESIZE:
            Event_SetWindowSize(game_vars, ev.window.data1, ev.window.data2);
            break;
        default:
            break;
        }
    }
    return game_vars->state;
}
Esempio n. 2
0
int main(int argc, char **argv)
{
    srand(time(NULL));
    clock_t beg, end;

    int size = 50;
    grid *grd = grid_allocate(size, size);

    beg = clock();
    grid_create(grd, 0.6);
    cl_list* clusters = clusterization(grd);
    end = clock();
    
    int i, j;
    for (i = 0; i < size; i++)
    {
        for (j = 0; j < size; j++)
            printf("%d", grd->cells[i * size + j]);
        printf("\n");
    }
    cl_list_print(clusters);
    
    create_image("img.png", 2000, grd, clusters);
    
    grid_free(grd);
    
    printf("Finished in %g sec\n", (double)(end - beg) / CLOCKS_PER_SEC);
    
    return 0;
}
Esempio n. 3
0
struct grid_trie_node *grid_node_compact (struct grid_trie_node *self)
{
    /*  Tries to merge the node with the child node. Returns pointer to
        the compacted node. */

    struct grid_trie_node *ch;

    /*  Node that is a subscription cannot be compacted. */
    if (grid_node_has_subscribers (self))
        return self;

    /*  Only a node with a single child can be compacted. */
    if (self->type != 1)
        return self;

    /*  Check whether combined prefixes would fix into a single node. */
    ch = *grid_node_child (self, 0);
    if (self->prefix_len + ch->prefix_len + 1 > GRID_TRIE_PREFIX_MAX)
        return self;

    /*  Concatenate the prefixes. */
    memmove (ch->prefix + self->prefix_len + 1, ch->prefix, ch->prefix_len);
    memcpy (ch->prefix, self->prefix, self->prefix_len);
    ch->prefix [self->prefix_len] = self->u.sparse.children [0];
    ch->prefix_len += self->prefix_len + 1;

    /*  Get rid of the obsolete parent node. */
    grid_free (self);

    /*  Return the new compacted node. */
    return ch;
}
Esempio n. 4
0
File: xreq.c Progetto: gridmq/gridmq
static void grid_xreq_destroy (struct grid_sockbase *self)
{
    struct grid_xreq *xreq;

    xreq = grid_cont (self, struct grid_xreq, sockbase);

    grid_xreq_term (xreq);
    grid_free (xreq);
}
Esempio n. 5
0
File: xreq.c Progetto: gridmq/gridmq
void grid_xreq_rm (struct grid_sockbase *self, struct grid_pipe *pipe)
{
    struct grid_xreq *xreq;
    struct grid_xreq_data *data;

    xreq = grid_cont (self, struct grid_xreq, sockbase);
    data = grid_pipe_getdata (pipe);
    grid_lb_rm (&xreq->lb, &data->lb);
    grid_fq_rm (&xreq->fq, &data->fq);
    grid_free (data);

    grid_sockbase_stat_increment (self, GRID_STAT_CURRENT_SND_PRIORITY,
        grid_lb_get_priority (&xreq->lb));
}
Esempio n. 6
0
void grid_node_term (struct grid_trie_node *self)
{
    int children;
    int i;

    /*  Trivial case of the recursive algorithm. */
    if (!self)
        return;

    /*  Recursively destroy the child nodes. */
    children = self->type <= GRID_TRIE_SPARSE_MAX ?
        self->type : (self->u.dense.max - self->u.dense.min + 1);
    for (i = 0; i != children; ++i)
        grid_node_term (*grid_node_child (self, i));

    /*  Deallocate this node. */
    grid_free (self);
}
Esempio n. 7
0
/* =============================================================================
 * maze_free
 * =============================================================================
 */
void
maze_free (maze_t* mazePtr)
{
    coordinate_t* coordPtr;
    if (mazePtr->gridPtr != NULL) {
        grid_free(mazePtr->gridPtr);
    }
    queue_free(mazePtr->workQueuePtr);
    vector_free(mazePtr->wallVectorPtr);
    while ((coordPtr = (coordinate_t *)vector_popBack (mazePtr->srcVectorPtr)) != NULL) {
        coordinate_free(coordPtr);
    }
    vector_free(mazePtr->srcVectorPtr);
    while ((coordPtr = (coordinate_t *)vector_popBack (mazePtr->dstVectorPtr)) != NULL) {
        coordinate_free(coordPtr);
    }
    vector_free(mazePtr->dstVectorPtr);
    free(mazePtr);
}
Esempio n. 8
0
void grid_usock_term (struct grid_usock *self)
{
    grid_assert_state (self, GRID_USOCK_STATE_IDLE);

    if (self->in.batch)
        grid_free (self->in.batch);

    grid_fsm_event_term (&self->event_error);
    grid_fsm_event_term (&self->event_received);
    grid_fsm_event_term (&self->event_sent);
    grid_fsm_event_term (&self->event_established);

    grid_worker_cancel (self->worker, &self->task_recv);

    grid_worker_task_term (&self->task_stop);
    grid_worker_task_term (&self->task_recv);
    grid_worker_task_term (&self->task_send);
    grid_worker_task_term (&self->task_accept);
    grid_worker_task_term (&self->task_connected);
    grid_worker_task_term (&self->task_connecting);
    grid_worker_fd_term (&self->wfd);

    grid_fsm_term (&self->fsm);
}
Esempio n. 9
0
static int grid_node_unsubscribe (struct grid_trie_node **self,
    const uint8_t *data, size_t size)
{
    int i;
    int j;
    int index;
    int new_min;
    struct grid_trie_node **ch;
    struct grid_trie_node *new_node;
    struct grid_trie_node *ch2;

    if (!size)
        goto found;

    /*  If prefix does not match the data, return. */
    if (grid_node_check_prefix (*self, data, size) != (*self)->prefix_len)
        return 0;

    /*  Skip the prefix. */
    data += (*self)->prefix_len;
    size -= (*self)->prefix_len;

    if (!size)
        goto found;

    /*  Move to the next node. */
    ch = grid_node_next (*self, *data);
    if (!ch)
        return 0; /*  TODO: This should be an error. */

    /*  Recursive traversal of the trie happens here. If the subscription
        wasn't really removed, nothing have changed in the trie and
        no additional pruning is needed. */
    if (grid_node_unsubscribe (ch, data + 1, size - 1) == 0)
        return 0;

    /*  Subscription removal is already done. Now we are going to compact
        the trie. However, if the following node remains in place, there's
        nothing to compact here. */
    if (*ch)
        return 1;

    /*  Sparse array. */
    if ((*self)->type < GRID_TRIE_DENSE_TYPE) {

        /*  Get the indices of the removed child. */
        for (index = 0; index != (*self)->type; ++index)
            if ((*self)->u.sparse.children [index] == *data)
                break;
        assert (index != (*self)->type);

        /*  Remove the destroyed child from both lists of children. */
        memmove (
            (*self)->u.sparse.children + index,
            (*self)->u.sparse.children + index + 1,
            (*self)->type - index - 1);
        memmove (
            grid_node_child (*self, index),
            grid_node_child (*self, index + 1),
            ((*self)->type - index - 1) * sizeof (struct grid_trie_node*));
        --(*self)->type;
        *self = grid_realloc (*self, sizeof (struct grid_trie_node) +
            ((*self)->type * sizeof (struct grid_trie_node*)));
        assert (*self);
        
        /*  If there are no more children and no refcount, we can delete
            the node altogether. */
        if (!(*self)->type && !grid_node_has_subscribers (*self)) {
            grid_free (*self);
            *self = NULL;
            return 1;
        }

        /*  Try to merge the node with the following node. */
        *self = grid_node_compact (*self);

        return 1;
    }

    /*  Dense array. */

    /*  In this case the array stays dense. We have to adjust the limits of
        the array, if appropriate. */
    if ((*self)->u.dense.nbr > GRID_TRIE_SPARSE_MAX + 1) {

        /*  If the removed item is the leftmost one, trim the array from
            the left side. */
        if (*data == (*self)->u.dense.min) {
             for (i = 0; i != (*self)->u.dense.max - (*self)->u.dense.min + 1;
                   ++i)
                 if (*grid_node_child (*self, i))
                     break;
             new_min = i + (*self)->u.dense.min;
             memmove (grid_node_child (*self, 0), grid_node_child (*self, i),
                 ((*self)->u.dense.max - new_min + 1) *
                 sizeof (struct grid_trie_node*));
             (*self)->u.dense.min = new_min;
             --(*self)->u.dense.nbr;
             *self = grid_realloc (*self, sizeof (struct grid_trie_node) +
                 ((*self)->u.dense.max - new_min + 1) *
                 sizeof (struct grid_trie_node*));
             assert (*self);
             return 1;
        }

        /*  If the removed item is the rightmost one, trim the array from
            the right side. */
        if (*data == (*self)->u.dense.max) {
             for (i = (*self)->u.dense.max - (*self)->u.dense.min; i != 0; --i)
                 if (*grid_node_child (*self, i))
                     break;
             (*self)->u.dense.max = i + (*self)->u.dense.min;
             --(*self)->u.dense.nbr;
             *self = grid_realloc (*self, sizeof (struct grid_trie_node) +
                 ((*self)->u.dense.max - (*self)->u.dense.min + 1) *
                 sizeof (struct grid_trie_node*));
             assert (*self);
             return 1;
        }

        /*  If the item is removed from the middle of the array, do nothing. */
        --(*self)->u.dense.nbr;
        return 1;
    }

    /*  Convert dense array into sparse array. */
    {
        new_node = grid_alloc (sizeof (struct grid_trie_node) +
            GRID_TRIE_SPARSE_MAX * sizeof (struct grid_trie_node*), "trie node");
        assert (new_node);
        new_node->refcount = 0;
        new_node->prefix_len = (*self)->prefix_len;
        memcpy (new_node->prefix, (*self)->prefix, new_node->prefix_len);
        new_node->type = GRID_TRIE_SPARSE_MAX;
        j = 0;
        for (i = 0; i != (*self)->u.dense.max - (*self)->u.dense.min + 1;
              ++i) {
            ch2 = *grid_node_child (*self, i);
            if (ch2) {
                new_node->u.sparse.children [j] = i + (*self)->u.dense.min;
                *grid_node_child (new_node, j) = ch2;
                ++j;
            }
        }
        assert (j == GRID_TRIE_SPARSE_MAX);
        grid_free (*self);
        *self = new_node;
        return 1;
    }

found:

    /*  We are at the end of the subscription here. */

    /*  Subscription doesn't exist. */
    if (grid_slow (!*self || !grid_node_has_subscribers (*self)))
        return -EINVAL;

    /*  Subscription exists. Unsubscribe. */
    --(*self)->refcount;

    /*  If reference count has dropped to zero we can try to compact
        the node. */
    if (!(*self)->refcount) {

        /*  If there are no children, we can delete the node altogether. */
        if (!(*self)->type) {
            grid_free (*self);
            *self = NULL;
            return 1;
        }

        /*  Try to merge the node with the following node. */
        *self = grid_node_compact (*self);
        return 1;
    }

    return 0;
}
Esempio n. 10
0
int grid_trie_subscribe (struct grid_trie *self, const uint8_t *data, size_t size)
{
    int i;
    struct grid_trie_node **node;
    struct grid_trie_node **n;
    struct grid_trie_node *ch;
    struct grid_trie_node *old_node;
    int pos;
    uint8_t c;
    uint8_t c2;
    uint8_t new_min;
    uint8_t new_max;
    int old_children;
    int new_children;
    int inserted;
    int more_nodes;

    /*  Step 1 -- Traverse the trie. */

    node = &self->root;
    pos = 0;
    while (1) {

        /*  If there are no more nodes on the path, go to step 4. */
        if (!*node)
            goto step4;

        /*  Check whether prefix matches the new subscription. */
        pos = grid_node_check_prefix (*node, data, size);
        data += pos;
        size -= pos;

        /*  If only part of the prefix matches, go to step 2. */
        if (pos < (*node)->prefix_len)
            goto step2;

        /*  Even if whole prefix matches and there's no more data to match,
            go directly to step 5. */
        if (!size)
            goto step5;

        /*  Move to the next node. If it is not present, go to step 3. */
        n = grid_node_next (*node, *data);
        if (!n || !*n)
            goto step3;
        node = n;
        ++data;
        --size;
    }

    /*  Step 2 -- Split the prefix into two parts if required. */
step2:

    ch = *node;
    *node = grid_alloc (sizeof (struct grid_trie_node) +
        sizeof (struct grid_trie_node*), "trie node");
    assert (*node);
    (*node)->refcount = 0;
    (*node)->prefix_len = pos;
    (*node)->type = 1;
    memcpy ((*node)->prefix, ch->prefix, pos);
    (*node)->u.sparse.children [0] = ch->prefix [pos];
    ch->prefix_len -= (pos + 1);
    memmove (ch->prefix, ch->prefix + pos + 1, ch->prefix_len);
    ch = grid_node_compact (ch);
    *grid_node_child (*node, 0) = ch;
    pos = (*node)->prefix_len;

    /*  Step 3 -- Adjust the child array to accommodate the new character. */
step3:

    /*  If there are no more data in the subscription, there's nothing to
        adjust in the child array. Proceed directly to the step 5. */
    if (!size)
        goto step5;

    /*  If the new branch fits into sparse array... */
    if ((*node)->type < GRID_TRIE_SPARSE_MAX) {
        *node = grid_realloc (*node, sizeof (struct grid_trie_node) +
            ((*node)->type + 1) * sizeof (struct grid_trie_node*));
        assert (*node);
        (*node)->u.sparse.children [(*node)->type] = *data;
        ++(*node)->type;
        node = grid_node_child (*node, (*node)->type - 1);
        *node = NULL;
        ++data;
        --size;
        goto step4;
    }

    /*  If the node is already a dense array, resize it to fit the next
        character. */
    if ((*node)->type == GRID_TRIE_DENSE_TYPE) {
        c = *data;
        if (c < (*node)->u.dense.min || c > (*node)->u.dense.max) {
            new_min = (*node)->u.dense.min < c ? (*node)->u.dense.min : c;
            new_max = (*node)->u.dense.max > c ? (*node)->u.dense.max : c;
            *node = grid_realloc (*node, sizeof (struct grid_trie_node) +
                (new_max - new_min + 1) * sizeof (struct grid_trie_node*));
            assert (*node);
            old_children = (*node)->u.dense.max - (*node)->u.dense.min + 1;
            new_children = new_max - new_min + 1;
            if ((*node)->u.dense.min != new_min) {
                inserted = (*node)->u.dense.min - new_min;
                memmove (grid_node_child (*node, inserted),
                    grid_node_child (*node, 0),
                    old_children * sizeof (struct grid_trie_node*));
                memset (grid_node_child (*node, 0), 0,
                    inserted * sizeof (struct grid_trie_node*));
            }
            else {
                memset (grid_node_child (*node, old_children), 0,
                    (new_children - old_children) *
                    sizeof (struct grid_trie_node*));
            }
            (*node)->u.dense.min = new_min;
            (*node)->u.dense.max = new_max;
        }
        ++(*node)->u.dense.nbr;

        node = grid_node_child (*node, c - (*node)->u.dense.min);
        ++data;
        --size;
        goto step4;
    }

    /*  This is a sparse array, but no more children can be added to it.
        We have to convert it into a dense array. */
    {
        /*  First, determine the range of children. */
        new_min = 255;
        new_max = 0;
        for (i = 0; i != (*node)->type; ++i) {
            c2 = (*node)->u.sparse.children [i];
            new_min = new_min < c2 ? new_min : c2;
            new_max = new_max > c2 ? new_max : c2;
        }
        new_min = new_min < *data ? new_min : *data;
        new_max = new_max > *data ? new_max : *data;

        /*  Create a new mode, while keeping the old one for a while. */
        old_node = *node;
        *node = (struct grid_trie_node*) grid_alloc (sizeof (struct grid_trie_node) +
            (new_max - new_min + 1) * sizeof (struct grid_trie_node*),
            "trie node");
        assert (*node);

        /*  Fill in the new node. */
        (*node)->refcount = 0;
        (*node)->prefix_len = old_node->prefix_len;
        (*node)->type = GRID_TRIE_DENSE_TYPE;
        memcpy ((*node)->prefix, old_node->prefix, old_node->prefix_len);
        (*node)->u.dense.min = new_min;
        (*node)->u.dense.max = new_max;
        (*node)->u.dense.nbr = old_node->type + 1;
        memset (*node + 1, 0, (new_max - new_min + 1) *
            sizeof (struct grid_trie_node*));
        for (i = 0; i != old_node->type; ++i)
            *grid_node_child (*node, old_node->u.sparse.children [i] - new_min) =
                *grid_node_child (old_node, i);
        node = grid_node_next (*node, *data);
        ++data;
        --size;

        /*  Get rid of the obsolete old node. */
        grid_free (old_node);
    }

    /*  Step 4 -- Create new nodes for remaining part of the subscription. */
step4:

    assert (!*node);
    while (1) {

        /*  Create a new node to hold the next part of the subscription. */
        more_nodes = size > GRID_TRIE_PREFIX_MAX;
        *node = grid_alloc (sizeof (struct grid_trie_node) +
            (more_nodes ? sizeof (struct grid_trie_node*) : 0), "trie node");
        assert (*node);

        /*  Fill in the new node. */
        (*node)->refcount = 0;
        (*node)->type = more_nodes ? 1 : 0;
        (*node)->prefix_len = size < (uint8_t) GRID_TRIE_PREFIX_MAX ?
            (uint8_t) size : (uint8_t) GRID_TRIE_PREFIX_MAX;
        memcpy ((*node)->prefix, data, (*node)->prefix_len);
        data += (*node)->prefix_len;
        size -= (*node)->prefix_len;
        if (!more_nodes)
            break;
        (*node)->u.sparse.children [0] = *data;
        node = grid_node_child (*node, 0);
        ++data;
        --size;
    }

    /*  Step 5 -- Create the subscription as such. */
step5:

    ++(*node)->refcount;

    /*  Return 1 in case of a fresh subscription. */
    return (*node)->refcount == 1 ? 1 : 0;
}
Esempio n. 11
0
void UPnP_Media_Server(IDirectFBEventBuffer *p_eventbuffer)
{							
	GridObj *grid=NULL, *text_grid=NULL;		
	IconObj *icon=NULL;				
	TextObj *text=NULL, *text_selected=NULL;
	UPnPNode *head=NULL, *unode_selected=NULL;	
	DFBRectangle *page_space;
	int key = 0, grid_count = 1, serv_response = 0;	
	int page_size=5, line_distance=50;
						     
	serv_response = upnp_cmd_handler(p_eventbuffer, &head, NULL, SHOWMS); 	
	if(serv_response!=REQ_SUCCESS) return; 	
	icon_alert(PHOTO_LOADING_G, D_MOVE_CENTER);
	page_space = (DFBRectangle*)malloc(sizeof(DFBRectangle));
	grid_init(page_space, screen_space->x+50, screen_space->y+80, screen_space->w-100, screen_space->h-160);
	grid=create_view_tree(grid_count, page_space);			
	icon=create_icon_tree(grid, main_layer, win_dsc); 				
	text_grid = create_text_grid_tree(page_size, line_distance, page_space);	
	text = create_text_node_tree(text_grid); 				
	upnp_text_node_map(head, text); 			
	draw_text_table(text, icon->window_surface);
	icon_opacity(icon, 255);	 	 	    			
	icon_stackclass(icon, DWSC_MIDDLE);	     	
	close_icon_alert();
	text_selected=text;
	unode_selected=head;	
	
	while(1)
	{            
		key = GetInputDeviceEventByType(p_eventbuffer,PTYPE_NOSCREEN_API);    			           							
 		if( key == DIKI_UP )
 		{ 	 			 			 						
	 		upnp_cmd_handler(p_eventbuffer, NULL, NULL, CDUP); 	
	 		free(page_space);
	 		grid_free(grid);
			grid_free(text_grid);
	 		icons_free(icon); 		
	 		texts_free(text);		 			
	 		delete_unode_tree(head);	 			
	 		return;	       	 			 					 			
		}else if( key == DIKI_LEFT ){												
			if(unode_selected->elder_brother_node!=NULL) 
 			{
	 			if(text_selected->left!=NULL&&text_selected->left->content!=NULL)
	 			{	 				
		 				unode_selected=unode_selected->elder_brother_node;
		 				shift_text_left(&text_selected, icon->window_surface); 						 				
	 			}else { 									
						go_prev_page(page_size, &unode_selected, text, icon->window_surface);
						text_selected=text;											
	 			}
 			} 											
		}else if( key == DIKI_RIGHT ){							 															
			if(unode_selected->brother_node!=NULL) 
			{
				unode_selected=unode_selected->brother_node;
				if(text_selected->right!=NULL&&text_selected->right->content!=NULL)
				{ 					
					shift_text_right(&text_selected, icon->window_surface);												
				}else{										
					go_next_page(unode_selected, text, icon->window_surface);
					text_selected=text;											
				}	
			}  																	
		}else if( key == DIKI_DOWN ){													
				 		
		}else if( key == DIKI_ENTER ){
			serv_response = upnp_cmd_handler(p_eventbuffer, NULL, unode_selected->guid, SETMS); 							
			icon_opacity(icon, 0);	
			UPnP_OpenMediaServer(p_eventbuffer, NULL);		
			draw_title_string("Select Media Server", font_title, rgba, title_space, title_window_surface); 
			title_window_surface->Flip(title_window_surface, NULL, DSFLIP_NONE);		
			icon_opacity(icon, 255);				
		}else if( key == DIKI_A || key == DIKI_B ){																	
			icon_opacity(icon, 0);
			Detect_USBMount(p_eventbuffer);
			icon_opacity(icon, 255);
			p_eventbuffer->Reset(p_eventbuffer);						
		}
		p_eventbuffer->Reset(p_eventbuffer);							
	}	    				                        
}
Esempio n. 12
0
void UPnP_MediaController(IDirectFBEventBuffer *p_eventbuffer, char *media_device_guid)
{
	GridObj *grid=NULL;		
	IconObj *toolbar_icon=NULL;						
	FcNode *toolbar_node=NULL;
	DFBRectangle *toolbar_space, *toolbar_icon_space;
	int key = 0, grid_count = 6, serv_response = 0, toolbar_style=H_STYLE;		
	char *toolbar[]={"play","pause","stop","mute","voice up","voice down","0x"};
	char *toolbar_path[]={MEDIA_PLAY_0_G, MEDIA_PLAY_1_G, MEDIA_PLAY_2_G, MEDIA_PLAY_3_G, MEDIA_PLAY_4_G, MEDIA_PLAY_5_G,"0x"};
			
	serv_response = upnp_cmd_handler(p_eventbuffer, NULL, media_device_guid, OPEN);
	if(serv_response !=REQ_SUCCESS) return;						
	toolbar_space = (DFBRectangle*)malloc(sizeof(DFBRectangle));	
	toolbar_icon_space = (DFBRectangle*)malloc(sizeof(DFBRectangle));	
	grid_init(toolbar_space, screen_space->x+100, screen_space->y+380, screen_space->w-100, screen_space->h-350);
	grid_init(toolbar_icon_space, 0, 0, 50, 50);
	grid=create_button_tree(grid_count, toolbar_space, toolbar_style);				
	toolbar_icon=create_icon_tree(grid, main_layer, win_dsc);
	toolbar_node=create_menu_tree(toolbar, toolbar_path);	
	draw_icon_tree(toolbar_node, toolbar_icon, toolbar_icon_space, gp_dfb);	
	icon_opacity(toolbar_icon, 100);	 	 	    			
	toolbar_icon->window->SetOpacity(toolbar_icon->window, 255);
	icon_stackclass(toolbar_icon, DWSC_MIDDLE);	     		
	
	while(1)
	{            
		key = GetInputDeviceEventByType(p_eventbuffer,PTYPE_NOSCREEN_API);    			           							
 		if( key == DIKI_UP )
 		{ 	 			 			
 			free(toolbar_space);	 												
 			free(toolbar_icon_space);	 	
			grid_free(grid);			
 			icons_free(toolbar_icon); 	 		
 			delete_fcnode_tree(toolbar_node);			 			
 			return;	       		 		 			
		}else if( key == DIKI_LEFT ){	
			if(toolbar_node->elder_brother_node!=NULL) 
			{
				toolbar_node=toolbar_node->elder_brother_node;	
				toolbar_icon->window->SetOpacity(toolbar_icon->window, 100);		
				toolbar_icon=toolbar_icon->left;								
				toolbar_icon->window->SetOpacity(toolbar_icon->window, 255);		
			}	
		}else if( key == DIKI_RIGHT ){						 		
			if(toolbar_node->brother_node!=NULL) 
			{
				toolbar_node=toolbar_node->brother_node;
				toolbar_icon->window->SetOpacity(toolbar_icon->window, 100);		
				toolbar_icon=toolbar_icon->right;																																								
				toolbar_icon->window->SetOpacity(toolbar_icon->window, 255);	
			}	
		}else if( key == DIKI_DOWN ){		
			free(toolbar_space);	 	
			free(toolbar_icon_space);	 	
			grid_free(grid);			
 			icons_free(toolbar_icon); 	 				 			 			
 			delete_fcnode_tree(toolbar_node);			 			
 			return;	       		 		
		}else if( key == DIKI_ENTER ){						
			if(!strcmp(toolbar_node->title,toolbar[0])){							
				serv_response = upnp_cmd_handler(p_eventbuffer, NULL, NULL, PLAY);															
			}else if(!strcmp(toolbar_node->title,toolbar[1])){								
				serv_response = upnp_cmd_handler(p_eventbuffer, NULL, NULL, STOP);							
			}else if(!strcmp(toolbar_node->title,toolbar[2])){					
				serv_response = upnp_cmd_handler(p_eventbuffer, NULL, NULL, PAUSE);							
			}else if(!strcmp(toolbar_node->title,toolbar[3])){					
				serv_response = upnp_cmd_handler(p_eventbuffer, NULL, NULL, MUTE);							
			}else if(!strcmp(toolbar_node->title,toolbar[4])){									
				serv_response = upnp_cmd_handler(p_eventbuffer, NULL, NULL, VUP);						
			}else if(!strcmp(toolbar_node->title,toolbar[5])){								
				serv_response = upnp_cmd_handler(p_eventbuffer, NULL, NULL, VDOWN);					
			}			
		}else if( key == DIKI_A || key == DIKI_B ){																	
			icon_opacity(toolbar_icon, 0);
			Detect_USBMount(p_eventbuffer);
			icon_opacity(toolbar_icon, 255);
			p_eventbuffer->Reset(p_eventbuffer);						
		}
		p_eventbuffer->Reset(p_eventbuffer);							
	}	    				                			
}
Esempio n. 13
0
int grid_poll (struct grid_pollfd *fds, int nfds, int timeout)
{
    int rc;
    int i;
    int pos;
    int fd;
    int res;
    size_t sz;
    struct pollfd *pfd;

    /*  Construct a pollset to be used with OS-level 'poll' function. */
    pfd = grid_alloc (sizeof (struct pollfd) * nfds * 2, "pollset");
    alloc_assert (pfd);
    pos = 0;
    for (i = 0; i != nfds; ++i) {
        if (fds [i].events & GRID_POLLIN) {
            sz = sizeof (fd);
            rc = grid_getsockopt (fds [i].fd, GRID_SOL_SOCKET, GRID_RCVFD, &fd, &sz);
            if (grid_slow (rc < 0)) {
                grid_free (pfd);
                errno = -rc;
                return -1;
            }
            grid_assert (sz == sizeof (fd));
            pfd [pos].fd = fd;
            pfd [pos].events = POLLIN;
            ++pos;
        }
        if (fds [i].events & GRID_POLLOUT) {
            sz = sizeof (fd);
            rc = grid_getsockopt (fds [i].fd, GRID_SOL_SOCKET, GRID_SNDFD, &fd, &sz);
            if (grid_slow (rc < 0)) {
                grid_free (pfd);
                errno = -rc;
                return -1;
            }
            grid_assert (sz == sizeof (fd));
            pfd [pos].fd = fd;
            pfd [pos].events = POLLIN;
            ++pos;
        }
    }    

    /*  Do the polling itself. */
    rc = poll (pfd, pos, timeout);
    if (grid_slow (rc <= 0)) {
        res = errno;
        grid_free (pfd);
        errno = res;
        return rc;
    }

    /*  Move the results from OS-level poll to grid_poll's pollset. */
    res = 0;
    pos = 0;
    for (i = 0; i != nfds; ++i) {
        fds [i].revents = 0;
        if (fds [i].events & GRID_POLLIN) {
            if (pfd [pos].revents & POLLIN)
                fds [i].revents |= GRID_POLLIN;
            ++pos;
        }
        if (fds [i].events & GRID_POLLOUT) {
            if (pfd [pos].revents & POLLIN)
                fds [i].revents |= GRID_POLLOUT;
            ++pos;
        }
        if (fds [i].revents)
            ++res;
    }

    grid_free (pfd);
    return res;
}
Esempio n. 14
0
/* =============================================================================
 * maze_checkPaths
 * =============================================================================
 */
bool_t
maze_checkPaths (maze_t* mazePtr, list_t* pathVectorListPtr, bool_t doPrintPaths)
{
    grid_t* gridPtr = mazePtr->gridPtr;
    long width  = gridPtr->width;
    long height = gridPtr->height;
    long depth  = gridPtr->depth;
    long i;

    /* Mark walls */
    grid_t* testGridPtr = grid_alloc(width, height, depth);
    grid_addPath(testGridPtr, mazePtr->wallVectorPtr);

    /* Mark sources */
    vector_t* srcVectorPtr = mazePtr->srcVectorPtr;
    long numSrc = vector_getSize(srcVectorPtr);
    for (i = 0; i < numSrc; i++) {
        coordinate_t* srcPtr = (coordinate_t*)vector_at(srcVectorPtr, i);
        grid_setPoint(testGridPtr, srcPtr->x, srcPtr->y, srcPtr->z, 0);
    }

    /* Mark destinations */
    vector_t* dstVectorPtr = mazePtr->dstVectorPtr;
    long numDst = vector_getSize(dstVectorPtr);
    for (i = 0; i < numDst; i++) {
        coordinate_t* dstPtr = (coordinate_t*)vector_at(dstVectorPtr, i);
        grid_setPoint(testGridPtr, dstPtr->x, dstPtr->y, dstPtr->z, 0);
    }

    /* Make sure path is contiguous and does not overlap */
    long id = 0;
    list_iter_t it;
    list_iter_reset(&it, pathVectorListPtr);
    while (list_iter_hasNext(&it)) {
        vector_t* pathVectorPtr = (vector_t*)list_iter_next(&it);
        long numPath = vector_getSize(pathVectorPtr);
        long i;
        for (i = 0; i < numPath; i++) {
            id++;
            vector_t* pointVectorPtr = (vector_t*)vector_at(pathVectorPtr, i);
            /* Check start */
            long* prevGridPointPtr = (long*)vector_at(pointVectorPtr, 0);
            long x;
            long y;
            long z;
            grid_getPointIndices(gridPtr, prevGridPointPtr, &x, &y, &z);
            if (grid_getPoint(testGridPtr, x, y, z) != 0) {
                grid_free(testGridPtr);
                return FALSE;
            }
            coordinate_t prevCoordinate;
            grid_getPointIndices(gridPtr,
                                 prevGridPointPtr,
                                 &prevCoordinate.x,
                                 &prevCoordinate.y,
                                 &prevCoordinate.z);
            long numPoint = vector_getSize(pointVectorPtr);
            long j;
            for (j = 1; j < (numPoint-1); j++) { /* no need to check endpoints */
                long* currGridPointPtr = (long*)vector_at(pointVectorPtr, j);
                coordinate_t currCoordinate;
                grid_getPointIndices(gridPtr,
                                     currGridPointPtr,
                                     &currCoordinate.x,
                                     &currCoordinate.y,
                                     &currCoordinate.z);
                if (!coordinate_areAdjacent(&currCoordinate, &prevCoordinate)) {
                    grid_free(testGridPtr);
                    return FALSE;
                }
                prevCoordinate = currCoordinate;
                long x = currCoordinate.x;
                long y = currCoordinate.y;
                long z = currCoordinate.z;
                if (grid_getPoint(testGridPtr, x, y, z) != GRID_POINT_EMPTY) {
                    grid_free(testGridPtr);
                    return FALSE;
                } else {
                    grid_setPoint(testGridPtr, x, y, z, id);
                }
            }
            /* Check end */
            long* lastGridPointPtr = (long*)vector_at(pointVectorPtr, j);
            grid_getPointIndices(gridPtr, lastGridPointPtr, &x, &y, &z);
            if (grid_getPoint(testGridPtr, x, y, z) != 0) {
                grid_free(testGridPtr);
                return FALSE;
            }
        } /* iteratate over pathVector */
    } /* iterate over pathVectorList */

    if (doPrintPaths) {
        puts("\nRouted Maze:");
        grid_print(testGridPtr);
    }

    grid_free(testGridPtr);

    return TRUE;
}