Tuesday, July 28, 2009

Project help.?

I want to write a program on Client-server program using OLTP i.e., Online transaction processing. Using Decentralized solution, But the answer is in windows C, but I want it in Unix C,Can You please help by making changes in this program. Since I am not getting the output.





/*


%26lt;"OLTP" a client-server simulation%26gt;


File Name:client_oltp.c


Discription:Compile %26amp; Run as CLIENT PROCESS.


*/





#include "oltp.h" /*This file contains all the header files needed for both Client and Server*/





/*Function prototypes*/


int chan_req(int,int);


OLTP_MSG_BUFF send_msg(int,int,OLTP_MSG_BUFF);


void print_mdf(void);


void print_error(int);


void print_oltp(void);


int valid_choice(char);


int getint(void);





/*Globle variables*/


int MAX_Y,MAX_X;


time_t LOCAL_TIME;


char TIME_STRING[30];





main()


{


int semd,msgd,i,j,acc_ph,acc_no,amount,pid,a...


chtype key,user_choice;


time_t local_time;


char time_string[30];


OLTP_MSG_BUFF master_req,req_msg,reply_msg;


initscr();


getmaxyx(stdscr,MAX_Y,MAX_X);


keypad(stdscr,TRUE);


raw();


echo();


attron(A_REVERSE);


printw("\n WELCOME TO OLTP--A CLIENT SERVER SIMULATION BY %26lt;mdshreenath@yahoo.com%26gt; \n\n");


sleep(1);


refresh();


attroff(A_REVERSE);


semd=semget(OLTP_SEMID,1,0);


if(semd %26lt;0)


{


printw("\n\t\t\tFailed semget().........Restart the Server ! !\n");


refresh();


getch();


endwin();


exit(1);


}


msgd=msgget(OLTP_MSGID,0);


if(msgd %26lt; 0)


{


printw("\n\t\t\tFailed msgget().........Restart the Server ! !\n");


semctl(semd,0,IPC_RMID,0);


refresh();


getch();


endwin();


exit(2);


}


req_msg.mtype=chan_req(msgd,semd);


time(%26amp;LOCAL_TIME);


ctime_r(%26amp;LOCAL_TIME,TIME_STRING);


TIME_STRING[24]='\0';


printw("\n\t\t\tStarted ON:");


refresh();


attron(A_DIM);


printw("%s\n\n",TIME_STRING);


refresh();


attroff(A_DIM);


printw("\n\t\t\tPRESS [ENTER] to continue...........");


refresh();


getch();


print_oltp();refresh();


req_msg.pid=pid=getpid();


while(1)


{


printw("\n\tPRESS\n");


printw("\t\t\tc:Create A New Account\n");


printw("\t\t\te:Edit Existing Account\n");


printw("\t\t\tv:View Account Information\n");


printw("\t\t\td:Deposite To Existing Account\n");


printw("\t\t\tw:Withdraw From Existing Account\n");


printw("\t\t\tx:Transactions OVER...Want to eXit ! !\n");


printw("\t\t\ta:Adminstration\n");


printw("\n\tCHOICE");


refresh();


attron(A_BLINK);


printw(":");


attroff(A_BLINK);


refresh();


noecho();


user_choice=getch();


if(user_choice == 27) user_choice='x';


else if(!valid_choice(user_choice))


{


attron(A_BLINK);


addch(user_choice);


attroff(A_BLINK);


refresh();


attron(A_DIM);


printw("--INVALID CHOICE");


refresh();


beep();


sleep(1);


attroff(A_DIM);


print_oltp();


continue;


}


echo();


IP_AGAIN: print_oltp();


refresh();


switch(user_choice)


{


case 'c':


attron(A_DIM);printw("\n\t\t\tYou Are about to CREAT new Account\n");


refresh();


attroff(A_DIM);


printw("\n\t\t\tAccount Payee Phone Number:");


refresh();


acc_ph=getint();


if(acc_ph%26lt;=0)


{


print_oltp();


continue;/*goto infinite while again*/


}


printw("\n\t\t\tCONFIRM.. [Y/N] :");


refresh();


key=getch();


if(key == 'n' || key == 27) goto IP_AGAIN;


req_msg.acc_no=0;


req_msg.req_type=1;


req_msg.req_rep_info=acc_ph;


reply_msg=send_msg(msgd,1,req_msg)...


if(reply_msg.req_rep_info %26lt; 0)


{


print_error(reply_msg.req_rep_inf...


getch();


print_oltp();


continue;


}


attron(A_REVERSE);


printw("\n New Account Created !! #Acc_no:%d Having #Acc_ph:%d ",reply_msg.req_rep_info,acc_ph);


refresh();


attroff(A_REVERSE);


attron(A_DIM | A_BLINK);


printw("\n\npress [ENTER]");


refresh();


attroff(A_DIM | A_BLINK);


getch();


break;


case 'e':


attron(A_DIM);


printw("\n\t\t\tYou are about to EDIT an account\n");


refresh();


attroff(A_DIM);


printw("\n\t\t\tAccount Number:");


refresh();


acc_no=getint();


if(acc_no%26lt;=0)


{


print_oltp();


continue;/*goto infinite while again*/


}


printw("\n\t\t\tNew Tel_No:");


acc_ph=getint();


if(acc_ph%26lt;=0)


{


print_oltp();


continue;/*goto infinite while again*/


}


printw("\n\t\t\tCINFIRM... [Y/N]:",acc_no,acc_ph);


refresh();


key=getch();


if(key == 'n') goto IP_AGAIN;


req_msg.acc_no=acc_no;


req_msg.req_type=2;


req_msg.req_rep_info=acc_ph;


reply_msg=send_msg(msgd,2,req_msg)...


if(reply_msg.req_rep_info %26lt; 0)


{


print_error(reply_msg.req_rep_inf...


getch();


print_oltp();


continue;


}


attron(A_REVERSE);


printw("\n Account Edited !! #Acc_no:%d #New Acc_ph:%d ",acc_no,reply_msg.req_rep_info);


refresh();


attroff(A_REVERSE);


attron(A_DIM | A_BLINK);


printw("\n\npress [ENTER]");


refresh();


attroff(A_DIM | A_BLINK);


getch();


break;





case 'v':


attron(A_DIM);


printw("\n\t\t\tYou are about to VIEW an acount information\n");


attroff(A_DIM);


printw("\n\t\t\tAccount Number:");


refresh();


acc_no=getint();


if(acc_no%26lt;=0)


{


print_oltp();


continue;/*goto infinite while again*/


}


printw("\n\t\t\tCONFIRM...[Y/N]:",...


refresh();


key=getch();


if(key == 'n' || key == 27) goto IP_AGAIN;


req_msg.acc_no=acc_no;


req_msg.req_type=3;


req_msg.req_rep_info=acc_no;


reply_msg=send_msg(msgd,3,req_msg)...


if(reply_msg.req_rep_info %26lt; 0)


{


print_error(reply_msg.req_rep_inf...


getch();


print_oltp();


continue;


}


attron(A_DIM);


printw("\n\t\t\t------------------...


printw("\n\t\t\tAccount No:%d",acc_no);


printw("\n\t\t\tTelephone No:%d",reply_msg.acc_no);


printw("\n\t\t\tCurrent Balence:%d",reply_msg.req_rep_info);


printw("\n\t\t\t------------------...


attron(A_BLINK);printw("\n\n\t\t\t... [ENTER]");


refresh();


attroff(A_DIM | A_BLINK);


getch();


break;








case 'd':


attron(A_DIM);


printw("\n\t\t\tYou are about to DEPOSITE\n");


attroff(A_DIM);


refresh();


printw("\n\t\t\tAccount Number:");


refresh();


acc_no=getint();


if(acc_no%26lt;=0)


{


print_oltp();


continue;/*goto infinite while again*/


}


printw("\n\t\t\tDebit:");


refresh();


amount=getint();


if(amount%26lt;=0)


{


print_oltp();


continue;/*goto infinite while again*/


}


printw("\n\t\t\tCONFIRM... [Y/N]:",amount,acc_no);


refresh();


key=getch();


if(key == 'n' || key == 27) goto IP_AGAIN;


req_msg.acc_no=acc_no;


req_msg.req_type=4;


req_msg.req_rep_info=amount;


reply_msg=send_msg(msgd,4,req_msg)...


if(reply_msg.req_rep_info %26lt; 0)


{


print_error(reply_msg.req_rep_inf...


getch();


print_oltp();


continue;


}


attron(A_REVERSE);


printw("\n Debited!! #Acc_no:%d Now Has #Ballence:%d ",acc_no,reply_msg.req_rep_info);


refresh();


attroff(A_REVERSE);


attron(A_DIM | A_BLINK);


printw("\n\npress [ENTER]");


refresh();


attroff(A_BLINK | A_DIM);


getch();


break;


case 'w':


attron(A_DIM);


printw("\n\t\t\tYou are about to WITHDRAW\n");


refresh();


attroff(A_DIM);


printw("\n\t\t\tAccount Number:");


refresh();


acc_no=getint();


if(acc_no%26lt;=0)


{


print_oltp();


continue;/*goto infinite while again*/


}


printw("\n\t\t\tWithdraw:");


refresh();


amount=getint();


if(amount%26lt;=0)


{


print_oltp();


continue;/*goto infinite while again*/


}


printw("\n\t\t\tCONFIRM...[Y/N]:",...


refresh();


key=getch();


if(key == 'n' || key == 27) goto IP_AGAIN;


req_msg.acc_no=acc_no;


req_msg.req_type=5;


req_msg.req_rep_info=amount;


reply_msg=send_msg(msgd,5,req_msg)...


if(reply_msg.req_rep_info %26lt; 0)


{


print_error(reply_msg.req_rep_inf...


getch();


print_oltp();


continue;


}


attron(A_REVERSE);


printw(" Withdrawn !! #Acc_no:%d Now Has #Balence:%d ",acc_no,reply_msg.req_rep_info);


refresh();


attroff(A_REVERSE);


attron(A_DIM | A_BLINK);


printw("\n\npress [ENTER]");


refresh();


attroff(A_DIM | A_BLINK);


getch();


break;


case 'x':


attron(A_DIM);


printw("\n\t\t\tYOU ARE ABOUT TO EXIT\n\n");


refresh();


attroff(A_DIM);


printw("\n\t\t\tCONFIRM EXIT[Y/N]:");


refresh();


key=getch();


if(key == 'Y' || key == 'y')


{


req_msg.req_type=6;


req_msg.req_rep_info=req_msg.mtyp...


reply_msg=send_msg(msgd,6,req_msg...


if(reply_msg.req_rep_info == BYE)


{


printw("\n\t\t\tLogged OUT ON:");


refresh();


time(%26amp;local_time);


ctime_r(%26amp;local_time,time_string)...


attron(A_DIM);printw("%s\n",time...


refresh();


attroff(A_DIM);


}


else


{


printw("\n\t\t\tAbnormal EXIT ! !");


refresh();


}


sleep(1);


attron(A_BOLD);


printw("\n\t\t\tDO YOU WANT GENERATE ALL ACCOUNTS INFORMATION [Y/N]:");


refresh();


key=getch();


attroff(A_BOLD);


if(key == 'y') print_mdf();


attron(A_DIM);


printw("\nThanks FOR TRYING OLTP ! !");


printw("\nANY BUGS TO %26lt;");refresh();


attroff(A_DIM);


attron(A_BLINK);


printw("mdshreenath@yahoo.com");


refresh();


attroff(A_BLINK);


attron(A_DIM);


printw("%26gt;");


refresh();


attroff(A_DIM);


getch();


endwin();


exit(0);


}


print_oltp();


continue;





case 'a':


attron(A_BOLD);


printw("\n\t\t\t[YOU ARE ABOUT TO SHUTDOWN THE SERVER...]\n\n");


printw("\n\t\t\tWANT TO CONTINUE [Y/N]:");


attroff(A_BOLD);


refresh();


key=getch();


if(key != 'y')


{


print_oltp();


continue;


}


printw("\n\t\t\tADMIN KEY:");


refresh();


noecho();


refresh();


scanw("%d",%26amp;admin_key);


echo();


req_msg.req_type=7;


req_msg.req_rep_info=admin_key;


reply_msg=send_msg(msgd,7,req_msg)...


if(reply_msg.req_rep_info %26lt; 0)


{


print_error(reply_msg.req_rep_inf...


getch();


print_oltp();


continue;


}


clear();


print_oltp();





attron(A_BOLD);


printw("\n\t\t\tAS ADMINSTRATOR.....ON: ");


refresh();


attroff(A_BOLD);


time(%26amp;local_time);


ctime_r(%26amp;local_time,time_string);


attron(A_DIM);


printw("%s\n",time_string);refresh...


attroff(A_DIM);


sleep(1);


printw("\n\t\t\tDO YOU WANT GENERATE ALL ACCOUNTS INFORMATION..[Y/N]:");


refresh();


attroff(A_BOLD);


key=getch();


if(key == 'y') print_mdf();


attron(A_DIM);


printw("\nThanks FOR TRYING OLTP ! !");


printw("\nANY BUGS TO %26lt;");refresh();


attroff(A_DIM);


attron(A_BLINK);


printw("mdshreenath@yahoo.com");


refresh();


attroff(A_BLINK);


attron(A_DIM);


printw("%26gt;");


refresh();


attroff(A_DIM);


getch();


endwin();


exit(0);


default:


printw("\n\t\t\t");


attron(A_BOLD | A_BLINK | A_REVERSE);


printw("Wrong Choise");


refresh();


attroff(A_BOLD | A_BLINK | A_REVERSE);


getch();


print_oltp();


continue;





}/*End of Switch*/


print_oltp();


}/*infinite loop end*/


endwin();


}





/*This function is to send message to server through a channel number got using chan_req() function


This function returns reply message*/


OLTP_MSG_BUFF send_msg(int msgd,int msg_type,OLTP_MSG_BUFF req_msg)


{


int pid,nof_try=0;


char key;


OLTP_MSG_BUFF reply_msg;


printw("\n\t\t\tComunicating with the server...\n");


refresh();


while(msgsnd(msgd,(struct msgbuf*)(%26amp;req_msg),MSG_LEN,IPC_NOWAIT) %26lt; 0)


{


sleep(1);


nof_try++;


if(nof_try %26lt; 3) continue;


printw("\n\t\t\tServer NOT responding...TRY AGAIN [Y/N]:");


refresh();


key=getch();


if(key == 'N' || key == 'n')


{


printw("\n\t\t\tRestart the server.....\n");


refresh();


getch();


endwin();


exit(3);


}


}


pid=getpid();


nof_try=0;


while(msgrcv(msgd,(struct msgbuf*)(%26amp;reply_msg),MSG_LEN,pid,IPC_NOW... %26lt; 0)


{


sleep(1);


nof_try++;


if(nof_try %26lt; 3) continue;


printw("\n\t\t\tServer NOT responding...TRY AGAIN [Y/N]:");


refresh();


key=getch();


if(key == 'N' || key == 'n')


{


printw("\n\t\t\tRestart the server.....\n");


refresh();


getch();


endwin();


exit(4);


}


}


sleep(2);


printw("\n\t\t\t.....[DONE]\n");


refresh();


return(reply_msg);





}





/*This function is to requst the server process through MASTER CHANNEL for a uniq channel for


the future communication*/


int chan_req(int msgd,int semd)


{


int ret,key,nof_try=0;


OLTP_MSG_BUFF req_msg,reply_msg;


struct sembuf sops;


int pid;


pid=getpid();


req_msg.mtype=MASTER_CHAN;


req_msg.pid=getpid();


req_msg.acc_no=0;


req_msg.req_type=0;


req_msg.req_rep_info=getpid();


printw("\n\t\t\tRequesting Chanel for Communication...\n");


refresh();


sops.sem_num=0;


sops.sem_op=-1;


sops.sem_flg=0;


if(semop(semd,%26amp;sops,1) %26lt; 0)


{


printw("\n\t\t\tsemop failed ! !");


refresh();


getch();


endwin();


exit(1);


}


while(msgsnd(msgd,(struct msgbuf*)(%26amp;req_msg),MSG_LEN,IPC_NOWAIT) %26lt; 0)


{


sleep(1);


nof_try++;


if(nof_try %26lt; 3) continue;


printw("\n\t\t\tServer NOT responding...TRY AGAIN [Y/N]:");


refresh();


key=getch();


if(key == 'N' || key == 'n')


{


printw("\n\t\t\tRestart the server.....\n");


refresh();


sops.sem_op=1;


semop(semd,%26amp;sops,1);


getch();


endwin();


exit(2);


}


}


nof_try=0;


while(ret=msgrcv(msgd,(struct msgbuf*)(%26amp;reply_msg),MSG_LEN,pid,IPC_NOW... %26lt; 0)


{


sleep(1);


nof_try++;


if(nof_try %26lt; 3) continue;


printw("\n\t\t\tServer NOT responding...TRY AGAIN [Y/N]:");


refresh();


key=getch();


if(key == 'N' || key == 'n')


{


printw("\n\t\t\tRestart the server.....\n");


refresh();


sops.sem_op=1;


semop(semd,%26amp;sops,1);


getch();


endwin();


exit(2);


}


}


sops.sem_op=1;


semop(semd,%26amp;sops,1);


printw("\n\t\t\t.....GOT Chanel %d\n",reply_msg.req_rep_info);


refresh();


return(reply_msg.req_rep_info);


}





/*This function is to print the Master Data Base file in READABLE format*/


void print_mdf(void)


{


int off,mdf_d,i=1;


time_t local_time;


char time_ch[30];


FILE *acc_fd;


SB_ACC sb_acc;


mdf_d=open("./MDF.dbase",O_RDONLY);


acc_fd=fopen("./Accounts.txt","w");


if(acc_fd == NULL)


{


printw("\n\t\t\tERROR opening ./Accounts.txt\n");


return;


}


off=sizeof(struct SB_ACC);


lseek(mdf_d,0,0);


clear();


print_oltp();


time(%26amp;local_time);


ctime_r(%26amp;local_time,time_ch);


fprintf(acc_fd,"#### THESE ARE THE ACCOUNT informations...as on: %s",time_ch);


while(read(mdf_d,(char*)(%26amp;sb_acc),off... == off)


{


fprintf(acc_fd,"\n------------------...


fprintf(acc_fd,"\nAcc_no:%d\tPhone_n...


}


fprintf(acc_fd,"\n-------------------...


fprintf(acc_fd,"\n\n%26lt; FILE GENERATED BY OLTP CLIENT PROCESS WITH PID:%d %26gt;\n",getpid());


fprintf(acc_fd,"\n%26lt; Contact Shreenath Deshpande %26lt;mdshreenath@yahoo.com %26gt;\n");


printw("\n\t\t\tWRITTEN ./Accounts.txt\n");


return;


}





/*This function is to flag error*/


void print_error(int err)


{


printw("\n\t\t\t");


attron(A_BLINK | A_REVERSE);


switch(err)


{


case -55:


printw(" Balence UNDERFLOW......You can't WITHDRAW ! ! ");


break;





case -7:


printw(" AUTHENTIFICATION FAILED ! ! ");


break;





case -3:


printw(" OPEN ACCOUNT ERROR ! ! ");


break;





default:


printw(" OPEN ACCOUNT ERROR ! ! ");


break;


}


attroff(A_BLINK | A_REVERSE);


printw("\n\n\t\t\tpress[ENTER]");refr...


return;





}





/*This function is to just print welcome message*/


void print_oltp(void)


{


int cur_y,cur_x;


char started_time[30];





clear();


attron(A_DIM);


printw("-----------------------------...


attron(A_BOLD | A_REVERSE);


printw(" YOU ARE RUNNING OLTP--A CLIENT SERVER SIMULATION BY %26lt;mdshreenath@yahoo.com%26gt; \n");


attroff(A_BOLD | A_REVERSE);


printw("-----------------------------...


refresh();


getyx(stdscr,cur_y,cur_x);


move(MAX_Y-3,0);


printw("-----------------------------...


attron(A_BOLD | A_REVERSE);


printw(" PID:%d OLTP-CLIENT %s ",getpid(),TIME_STRING);


attroff(A_BOLD | A_REVERSE);


refresh();


printw("\n---------------------------...


refresh();


attroff(A_BOLD | A_DIM | A_REVERSE);


move(cur_y,cur_x);


return;


}





/*This function is to check for valid choice*/


int valid_choice(char c)


{


if( c=='c' || c=='e' || c=='v' || c=='d' || c=='w' || c=='x' || c=='a') return(1);


else return(0);


}





/*This function is to get an integer from charecters*/


int getint(void)


{


char string[10];


chtype c;


int i=-1,val,x,y,pos;


//attron(A_BOLD);


noecho();





while(1)


{


c=getch();


if(c == 10) break;


if(c == 27) return(-1);


if(isdigit(c) %26gt; 0)


{


echo();


printw("%c",c);


refresh();


i++;


string[i]=c;


noecho();


continue;


}


beep();


}


string[i+1]='\0';


val=atoi(string);


return(val);


}


/*Physical End*/

Project help.?
Why did you post twice?

survey software

No comments:

Post a Comment