Essay on Assignment4 Handout

Submitted By Jiajun-Ni
Words: 2165
Pages: 9

CSCI 4061 Spring 2015 | Assignment 4: A Threaded Image Organiser
Due:
Due on Thursday 04/19/2015 by 11:59 PM (Online, no hard copy)

Purpose:
The purpose of this assignment is to understand multi-threaded programming in C using POSIX thread library along with signaling and synchronization methods.

Scenario:
Think of any photo gallery app or picture organizer program, for e.g., Google’s Picasa, which manages image files on your desktop. In order to accomplish these tasks, the application should have the capability to browse through the user’s directories, locate relevant files and maintain path information for all files thereby creating a “catalog.”

Assignment:
You are required to write a multithreaded C program using standard GNU C Library functions ONLY.
The program has to take as input the absolute path to a directory. For e.g. the home directory for an CSELAB UNIX user and parses through the directory tree extracting file specific information for files with four types of extensions: JPG, PNG, BMP and GIF. The file information gathered is written into a HTML file. Thread logs must be captured in a separate log file.

Task: File Information
For every image file of the given type in the directory tree capture the following information tuple (Hint: you could use a struct data type) in the following order:
FileId, FileName, FileType, Size, TimeofModification, ThreadId

where FileId: inode number of the file in the directory, FileName: Name of the image file in the directory, FileType: Type of the file in the directory, Size: Size in bytes of the file,
TimeOfModification: Time when this file was last modified, ThreadId: Unique identifier of the thread responsible for writing the aforementioned information of the current image file to the HTML file.

Implementation variants
As you would have already realized, you can scan through the directory using threads in many ways. This assignment expects two different implementations which varies on thread creation.

Variant 1: In the first variant referred to as argument v1, the thread creation is done at a directory level.
As directories are organized into a tree like structure, your program should assign a thread to every directory in the directory tree. Each of these threads search for files with valid image extensions, viz. jpg, bmp, gif, and png, within their assigned directory. If a thread encounters a subdirectory within its directory, it must then create another thread to scan through the subdirectory and so on and so forth.

Variant 2: In this second variant referred to as argument v2, you will have to create a thread for each directory as in variant 1 and then four new threads, one per file format for this specific directory. Thus, there will be five threads per directory regardless of the fact that the directory has pictures of all formats or not or subdirectories.

Task: HTML File Generation
Your program should create one HTML file in all which contains all the information in a record.
Individual worker threads write all the information to the HTML file. This HTML file would consist of a list of images where an image icon (an icon of size 100X100 irrespective of the actual size of the image) provides a hyperlink to the original image file. Below each image hyperlink, the information tuple should be clearly documented.
NOTE: HTML file is written by all threads (including main threads), therefore you need to do synchronization among them (e.g. use mutex, semaphores). You have to make sure your program generates a working HTML. Please find a partial example of the HTML file below.
Your HTML must be called “catalog.html” If an HTML file already exists in the output directory when your program begins to run or for each variant you can safely you can override the same catalog.html saved in the output directory.
<html><head><title>My Image Manager BMP</title></head><body> <a href="./dir/5.bmp">
<img src="./dir/5.bmp" width=100 height=100></img></a><p align= “left”> FileId,…