Skip to content

RBM is a system that applies the theory of OS process scheduling to schedule real-time bookings of facilities according to time and priority conditions

Notifications You must be signed in to change notification settings

BanjiBear/Room-Booking-Manager-RBM-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

[2021] Room Booking Management Program RBM

Introduction

The Room Booking Managment Program (officially named RBM) is a project implemented in C that utilize the Operating System scheduling technique and Linux system calls to build a booking system. The system allows user to book rooms and facilities one by one or in batch by feeding in batch files. RBM is allowed to schedule booking according to different rules: First-Come-First-Serve, Priority, or Optimized. It accepts and rejects dynamically according to real-time results and is also capable of handling exceptions. The components of RBM consist of:

  • five tenants: tenant_A, tenant_B, tenant_C, tenant_D and tenant_E
  • three meeting rooms: room_A, room_B and room_C (room_A and room_B are of the small meeting rooms (<=10) while room_C (<=20) is the largest one)
  • three webcams: webcam_FHD × 2 and webcam UHD × 1
  • three monitors: monitor_50 × 2 and monitor_75 × 1
  • three projectors: projector_2K × 2 and projector_4K × 1
  • three projection screens: screen_100 × 2 and screen_150 × 1

Summary of the requriements for the project include:

  • Develop a program that allows users to add details of a booking (date, time,duration, and/or callees etc.) to the schedule. RBM should be able to read in line by line and batch files
  • Implement several scheduling algorithms, including FCFS, Priority, and Optimized. Priority schedules booking according to profits and Optimized reschedule all REJECTED bookings to optimize all requests
  • Assign priorities to room and facilities according to booking. e.g., if a room is booked for a presentation and should be equipped with projector and screen, the projector and screen will be reserved for that booking with a higher priority. If someone reserves only the two pieces of equipment by that moment, the booking would be then rejected.
  • Generate timetables for all bookings
  • Print booking schedule for meeting rooms and related devices, including both ACCEPTED and REJECTED, according to different scheduling algorithms
  • Generate a summary report to analyze the results of different scheduling

(Rules, Requirements, and Assumptions of this project are rather long, for detailed, you are recommended to read the file [Detailed] Project Description in this repository)

Untitled Diagram drawio-2 Untitled Diagram drawio-3 image

Required Commands for RBM

addMeeting

addMeeting -aaa YYYY-MM-DD hh:mm n.n p bbb ccc;
e.g. addMeeting –tenant_A 2021-05-16 10:00 3.0 9 projector_2K screen_100;

This command is to add a booking for a meeting room with certain devices together. It is an optional choice to book any add-on facilities. Tenants may simply book a meeting room only. As in the example, [tenant_A] is to make a booking on [May 16, 2021] at [10:00], and the duration is [3.0] hours. In addition, it also requires a projector (projector_2K) and a screen (screen_100).

addPresentation

addPresentation -aaa YYYY-MM-DD hh:mm n.n p bbb ccc;
e.g. addPresentation –tenant_B 2021-05-14 08:00 3.0 12 projector_4K screen_150;

This is to make a booking for a presentation. a request made by [tenant_B] who would conduct a presentation on [May 14, 2021] at [08:00] for [3.0] hours long. And, there would be 12 persons to take part in the presentation. In addition, the room should be equipped with [project_4K] and [screen_150] – Additional devices are required (mandatorily include).

addConference

addConference -aaa YYYY-MM-DD hh:mm n.n bbb ccc ddd;
e.g. addConference –tenant_E 2021-05-16 14:00 2.0 15 webcam_UHD monitor_75;

Similarly, to add a booking for conference. This would have a higher priority than addPresentation if the scheduling algorithm is set to Priority.

bookDevice

bookDevice -aaa YYYY-MM-DD hh:mm n.n bbb
e.g. bookDevice –tenant_C 2021-05-011 13:00 4.0 projector_4K;

Command simply to reserve a specific device.

addBatch

addBatch -xxxxx
e.g. addBatch –batch001.dat

To read in a batch file, batch001.dat which is a plain text document that contains records of one or multiple booking requests.

image

printBookings

printBookings –xxx –[fcfs/prio/opti/ALL]
e.g. printBookings –fcfs

The command to print the schedule (Accepted and Rejected) for all users. If the algorithm is ALL, a Performance Report is needed. The Performance Report is a summary of how many bookings are received and allocated, and how many are rejected in total that based on the algorithm used.

endProgram

endProgram;
image

Program Installation and Execution

The program is developed solely in C. Thus, the RBM should be able to compile and execute on all platform and OS with the proper gcc compiler installed. Before compilation, please verify the gcc installation using the following command

gcc --version

Compile and Execute the system by

gcc RBM_G08.c -o RBM
./RBM

System Design and Implementation

The implementation of the booking system is written in C. In order to constantly read in input and process one or multiple booking request in real-time, a Parent-Child process architecture is utilized.

// pipe creation
int i, j, n;
int p2cfd[15][2]; // parent to child pipes
int c2pfd[15][2]; // child to parent pipes

for (i = 0; i < 15; i++){
  if (pipe(p2cfd[i]) < 0){
    printf("Errors when creating pipes!\n");
    exit(1);
  }
  if (pipe(c2pfd[i]) < 0){
    printf("Errors when creating pipes!\n");
    exit(1);
  }
}

// child processes creation and initialization
int parentid, myid, pid, index = -1;
int timeslots[7][24]; // the test schedule is seven days (5.10-5.16)
char message[30] = {0};
parentid = getpid();
for (i = 0; i < 15; i++){ // create 15 child processes
  if (getpid() == parentid){
    fork();
    if (getpid() != parentid) index = i;
  }
}

The Parent process is responsible for reading in requests and validate the request. The processing here simply verifies the command syntax and does not schedule the bookings at all! The parent process also clears all logging files in the same folder with the application code.

else if (getpid() == parentid){
	// clear all records in the text file
    FILE *booking = fopen("Booking.txt", "wb");
    ...
    fclose(booking);
    ...

    while(1){
		...
		// handle the booking request
		int code = 0;
		code = processRequest(input, p2cfd, c2pfd);
		...
	}
}

On the other hand, the Child process is responsible for logging and the actual scheduling. We adopt a lazy scheduling approach, that is, not until a printBooking command is called, the system does not schedule any bookings but simply stores them. Once a printBooking command is fed in, the Child process reads from the logging file and schedule according to given condition.

int processRequest(char input[1024], int p2cfd[15][2], int c2pfd[15][2]){
	char commandType[15] = {0};
	int i, j, n, code;
	cutCommandType(input, commandType);
	
	// handle request 
	if (ifValid(input) == 0){ // invalid input
		FILE *invalid = fopen("Invalid.txt", "a");
		fprintf(invalid, "%s", input);
		fclose(invalid);
		return 0;
	}

	if (strncmp(commandType, "addConference", 13) == 0){
			fprintf(conference, "%s", input);
			fprintf(booking, "%s", input);
			printf("-> [Pending]\n");
			code = 0;
	}
	else if (strncmp(commandType, "addPresentation", 15) == 0){
			fprintf(presentation, "%s", input);
			fprintf(booking, "%s", input);
			printf("-> [Pending]\n");
			code = 0;
	}
	else if (strncmp(commandType, "addMeeting", 10) == 0){
			fprintf(meeting, "%s", input);
			fprintf(booking, "%s", input);
			printf("-> [Pending]\n");
			code = 0;
	}
	else if (strncmp(commandType, "bookDevice", 10) == 0){
			fprintf(device, "%s", input);
			fprintf(booking, "%s", input);
			printf("-> [Pending]\n");
			code = 0;
	}
	else if (strncmp(commandType, "addBatch", 8) == 0){
		char filename[20] = {0};
		cutBatch(input, filename);
			FILE *batch = fopen(filename, "r");
			char request[1024] = {0};
			while (fgets(request, 1024, batch) != NULL){
					processRequest(request, p2cfd, c2pfd);
			}
			printf("-> [Pending]\n");
			code = 0;
			fclose(batch);
	}
	else if (strncmp(commandType, "printBookings", 13) == 0){
			if (input[15] == 'f'){
					printBookings(0, p2cfd, c2pfd);
					printOutput(0);
			}
			else if (input[15] == 'p'){
					printBookings(1, p2cfd, c2pfd);
					printOutput(1);
			}
			else{ // ALL
					printBookings(0, p2cfd, c2pfd);
					printOutput(0);
					printBookings(1, p2cfd, c2pfd);
					printOutput(1);
					printBookings(0, p2cfd, c2pfd);
					printSummary(0, p2cfd, c2pfd);
					printBookings(1, p2cfd, c2pfd);
					printSummary(1, p2cfd, c2pfd);
			}
			printf("-> [Done!]\n");
			code = 0;
	}
	else{ // end the program
			code = 1;
	}
	
	return code;
}
Screenshot 2024-05-21 at 11 41 57 AM

About

RBM is a system that applies the theory of OS process scheduling to schedule real-time bookings of facilities according to time and priority conditions

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages