RCFC |
Remote C Function Call |
by Pierre Mavrikios | rcfc@petros.it | 2010-09-01 |
Chat example
Project directory tree. |
< < < < < < < < |
Higher level top_chat/rcfc_app.c |
Lower level top_chat/term/rcfc_app.c |
Gets the user nick name from the command line argument. if ( argc != 2 ) { printf ( "Error: User nick name is missing\n" ); exit (-1); } nick = argv [1]; |
|
Initializes rcfc and grants the offered services (functions declared in "term/rcfc_functions.def") // init rcfc grant functions if ( !rcfc_grant_functions ( port, app_ide ) ) exit ( -1 ); |
Initializes rcfc and offers the services to the "granter"(functions declared in "term/rcfc_functions.def") // init rcfc offer functions if ( !rcfc_offer_functions ( host, port, app_ide ) ) exit ( -1 ); |
Wait until rcfc is ready. while ( !rcfc_is_offer_ready () ); |
|
Main
application loop while rcfc is alive ( kill it with CTRL C). The
main loop does nothing. It just keeps the program running. while ( rcfc_is_grant_running () ) { sleep ( 1 ); } |
Main application loop while rcfc is alive ( kill it with CTRL C) while ( rcfc_is_offer_running () ) { |
Wait a message string from the terminal input. if ( fgets ( line, LINE_LEN, stdin ) != NULL ) |
|
Call the higher level remote function "rf_say" passing the nick name of the user and the inputed message string. if ( !rf_say ( nick, line ) ) printf ( "Not responding\n" ); |
|
The "rf_say" function is executed, calling all lower level nodes function "rf_show" and returning the returned value. int rf_say ( char *from, char *msg ) { int ret; ret = rf_show ( from, msg ); return ret; } |
|
The
"rf_say" function is executed printing the formated string of the user's
nick name and the sent message to the terminal, and returning "true"
value. int rf_show ( char *from, char *msg ) { printf ( "%s->%s", from, msg ); return true; } |
"top_chat" directory. |
"top_chat/term" directory. |
gcc -Iinclude -o apu rcfc_app.c -Lrcfc -lrcfc_libs.x86_64 -lpthread |
gcc -I../include -o apb rcfc_app.c -Lrcfc -lrcfc_libs.x86_64 -lpthread |