Vitaly Buka | 4615e0d | 2015-10-14 15:35:12 -0700 | [diff] [blame] | 1 | // Copyright 2015 The Weave Authors. All rights reserved. |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Vitaly Buka | 912b698 | 2015-07-06 11:13:03 -0700 | [diff] [blame] | 5 | #ifndef LIBWEAVE_SRC_PRIVET_DEVICE_DELEGATE_H_ |
| 6 | #define LIBWEAVE_SRC_PRIVET_DEVICE_DELEGATE_H_ |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 7 | |
| 8 | #include <memory> |
| 9 | #include <utility> |
| 10 | |
Alex Vakulenko | efee3a2 | 2015-11-17 15:08:38 -0800 | [diff] [blame] | 11 | #include <base/callback.h> |
| 12 | #include <base/location.h> |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 13 | #include <base/time/time.h> |
| 14 | |
Vitaly Buka | b6f015a | 2015-07-09 14:59:23 -0700 | [diff] [blame] | 15 | namespace weave { |
Alex Vakulenko | efee3a2 | 2015-11-17 15:08:38 -0800 | [diff] [blame] | 16 | |
| 17 | namespace provider { |
| 18 | class TaskRunner; |
| 19 | } |
| 20 | |
Vitaly Buka | b6f015a | 2015-07-09 14:59:23 -0700 | [diff] [blame] | 21 | namespace privet { |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 22 | |
| 23 | // Interface to provide access to general information about device. |
| 24 | class DeviceDelegate { |
| 25 | public: |
| 26 | DeviceDelegate(); |
| 27 | virtual ~DeviceDelegate(); |
| 28 | |
| 29 | // Returns HTTP ports for Privet. The first one is the primary port, |
| 30 | // the second is the port for a pooling updates requests. The second value |
Alex Vakulenko | efee3a2 | 2015-11-17 15:08:38 -0800 | [diff] [blame] | 31 | // could be 0. In this case the first port would be used for regular and for |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 32 | // updates requests. |
| 33 | virtual std::pair<uint16_t, uint16_t> GetHttpEnpoint() const = 0; |
| 34 | |
| 35 | // The same |GetHttpEnpoint| but for HTTPS. |
| 36 | virtual std::pair<uint16_t, uint16_t> GetHttpsEnpoint() const = 0; |
| 37 | |
Alex Vakulenko | efee3a2 | 2015-11-17 15:08:38 -0800 | [diff] [blame] | 38 | // Returns device uptime. |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 39 | virtual base::TimeDelta GetUptime() const = 0; |
| 40 | |
Alex Vakulenko | efee3a2 | 2015-11-17 15:08:38 -0800 | [diff] [blame] | 41 | // Returns the max request timeout of http server. Returns TimeDelta::Max() if |
| 42 | // no timeout is set. |
| 43 | virtual base::TimeDelta GetHttpRequestTimeout() const = 0; |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 44 | |
Alex Vakulenko | efee3a2 | 2015-11-17 15:08:38 -0800 | [diff] [blame] | 45 | // Schedules a background task on the embedded TaskRunner. |
| 46 | virtual void PostDelayedTask(const tracked_objects::Location& from_here, |
| 47 | const base::Closure& task, |
| 48 | base::TimeDelta delay) = 0; |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 49 | |
| 50 | // Create default instance. |
Alex Vakulenko | efee3a2 | 2015-11-17 15:08:38 -0800 | [diff] [blame] | 51 | static std::unique_ptr<DeviceDelegate> CreateDefault( |
| 52 | provider::TaskRunner* task_runner, |
| 53 | uint16_t http_port, |
| 54 | uint16_t https_port, |
| 55 | base::TimeDelta http_request_timeout); |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
Vitaly Buka | b6f015a | 2015-07-09 14:59:23 -0700 | [diff] [blame] | 58 | } // namespace privet |
| 59 | } // namespace weave |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 60 | |
Vitaly Buka | 912b698 | 2015-07-06 11:13:03 -0700 | [diff] [blame] | 61 | #endif // LIBWEAVE_SRC_PRIVET_DEVICE_DELEGATE_H_ |