blob: 1affa1b97ee68977c30b5d47d6e29956dfd55eaa [file] [log] [blame]
Vitaly Buka4615e0d2015-10-14 15:35:12 -07001// Copyright 2015 The Weave Authors. All rights reserved.
Vitaly Buka7ce499f2015-06-09 08:04:11 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Vitaly Buka912b6982015-07-06 11:13:03 -07005#ifndef LIBWEAVE_SRC_PRIVET_DEVICE_DELEGATE_H_
6#define LIBWEAVE_SRC_PRIVET_DEVICE_DELEGATE_H_
Vitaly Buka7ce499f2015-06-09 08:04:11 -07007
8#include <memory>
9#include <utility>
10
Alex Vakulenkoefee3a22015-11-17 15:08:38 -080011#include <base/callback.h>
12#include <base/location.h>
Vitaly Buka7ce499f2015-06-09 08:04:11 -070013#include <base/time/time.h>
14
Vitaly Bukab6f015a2015-07-09 14:59:23 -070015namespace weave {
Alex Vakulenkoefee3a22015-11-17 15:08:38 -080016
17namespace provider {
18class TaskRunner;
19}
20
Vitaly Bukab6f015a2015-07-09 14:59:23 -070021namespace privet {
Vitaly Buka7ce499f2015-06-09 08:04:11 -070022
23// Interface to provide access to general information about device.
24class 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 Vakulenkoefee3a22015-11-17 15:08:38 -080031 // could be 0. In this case the first port would be used for regular and for
Vitaly Buka7ce499f2015-06-09 08:04:11 -070032 // 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 Vakulenkoefee3a22015-11-17 15:08:38 -080038 // Returns device uptime.
Vitaly Buka7ce499f2015-06-09 08:04:11 -070039 virtual base::TimeDelta GetUptime() const = 0;
40
Alex Vakulenkoefee3a22015-11-17 15:08:38 -080041 // 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 Buka7ce499f2015-06-09 08:04:11 -070044
Alex Vakulenkoefee3a22015-11-17 15:08:38 -080045 // 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 Buka7ce499f2015-06-09 08:04:11 -070049
50 // Create default instance.
Alex Vakulenkoefee3a22015-11-17 15:08:38 -080051 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 Buka7ce499f2015-06-09 08:04:11 -070056};
57
Vitaly Bukab6f015a2015-07-09 14:59:23 -070058} // namespace privet
59} // namespace weave
Vitaly Buka7ce499f2015-06-09 08:04:11 -070060
Vitaly Buka912b6982015-07-06 11:13:03 -070061#endif // LIBWEAVE_SRC_PRIVET_DEVICE_DELEGATE_H_