| 1 | = Trickle message API = |
| 2 | |
| 3 | The interface for [http://boinc.berkeley.edu/trickle.php trickle messages] includes both client-side and server-side components. |
| 4 | |
| 5 | == Client-side API == |
| 6 | |
| 7 | To send a trickle-up message, call |
| 8 | |
| 9 | {{{ |
| 10 | int boinc_send_trickle_up(char* variety, char* text) |
| 11 | }}} |
| 12 | |
| 13 | To receive a trickle-down message, call |
| 14 | |
| 15 | {{{ |
| 16 | int boinc_receive_trickle_down(char* buf, int len) |
| 17 | }}} |
| 18 | |
| 19 | This returns true (nonzero) if there was a message. |
| 20 | |
| 21 | == Server-side API == |
| 22 | |
| 23 | To handle trickle-up messages, use a 'trickle_handler' daemon. This is a program, based on sched/trickle_handler.C, linked with a function |
| 24 | |
| 25 | {{{ |
| 26 | int handle_trickle(MSG_FROM_HOST&); |
| 27 | |
| 28 | struct MSG_FROM_HOST { |
| 29 | int create_time; |
| 30 | int hostid; |
| 31 | char variety[256]; // project-defined; what kind of msg |
| 32 | char xml[MSG_FROM_HOST_BLOB_SIZE]; |
| 33 | }; |
| 34 | }}} |
| 35 | |
| 36 | This function should return zero if the message was handled successfully; otherwise it will be retried later. The 'hostid' field identifies the host from which the message was sent. The daemon must be passed a '-variety X' command-line argument, telling it what kind of messages to handle. The daemon should be specified in the [http://boinc.berkeley.edu/project_daemons.php project configuration file]. |
| 37 | |
| 38 | To send send trickle-down messages (from a trickle handler daemon or other program) you must insert a record in the 'msg_to_host' table. From C/C++, this is done as follows: |
| 39 | |
| 40 | {{{ |
| 41 | DB_MSG_TO_HOST mth; |
| 42 | |
| 43 | mth.clear(); |
| 44 | mth.create_time = time(0); |
| 45 | mth.hostid = hostid; |
| 46 | sprintf(mth.xml, |
| 47 | "<trickle_down>\n" |
| 48 | " <result_name>%s</result_name>\n" |
| 49 | " ...\n" |
| 50 | "</trickle_down>\n", |
| 51 | ... |
| 52 | ); |
| 53 | retval = mth.insert(); |
| 54 | }}} |
| 55 | |
| 56 | To send trickle-down messages, a project must include the line |
| 57 | |
| 58 | {{{ |
| 59 | <msg_to_host/> |
| 60 | }}} |
| 61 | |
| 62 | in the [http://boinc.berkeley.edu/configuration.php configuration] (config.xml) file. |