1 /** \addtogroup GRAS_API
3 \section GRAS_funct Offered functionnalities
4 - <b>Communication facilities</b>: Exchanging messages between peers
5 - \ref GRAS_dd: any data which may transit on the network must be
6 described beforehand so that GRAS can handle the platform
7 heterogeneity and convert them if needed.
8 - \ref GRAS_sock: this is how to open a communication channel to
9 other processes, and retrive information about them.
10 - \ref GRAS_msg: communications are message oriented. You have to
11 describe all possible messages and their payload beforehand, and
12 can then attach callbacks to the arrival of a given kind of message.
13 - <b>Virtualization</b>: Running both on top of the simulator and on
14 top of real platforms, and portability support.
15 - \ref GRAS_globals: The use of globals is forbidden since the
16 "processes" are threads in simulation mode. \n
17 This is how to let GRAS handle your globals properly.
18 - \ref GRAS_main_generation: Since processes are threads in
19 simulation mode and regular processes in the real world, GRAS does
20 generate your main functions for you.
21 - \ref GRAS_cond: How to declare specific code for the simulation mode
23 - \ref GRAS_virtu: You naturally don't want to call the
24 gettimeofday(2) function in simulation mode since it would give
25 you the time on the host running the simulation, not the time in
26 the simulated world (you are belonging to).\n
27 This a system call virtualization layer, which also acts as a
30 \section GRAS_example Examples
32 There is for now rather few examples of GRAS, but it's better than
38 /** \defgroup GRAS_dd Data description */
39 /** \defgroup GRAS_sock Sockets */
40 /** \defgroup GRAS_msg Messages */
42 /** \defgroup GRAS_globals Globals */
43 /** \defgroup GRAS_cond Conditional execution */
44 /** \defgroup GRAS_virtu Syscalls */
48 /** \page GRAS_main_generation main() and GRAS
50 <center>[\ref GRAS_API]</center>
52 \section GRAS_maingen_intro What's the matter with main() functions in GRAS?
54 In simulation mode, all processes are run as thread of the same process
55 while they are real processes in the real life. Unfortunately, the main
56 function of a real process must be called <tt>main</tt> while this
57 function must not use this name for threads.
59 To deal with this, you should call the main function of your processes
60 with another name (usually, the process function such as client, server,
61 or such). Then GRAS can generate the wrapper functions adapted to the
62 real and simulated modes.
64 \section GRAS_maingen_script Generating the main()s manually with
66 This is done by the gras_stub_generator program, which gets installed on
67 <tt>make install</tt> (the source resides in the tools/gras/ directory).
68 Here is the calling syntax:
69 \verbatim gras_stub_generator <project_name> <deployment_file.xml>\endverbatim
71 It parses the deployment file, searching for all the kind of processes
72 you have in your project. It then generates the following C files:
73 - a <tt>_<project_name>_<process_kind>.c</tt> file for each process kind you
75 They are used to launch your project in real life. They
76 contain a main() in charge of initializing the GRAS infrastructure and
77 launching your code afterward.
78 - a <tt>_<project_name>_simulator.c</tt> file.\n
79 This file is suited to the simulation mode. It contains a main()
80 function initializing the simulator and launching your project within.
82 For this to work, the name of process described in your deployment file
83 should match the name of a function in your code, which prototype is for
84 example: \verbatim int client(int argc,char *argv[]);\endverbatim
86 Unfortunately, all this is still partially documented. I guess I ought
87 to improve this situation somehow. In the meanwhile, check the generated
88 code and maybe also the GRAS \ref GRAS_example, sorry.
90 \section GRAS_maingen_make Integration within your Makefile
92 The easiest to set it up is to add the following chunk at the end of
93 your Makefile (or Makefile.am), putting the right values into NAME and
95 \verbatim NAME=your_project_name
96 PROCESSES=list of processes type in your project
98 $(foreach proc, $(PROCESSES), _$(NAME)_$(proc).c) _$(NAME)_simulator.c: $(NAME).c $(NAME)_deployment.xml
99 path/to/gras_stub_generator $(NAME) $(NAME)_deployment.xml >/dev/null
102 Of course, your personal millage may vary. For the \ref GRAS_ex_ping, may read:
103 \verbatim _ping_client.c _ping_server.c _ping_simulator.c: ping.c ping_deployment.xml
104 $(top_srcdir)/tools/gras/gras_stub_generator ping ping_deployment.xml >/dev/null
109 /** \page GRAS_ex_ping The classical Ping-Pong in GRAS
111 <center>[\ref GRAS_API]</center>
113 This example implements the very classical ping-pong in GRAS. It
114 involves a client (initiating the ping-pong) and a server (answering to
117 It works the following way:
118 - Both the client and the server register all needed messages
119 - The server registers a callback to the ping message, which sends pong
121 - The client sends the ping message to the server, and waits for the
122 pong message as an answer.
124 This example resides in the <b>examples/gras/ping/ping.c</b> file. Yes, both
125 the code of the client and of the server is placed in the same file. See
126 the \ref GRAS_main_generation section if wondering.
128 \section GRAS_ex_ping_over Overview
129 - \ref GRAS_ex_ping_common
130 - \ref GRAS_ex_ping_initial
131 - \ref GRAS_ex_ping_register
132 - \ref GRAS_ex_ping_server
133 - \ref GRAS_ex_ping_serdata
134 - \ref GRAS_ex_ping_sercb
135 - \ref GRAS_ex_ping_sermain
136 - \ref GRAS_ex_ping_client
137 - \ref GRAS_ex_ping_climain
141 \dontinclude gras/ping/ping.c
143 \section GRAS_ex_ping_common 1) Common code to the client and the server
145 \subsection GRAS_ex_ping_initial 1.a) Initial settings
147 Let's first load the gras header and declare a logging category (see
148 \ref XBT_log for more info on logging).
153 \subsection GRAS_ex_ping_register 1.b) Register the messages
155 This function, called by both the client and the server is in charge of
156 declaring the existing messages to GRAS. Since the payload does not
157 involve any newly created types but only int, this is quite easy.
158 (to exchange more complicated types, see \ref GRAS_dd)
160 \skip register_messages
163 \section GRAS_ex_ping_server 2) Server's code
165 \subsection GRAS_ex_ping_serdata 2.a) The server's globals
167 In order to ensure the communication between the "main" and the callback
168 of the server, we need to declare some globals. We have to put them in a
169 struct definition so that they can be handled properly in GRAS (see the
170 \ref GRAS_globals for more info).
175 \subsection GRAS_ex_ping_sercb 2.b) The callback to the ping message
177 Here is the callback run when the server receives any ping message (this
178 will be registered later by the server).
180 \skip server_cb_ping_handler
181 \until end_of_server_cb_ping_handler
183 \subsection GRAS_ex_ping_sermain 2.c) The "main" of the server
185 This is the "main" of the server. As explained in the \ref
186 GRAS_main_generation, you don't have to (and shouldn't) write any main()
187 function yourself. Instead, you just have to write a regular function
188 like this one which will act as a main.
193 \section GRAS_ex_ping_client 3) Client's code
195 \subsection GRAS_ex_ping_climain 3.a) Client's "main" function