boinc_api.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. // This file is part of BOINC.
  2. // http://boinc.berkeley.edu
  3. // Copyright (C) 2008 University of California
  4. //
  5. // BOINC is free software; you can redistribute it and/or modify it
  6. // under the terms of the GNU Lesser General Public License
  7. // as published by the Free Software Foundation,
  8. // either version 3 of the License, or (at your option) any later version.
  9. //
  10. // BOINC is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. // See the GNU Lesser General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Lesser General Public License
  16. // along with BOINC. If not, see <http://www.gnu.org/licenses/>.
  17. #ifndef BOINC_BOINC_API_H
  18. #define BOINC_BOINC_API_H
  19. #include <stddef.h> // for NULL
  20. #ifdef _WIN32
  21. #include "boinc_win.h"
  22. #endif
  23. #include "app_ipc.h"
  24. // ANSI C API BEGINS HERE
  25. // Do not put implementation stuff here
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. // parameters passed to the BOINC runtime system
  30. //
  31. typedef struct BOINC_OPTIONS {
  32. // the following are booleans, implemented as ints for portability
  33. int normal_thread_priority;
  34. // run worker thread at normal thread priority on Win.
  35. // (default is idle priority)
  36. int main_program;
  37. // this is the main program, so
  38. // - lock a lock file in the slot directory
  39. // - write finish file on successful boinc_finish()
  40. int check_heartbeat;
  41. // check for timeout of heartbeats from the client;
  42. // action is determined by direct_process_action (see below)
  43. int handle_process_control;
  44. // whether runtime system should read suspend/resume/quit/abort
  45. // msgs from client.
  46. // action is determined by direct_process_action (see below)
  47. int send_status_msgs;
  48. // whether runtime system should send CPU time / fraction done msgs
  49. int direct_process_action;
  50. // if heartbeat fail, or get process control msg, take
  51. // direction action (exit, suspend, resume).
  52. // Otherwise just set flag in BOINC status
  53. // This is true for regular apps, false for wrappers
  54. int multi_thread;
  55. // set this if application creates threads in main process
  56. int multi_process;
  57. // set this if application creates subprocesses.
  58. } BOINC_OPTIONS;
  59. typedef struct BOINC_STATUS {
  60. int no_heartbeat;
  61. int suspended;
  62. int quit_request;
  63. int reread_init_data_file;
  64. int abort_request;
  65. double working_set_size;
  66. double max_working_set_size;
  67. int network_suspended;
  68. } BOINC_STATUS;
  69. extern volatile BOINC_STATUS boinc_status;
  70. typedef void (*FUNC_PTR)(void);
  71. struct APP_INIT_DATA;
  72. extern int boinc_init(void);
  73. extern int boinc_finish(int status);
  74. extern int boinc_get_init_data_p(struct APP_INIT_DATA*);
  75. extern int boinc_parse_init_data_file(void);
  76. extern int boinc_send_trickle_up(char* variety, char* text);
  77. extern int boinc_set_min_checkpoint_period(int);
  78. extern int boinc_checkpoint_completed(void);
  79. extern int boinc_fraction_done(double);
  80. extern int boinc_suspend_other_activities(void);
  81. extern int boinc_resume_other_activities(void);
  82. extern int boinc_report_app_status(
  83. double cpu_time, double checkpoint_cpu_time, double _fraction_done
  84. );
  85. extern int boinc_time_to_checkpoint(void);
  86. extern void boinc_begin_critical_section(void);
  87. extern void boinc_end_critical_section(void);
  88. extern void boinc_need_network(void);
  89. extern int boinc_network_poll(void);
  90. extern void boinc_network_done(void);
  91. extern void boinc_network_usage(double sent, double received);
  92. extern int boinc_is_standalone(void);
  93. extern void boinc_ops_per_cpu_sec(double fp, double integer);
  94. extern void boinc_ops_cumulative(double fp, double integer);
  95. extern void boinc_set_credit_claim(double credit);
  96. extern int boinc_receive_trickle_down(char* buf, int len);
  97. extern int boinc_init_options(BOINC_OPTIONS*);
  98. extern int boinc_get_status(BOINC_STATUS*);
  99. extern double boinc_get_fraction_done(void);
  100. extern void boinc_register_timer_callback(FUNC_PTR);
  101. extern double boinc_worker_thread_cpu_time(void);
  102. extern int boinc_init_parallel(void);
  103. extern void boinc_web_graphics_url(char*);
  104. extern void boinc_remote_desktop_addr(char*);
  105. #ifdef __APPLE__
  106. extern int setMacPList(void);
  107. extern int setMacIcon(char *filename, char *iconData, long iconSize);
  108. #endif
  109. #ifdef __cplusplus
  110. } // extern "C" {
  111. #endif
  112. // C++ API follows
  113. #ifdef __cplusplus
  114. #include <string>
  115. extern int boinc_get_init_data(APP_INIT_DATA&);
  116. extern int boinc_wu_cpu_time(double&);
  117. extern double boinc_elapsed_time(void);
  118. extern int boinc_upload_file(std::string& name);
  119. extern int boinc_upload_status(std::string& name);
  120. extern char* boinc_msg_prefix(char*, int);
  121. extern int boinc_report_app_status_aux(
  122. double cpu_time, double checkpoint_cpu_time, double _fraction_done,
  123. int other_pid, double bytes_sent, double bytes_received
  124. );
  125. extern int boinc_temporary_exit(
  126. int delay, const char* reason=NULL, bool is_notice=false
  127. );
  128. extern int boinc_finish_message(
  129. int status, const char* message, bool is_notice
  130. );
  131. /////////// API ENDS HERE
  132. /////////// IMPLEMENTATION STUFF BEGINS HERE
  133. extern void options_defaults(BOINC_OPTIONS&);
  134. extern APP_CLIENT_SHM *app_client_shm;
  135. #ifdef _WIN32
  136. extern HANDLE worker_thread_handle;
  137. #endif
  138. extern int boinc_init_options_general(BOINC_OPTIONS& opt);
  139. extern int start_timer_thread(void);
  140. extern bool boinc_disable_timer_thread;
  141. inline void boinc_options_defaults(BOINC_OPTIONS& b) {
  142. b.main_program = 1;
  143. b.check_heartbeat = 1;
  144. b.handle_process_control = 1;
  145. b.send_status_msgs = 1;
  146. b.direct_process_action = 1;
  147. b.normal_thread_priority = 0;
  148. b.multi_thread = 0;
  149. b.multi_process = 0;
  150. }
  151. /////////// IMPLEMENTATION STUFF ENDS HERE
  152. #endif // C++ part
  153. #endif // double-inclusion protection