1 /** @file
2  *
3  *  Interface for providing transfer progress
4  *
5  *  @section license License
6  *
7  *  Licensed to the Apache Software Foundation (ASF) under one
8  *  or more contributor license agreements.  See the NOTICE file
9  *  distributed with this work for additional information
10  *  regarding copyright ownership.  The ASF licenses this file
11  *  to you under the Apache License, Version 2.0 (the
12  *  "License"); you may not use this file except in compliance
13  *  with the License.  You may obtain a copy of the License at
14  *
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  *
17  *  Unless required by applicable law or agreed to in writing, software
18  *  distributed under the License is distributed on an "AS IS" BASIS,
19  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  *  See the License for the specific language governing permissions and
21  *  limitations under the License.
22  */
23 
24 #include "I_VIO.h"
25 
26 #pragma once
27 
28 class QUICTransferProgressProvider
29 {
30 public:
31   virtual bool is_transfer_goal_set() const  = 0;
32   virtual uint64_t transfer_progress() const = 0;
33   virtual uint64_t transfer_goal() const     = 0;
34   virtual bool is_cancelled() const          = 0;
35 
36   virtual bool
is_transfer_complete()37   is_transfer_complete() const
38   {
39     return this->transfer_progress() == this->transfer_goal();
40   }
41 };
42 
43 class QUICTransferProgressProviderVIO : public QUICTransferProgressProvider
44 {
45 public:
QUICTransferProgressProviderVIO(VIO & vio)46   QUICTransferProgressProviderVIO(VIO &vio) : _vio(vio) {}
47 
48   bool
is_transfer_goal_set()49   is_transfer_goal_set() const
50   {
51     return this->_vio.nbytes != INT64_MAX;
52   }
53 
54   uint64_t
transfer_progress()55   transfer_progress() const
56   {
57     return this->_vio.ndone;
58   }
59 
60   uint64_t
transfer_goal()61   transfer_goal() const
62   {
63     return this->_vio.nbytes;
64   }
65 
66   bool
is_cancelled()67   is_cancelled() const
68   {
69     return false;
70   }
71 
72 private:
73   VIO &_vio;
74 };
75