コード例 #1
0
/*
* Name:                 run_url_browser
* Input arguments:      'nTabIndex': URL-RENDERING tab index
* Output arguments:     void
* Function:             This function will make a URL-RENDRERING tab Note.
*                       You need to use below functions to handle tab event. 
*                       1. process_all_gtk_events();
*                       2. process_single_gtk_event();
*                       3. render_web_page_in_tab(uri, b_window);
*                       For more details please Appendix B.
*/
int run_url_browser(int nTabIndex)	
{
	browser_window * b_window = NULL;
	int bytesRead = 0;
	char uri [512];
	// Launch a url rendering browser
	create_browser(URL_RENDERING_TAB, nTabIndex, G_CALLBACK(new_tab_created_cb), G_CALLBACK(uri_entered_cb), &b_window, comm[nTabIndex]);
	// Check for instructions sent from the router or gtk events
	child_req_to_parent req;
	while (1) 
	{
		usleep(1000);
		if((bytesRead = read(comm[nTabIndex].parent_to_child_fd[0], &req, sizeof(child_req_to_parent))) == -1){ 
			if(errno == EAGAIN)			// if nothing to be read yet, process browser events and wait for another round
				process_single_gtk_event();
			else
				perror("run_url_browser@134: Url browser reads from pipe");
		}
		else{							// perform instructions
			switch(req.type){	
				case NEW_URI_ENTERED:	// render the given uri
				    strcpy(uri,req.req.uri_req.uri);
					render_web_page_in_tab(uri, b_window);
					break;
				case TAB_KILLED:		// process gtk events and terminate this process with exit success
					process_single_gtk_event();
					exit(EXIT_SUCCESS);
				default: 				// invalid request type
					fprintf(stderr, "run_url_browser@149: Invalid request for url rendering browser\n");
					break;
			}
		}
	}
	return 0;
}
コード例 #2
0
ファイル: browser.c プロジェクト: dbelling/operating-systems
int run_url_browser(int nTabIndex, comm_channel comm)
{
	browser_window * b_window = NULL;
	
	// Create controler window
	create_browser(URL_RENDERING_TAB, nTabIndex, G_CALLBACK(new_tab_created_cb), G_CALLBACK(uri_entered_cb), &b_window, comm);

	child_req_to_parent request;
	char uri_req[512];	
	int r;

	while (1) // Need to communicate with Router process here. Will receieve requests for processing.
	{
		process_single_gtk_event();
		usleep(1000);
		
		// Insert code here!!
		
		// 1. process_all_gtk_events();
		// 2. process_single_gtk_event();
        	// 3. render_web_page_in_tab(uri, b_window);

		// Read the request from the comm_channel

		r = read(comm.parent_to_child_fd[0], &request, sizeof(child_req_to_parent));
		
	    /*
	     * Handle each type of message (few mentioned below)
	     */
		
		if(r == -1)
		{
			//do nothing
		}
		else
		{
			if(request.type == NEW_URI_ENTERED) //  NEW_URI_ENTERED: render_web_page_in_tab(uri, b_window);
			{
				strcpy(uri_req, request.req.uri_req.uri);
				render_web_page_in_tab(uri_req, b_window);
			}
			//  TAB_KILLED: process all gtk events();
			if(request.type == TAB_KILLED)
			{
				process_all_gtk_events();
				break;
			}
		}
	}

	return 0;
}