1 // Copyright 2015 The Weave Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef LIBWEAVE_SRC_PRIVET_DEVICE_DELEGATE_H_ 6 #define LIBWEAVE_SRC_PRIVET_DEVICE_DELEGATE_H_ 7 8 #include <memory> 9 #include <utility> 10 11 #include <base/callback.h> 12 #include <base/location.h> 13 #include <base/time/time.h> 14 15 namespace weave { 16 17 namespace provider { 18 class TaskRunner; 19 } 20 21 namespace privet { 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 31 // could be 0. In this case the first port would be used for regular and for 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 38 // Returns the max request timeout of http server. Returns TimeDelta::Max() if 39 // no timeout is set. 40 virtual base::TimeDelta GetHttpRequestTimeout() const = 0; 41 42 // Schedules a background task on the embedded TaskRunner. 43 virtual void PostDelayedTask(const tracked_objects::Location& from_here, 44 const base::Closure& task, 45 base::TimeDelta delay) = 0; 46 47 // Create default instance. 48 static std::unique_ptr<DeviceDelegate> CreateDefault( 49 provider::TaskRunner* task_runner, 50 uint16_t http_port, 51 uint16_t https_port, 52 base::TimeDelta http_request_timeout); 53 }; 54 55 } // namespace privet 56 } // namespace weave 57 58 #endif // LIBWEAVE_SRC_PRIVET_DEVICE_DELEGATE_H_ 59