forked from flightaware/dump978
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskyaware_writer.h
50 lines (38 loc) · 2.12 KB
/
skyaware_writer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// -*- c++ -*-
// Copyright (c) 2019, FlightAware LLC.
// All rights reserved.
// Licensed under the 2-clause BSD license; see the LICENSE file
#ifndef SKYAWARE_WRITER_H
#define SKYAWARE_WRITER_H
#include <chrono>
#include <memory>
#include <boost/asio/io_service.hpp>
#include <boost/asio/steady_timer.hpp>
#include <boost/asio/strand.hpp>
#include <boost/filesystem.hpp>
#include "track.h"
#include "uat_message.h"
namespace flightaware::skyaware {
class SkyAwareWriter : public std::enable_shared_from_this<SkyAwareWriter> {
public:
typedef std::shared_ptr<SkyAwareWriter> Pointer;
static Pointer Create(boost::asio::io_service &service, flightaware::uat::Tracker::Pointer tracker, const boost::filesystem::path &dir, std::chrono::milliseconds interval, unsigned history_count, std::chrono::milliseconds history_interval, boost::optional<std::pair<double, double>> location) { return Pointer(new SkyAwareWriter(service, tracker, dir, interval, history_count, history_interval, location)); }
void Start();
void Stop();
private:
SkyAwareWriter(boost::asio::io_service &service, flightaware::uat::Tracker::Pointer tracker, const boost::filesystem::path &dir, std::chrono::milliseconds interval, unsigned history_count, std::chrono::milliseconds history_interval, boost::optional<std::pair<double, double>> location) : service_(service), strand_(service), timer_(service), tracker_(tracker), dir_(dir), interval_(interval), history_count_(history_count), history_interval_(history_interval), location_(location) {}
void PeriodicWrite();
boost::asio::io_service &service_;
boost::asio::io_service::strand strand_;
boost::asio::steady_timer timer_;
flightaware::uat::Tracker::Pointer tracker_;
boost::filesystem::path dir_;
std::chrono::milliseconds interval_;
unsigned history_count_;
std::chrono::milliseconds history_interval_;
boost::optional<std::pair<double, double>> location_;
unsigned next_history_index_ = 0;
std::uint64_t next_history_time_ = 0;
};
} // namespace flightaware::skyaware
#endif