• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2023 Huawei Device Co., Ltd.
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 //     http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 
14 #[derive(Clone, Copy, PartialEq, Debug)]
15 #[repr(u8)]
16 pub(crate) enum Reason {
17     Default = 0,
18     TaskSurvivalOneMonth,
19     WaitingNetworkOneDay,
20     StoppedByNewFrontTask,
21     RunningTaskMeetLimits,
22     UserOperation,
23     AppBackgroundOrTerminate,
24     NetworkOffline,
25     UnsupportedNetworkType,
26     BuildClientFailed,
27     BuildRequestFailed,
28     GetFileSizeFailed,
29     ContinuousTaskTimeout,
30     ConnectError,
31     RequestError,
32     UploadFileError,
33     RedirectError,
34     ProtocolError,
35     IoError,
36     UnsupportedRangeRequest,
37     OthersError,
38     NetworkChanged,
39 }
40 
41 impl From<u8> for Reason {
from(value: u8) -> Self42     fn from(value: u8) -> Self {
43         match value {
44             0 => Reason::Default,
45             1 => Reason::TaskSurvivalOneMonth,
46             2 => Reason::WaitingNetworkOneDay,
47             3 => Reason::StoppedByNewFrontTask,
48             4 => Reason::RunningTaskMeetLimits,
49             5 => Reason::UserOperation,
50             6 => Reason::AppBackgroundOrTerminate,
51             7 => Reason::NetworkOffline,
52             8 => Reason::UnsupportedNetworkType,
53             9 => Reason::BuildClientFailed,
54             10 => Reason::BuildRequestFailed,
55             11 => Reason::GetFileSizeFailed,
56             12 => Reason::ContinuousTaskTimeout,
57             13 => Reason::ConnectError,
58             14 => Reason::RequestError,
59             15 => Reason::UploadFileError,
60             16 => Reason::RedirectError,
61             17 => Reason::ProtocolError,
62             18 => Reason::IoError,
63             19 => Reason::UnsupportedRangeRequest,
64             21 => Reason::NetworkChanged,
65             _ => Reason::OthersError,
66         }
67     }
68 }
69 
70 impl Reason {
to_str(self) -> &'static str71     pub(crate) fn to_str(self) -> &'static str {
72         match self {
73             Reason::Default => "",
74             Reason::TaskSurvivalOneMonth => "The task has not been completed for a month yet",
75             Reason::WaitingNetworkOneDay => "The task waiting for network recovery has not been completed for a day yet",
76             Reason::StoppedByNewFrontTask => "Stopped by a new front task",
77             Reason::RunningTaskMeetLimits => "Too many task in running state",
78             Reason::UserOperation => "User operation",
79             Reason::AppBackgroundOrTerminate => "The app is background or terminate",
80             Reason::NetworkOffline => "NetWork is offline",
81             Reason::UnsupportedNetworkType => "NetWork type not meet the task config",
82             Reason::BuildClientFailed => "Build client error",
83             Reason::BuildRequestFailed => "Build request error",
84             Reason::GetFileSizeFailed => "Failed because cannot get the file size from the server and the precise is setted true by user",
85             Reason::ContinuousTaskTimeout => "Continuous processing task time out",
86             Reason::ConnectError => "Connect error",
87             Reason::RequestError => "Request error",
88             Reason::UploadFileError => "There are some files upload failed",
89             Reason::RedirectError => "Redirect error",
90             Reason::ProtocolError => "Http protocol error",
91             Reason::IoError => "Io Error",
92             Reason::UnsupportedRangeRequest => "The server is not support range request",
93             Reason::OthersError => "Some other error occured",
94             Reason::NetworkChanged => "Network changed",
95         }
96     }
97 }
98