client.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gtk-2.0/gtk/gtk.h>
#include <regex.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <pthread.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <time.h>
#include <poll.h>

Go to the source code of this file.

Defines

#define BUFFER   1024
 Client.c.
#define PORT_NUMBER   9999
#define SERVER_ADDRESS   "127.0.0.1"
#define LABEL_MAX_LENGTH   100

Functions

void show_questions ()
 Question frames.
void update_time_thread ()
 This is used to update the time left.
void time_thread (void *time_wait)
 This is a thread that sleeps for the time the test run or the allowed time for the user to answer the test.
int Socket (int domain, int type, int protocol)
 Socket function reimplementation with error handling .
ssize_t Read (int fd, void *buf, size_t count)
 Read function reimplementation with error handling .
ssize_t Write (int fd, const void *buf, size_t count)
 write function reimplementation with error handling .
void Close (int fd)
 Close function reimplementation with error handling.
int Open (const char *pathname, int flags)
 to open a file
static gboolean delete (GtkWidget *widget, GtkWidget *event, gpointer data)
 Used to destroy the window.
void check_radio (GtkWidget *widget, gpointer ans)
 Used to copy the option selected by the user in the radio button to global answer variable.
void label_length_check (char *check_string)
 Used to check the length of the labels if its more than LABEL_MAX_LENGTH then insert a new line after each LABEL_MAX_LENGTH.
void start_test ()
 this is the function that is used to create a different thread for time out and then call tha show_questions()
static void add_welcome_frame ()
 welcome frame.
void verify_user ()
 Verify user first sends the username and password to the server and recieves the reply whether the username and passwords validates.It the authenticates the user and pass over to the next screen containing welcome user message and test instruction.
void add_login_frame ()
 Login Frame.
int main (int argc, char *argv[])
 Main function declares all variables and performs connection with the server and socket file descriptor is set.

Variables

GtkWidget * window
 Gtk Window.
GtkWidget * entry1
 Gtk related global parameters.
GtkWidget * entry2
 Gtk related global parameters.
GtkWidget * notebook
 Gtk related global parameters.
GtkWidget * label_timeleft
 Gtk gloabal variable for updating time via a time update thread.
int socket_file_descriptor
 Socket gloabal variable socket file descriptor.
int characters_read
 used to store the characters read from the socket
char username [BUFFER]
 used to store the username
char password [BUFFER]
 used to store the password
int tot_question
 used to store total no of Questions
int current_question
 used to store current question being answered.
int tot_time
 used to store total time
int marks
 used to store marks obtained by user
char answer [BUFFER]
 to store the anser given by the user
char input_data [BUFFER]
char ack [10]
char login_status [10]
char connection_flag
char time_flag
time_t start
 Records the start time of the exam.
double dif
 used to take the time difference
int time_left
 updates time left to the label in time update thread.
int data_file_descriptor
 data file descripter for image file

Define Documentation

#define BUFFER   1024

Client.c.

Author:
:Prashant sharma & Narendra Singh
Version:
:1.0

Definition at line 23 of file client.c.

Referenced by handle_client_thread(), show_questions(), and verify_user().

#define LABEL_MAX_LENGTH   100

Definition at line 26 of file client.c.

Referenced by label_length_check().

#define PORT_NUMBER   9999

Definition at line 24 of file client.c.

Referenced by main().

#define SERVER_ADDRESS   "127.0.0.1"

Definition at line 25 of file client.c.

Referenced by main().


Function Documentation

void add_login_frame (  ) 

Login Frame.

Adds the login frame that is the first screen displayed to the notebook and calls verify user when user clicks the submit button.

See also:
verify_user()

Definition at line 1119 of file client.c.

References entry1, entry2, notebook, and verify_user().

Referenced by main().

01119                        {
01120     //GtkWidget *login;
01121     GtkWidget *label_heading;
01122     GtkWidget *label_empty;
01123     GtkWidget *label_username;
01124     GtkWidget *label_password;
01125     //GtkWidget *box;
01126     GtkWidget *button;
01127     GtkWidget *gridLayout;
01128     GtkWidget *frame;
01129     GtkWidget *label;
01130     GtkWidget *halign;
01131     GtkWidget *hseparator;
01132 
01133     /* Arranging the components of the frame in table */
01134     gridLayout = gtk_table_new(8, 4, FALSE);
01135     gtk_table_set_col_spacings(GTK_TABLE(gridLayout), 10);
01136     gtk_table_set_row_spacings(GTK_TABLE(gridLayout), 7);
01137 
01138     /* first row */
01139     label_empty = gtk_label_new("");
01140     gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 0, 4, 0, 1,
01141             GTK_FILL | GTK_EXPAND, GTK_FILL, 1, 1);
01142     gtk_widget_show(label_empty);
01143 
01144     /* second row */
01145     label_empty = gtk_label_new("");
01146     gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 0, 1, 1, 2,
01147             GTK_FILL | GTK_EXPAND, GTK_FILL, 1, 1);
01148     gtk_widget_show(label_empty);
01149 
01150     label_heading = gtk_label_new("ONLINE EXAMINATION PORTAL");
01151     halign = gtk_alignment_new(.5, .5, .5, .5);
01152     gtk_container_add(GTK_CONTAINER(halign), label_heading);
01153     gtk_table_attach(GTK_TABLE(gridLayout), halign, 1, 3, 1, 2,
01154             GTK_FILL, GTK_FILL, 0, 0);
01155     gtk_widget_show(label_heading);
01156 
01157     label_empty = gtk_label_new("");
01158     gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 3, 4, 1, 2,
01159             GTK_FILL | GTK_EXPAND, GTK_FILL, 1, 1);
01160     gtk_widget_show(label_empty);
01161 
01162     /* third row */
01163     label_empty = gtk_label_new("");
01164     gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 0, 1, 2, 3,
01165             GTK_FILL | GTK_EXPAND, GTK_FILL, 1, 1);
01166     gtk_widget_show(label_empty);
01167 
01168     hseparator = gtk_hseparator_new();
01169     halign = gtk_alignment_new(0, 0, 0, 0);
01170     gtk_table_attach(GTK_TABLE(gridLayout), hseparator, 1, 3, 2, 3,
01171             GTK_FILL | GTK_EXPAND, GTK_FILL, 1, 1);
01172     gtk_widget_show(hseparator);
01173 
01174     label_empty = gtk_label_new("");
01175     gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 3, 4, 2, 3,
01176             GTK_FILL | GTK_EXPAND, GTK_FILL, 1, 1);
01177     gtk_widget_show(label_empty);
01178 
01179     /* fourth row */
01180     label_empty = gtk_label_new("");
01181     gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 0, 1, 3, 4,
01182             GTK_FILL | GTK_EXPAND, GTK_FILL, 1, 1);
01183     gtk_widget_show(label_empty);
01184 
01185     label_username = gtk_label_new("Username :");
01186     halign = gtk_alignment_new(1, .5, 0, .5);
01187     gtk_container_add(GTK_CONTAINER(halign), label_username);
01188     gtk_table_attach(GTK_TABLE(gridLayout), halign, 1, 2, 3, 4,
01189             GTK_FILL, GTK_FILL, 1, 1);
01190     gtk_widget_show(label_username);
01191 
01192     entry1 = gtk_entry_new();
01193     gtk_entry_set_max_length(GTK_ENTRY(entry1), 80);
01194     halign = gtk_alignment_new(0, .5, 0, .5);
01195     gtk_container_add(GTK_CONTAINER(halign), entry1);
01196     gtk_table_attach(GTK_TABLE(gridLayout), halign, 2, 3, 3, 4,
01197             GTK_FILL, GTK_FILL, 1, 1);
01198     gtk_widget_show(entry1);
01199 
01200     label_empty = gtk_label_new("");
01201     gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 3, 4, 3, 4,
01202             GTK_FILL | GTK_EXPAND, GTK_FILL, 1, 1);
01203     gtk_widget_show(label_empty);
01204 
01205     /* fifth row */
01206     label_empty = gtk_label_new("");
01207     gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 0, 1, 4, 5,
01208             GTK_FILL | GTK_EXPAND, GTK_FILL, 1, 1);
01209     gtk_widget_show(label_empty);
01210 
01211     label_password = gtk_label_new("Password  :");
01212     halign = gtk_alignment_new(1, .5, 0, .5);
01213     gtk_container_add(GTK_CONTAINER(halign), label_password);
01214     gtk_table_attach(GTK_TABLE(gridLayout), halign, 1, 2, 4, 5,
01215             GTK_FILL, GTK_FILL, 1, 1);
01216     gtk_widget_show(label_password);
01217 
01218     entry2 = gtk_entry_new();
01219     gtk_entry_set_max_length(GTK_ENTRY(entry2), 80);
01220     gtk_entry_set_visibility(GTK_ENTRY(entry2), FALSE);
01221     halign = gtk_alignment_new(0, .5, 0, .5);
01222     gtk_container_add(GTK_CONTAINER(halign), entry2);
01223     gtk_table_attach(GTK_TABLE(gridLayout), halign, 2, 3, 4, 5,
01224             GTK_FILL, GTK_FILL, 1, 1);
01225     gtk_widget_show(entry2);
01226 
01227     label_empty = gtk_label_new("");
01228     gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 3, 4, 4, 5,
01229             GTK_FILL | GTK_EXPAND, GTK_FILL, 1, 1);
01230     gtk_widget_show(label_empty);
01231 
01232     /* sixth row */
01233     label_empty = gtk_label_new("");
01234     gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 0, 1, 5, 6,
01235             GTK_FILL | GTK_EXPAND, GTK_FILL, 1, 1);
01236     gtk_widget_show(label_empty);
01237 
01238     hseparator = gtk_hseparator_new();
01239     halign = gtk_alignment_new(0, 0, 0, 0);
01240     gtk_table_attach(GTK_TABLE(gridLayout), hseparator, 1, 3, 5, 6,
01241             GTK_FILL | GTK_EXPAND, GTK_FILL, 1, 1);
01242     gtk_widget_show(hseparator);
01243 
01244     label_empty = gtk_label_new("");
01245     gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 3, 4, 5, 6,
01246             GTK_FILL | GTK_EXPAND, GTK_FILL, 1, 1);
01247 
01248 
01249     /* seventh row */
01250     gtk_widget_show(label_empty);
01251     label_empty = gtk_label_new("");
01252     gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 0, 2, 6, 7,
01253             GTK_FILL | GTK_EXPAND, GTK_FILL, 1, 1);
01254     gtk_widget_show(label_empty);
01255 
01256     button = gtk_button_new_with_label("Sign In");
01257     gtk_widget_set_size_request(button, 70, 30);
01258     g_signal_connect_swapped(G_OBJECT(button), "clicked",
01259             G_CALLBACK(verify_user),
01260             (gpointer) notebook);
01261     halign = gtk_alignment_new(0, .5, 0, .5);
01262     gtk_container_add(GTK_CONTAINER(halign), button);
01263     gtk_table_attach(GTK_TABLE(gridLayout), halign, 2, 3, 6, 7,
01264             GTK_FILL, GTK_FILL, 1, 1);
01265     gtk_widget_show(button);
01266 
01267     label_empty = gtk_label_new("");
01268     gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 3, 4, 6, 7,
01269             GTK_FILL | GTK_EXPAND, GTK_FILL, 1, 1);
01270     gtk_widget_show(label_empty);
01271 
01272     /* last row */
01273     label_empty = gtk_label_new("");
01274     gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 0, 4, 7, 8,
01275             GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 1, 1);
01276     gtk_widget_show(label_empty);
01277 
01278     frame = gtk_frame_new("Login Page");
01279     gtk_container_set_border_width(GTK_CONTAINER(frame), 10);
01280     gtk_widget_set_size_request(frame, 580, 580);
01281     gtk_widget_show(frame);
01282     gtk_container_add(GTK_CONTAINER(frame), gridLayout);
01283     gtk_widget_show_all(gridLayout);
01284 
01285 
01286     label = gtk_label_new("Login Page");
01287     gtk_notebook_append_page(GTK_NOTEBOOK(notebook), frame, label);
01288 }

static void add_welcome_frame (  )  [static]

welcome frame.

This function adds the welcome frame to the notebook and then it is displayed to the user all the test realted intructions.

Definition at line 870 of file client.c.

References notebook, start_test(), and username.

Referenced by verify_user().

00870                                 {
00871 
00872     GtkWidget *label_heading;
00873     GtkWidget *label_empty;
00874     GtkWidget *button;
00875     GtkWidget *gridLayout;
00876     GtkWidget *frame;
00877     GtkWidget *label;
00878     GtkWidget *halign;
00879     GtkWidget *hseparator;
00880 
00881     char welcome_string[100];
00882     /* Arranging the components of the frame in table */
00883     gridLayout = gtk_table_new(6, 3, FALSE);
00884     gtk_table_set_col_spacings(GTK_TABLE(gridLayout), 10);
00885     gtk_table_set_row_spacings(GTK_TABLE(gridLayout), 10);
00886 
00887     /* first row */
00888     label_empty = gtk_label_new("");
00889     gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 0, 3, 0, 1,
00890             GTK_FILL, GTK_FILL, 1, 1);
00891     gtk_widget_show(label_empty);
00892 
00893     /* second row */
00894     label_empty = gtk_label_new("");
00895     gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 0, 1, 1, 2,
00896             GTK_FILL, GTK_FILL, 1, 1);
00897     gtk_widget_show(label_empty);
00898 
00899     sprintf(welcome_string, "Welcome %s", username);
00900     label_heading = gtk_label_new(welcome_string);
00901     //gtk_label_set_justify(GTK_LABEL(label_heading), GTK_JUSTIFY_LEFT);
00902     halign = gtk_alignment_new(0, 0, 0, 0);
00903     gtk_container_add(GTK_CONTAINER(halign), label_heading);
00904     gtk_table_attach(GTK_TABLE(gridLayout), halign, 1, 2, 1, 2,
00905             GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
00906     gtk_widget_show(label_heading);
00907 
00908     label_empty = gtk_label_new("");
00909     gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 2, 3, 1, 2,
00910             GTK_FILL, GTK_FILL, 1, 1);
00911     gtk_widget_show(label_empty);
00912 
00913     /* third row */
00914     hseparator = gtk_hseparator_new();
00915     halign = gtk_alignment_new(0, 0, 0, 0);
00916     gtk_table_attach(GTK_TABLE(gridLayout), hseparator, 0, 3, 2, 3,
00917             GTK_FILL, GTK_FILL, 1, 1);
00918     gtk_widget_show(hseparator);
00919 
00920     /* fourth row */
00921     label_empty = gtk_label_new("");
00922     gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 0, 1, 3, 4,
00923             GTK_FILL, GTK_FILL | GTK_EXPAND, 1, 1);
00924     gtk_widget_show(label_empty);
00925 
00926     label = gtk_label_new("Instructions\n\
00927 \n\
00928 1.This exam contain 10 Questions\n\
00929 \n\
00930 2.You can exit the test anytime using Quit Test button\n\
00931 \n\
00932 3.In that case your examination will be treated cancelled\n\
00933 \n\
00934 4.Use Next button to see next page/question\n\
00935 \n\
00936 5.You have 15 mins for this exam\n\
00937 \n\
00938 6.Maximum score is 800\n\
00939 \n\
00940 7.You can start the test using Start Test button\n\
00941 \n\
00942 Good Luck!!!");
00943     //gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
00944     halign = gtk_alignment_new(0, 0, 0, 0);
00945     gtk_container_add(GTK_CONTAINER(halign), label);
00946     gtk_table_attach(GTK_TABLE(gridLayout), halign, 1, 2, 3, 4,
00947             GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 1, 1);
00948     gtk_widget_show(label);
00949 
00950     label_empty = gtk_label_new("");
00951     gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 2, 3, 3, 4,
00952             GTK_FILL, GTK_FILL | GTK_EXPAND, 1, 1);
00953     gtk_widget_show(label_empty);
00954 
00955     /* fifth row */
00956 
00957     hseparator = gtk_hseparator_new();
00958     halign = gtk_alignment_new(0, 0, 0, 0);
00959     gtk_table_attach(GTK_TABLE(gridLayout), hseparator, 0, 3, 4, 5,
00960             GTK_FILL, GTK_FILL, 1, 1);
00961     gtk_widget_show(hseparator);
00962 
00963     /* sixth row */
00964     button = gtk_button_new_with_label("Quit Test");
00965     gtk_widget_set_size_request(button, 70, 30);
00966     g_signal_connect_swapped(G_OBJECT(button), "clicked",
00967             G_CALLBACK(delete), NULL);
00968     halign = gtk_alignment_new(0, 0, 0, 0);
00969     gtk_container_add(GTK_CONTAINER(halign), button);
00970     gtk_table_attach(GTK_TABLE(gridLayout), halign, 0, 1, 5, 6,
00971             GTK_SHRINK, GTK_SHRINK, 1, 1);
00972     gtk_widget_show(button);
00973 
00974     gtk_widget_show(label_empty);
00975     label_empty = gtk_label_new("");
00976     gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 1, 2, 5, 6,
00977             GTK_FILL | GTK_EXPAND, GTK_FILL, 1, 1);
00978     gtk_widget_show(label_empty);
00979 
00980     button = gtk_button_new_with_label("Start Test");
00981     gtk_widget_set_size_request(button, 70, 30);
00982     g_signal_connect_swapped(G_OBJECT(button), "clicked",
00983             G_CALLBACK(start_test),
00984             G_OBJECT(notebook));
00985     halign = gtk_alignment_new(0, 0, 0, 0);
00986     gtk_container_add(GTK_CONTAINER(halign), button);
00987     gtk_table_attach(GTK_TABLE(gridLayout), halign, 2, 3, 5, 6,
00988             GTK_SHRINK, GTK_SHRINK, 1, 1);
00989     gtk_widget_show(button);
00990 
00991 
00992 
00993     frame = gtk_frame_new("Welcome Page");
00994     gtk_container_set_border_width(GTK_CONTAINER(frame), 10);
00995     gtk_widget_set_size_request(frame, 580, 580);
00996     gtk_widget_show(frame);
00997     gtk_container_add(GTK_CONTAINER(frame), gridLayout);
00998     gtk_widget_show_all(gridLayout);
00999 
01000     label = gtk_label_new("Welcome Page");
01001     gtk_notebook_append_page(GTK_NOTEBOOK(notebook), frame, label);
01002 }

void check_radio ( GtkWidget *  widget,
gpointer  ans 
)

Used to copy the option selected by the user in the radio button to global answer variable.

Definition at line 226 of file client.c.

References answer.

Referenced by show_questions().

00226                                                   {
00227 
00228     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
00229         strcpy(answer, ans);
00230     }
00231 
00232 }

void Close ( int  fd  ) 

Close function reimplementation with error handling.

Parameters:
fd filedescriptor to close

Definition at line 183 of file client.c.

Referenced by Accept(), handle_client_thread(), main(), and show_questions().

00183                    {
00184     int return_value;
00185     return_value = close(fd);
00186     if (return_value < 0) {
00187         fprintf(stderr, "Cannot close\n");
00188         perror("REASON");
00189 
00190     }
00191 }

static gboolean delete ( GtkWidget *  widget,
GtkWidget *  event,
gpointer  data 
) [static]

Used to destroy the window.

Definition at line 215 of file client.c.

00217                        {
00218     gtk_main_quit();
00219     return FALSE;
00220 }

void label_length_check ( char *  check_string  ) 

Used to check the length of the labels if its more than LABEL_MAX_LENGTH then insert a new line after each LABEL_MAX_LENGTH.

Parameters:
check_string string to be checked

Definition at line 239 of file client.c.

References LABEL_MAX_LENGTH.

Referenced by show_questions().

00239                                             {
00240     /* Label length check */
00241     int temp_length;
00242     char temp_ch1, temp_ch2;
00243     temp_length = strlen(check_string);
00244     if (temp_length > LABEL_MAX_LENGTH) {
00245         int i, j, k, l, x;
00246         x = temp_length / LABEL_MAX_LENGTH;
00247         for (i = 1; i <= x; i++) {
00248 
00249             if (i == 1) {
00250                 j = (i * LABEL_MAX_LENGTH) + 1;
00251                 temp_ch1 = check_string[j];
00252                 check_string[j] = '\n';
00253             }
00254             for (k = j; k < j + i; k++) {
00255                 l = k;
00256                 while (l < temp_length && l < ((i + 1) * LABEL_MAX_LENGTH)) {
00257                     l = l + i;
00258                     temp_ch2 = check_string[l];
00259                     check_string[l] = temp_ch1;
00260                     temp_ch1 = temp_ch2;
00261                 }
00262             }
00263             j = l;
00264             if (j < temp_length) {
00265                 check_string[j + i] = '\n';
00266             } else {
00267                 check_string[j + i] = temp_ch1;
00268                 check_string[j + i + 1] = '\0';
00269             }
00270             temp_length = temp_length + 1;
00271         }
00272     }
00273     return;
00274 }

int main ( int  argc,
char *  argv[] 
)

Main function declares all variables and performs connection with the server and socket file descriptor is set.

Parameters:
argc command line arguments length
argv command line arguments.
Returns:
returns Zero on success.

Definition at line 1297 of file client.c.

References ack, add_login_frame(), connection_flag, notebook, PORT_NUMBER, SERVER_ADDRESS, Socket(), socket_file_descriptor, and window.

01297                                  {
01298 
01299 
01300     int connection_file_descriptor;
01301     struct sockaddr_in server_address;
01302 
01303     GtkWidget *table;
01304 
01305     //Connection to server
01306 
01307     connection_flag = 0;
01308     strcpy(ack, "ACK");
01309     //try to open socket
01310     socket_file_descriptor = Socket(AF_INET, SOCK_STREAM, 0);
01311 
01312     //if socket opening failed then print error message and quit
01313     if (socket_file_descriptor < 0) {
01314         fprintf(stderr, "cannot open socket.\n");
01315         connection_flag = 1;
01316     }
01317 
01318     //initialize struct server_address to all zeros.
01319     bzero(&server_address, sizeof (server_address));
01320 
01321     //set the protocol used to be ipv4
01322     server_address.sin_family = AF_INET;
01323 
01324     server_address.sin_port = htons(PORT_NUMBER);
01325 
01326     if (inet_pton(AF_INET, SERVER_ADDRESS, &server_address.sin_addr) <= 0) {
01327         fprintf(stderr, ": the supplied ipv4 address  is incorrect.\n");
01328         connection_flag = 1;
01329     }
01330 
01331     if ((connection_file_descriptor = connect(socket_file_descriptor, (struct sockaddr *) & server_address, sizeof (server_address))) < 0) {
01332         fprintf(stderr, ": cannot connect to server \n");
01333         connection_flag = 1;
01334     }
01335 
01336 
01337     //GTK part
01338     gtk_init(&argc, &argv);
01339 
01340     window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
01341 
01342     g_signal_connect(G_OBJECT(window), "delete_event",
01343             G_CALLBACK(delete), NULL);
01344 
01345     gtk_window_set_title(GTK_WINDOW(window), "Examination Portal");
01346     gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
01347     gtk_widget_set_size_request(window, 900, 600);
01348     //gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
01349     gtk_container_set_border_width(GTK_CONTAINER(window), 10);
01350 
01351 
01352     table = gtk_table_new(2, 2, FALSE);
01353     gtk_table_set_col_spacings(GTK_TABLE(table), 3);
01354     gtk_table_set_row_spacings(GTK_TABLE(table), 3);
01355     gtk_container_add(GTK_CONTAINER(window), table);
01356 
01357     /* Create a new notebook */
01358     notebook = gtk_notebook_new();
01359     gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook), FALSE);
01360     gtk_table_attach(GTK_TABLE(table), notebook, 0, 2, 0, 2,
01361             GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 1, 1);
01362     gtk_widget_show(notebook);
01363     add_login_frame();
01364 
01365     /* Set what page to start at page that is login page */
01366     gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 1);
01367     gtk_widget_show(table);
01368     gtk_widget_show(window);
01369 
01370     gtk_main();
01371 
01372     close(socket_file_descriptor);
01373 
01374     return 0;
01375 }

int Open ( const char *  pathname,
int  flags 
)

to open a file

Parameters:
pathname path of the file
flags read,write etc

Definition at line 197 of file client.c.

Referenced by handle_client_thread(), and show_questions().

00198 {
00199     int file_descriptor;
00200     file_descriptor=open(pathname,flags,0777);
00201     if(file_descriptor < 0)
00202     {
00203         fprintf(stderr, "Cannot open file\n");
00204     perror("REASON");
00205     
00206     }
00207     return file_descriptor;
00208 }

ssize_t Read ( int  fd,
void *  buf,
size_t  count 
)

Read function reimplementation with error handling .

Parameters:
fd filedescriptor to read
buf Buffer it is read into
count no of bytes to read.

Definition at line 149 of file client.c.

References characters_read.

Referenced by handle_client_thread(), show_questions(), and verify_user().

00149                                               {
00150     ssize_t characters_read;
00151     characters_read = read(fd, buf, count);
00152     if (characters_read < 0) {
00153         perror("Can't read");
00154         exit(1);
00155     }
00156     return characters_read;
00157 }

void show_questions (  ) 

Question frames.

Used to get the Questions from the server and display them in frames.

first row

second row

third row

fourth row

fifth row

sixth row

seventh row

eighth row

nineth row

tenth row

eleventh row

Arranging the components of the frame in table

first row

second row

third row

fourth row

fifth row

sixth row

Arranging the components of the frame in table

first row

second row

Third row

fourth row

fifth row

Definition at line 295 of file client.c.

References ack, answer, BUFFER, characters_read, check_radio(), Close(), current_question, data_file_descriptor, input_data, label_length_check(), label_timeleft, marks, notebook, Open(), Read(), socket_file_descriptor, time_flag, tot_question, username, window, and Write().

Referenced by start_test(), and time_thread().

00295                       {
00296     
00297     /*Variable declaration of GtkWidget for different components of the window*/
00298 
00299     GtkWidget *label_empty;
00300     GtkWidget *label_qno;
00301     GtkWidget *label_question;
00302     GtkWidget *label;
00303     GtkWidget *image;
00304     GtkWidget *button;
00305     GtkWidget *gridLayout;
00306     GtkWidget *frame;
00307     GtkWidget *halign;
00308     GtkWidget *hseparator;
00309     GtkWidget *radio1, *radio2, *radio3, *radio4;
00310 
00311 
00312     /* Buffers storing various components of the questions. eg. Question statement options etc.. */
00313     char question_imageurl[BUFFER];
00314     char question_statement[BUFFER];
00315     char question_optiona[BUFFER];
00316     char question_optionb[BUFFER];
00317     char question_optionc[BUFFER];
00318     char question_optiond[BUFFER];
00319     char temp_string[BUFFER];
00320 
00321 
00322     if (current_question == tot_question + 1) {
00323         
00324         //answer
00325         Write(socket_file_descriptor, answer, strlen(answer));
00326         if(time_flag == 1)
00327     {
00328         
00329         //read imageurl just to synchronization
00330             characters_read = Read(socket_file_descriptor, question_imageurl, BUFFER - 1);
00331             question_imageurl[characters_read] = '\0';
00332 
00333             //write an ack to server
00334             Write(socket_file_descriptor, "Timeout",7);
00335     }
00336     
00337        
00338         //read marks
00339         characters_read = Read(socket_file_descriptor, input_data, BUFFER - 1);
00340         input_data[characters_read] = '\0';
00341         marks = atoi(input_data);
00342     
00343         //write an ack to server
00344         Write(socket_file_descriptor, ack, strlen(ack));
00345     }
00346     if (current_question <= tot_question) {
00347 
00348         //answer
00349     if(current_question != 1)
00350     {
00351         Write(socket_file_descriptor, answer, strlen(answer));
00352         
00353     }
00354     strcpy(answer, "A");
00355         
00356 
00357         /* get the question data */
00358 
00359         //read imageurl
00360         characters_read = Read(socket_file_descriptor, question_imageurl, BUFFER - 1);
00361         question_imageurl[characters_read] = '\0';
00362     
00363      
00364         //write an ack to server
00365         Write(socket_file_descriptor, ack, strlen(ack));
00366     
00367     //if there is an image url
00368     if(strcmp(question_imageurl,"NO IMAGE"))
00369     {
00370         
00371         struct pollfd pfd[1];
00372         pfd[0].fd = socket_file_descriptor;
00373         pfd[0].events = POLLIN;
00374        
00375         data_file_descriptor = Open(question_imageurl, O_WRONLY | O_CREAT | O_TRUNC);
00376         if(data_file_descriptor < 0)
00377         {
00378         printf("Image file can not created\n");           
00379         }
00380         else
00381         {
00382         
00383           
00384         characters_read = Read(socket_file_descriptor, input_data, BUFFER -1);
00385         //fprintf(stderr,"%s",input_data);
00386         while(1)
00387         {
00388             poll (pfd, 1, 200);
00389             if (!pfd[0].revents)
00390             {
00391             break;
00392             }
00393             Write(data_file_descriptor, input_data, characters_read);
00394             characters_read = Read(socket_file_descriptor, input_data, BUFFER -1);
00395           //  fprintf(stderr,"%s",input_data);
00396             
00397         }
00398         if(characters_read > 0)
00399         {    
00400            Write(data_file_descriptor, input_data, characters_read);
00401         }
00402         
00403              //write an ack to server
00404                 Write(socket_file_descriptor, ack, strlen(ack));
00405 
00406         Close(data_file_descriptor);
00407         }
00408     }
00409     
00410     
00411 
00412      
00413       
00414         //read question statement
00415         characters_read = Read(socket_file_descriptor, question_statement, BUFFER - 1);
00416         question_statement[characters_read] = '\0';
00417         //write an ack to server
00418         Write(socket_file_descriptor, ack, strlen(ack));
00419 
00420         //read optiona
00421         characters_read = Read(socket_file_descriptor, question_optiona, BUFFER - 1);
00422         question_optiona[characters_read] = '\0';
00423         //write an ack to server
00424         Write(socket_file_descriptor, ack, strlen(ack));
00425 
00426         //read optionb
00427         characters_read = Read(socket_file_descriptor, question_optionb, BUFFER - 1);
00428         question_optionb[characters_read] = '\0';
00429         //write an ack to server
00430         Write(socket_file_descriptor, ack, strlen(ack));
00431 
00432         //read optionc
00433         characters_read = Read(socket_file_descriptor, question_optionc, BUFFER - 1);
00434         question_optionc[characters_read] = '\0';
00435         //write an ack to server
00436         Write(socket_file_descriptor, ack, strlen(ack));
00437 
00438         //read optiond
00439         characters_read = Read(socket_file_descriptor, question_optiond, BUFFER - 1);
00440         question_optiond[characters_read] = '\0';
00441         //write an ack to server
00442         Write(socket_file_descriptor, ack, strlen(ack));
00443 
00444         //read ack ignore
00445         characters_read = Read(socket_file_descriptor, input_data, BUFFER - 1);
00446         input_data[characters_read] = '\0';
00447 
00448     
00449          
00450 
00451         /* Label length check */
00452         label_length_check(question_statement);
00453         label_length_check(question_optiona);
00454         label_length_check(question_optionb);
00455         label_length_check(question_optionc);
00456         label_length_check(question_optiond);
00457 
00458 
00459         /* Arranging the components of the frame in table */
00460         gridLayout = gtk_table_new(11, 3, FALSE);
00461         gtk_table_set_col_spacings(GTK_TABLE(gridLayout), 10);
00462         gtk_table_set_row_spacings(GTK_TABLE(gridLayout), 10);
00463         
00465         label_empty = gtk_label_new("");
00466         gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 0, 3, 0, 1,
00467                 GTK_FILL, GTK_FILL, 1, 1);
00468         gtk_widget_show(label_empty);
00469 
00471         label_timeleft = gtk_label_new("Time Left:");
00472         halign = gtk_alignment_new(0, 0, 0, 0);
00473         gtk_container_add(GTK_CONTAINER(halign), label_timeleft);
00474         gtk_table_attach(GTK_TABLE(gridLayout), halign, 0, 1, 1, 2,
00475                 GTK_FILL, GTK_FILL, 1, 1);
00476         gtk_widget_show(label_timeleft);
00477 
00478         label_empty = gtk_label_new("");
00479         gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 1, 2, 1, 2,
00480                 GTK_FILL | GTK_EXPAND, GTK_FILL, 1, 1);
00481         gtk_widget_show(label_empty);
00482 
00483         sprintf(temp_string, "%d of %d", current_question, tot_question);
00484         label_qno = gtk_label_new(temp_string);
00485         halign = gtk_alignment_new(1, 0, 0, 0);
00486         gtk_container_add(GTK_CONTAINER(halign), label_qno);
00487         gtk_table_attach(GTK_TABLE(gridLayout), halign, 2, 3, 1, 2,
00488                 GTK_FILL, GTK_FILL, 1, 1);
00489         gtk_widget_show(label_qno);
00490 
00492         hseparator = gtk_hseparator_new();
00493         halign = gtk_alignment_new(0, 0, 0, 0);
00494         gtk_table_attach(GTK_TABLE(gridLayout), hseparator, 0, 3, 2, 3,
00495                 GTK_FILL, GTK_FILL, 1, 1);
00496         gtk_widget_show(hseparator);
00497 
00499         label_empty = gtk_label_new("");
00500         gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 0, 1, 3, 4,
00501                 GTK_FILL, GTK_FILL, 1, 1);
00502         gtk_widget_show(label_empty);
00503         //
00504         if (!strcmp(question_imageurl, "NO IMAGE")) {
00505             label_empty = gtk_label_new("");
00506             gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 1, 2, 3, 4,
00507                     GTK_FILL | GTK_EXPAND, GTK_FILL, 1, 1);
00508             gtk_widget_show(label_empty);
00509         } else {
00510             image = gtk_image_new_from_file(question_imageurl);
00511             gtk_table_attach(GTK_TABLE(gridLayout), image, 1, 2, 3, 4,
00512                     GTK_SHRINK, GTK_SHRINK, 1, 1);
00513             gtk_widget_show(image);
00514         }
00515         label_empty = gtk_label_new("");
00516         gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 2, 3, 3, 4,
00517                 GTK_FILL, GTK_FILL, 1, 1);
00518         gtk_widget_show(label_empty);
00519 
00521         label_empty = gtk_label_new("");
00522         gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 0, 1, 4, 5,
00523                 GTK_FILL, GTK_FILL, 1, 1);
00524         gtk_widget_show(label_empty);
00525 
00526         label_question = gtk_label_new(question_statement);
00527         halign = gtk_alignment_new(0, 0, 0, 0);
00528         gtk_container_add(GTK_CONTAINER(halign), label_question);
00529         gtk_table_attach(GTK_TABLE(gridLayout), halign, 1, 2, 4, 5,
00530                 GTK_FILL | GTK_EXPAND, GTK_FILL, 1, 1);
00531         gtk_widget_show(label_question);
00532 
00533         label_empty = gtk_label_new("");
00534         gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 2, 3, 4, 5,
00535                 GTK_FILL, GTK_FILL, 1, 1);
00536         gtk_widget_show(label_empty);
00537 
00539         label_empty = gtk_label_new("");
00540         gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 0, 1, 5, 6,
00541                 GTK_FILL, GTK_FILL, 1, 1);
00542         gtk_widget_show(label_empty);
00543 
00544         radio1 = gtk_radio_button_new_with_label_from_widget(NULL, question_optiona);
00545         g_signal_connect(G_OBJECT(radio1), "toggled", G_CALLBACK(check_radio), (gpointer) "A");
00546         halign = gtk_alignment_new(0, 0, 0, 0);
00547         gtk_container_add(GTK_CONTAINER(halign), radio1);
00548         gtk_table_attach(GTK_TABLE(gridLayout), halign, 1, 2, 5, 6,
00549                 GTK_FILL | GTK_EXPAND, GTK_FILL, 1, 1);
00550         gtk_widget_show(radio1);
00551 
00552         label_empty = gtk_label_new("");
00553         gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 2, 3, 5, 6,
00554                 GTK_FILL, GTK_FILL, 1, 1);
00555         gtk_widget_show(label_empty);
00556 
00558         label_empty = gtk_label_new("");
00559         gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 0, 1, 6, 7,
00560                 GTK_FILL, GTK_FILL, 1, 1);
00561         gtk_widget_show(label_empty);
00562 
00563         radio2 = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(radio1), question_optionb);
00564         g_signal_connect(G_OBJECT(radio2), "toggled", G_CALLBACK(check_radio), (gpointer) "B");
00565         halign = gtk_alignment_new(0, 0, 0, 0);
00566         gtk_container_add(GTK_CONTAINER(halign), radio2);
00567         gtk_table_attach(GTK_TABLE(gridLayout), halign, 1, 2, 6, 7,
00568                 GTK_FILL | GTK_EXPAND, GTK_FILL, 1, 1);
00569         gtk_widget_show(radio2);
00570 
00571         label_empty = gtk_label_new("");
00572         gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 2, 3, 6, 7,
00573                 GTK_FILL, GTK_FILL, 1, 1);
00574         gtk_widget_show(label_empty);
00575 
00577         label_empty = gtk_label_new("");
00578         gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 0, 1, 7, 8,
00579                 GTK_FILL, GTK_FILL, 1, 1);
00580         gtk_widget_show(label_empty);
00581 
00582         radio3 = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(radio1), question_optionc);
00583         g_signal_connect(G_OBJECT(radio3), "toggled", G_CALLBACK(check_radio), (gpointer) "C");
00584         halign = gtk_alignment_new(0, 0, 0, 0);
00585         gtk_container_add(GTK_CONTAINER(halign), radio3);
00586         gtk_table_attach(GTK_TABLE(gridLayout), halign, 1, 2, 7, 8,
00587                 GTK_FILL | GTK_EXPAND, GTK_FILL, 1, 1);
00588         gtk_widget_show(radio3);
00589 
00590         label_empty = gtk_label_new("");
00591         gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 2, 3, 7, 8,
00592                 GTK_FILL, GTK_FILL, 1, 1);
00593         gtk_widget_show(label_empty);
00594 
00596         label_empty = gtk_label_new("");
00597         gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 0, 1, 8, 9,
00598                 GTK_FILL, GTK_FILL, 1, 1);
00599         gtk_widget_show(label_empty);
00600 
00601         radio4 = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(radio1), question_optiond);
00602         g_signal_connect(G_OBJECT(radio4), "toggled", G_CALLBACK(check_radio), (gpointer) "D");
00603         halign = gtk_alignment_new(0, 0, 0, 0);
00604         gtk_container_add(GTK_CONTAINER(halign), radio4);
00605         gtk_table_attach(GTK_TABLE(gridLayout), halign, 1, 2, 8, 9,
00606                 GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 1, 1);
00607         gtk_widget_show(radio4);
00608 
00609         label_empty = gtk_label_new("");
00610         gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 2, 3, 8, 9,
00611                 GTK_FILL, GTK_FILL, 1, 1);
00612         gtk_widget_show(label_empty);
00613 
00614 
00617         hseparator = gtk_hseparator_new();
00618         halign = gtk_alignment_new(0, 0, 0, 0);
00619         gtk_table_attach(GTK_TABLE(gridLayout), hseparator, 0, 3, 9, 10,
00620                 GTK_FILL, GTK_FILL, 1, 1);
00621         gtk_widget_show(hseparator);
00622 
00624         button = gtk_button_new_with_label("Quit Test");
00625         gtk_widget_set_size_request(button, 70, 30);
00626         g_signal_connect_swapped(G_OBJECT(button), "clicked",
00627                 G_CALLBACK(delete), NULL);
00628         halign = gtk_alignment_new(0, 0, 0, 0);
00629         gtk_container_add(GTK_CONTAINER(halign), button);
00630         gtk_table_attach(GTK_TABLE(gridLayout), halign, 0, 1, 10, 11,
00631                 GTK_SHRINK, GTK_SHRINK, 1, 1);
00632         gtk_widget_show(button);
00633 
00634         gtk_widget_show(label_empty);
00635         label_empty = gtk_label_new("");
00636         gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 1, 2, 10, 11,
00637                 GTK_FILL | GTK_EXPAND, GTK_FILL, 1, 1);
00638         gtk_widget_show(label_empty);
00639 
00640         button = gtk_button_new_with_label("Next");
00641         gtk_widget_set_size_request(button, 70, 30);
00642         g_signal_connect_swapped(G_OBJECT(button), "clicked",
00643                 G_CALLBACK(show_questions),
00644                 G_OBJECT(notebook));
00645         halign = gtk_alignment_new(0, 0, 0, 0);
00646         gtk_container_add(GTK_CONTAINER(halign), button);
00647         gtk_table_attach(GTK_TABLE(gridLayout), halign, 2, 3, 10, 11,
00648                 GTK_SHRINK, GTK_SHRINK, 1, 1);
00649         gtk_widget_show(button);
00650 
00651 
00652 
00653         frame = gtk_frame_new(temp_string);
00654         gtk_container_set_border_width(GTK_CONTAINER(frame), 10);
00655         gtk_widget_set_size_request(frame, 580, 580);
00656         gtk_widget_show(frame);
00657         gtk_container_add(GTK_CONTAINER(frame), gridLayout);
00658         gtk_widget_show_all(gridLayout);
00659 
00660         label = gtk_label_new(temp_string);
00661         gtk_notebook_append_page(GTK_NOTEBOOK(notebook), frame, label);
00662 
00663         gtk_notebook_next_page(GTK_NOTEBOOK(notebook));
00664         current_question++;
00665     if(strcmp(question_imageurl,"NO IMAGE"))
00666     {
00667         unlink(question_imageurl);
00668     }
00669     } else if (current_question == tot_question + 1) {
00671         gridLayout = gtk_table_new(6, 3, FALSE);
00672         gtk_table_set_col_spacings(GTK_TABLE(gridLayout), 10);
00673         gtk_table_set_row_spacings(GTK_TABLE(gridLayout), 10);
00674 
00676         label_empty = gtk_label_new("");
00677         gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 0, 3, 0, 1,
00678                 GTK_FILL | GTK_EXPAND, GTK_FILL, 1, 1);
00679         gtk_widget_show(label_empty);
00680 
00682         label_empty = gtk_label_new("");
00683         gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 0, 1, 1, 2,
00684                 GTK_FILL | GTK_EXPAND, GTK_FILL, 1, 1);
00685         gtk_widget_show(label_empty);
00686 
00687         sprintf(temp_string, "Good Bye %s", username);
00688         label = gtk_label_new(temp_string);
00689         halign = gtk_alignment_new(0, 0, 0, 0);
00690         gtk_container_add(GTK_CONTAINER(halign), label);
00691         gtk_table_attach(GTK_TABLE(gridLayout), halign, 1, 2, 1, 2,
00692                 GTK_FILL, GTK_FILL, 0, 0);
00693         gtk_widget_show(label);
00694 
00695         label_empty = gtk_label_new("");
00696         gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 2, 3, 1, 2,
00697                 GTK_FILL | GTK_EXPAND, GTK_FILL, 1, 1);
00698         gtk_widget_show(label_empty);
00699 
00701         hseparator = gtk_hseparator_new();
00702         halign = gtk_alignment_new(0, 0, 0, 0);
00703         gtk_table_attach(GTK_TABLE(gridLayout), hseparator, 0, 3, 2, 3,
00704                 GTK_FILL | GTK_EXPAND, GTK_FILL, 1, 1);
00705         gtk_widget_show(hseparator);
00706 
00708         label_empty = gtk_label_new("");
00709         gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 0, 1, 3, 4,
00710                 GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 1, 1);
00711         gtk_widget_show(label_empty);
00712     if(time_flag == 0)
00713     {
00714         strcpy(temp_string, "\n\
00715 \n\
00716 You have completed the test\n\
00717 \n\
00718 Press OK button to see your Score\n\
00719 \n\
00720 Have a good time!!!");
00721     }
00722     else
00723     {
00724         strcpy(temp_string, "\n\
00725 \n\
00726 Time UP!!!\n\
00727 \n\
00728 Press OK button to see your Score\n\
00729 \n\
00730 Have a good time!!!");
00731     }
00732         label = gtk_label_new(temp_string);
00733         halign = gtk_alignment_new(0, 0, 0, 0);
00734         gtk_container_add(GTK_CONTAINER(halign), label);
00735         gtk_table_attach(GTK_TABLE(gridLayout), halign, 1, 2, 3, 4,
00736                 GTK_FILL, GTK_FILL | GTK_EXPAND, 1, 1);
00737         gtk_widget_show(label);
00738 
00739         label_empty = gtk_label_new("");
00740         gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 2, 3, 3, 4,
00741                 GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 1, 1);
00742         gtk_widget_show(label_empty);
00743 
00746         hseparator = gtk_hseparator_new();
00747         halign = gtk_alignment_new(0, 0, 0, 0);
00748         gtk_table_attach(GTK_TABLE(gridLayout), hseparator, 0, 3, 4, 5,
00749                 GTK_FILL | GTK_EXPAND, GTK_FILL, 1, 1);
00750         gtk_widget_show(hseparator);
00751 
00753         button = gtk_button_new_with_label("OK");
00754         gtk_widget_set_size_request(button, 70, 30);
00755         g_signal_connect_swapped(G_OBJECT(button), "clicked",
00756                 G_CALLBACK(show_questions),
00757                 G_OBJECT(notebook));
00758         halign = gtk_alignment_new(0, 0, 0, 0);
00759         gtk_container_add(GTK_CONTAINER(halign), button);
00760         gtk_table_attach(GTK_TABLE(gridLayout), halign, 0, 3, 5, 6,
00761                 GTK_SHRINK, GTK_SHRINK, 1, 1);
00762         gtk_widget_show(button);
00763 
00764 
00765 
00766         frame = gtk_frame_new("Test Completed");
00767         gtk_container_set_border_width(GTK_CONTAINER(frame), 10);
00768         gtk_widget_set_size_request(frame, 580, 580);
00769         gtk_widget_show(frame);
00770         gtk_container_add(GTK_CONTAINER(frame), gridLayout);
00771         gtk_widget_show_all(gridLayout);
00772 
00773         label = gtk_label_new("Test Completed");
00774         gtk_notebook_append_page(GTK_NOTEBOOK(notebook), frame, label);
00775         ;
00776 
00777         gtk_notebook_next_page(GTK_NOTEBOOK(notebook));
00778         current_question++;
00779     } else {
00781         gridLayout = gtk_table_new(5, 3, FALSE);
00782         gtk_table_set_col_spacings(GTK_TABLE(gridLayout), 10);
00783         gtk_table_set_row_spacings(GTK_TABLE(gridLayout), 10);
00784 
00786         label_empty = gtk_label_new("");
00787         gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 0, 3, 0, 1,
00788                 GTK_FILL | GTK_EXPAND, GTK_FILL, 1, 1);
00789         gtk_widget_show(label_empty);
00790 
00792         hseparator = gtk_hseparator_new();
00793         halign = gtk_alignment_new(0, 0, 0, 0);
00794         gtk_table_attach(GTK_TABLE(gridLayout), hseparator, 0, 3, 1, 2,
00795                 GTK_FILL | GTK_EXPAND, GTK_FILL, 1, 1);
00796         gtk_widget_show(hseparator);
00797 
00799         label_empty = gtk_label_new("");
00800         gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 0, 1, 2, 3,
00801                 GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 1, 1);
00802         gtk_widget_show(label_empty);
00803 
00804         sprintf(temp_string, "Your Score is \n\
00805 \n\
00806 %d\n\
00807 \n\
00808 Thanks for using Online Examination Portal\n\
00809 \n\
00810 Press Exit Button to exit\n\
00811 \n\
00812 Good Luck!!!", marks);
00813         label = gtk_label_new(temp_string);
00814         //gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
00815         halign = gtk_alignment_new(0, 0, 0, 0);
00816         gtk_container_add(GTK_CONTAINER(halign), label);
00817         gtk_table_attach(GTK_TABLE(gridLayout), halign, 1, 2, 2, 3,
00818                 GTK_FILL, GTK_FILL | GTK_EXPAND, 1, 1);
00819         gtk_widget_show(label);
00820 
00821         label_empty = gtk_label_new("");
00822         gtk_table_attach(GTK_TABLE(gridLayout), label_empty, 2, 3, 2, 3,
00823                 GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 1, 1);
00824         gtk_widget_show(label_empty);
00825 
00828         hseparator = gtk_hseparator_new();
00829         halign = gtk_alignment_new(0, 0, 0, 0);
00830         gtk_table_attach(GTK_TABLE(gridLayout), hseparator, 0, 3, 3, 4,
00831                 GTK_FILL | GTK_EXPAND, GTK_FILL, 1, 1);
00832         gtk_widget_show(hseparator);
00833 
00836         button = gtk_button_new_with_label("Finish");
00837         gtk_widget_set_size_request(button, 70, 30);
00838         g_signal_connect_swapped(G_OBJECT(button), "clicked",
00839                 G_CALLBACK(delete),
00840                 (gpointer) window);
00841         halign = gtk_alignment_new(0, 0, 0, 0);
00842         gtk_container_add(GTK_CONTAINER(halign), button);
00843         gtk_table_attach(GTK_TABLE(gridLayout), halign, 0, 3, 4, 5,
00844                 GTK_SHRINK, GTK_SHRINK, 1, 1);
00845         gtk_widget_show(button);
00846 
00847 
00848 
00849         frame = gtk_frame_new("Goodbye");
00850         gtk_container_set_border_width(GTK_CONTAINER(frame), 10);
00851         gtk_widget_set_size_request(frame, 580, 580);
00852         gtk_widget_show(frame);
00853         gtk_container_add(GTK_CONTAINER(frame), gridLayout);
00854         gtk_widget_show_all(gridLayout);
00855 
00856         label = gtk_label_new("Goodbye");
00857         gtk_notebook_append_page(GTK_NOTEBOOK(notebook), frame, label);
00858 
00859         gtk_notebook_next_page(GTK_NOTEBOOK(notebook));
00860     }
00861 
00862     return;
00863 
00864 }

int Socket ( int  domain,
int  type,
int  protocol 
)

Socket function reimplementation with error handling .

Parameters:
domain Domain value passed to the socket
type Type of socket.TCP/UDP
protocol protocol of the socket being created.

Definition at line 130 of file client.c.

Referenced by main().

00130                                                {
00131     int return_value;
00132     return_value = socket(domain, type, protocol);
00133     if (return_value < 0) {
00134         fprintf(stderr, "Cannot open socket.\n");
00135         perror("REASON");
00136         exit(1);
00137     }
00138     return return_value;
00139 }

void start_test (  ) 

this is the function that is used to create a different thread for time out and then call tha show_questions()

See also:
show_questions()

Definition at line 281 of file client.c.

References answer, show_questions(), time_flag, time_thread(), and tot_time.

Referenced by add_welcome_frame().

00281                   {
00282     pthread_t thread;
00283     
00284     pthread_create(&thread, NULL, (void *) & time_thread, (void *) & tot_time);
00285     time_flag=0;
00286     strcpy(answer, "A");
00287     show_questions();
00288 }

void time_thread ( void *  time_wait  ) 

This is a thread that sleeps for the time the test run or the allowed time for the user to answer the test.

Parameters:
time_wait Time allowed to take the test.
See also:
verify_user()

Definition at line 107 of file client.c.

References current_question, show_questions(), start, time_flag, tot_question, tot_time, and update_time_thread().

Referenced by start_test().

00107                                   {
00108     int temp=*((int*)time_wait);
00109     time (&start);
00110     pthread_t thread;
00111     pthread_create(&thread, NULL, (void *) & update_time_thread, (void *) & tot_time);
00112 
00113     sleep(temp * 60);
00114    
00115     //terminate test here :P
00116     time_flag=1;
00117     current_question=tot_question+1;
00118     show_questions();
00119     pthread_exit(0);
00120 }

void update_time_thread (  ) 

This is used to update the time left.

See also:
time_thread()

Definition at line 77 of file client.c.

References dif, label_timeleft, start, and tot_time.

Referenced by time_thread().

00077                           {
00078     char time_string[100];
00079     time_t current;
00080     int time_min;
00081     sleep(1);
00082     while (1) {
00083         time(&current);
00084         dif = difftime (current,start);
00085         time_min=tot_time-(int) dif/60;
00086         
00087         sprintf(time_string, "Time Left:%d Mins", time_min);
00088     if(time_min == 0)
00089     {      
00090           pthread_exit(0);
00091     }
00092     gtk_label_set_text((GtkLabel *) label_timeleft, (gchar *) time_string);
00093         //gtk_label_set_te
00094         gtk_widget_show(label_timeleft);
00095         sleep(1);
00096     }
00097 
00098 }

void verify_user (  ) 

Verify user first sends the username and password to the server and recieves the reply whether the username and passwords validates.It the authenticates the user and pass over to the next screen containing welcome user message and test instruction.

See also:
add_welcome_frame()

Definition at line 1012 of file client.c.

References ack, add_welcome_frame(), BUFFER, characters_read, connection_flag, current_question, entry1, entry2, input_data, login_status, notebook, password, Read(), socket_file_descriptor, time_left, tot_question, tot_time, username, window, and Write().

Referenced by add_login_frame(), and handle_client_thread().

01012                    {
01013     
01014     if (connection_flag == 1) {
01015         GtkWidget *dialog;
01016         dialog = gtk_message_dialog_new(GTK_WINDOW(window),
01017                 GTK_DIALOG_DESTROY_WITH_PARENT,
01018                 GTK_MESSAGE_ERROR,
01019                 GTK_BUTTONS_OK,
01020                 "Network Error:Connection to the \n server could notbe established\n");
01021         gtk_window_set_title(GTK_WINDOW(dialog), "ERROR");
01022         gtk_dialog_run(GTK_DIALOG(dialog));
01023         gtk_widget_destroy(dialog);
01024         return;
01025     }
01026 
01027     strcpy(username, gtk_entry_get_text(GTK_ENTRY(entry1)));
01028     strcpy(password, gtk_entry_get_text(GTK_ENTRY(entry2)));
01029     if (!strcmp(username, "") || !strcmp(password, "")) {
01030         GtkWidget *dialog;
01031         dialog = gtk_message_dialog_new(GTK_WINDOW(window),
01032                 GTK_DIALOG_DESTROY_WITH_PARENT,
01033                 GTK_MESSAGE_INFO,
01034                 GTK_BUTTONS_OK,
01035                 "\nEnter Username and Password\n");
01036         gtk_window_set_title(GTK_WINDOW(dialog), "ERROR");
01037         gtk_dialog_run(GTK_DIALOG(dialog));
01038         gtk_widget_destroy(dialog);
01039         return;
01040 
01041     }
01042 
01043 
01044     //username
01045     Write(socket_file_descriptor, username, strlen(username));
01046     //read ack ignore
01047     characters_read = Read(socket_file_descriptor, input_data, BUFFER - 1);
01048     input_data[characters_read] = '\0';
01049 
01050     //password
01051     Write(socket_file_descriptor, password, strlen(password));
01052     //read ack ignore
01053     characters_read = Read(socket_file_descriptor, input_data, BUFFER - 1);
01054     input_data[characters_read] = '\0';
01055 
01056     //write an ack to server
01057     Write(socket_file_descriptor, ack, strlen(ack));
01058 
01059     //read login status
01060     characters_read = Read(socket_file_descriptor, login_status, BUFFER - 1);
01061     login_status[characters_read] = '\0';
01062     //write an ack to server
01063     Write(socket_file_descriptor, ack, strlen(ack));
01064 
01065     if (!strcmp(login_status, "DBF")) {
01066         GtkWidget *dialog;
01067         dialog = gtk_message_dialog_new(GTK_WINDOW(window),
01068                 GTK_DIALOG_DESTROY_WITH_PARENT,
01069                 GTK_MESSAGE_ERROR,
01070                 GTK_BUTTONS_OK,
01071                 "\nError in Connection with Database\n");
01072         gtk_window_set_title(GTK_WINDOW(dialog), "ERROR");
01073         gtk_dialog_run(GTK_DIALOG(dialog));
01074         gtk_widget_destroy(dialog);
01075         return;
01076     }
01077     if (!strcmp(login_status, "UPNM")) {
01078         GtkWidget *dialog;
01079         dialog = gtk_message_dialog_new(GTK_WINDOW(window),
01080                 GTK_DIALOG_DESTROY_WITH_PARENT,
01081                 GTK_MESSAGE_INFO,
01082                 GTK_BUTTONS_OK,
01083                 "\nUsername or Password is incorrect\n");
01084         gtk_window_set_title(GTK_WINDOW(dialog), "ERROR");
01085         gtk_dialog_run(GTK_DIALOG(dialog));
01086         gtk_widget_destroy(dialog);
01087         return;
01088 
01089     }
01090 
01091 
01092     //read tot_question
01093     characters_read = Read(socket_file_descriptor, input_data, BUFFER - 1);
01094     input_data[characters_read] = '\0';
01095     tot_question = atoi(input_data);
01096     //write an ack to server
01097     Write(socket_file_descriptor, ack, strlen(ack));
01098 
01099     //read tot_question
01100     characters_read = Read(socket_file_descriptor, input_data, BUFFER - 1);
01101     input_data[characters_read] = '\0';
01102     tot_time = atoi(input_data);
01103     //place this at correct place
01104 
01105     time_left = tot_time;
01106     //write an ack to server
01107     Write(socket_file_descriptor, ack, strlen(ack));
01108 
01109     current_question = 1;
01110     add_welcome_frame();
01111     gtk_notebook_next_page(GTK_NOTEBOOK(notebook));
01112     return;
01113 }

ssize_t Write ( int  fd,
const void *  buf,
size_t  count 
)

write function reimplementation with error handling .

Parameters:
fd filedescriptor to read
buf Buffer it is read into
count no of bytes to read.

Definition at line 167 of file client.c.

Referenced by handle_client_thread(), show_questions(), and verify_user().

00167                                                      {
00168     ssize_t return_value;
00169     return_value = write(fd, buf, count);
00170     if (return_value < 0) {
00171         perror("Write failed\n");
00172         exit(1);
00173     }
00174     return return_value;
00175 }


Variable Documentation

char ack[10]

Definition at line 57 of file client.c.

Referenced by handle_client_thread(), main(), show_questions(), and verify_user().

char answer[BUFFER]

to store the anser given by the user

Definition at line 57 of file client.c.

Referenced by check_radio(), handle_client_thread(), show_questions(), and start_test().

used to store the characters read from the socket

Definition at line 42 of file client.c.

Referenced by handle_client_thread(), Read(), show_questions(), and verify_user().

Definition at line 57 of file client.c.

Referenced by main(), and verify_user().

used to store current question being answered.

Definition at line 51 of file client.c.

Referenced by handle_client_thread(), show_questions(), time_thread(), and verify_user().

data file descripter for image file

Definition at line 69 of file client.c.

Referenced by handle_client_thread(), and show_questions().

double dif

used to take the time difference

Definition at line 63 of file client.c.

Referenced by update_time_thread().

GtkWidget* entry1

Gtk related global parameters.

entry1 taking username from user.

Definition at line 32 of file client.c.

Referenced by add_login_frame(), and verify_user().

GtkWidget* entry2

Gtk related global parameters.

entry 2 for taking password from user.

Definition at line 34 of file client.c.

Referenced by add_login_frame(), and verify_user().

char input_data[BUFFER]

Definition at line 57 of file client.c.

Referenced by handle_client_thread(), show_questions(), and verify_user().

GtkWidget* label_timeleft

Gtk gloabal variable for updating time via a time update thread.

Definition at line 38 of file client.c.

Referenced by show_questions(), and update_time_thread().

char login_status[10]

Definition at line 57 of file client.c.

Referenced by handle_client_thread(), and verify_user().

int marks

used to store marks obtained by user

Definition at line 55 of file client.c.

Referenced by handle_client_thread(), and show_questions().

GtkWidget* notebook

Gtk related global parameters.

Gtknotebook instance

Definition at line 36 of file client.c.

Referenced by add_login_frame(), add_welcome_frame(), main(), show_questions(), and verify_user().

char password[BUFFER]

used to store the password

Definition at line 47 of file client.c.

Referenced by handle_client_thread(), and verify_user().

Socket gloabal variable socket file descriptor.

Definition at line 40 of file client.c.

Referenced by main(), show_questions(), and verify_user().

time_t start

Records the start time of the exam.

Definition at line 61 of file client.c.

Referenced by time_thread(), and update_time_thread().

char time_flag

Definition at line 57 of file client.c.

Referenced by show_questions(), start_test(), and time_thread().

int time_left

updates time left to the label in time update thread.

Definition at line 66 of file client.c.

Referenced by verify_user().

used to store total no of Questions

Definition at line 49 of file client.c.

Referenced by show_questions(), time_thread(), and verify_user().

int tot_time

used to store total time

Definition at line 53 of file client.c.

Referenced by start_test(), time_thread(), update_time_thread(), and verify_user().

char username[BUFFER]

used to store the username

Definition at line 45 of file client.c.

Referenced by add_welcome_frame(), handle_client_thread(), show_questions(), and verify_user().

GtkWidget* window

Gtk Window.

Definition at line 30 of file client.c.

Referenced by main(), show_questions(), and verify_user().

 All Files Functions Variables Defines

Generated on 18 Apr 2010 for Doxygentestproject by  doxygen 1.6.1