xref: /aosp_15_r20/external/webrtc/net/dcsctp/public/timeout.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1*d9f75844SAndroid Build Coastguard Worker /*
2*d9f75844SAndroid Build Coastguard Worker  *  Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
3*d9f75844SAndroid Build Coastguard Worker  *
4*d9f75844SAndroid Build Coastguard Worker  *  Use of this source code is governed by a BSD-style license
5*d9f75844SAndroid Build Coastguard Worker  *  that can be found in the LICENSE file in the root of the source
6*d9f75844SAndroid Build Coastguard Worker  *  tree. An additional intellectual property rights grant can be found
7*d9f75844SAndroid Build Coastguard Worker  *  in the file PATENTS.  All contributing project authors may
8*d9f75844SAndroid Build Coastguard Worker  *  be found in the AUTHORS file in the root of the source tree.
9*d9f75844SAndroid Build Coastguard Worker  */
10*d9f75844SAndroid Build Coastguard Worker #ifndef NET_DCSCTP_PUBLIC_TIMEOUT_H_
11*d9f75844SAndroid Build Coastguard Worker #define NET_DCSCTP_PUBLIC_TIMEOUT_H_
12*d9f75844SAndroid Build Coastguard Worker 
13*d9f75844SAndroid Build Coastguard Worker #include <cstdint>
14*d9f75844SAndroid Build Coastguard Worker 
15*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/public/types.h"
16*d9f75844SAndroid Build Coastguard Worker 
17*d9f75844SAndroid Build Coastguard Worker namespace dcsctp {
18*d9f75844SAndroid Build Coastguard Worker 
19*d9f75844SAndroid Build Coastguard Worker // A very simple timeout that can be started and stopped. When started,
20*d9f75844SAndroid Build Coastguard Worker // it will be given a unique `timeout_id` which should be provided to
21*d9f75844SAndroid Build Coastguard Worker // `DcSctpSocket::HandleTimeout` when it expires.
22*d9f75844SAndroid Build Coastguard Worker class Timeout {
23*d9f75844SAndroid Build Coastguard Worker  public:
24*d9f75844SAndroid Build Coastguard Worker   virtual ~Timeout() = default;
25*d9f75844SAndroid Build Coastguard Worker 
26*d9f75844SAndroid Build Coastguard Worker   // Called to start time timeout, with the duration in milliseconds as
27*d9f75844SAndroid Build Coastguard Worker   // `duration` and with the timeout identifier as `timeout_id`, which - if
28*d9f75844SAndroid Build Coastguard Worker   // the timeout expires - shall be provided to `DcSctpSocket::HandleTimeout`.
29*d9f75844SAndroid Build Coastguard Worker   //
30*d9f75844SAndroid Build Coastguard Worker   // `Start` and `Stop` will always be called in pairs. In other words will
31*d9f75844SAndroid Build Coastguard Worker   // ´Start` never be called twice, without a call to `Stop` in between.
32*d9f75844SAndroid Build Coastguard Worker   virtual void Start(DurationMs duration, TimeoutID timeout_id) = 0;
33*d9f75844SAndroid Build Coastguard Worker 
34*d9f75844SAndroid Build Coastguard Worker   // Called to stop the running timeout.
35*d9f75844SAndroid Build Coastguard Worker   //
36*d9f75844SAndroid Build Coastguard Worker   // `Start` and `Stop` will always be called in pairs. In other words will
37*d9f75844SAndroid Build Coastguard Worker   // ´Start` never be called twice, without a call to `Stop` in between.
38*d9f75844SAndroid Build Coastguard Worker   //
39*d9f75844SAndroid Build Coastguard Worker   // `Stop` will always be called prior to releasing this object.
40*d9f75844SAndroid Build Coastguard Worker   virtual void Stop() = 0;
41*d9f75844SAndroid Build Coastguard Worker 
42*d9f75844SAndroid Build Coastguard Worker   // Called to restart an already running timeout, with the `duration` and
43*d9f75844SAndroid Build Coastguard Worker   // `timeout_id` parameters as described in `Start`. This can be overridden by
44*d9f75844SAndroid Build Coastguard Worker   // the implementation to restart it more efficiently.
Restart(DurationMs duration,TimeoutID timeout_id)45*d9f75844SAndroid Build Coastguard Worker   virtual void Restart(DurationMs duration, TimeoutID timeout_id) {
46*d9f75844SAndroid Build Coastguard Worker     Stop();
47*d9f75844SAndroid Build Coastguard Worker     Start(duration, timeout_id);
48*d9f75844SAndroid Build Coastguard Worker   }
49*d9f75844SAndroid Build Coastguard Worker };
50*d9f75844SAndroid Build Coastguard Worker 
51*d9f75844SAndroid Build Coastguard Worker }  // namespace dcsctp
52*d9f75844SAndroid Build Coastguard Worker 
53*d9f75844SAndroid Build Coastguard Worker #endif  // NET_DCSCTP_PUBLIC_TIMEOUT_H_
54