master
go 107 lines 2.6 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 package boinc
4
5 import (
6 "encoding/xml"
7 )
8
9 // https://boinc.berkeley.edu/trac/wiki/GuiRpcProtocol
10
11 type boincRequest struct {
12 XMLName xml.Name `xml:"boinc_gui_rpc_request"`
13 Auth1 *struct{} `xml:"auth1"`
14 Auth2 *boincRequestAuthNonce `xml:"auth2"`
15 GetResults *boincRequestGetResults `xml:"get_results"`
16 }
17
18 type (
19 boincRequestAuthNonce struct {
20 Hash string `xml:"nonce_hash"`
21 }
22 boincRequestGetResults struct {
23 ActiveOnly int `xml:"active_only"`
24 }
25 )
26
27 type boincReply struct {
28 XMLName xml.Name `xml:"boinc_gui_rpc_reply"`
29 Error *string `xml:"error"`
30 BadRequest *struct{} `xml:"bad_request"`
31 Authorized *struct{} `xml:"authorized"`
32 Unauthorized *struct{} `xml:"unauthorized"`
33 Nonce *string `xml:"nonce"`
34 Results []boincReplyResult `xml:"results>result"`
35 }
36
37 type (
38 boincReplyResult struct {
39 State int `xml:"state"`
40 ActiveTask *boincReplyResultActiveTask `xml:"active_task"`
41 }
42 boincReplyResultActiveTask struct {
43 ActiveTaskState int `xml:"active_task_state"`
44 SchedulerState int `xml:"scheduler_state"`
45 }
46 )
47
48 func (r *boincReplyResult) state() string {
49 if v, ok := resultStateMap[r.State]; ok {
50 return v
51 }
52 return "unknown"
53 }
54
55 func (r *boincReplyResult) activeTaskState() string {
56 if r.ActiveTask == nil {
57 return "no_active_task"
58 }
59 if v, ok := activeTaskStateMap[r.ActiveTask.ActiveTaskState]; ok {
60 return v
61 }
62 return "unknown"
63 }
64
65 func (r *boincReplyResult) schedulerState() string {
66 if r.ActiveTask == nil {
67 return "no_scheduler"
68 }
69 if v, ok := schedulerStateMap[r.ActiveTask.SchedulerState]; ok {
70 return v
71 }
72 return "unknown"
73 }
74
75 var resultStateMap = map[int]string{
76 // https://github.com/BOINC/boinc/blob/a3b79635d87423c972125efa318e4e880ad698dd/html/inc/common_defs.inc#L75
77 0: "new",
78 1: "files_downloading",
79 2: "files_downloaded",
80 3: "compute_error",
81 4: "files_uploading",
82 5: "files_uploaded",
83 6: "aborted",
84 7: "upload_failed",
85 }
86
87 var activeTaskStateMap = map[int]string{
88 // https://github.com/BOINC/boinc/blob/a3b79635d87423c972125efa318e4e880ad698dd/lib/common_defs.h#L227
89 0: "uninitialized",
90 1: "executing",
91 //2: "exited",
92 //3: "was_signaled",
93 //4: "exit_unknown",
94 5: "abort_pending",
95 //6: "aborted",
96 //7: "couldnt_start",
97 8: "quit_pending",
98 9: "suspended",
99 10: "copy_pending",
100 }
101
102 var schedulerStateMap = map[int]string{
103 // https://github.com/BOINC/boinc/blob/a3b79635d87423c972125efa318e4e880ad698dd/lib/common_defs.h#L56
104 0: "uninitialized",
105 1: "preempted",
106 2: "scheduled",
107 }