~ubuntu-branches/ubuntu/precise/boinc/precise

« back to all changes in this revision

Viewing changes to lib/gui_rpc_client.h

Tags: 6.12.8+dfsg-1
* New upstream release.
* Simplified debian/rules

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
// a C++ interface to BOINC GUI RPC
19
19
 
20
20
#if !defined(_WIN32) || defined (__CYGWIN__)
21
 
#include <stdio.h>
 
21
#include <cstdio>
22
22
#include <string>
23
23
#include <vector>
24
24
#include <sys/socket.h>
33
33
#include "prefs.h"
34
34
#include "hostinfo.h"
35
35
#include "common_defs.h"
 
36
#include "notice.h"
 
37
#include "network.h"
36
38
 
37
39
struct GUI_URL {
38
40
    std::string name;
63
65
    std::string general_area;
64
66
    std::string specific_area;
65
67
    std::string description;
66
 
    std::string home;
67
 
    std::string image;
68
 
    double rand;
 
68
    std::string home;       // sponsoring organization
 
69
    std::string image;      // URL of logo
 
70
    std::vector<std::string> platforms;
 
71
        // platforms supported by project, or empty
69
72
 
70
73
    PROJECT_LIST_ENTRY();
71
74
    ~PROJECT_LIST_ENTRY();
72
75
 
73
76
    int parse(XML_PARSER&);
74
77
    void clear();
75
 
 
76
 
    bool operator<(const PROJECT_LIST_ENTRY& compare);
 
78
};
 
79
 
 
80
class AM_LIST_ENTRY {
 
81
public:
 
82
    std::string name;
 
83
    std::string url;
 
84
    std::string description;
 
85
    std::string image;
 
86
 
 
87
    AM_LIST_ENTRY();
 
88
    ~AM_LIST_ENTRY();
 
89
 
 
90
    int parse(XML_PARSER&);
 
91
    void clear();
 
92
};
 
93
 
 
94
class ALL_PROJECTS_LIST {
 
95
public:
 
96
    std::vector<PROJECT_LIST_ENTRY*> projects;
 
97
    std::vector<AM_LIST_ENTRY*> account_managers;
 
98
 
 
99
    ALL_PROJECTS_LIST();
 
100
    ~ALL_PROJECTS_LIST();
 
101
 
 
102
    void clear();
 
103
    void shuffle();
77
104
};
78
105
 
79
106
class PROJECT {
80
107
public:
81
 
    std::string master_url;
 
108
    char master_url[256];
82
109
    double resource_share;
83
110
    std::string project_name;
84
111
    std::string user_name;
85
112
    std::string team_name;
 
113
    int hostid;
86
114
    std::vector<GUI_URL> gui_urls;
87
115
    double user_total_credit;
88
116
    double user_expavg_credit;
93
121
                                // contact all scheduling servers
94
122
    int master_fetch_failures;
95
123
    double min_rpc_time;           // earliest time to contact any server
96
 
    double short_term_debt;
97
 
    double long_term_debt;
 
124
    double download_backoff;
 
125
    double upload_backoff;
 
126
 
 
127
    double cpu_short_term_debt;
 
128
    double cpu_long_term_debt;
 
129
    double cpu_backoff_time;
 
130
    double cpu_backoff_interval;
 
131
    double cuda_debt;
 
132
    double cuda_short_term_debt;
 
133
    double cuda_backoff_time;
 
134
    double cuda_backoff_interval;
 
135
    double ati_debt;
 
136
    double ati_short_term_debt;
 
137
    double ati_backoff_time;
 
138
    double ati_backoff_interval;
98
139
    double duration_correction_factor;
99
140
 
 
141
    bool anonymous_platform;
100
142
    bool master_url_fetch_pending; // need to fetch and parse the master URL
101
143
    int sched_rpc_pending;      // need to contact scheduling server
102
 
    int rr_sim_deadlines_missed;
 
144
        // encodes the reason for the request
103
145
    bool non_cpu_intensive;
104
146
    bool suspended_via_gui;
105
147
    bool dont_request_more_work;
107
149
    bool attached_via_acct_mgr;
108
150
    bool detach_when_done;
109
151
    bool ended;
 
152
    bool trickle_up_pending;
110
153
    double project_files_downloaded_time;
111
154
        // when the last project file download was finished
112
155
        // (i.e. the time when ALL project files were finished downloading)
113
156
    double last_rpc_time;
114
157
        // when the last successful scheduler RPC finished
115
158
    std::vector<DAILY_STATS> statistics; // credit data over the last x days
 
159
    bool no_cpu_pref;
 
160
    bool no_cuda_pref;
 
161
    bool no_ati_pref;
116
162
 
117
163
    // NOTE: if you add any data items above,
118
 
    // update parse(), copy() and clear() to include them!!
 
164
    // update parse(), and clear() to include them!!
119
165
 
120
166
    PROJECT();
121
167
    ~PROJECT();
122
168
 
123
169
    int parse(MIOFILE&);
124
170
    void print();
 
171
    void print_disk_usage();
125
172
    void clear();
126
173
    void get_name(std::string&);
127
 
    void copy(PROJECT&);        // copy to this object
128
174
 
129
175
    // temp - keep track of whether or not this record needs to be deleted
130
176
    bool flag_for_delete;
132
178
 
133
179
class APP {
134
180
public:
135
 
    std::string name;
136
 
    std::string user_friendly_name;
 
181
    char name[256];
 
182
    char user_friendly_name[256];
137
183
    PROJECT* project;
138
184
 
139
185
    APP();
146
192
 
147
193
class APP_VERSION {
148
194
public:
149
 
    std::string app_name;
 
195
    char app_name[256];
150
196
    int version_num;
151
 
    std::string plan_class;
 
197
    char platform[64];
 
198
    char plan_class[64];
 
199
    double avg_ncpus;
 
200
    double ncudas;
 
201
    double natis;
 
202
    double gpu_ram;
 
203
    double flops;
152
204
    APP* app;
153
205
    PROJECT* project;
154
206
 
156
208
    ~APP_VERSION();
157
209
 
158
210
    int parse(MIOFILE&);
 
211
    int parse_coproc(MIOFILE&);
159
212
    void print();
160
213
    void clear();
161
214
};
162
215
 
163
216
class WORKUNIT {
164
217
public:
165
 
    std::string name;
166
 
    std::string app_name;
167
 
    int version_num;
 
218
    char name[256];
 
219
    char app_name[256];
 
220
    int version_num;    // backwards compat
168
221
    double rsc_fpops_est;
169
222
    double rsc_fpops_bound;
170
223
    double rsc_memory_bound;
171
224
    double rsc_disk_bound;
172
225
    PROJECT* project;
173
226
    APP* app;
174
 
    APP_VERSION* avp;
175
227
 
176
228
    WORKUNIT();
177
229
    ~WORKUNIT();
183
235
 
184
236
class RESULT {
185
237
public:
186
 
    std::string name;
187
 
    std::string wu_name;
188
 
    std::string project_url;
189
 
    int report_deadline;
 
238
    char name[256];
 
239
    char wu_name[256];
 
240
    char project_url[256];
 
241
    int version_num;
 
242
    char plan_class[64];
 
243
    double report_deadline;
 
244
    double received_time;
190
245
    bool ready_to_report;
191
246
    bool got_server_ack;
192
247
    double final_cpu_time;
 
248
    double final_elapsed_time;
193
249
    int state;
194
250
    int scheduler_state;
195
251
    int exit_status;
196
252
    int signal;
197
 
    std::string stderr_out;
 
253
    //std::string stderr_out;
198
254
    bool suspended_via_gui;
199
255
    bool project_suspended_via_gui;
 
256
    bool coproc_missing;
 
257
    bool gpu_mem_wait;
200
258
 
201
259
    // the following defined if active
202
260
    bool active_task;
203
261
    int active_task_state;
204
262
    int app_version_num;
 
263
    int slot;
 
264
    int pid;
205
265
    double checkpoint_cpu_time;
206
266
    double current_cpu_time;
207
267
    double fraction_done;
 
268
    double elapsed_time;
208
269
    double swap_size;
209
270
    double working_set_size_smoothed;
210
271
    double estimated_cpu_time_remaining;
 
272
        // actually, estimated elapsed time remaining
211
273
    bool supports_graphics;
212
274
    int graphics_mode_acked;
213
275
    bool too_large;
214
276
    bool needs_shmem;
215
277
    bool edf_scheduled;
216
 
    std::string graphics_exec_path;
217
 
    std::string slot_path;
218
 
    std::string resources;
 
278
    char graphics_exec_path[512];
 
279
    char slot_path[512];
 
280
        // only present if graphics_exec_path is
 
281
    char resources[256];
219
282
 
220
283
    APP* app;
221
284
    WORKUNIT* wup;
222
285
    PROJECT* project;
 
286
    APP_VERSION* avp;
223
287
 
224
288
    RESULT();
225
289
    ~RESULT();
250
314
    double file_offset;
251
315
    double xfer_speed;
252
316
    std::string hostname;
 
317
    double project_backoff;
253
318
    PROJECT* project;
254
319
 
255
320
    FILE_TRANSFER();
307
372
    std::vector<APP_VERSION*> app_versions;
308
373
    std::vector<WORKUNIT*> wus;
309
374
    std::vector<RESULT*> results;
310
 
 
 
375
    std::vector<std::string> platforms;
 
376
        // platforms supported by client
311
377
    GLOBAL_PREFS global_prefs;  // working prefs, i.e. network + override
312
378
    VERSION_INFO version_info;  // populated only if talking to pre-5.6 CC
313
379
    bool executing_as_daemon;   // true if Client is running as a service / daemon
 
380
    bool have_cuda;
 
381
    bool have_ati;
 
382
    HOST_INFO host_info;
314
383
 
315
384
    CC_STATE();
316
385
    ~CC_STATE();
317
386
 
318
 
    PROJECT* lookup_project(std::string&);
319
 
    APP* lookup_app(std::string&, std::string&);
320
 
    APP* lookup_app(PROJECT*, std::string&);
321
 
    APP_VERSION* lookup_app_version(std::string&, std::string&, int);
322
 
    APP_VERSION* lookup_app_version(PROJECT*, std::string&, int);
323
 
    WORKUNIT* lookup_wu(std::string&, std::string&);
324
 
    WORKUNIT* lookup_wu(PROJECT*, std::string&);
325
 
    RESULT* lookup_result(std::string&, std::string&);
326
 
    RESULT* lookup_result(PROJECT*, std::string&);
 
387
    PROJECT* lookup_project(char* url);
 
388
    APP* lookup_app(PROJECT*, char* name);
 
389
    APP_VERSION* lookup_app_version(PROJECT*, APP*, int, char* plan_class);
 
390
    APP_VERSION* lookup_app_version_old(PROJECT*, APP*, int);
 
391
    WORKUNIT* lookup_wu(PROJECT*, char* name);
 
392
    RESULT* lookup_result(PROJECT*, char* name);
 
393
    RESULT* lookup_result(char* url, char* name);
327
394
 
328
395
    void print();
329
396
    void clear();
330
 
};
331
 
 
332
 
class ALL_PROJECTS_LIST {
333
 
public:
334
 
    std::vector<PROJECT_LIST_ENTRY*> projects;
335
 
 
336
 
    ALL_PROJECTS_LIST();
337
 
    ~ALL_PROJECTS_LIST();
338
 
 
339
 
    void clear();
340
 
    void shuffle();
 
397
    int parse(MIOFILE&);
341
398
};
342
399
 
343
400
class PROJECTS {
398
455
    void clear();
399
456
};
400
457
 
 
458
class NOTICES {
 
459
public:
 
460
    bool complete;
 
461
        // whether vector contains all notices, or just new ones
 
462
    std::vector<NOTICE*> notices;
 
463
 
 
464
    NOTICES();
 
465
    ~NOTICES();
 
466
 
 
467
    void print();
 
468
    void clear();
 
469
};
 
470
 
401
471
struct DISPLAY_INFO {
402
472
    char window_station[256];   // windows
403
473
    char desktop[256];          // windows
411
481
    std::string acct_mgr_name;
412
482
    std::string acct_mgr_url;
413
483
    bool have_credentials;
 
484
    bool cookie_required;
 
485
    std::string cookie_failure_url;
414
486
    
415
487
    ACCT_MGR_INFO();
416
488
    ~ACCT_MGR_INFO(){}
444
516
struct PROJECT_INIT_STATUS {
445
517
    std::string url;
446
518
    std::string name;
 
519
    std::string team_name;
447
520
    bool has_account_key;
448
521
 
449
522
    PROJECT_INIT_STATUS();
456
529
struct PROJECT_CONFIG {
457
530
    int error_num;
458
531
    std::string name;
 
532
    std::string master_url;
 
533
    int local_revision;     // SVN changeset# of server software
459
534
    int min_passwd_length;
460
535
    bool account_manager;
461
 
    bool uses_username;
 
536
    bool uses_username;     // true for WCG
462
537
    bool account_creation_disabled;
463
 
    bool client_account_creation_disabled;
 
538
    bool client_account_creation_disabled;  // must create account on web
 
539
    bool sched_stopped;         // scheduler disabled
 
540
    bool web_stopped;           // DB-driven web functions disabled
 
541
    int min_client_version;
464
542
        std::string error_msg;
465
543
    std::string terms_of_use;
466
544
        // if present, show this text in an "accept terms of use?" dialog
467
545
        // before allowing attachment to continue.
 
546
    std::vector<std::string> platforms;
 
547
        // platforms supported by project, or empty
468
548
 
469
549
    PROJECT_CONFIG();
470
550
    ~PROJECT_CONFIG();
477
557
struct ACCOUNT_IN {
478
558
    std::string url;
479
559
    std::string email_addr;
480
 
        // this is the account identifier (email address or user name)
 
560
        // the account identifier (email address or user name)
481
561
    std::string user_name;
482
562
    std::string passwd;
 
563
    std::string team_name;
483
564
 
484
565
    ACCOUNT_IN();
485
566
    ~ACCOUNT_IN();
505
586
    bool ams_password_error;
506
587
    bool manager_must_quit;
507
588
    int task_suspend_reason;    // bitmap, see common_defs.h
 
589
    int task_mode;              // always/auto/never; see common_defs.h
 
590
    int task_mode_perm;                 // same, but permanent version
 
591
        double task_mode_delay;         // time until perm becomes actual
 
592
    int gpu_suspend_reason;
 
593
    int gpu_mode;
 
594
    int gpu_mode_perm;
 
595
        double gpu_mode_delay;
508
596
    int network_suspend_reason;
509
 
    int task_mode;              // always/auto/never; see common_defs.h
510
597
    int network_mode;
511
 
    int task_mode_perm;                 // same, but permanent version
512
598
    int network_mode_perm;
513
 
        double task_mode_delay;         // time until perm becomes actual
514
599
        double network_mode_delay;
515
600
    bool disallow_attach;
516
601
    bool simple_gui_only;
535
620
    double start_time;
536
621
    double timeout;
537
622
    bool retry;
538
 
    sockaddr_in addr;
 
623
    sockaddr_storage addr;
539
624
 
540
625
    int send_request(const char*);
541
626
    int get_reply(char*&);
542
627
    RPC_CLIENT();
543
628
    ~RPC_CLIENT();
 
629
    int get_ip_addr(const char* host, int port);
544
630
    int init(const char* host, int port=0);
545
631
    int init_asynch(
546
632
        const char* host, double timeout, bool retry, int port=GUI_RPC_PORT
559
645
    int authorize(const char* passwd);
560
646
    int exchange_versions(VERSION_INFO&);
561
647
    int get_state(CC_STATE&);
562
 
    int get_results(RESULTS&);
 
648
    int get_results(RESULTS&, bool active_only = false);
563
649
    int get_file_transfers(FILE_TRANSFERS&);
564
650
    int get_simple_gui_info(SIMPLE_GUI_INFO&);
565
 
    int get_simple_gui_info(CC_STATE&, RESULTS&);
566
 
    int get_project_status(CC_STATE&);
567
651
    int get_project_status(PROJECTS&);
568
652
    int get_all_projects_list(ALL_PROJECTS_LIST&);
569
653
    int get_disk_usage(DISK_USAGE&);
576
660
        // if duration is zero, change is permanent.
577
661
        // otherwise, after duration expires,
578
662
        // restore last permanent mode
 
663
    int set_gpu_mode(int mode, double duration);
579
664
    int set_network_mode(int mode, double duration);
580
665
    int get_screensaver_tasks(int& suspend_reason, RESULTS&);
581
666
    int run_benchmarks();
582
667
    int set_proxy_settings(GR_PROXY_INFO&);
583
668
    int get_proxy_settings(GR_PROXY_INFO&);
584
 
    int get_messages(int seqno, MESSAGES&);
 
669
    int get_messages(int seqno, MESSAGES&, bool translatable=false);
 
670
    int get_message_count(int& seqno);
 
671
    int get_notices(int seqno, NOTICES&);
 
672
    int get_notices_public(int seqno, NOTICES&);
585
673
    int file_transfer_op(FILE_TRANSFER&, const char*);
586
674
    int result_op(RESULT&, const char*);
587
675
    int get_host_info(HOST_INFO&);
614
702
    );
615
703
    int acct_mgr_rpc_poll(ACCT_MGR_RPC_REPLY&);
616
704
 
617
 
    int get_newer_version(std::string&);
 
705
    int get_newer_version(std::string&, std::string&);
618
706
    int read_global_prefs_override();
619
707
    int read_cc_config();
620
708
    int get_cc_status(CC_STATUS&);
639
727
    int parse_reply();
640
728
};
641
729
 
642
 
struct SET_LOCALE {
 
730
// We recommend using the XCode project under OS 10.5 to compile 
 
731
// the BOINC library, but some projects still use config & make, 
 
732
// so the following compatibility code avoids compiler errors when 
 
733
// building libboinc.a using config & make on system OS 10.3.9 or 
 
734
// with the OS 10.3.9 SDK (but using config & make is not recommended.)
 
735
//
 
736
#if defined(__APPLE__) && (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_4) && (!defined(BUILDING_MANAGER))
 
737
#define NO_PER_THREAD_LOCALE 1
 
738
#endif
 
739
 
 
740
// uselocal() API should be available on UNIX, Fedora & Ubuntu.
 
741
// For any platforms which do not support setting locale on a 
 
742
// per-thread basis, add code here similar to the following sample:
 
743
//#if defined(__UNIVAC__)
 
744
//#define NO_PER_THREAD_LOCALE 1
 
745
//#endif
 
746
#if defined(__HAIKU__)
 
747
#define NO_PER_THREAD_LOCALE 1
 
748
#endif
 
749
 
 
750
 
 
751
#ifdef NO_PER_THREAD_LOCALE  
 
752
    // Use this code for any platforms which do not support 
 
753
    // setting locale on a per-thread basis (see comment above)
 
754
 struct SET_LOCALE {
643
755
    std::string locale;
644
756
    inline SET_LOCALE() {
645
757
        locale = setlocale(LC_ALL, NULL);
649
761
        setlocale(LC_ALL, locale.c_str());
650
762
    }
651
763
};
 
764
 
 
765
#elif defined(__APPLE__) && (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_4)
 
766
// uselocale() is not available in OS 10.3.9 so use weak linking
 
767
#include <xlocale.h>
 
768
extern int              freelocale(locale_t) __attribute__((weak_import));
 
769
extern locale_t newlocale(int, __const char *, locale_t) __attribute__((weak_import));
 
770
extern locale_t uselocale(locale_t) __attribute__((weak_import));
 
771
 
 
772
 struct SET_LOCALE {
 
773
    locale_t old_locale, RPC_locale;
 
774
    std::string locale;
 
775
    inline SET_LOCALE() {
 
776
        if (uselocale == NULL) {
 
777
            locale = setlocale(LC_ALL, NULL);
 
778
            setlocale(LC_ALL, "C");
 
779
        }
 
780
    }
 
781
    inline ~SET_LOCALE() {
 
782
        if (uselocale == NULL) {
 
783
            setlocale(LC_ALL, locale.c_str());
 
784
        }
 
785
    }
 
786
};
 
787
 
 
788
#else
 
789
 
 
790
struct SET_LOCALE {
 
791
    // Don't need to juggle locales if we have per-thread locale
 
792
    inline SET_LOCALE() {
 
793
    }
 
794
    inline ~SET_LOCALE() {
 
795
    }
 
796
};
 
797
#endif
 
798
 
 
799
extern int read_gui_rpc_password(char*);