File: action.rs

package info (click to toggle)
firefox 147.0.4-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,683,532 kB
  • sloc: cpp: 7,607,356; javascript: 6,533,348; ansic: 3,775,236; python: 1,415,508; xml: 634,561; asm: 438,949; java: 186,241; sh: 62,760; makefile: 18,079; objc: 13,092; perl: 12,808; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (117 lines) | stat: -rw-r--r-- 3,935 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

//! `Action` is an enum describing what BITS action is being processed. This is
//! used mostly for logging and error reporting reasons.
//! The values of `Action` describe actions that could be in progress for
//! BitsService or BitsRequest. When specifying a type, `ServiceAction` or
//! `RequestAction`, can be used to restrict the action type to one of the two
//! categories.
//! A value of type `ServiceAction` or `RequestAction` can easily be converted
//! to an `Action` using the `into()` method.

use xpcom::interfaces::nsIBits;

#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum Action {
    StartDownload,
    MonitorDownload,
    Complete,
    Cancel,
    SetMonitorInterval,
    SetPriority,
    SetNoProgressTimeout,
    Resume,
    Suspend,
}

impl Action {
    pub fn description(&self) -> &'static str {
        match self {
            Action::StartDownload => "starting download",
            Action::MonitorDownload => "monitoring download",
            Action::Complete => "completing download",
            Action::Cancel => "cancelling download",
            Action::SetMonitorInterval => "changing monitor interval",
            Action::SetPriority => "setting download priority",
            Action::SetNoProgressTimeout => "setting no progress timeout",
            Action::Resume => "resuming download",
            Action::Suspend => "suspending download",
        }
    }

    pub fn as_error_code(&self) -> i32 {
        match self {
            Action::StartDownload => nsIBits::ERROR_ACTION_START_DOWNLOAD,
            Action::MonitorDownload => nsIBits::ERROR_ACTION_MONITOR_DOWNLOAD,
            Action::Complete => nsIBits::ERROR_ACTION_COMPLETE,
            Action::Cancel => nsIBits::ERROR_ACTION_CANCEL,
            Action::SetMonitorInterval => nsIBits::ERROR_ACTION_CHANGE_MONITOR_INTERVAL,
            Action::SetPriority => nsIBits::ERROR_ACTION_SET_PRIORITY,
            Action::SetNoProgressTimeout => nsIBits::ERROR_ACTION_SET_NO_PROGRESS_TIMEOUT,
            Action::Resume => nsIBits::ERROR_ACTION_RESUME,
            Action::Suspend => nsIBits::ERROR_ACTION_SUSPEND,
        }
    }
}

#[derive(Debug, PartialEq, Clone, Copy)]
pub enum ServiceAction {
    StartDownload,
    MonitorDownload,
}

impl From<ServiceAction> for Action {
    fn from(action: ServiceAction) -> Action {
        match action {
            ServiceAction::StartDownload => Action::StartDownload,
            ServiceAction::MonitorDownload => Action::MonitorDownload,
        }
    }
}

impl ServiceAction {
    pub fn as_error_code(&self) -> i32 {
        Action::as_error_code(&(self.clone()).into())
    }

    pub fn description(&self) -> &'static str {
        Action::description(&(self.clone()).into())
    }
}

#[derive(Debug, PartialEq, Clone, Copy)]
pub enum RequestAction {
    Complete,
    Cancel,
    SetMonitorInterval,
    SetPriority,
    SetNoProgressTimeout,
    Resume,
    Suspend,
}

impl From<RequestAction> for Action {
    fn from(action: RequestAction) -> Action {
        match action {
            RequestAction::Complete => Action::Complete,
            RequestAction::Cancel => Action::Cancel,
            RequestAction::SetMonitorInterval => Action::SetMonitorInterval,
            RequestAction::SetPriority => Action::SetPriority,
            RequestAction::SetNoProgressTimeout => Action::SetNoProgressTimeout,
            RequestAction::Resume => Action::Resume,
            RequestAction::Suspend => Action::Suspend,
        }
    }
}

impl RequestAction {
    pub fn as_error_code(&self) -> i32 {
        Action::as_error_code(&(self.clone()).into())
    }

    pub fn description(&self) -> &'static str {
        Action::description(&(self.clone()).into())
    }
}