Welcome to mirror list, hosted at ThFree Co, Russian Federation.

diff_manager.hpp « diff_scheme « storage - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0aa25f95ee14c3211982f92eeee43f9568b59ef0 (plain)
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
51
52
53
54
55
56
57
58
59
60
#pragma once

#include "storage/diff_scheme/diff_types.hpp"
#include "storage/index.hpp"

#include "base/observer_list.hpp"
#include "base/thread_checker.hpp"
#include "base/worker_thread.hpp"

#include <functional>
#include <mutex>
#include <utility>

namespace storage
{
namespace diffs
{
class Manager final
{
public:
  struct ApplyDiffParams
  {
    string m_diffReadyPath;
    TLocalFilePtr m_diffFile;
    TLocalFilePtr m_oldMwmFile;
  };

  class Observer
  {
  public:
    virtual ~Observer() = default;

    virtual void OnDiffStatusReceived(Status const status) = 0;
  };

  FileInfo const & InfoFor(storage::TCountryId const & countryId) const;
  bool IsPossibleToAutoupdate() const;
  bool HasDiffFor(storage::TCountryId const & countryId) const;

  Status GetStatus() const;
  void SetStatus(Status status);

  void Load(LocalMapsInfo && info);
  void ApplyDiff(ApplyDiffParams && p, std::function<void(bool const result)> const & task);

  bool AddObserver(Observer & observer) { return m_observers.Add(observer); }
  bool RemoveObserver(Observer const & observer) { return m_observers.Remove(observer); }

private:
  bool HasDiffForUnsafe(storage::TCountryId const & countryId) const;

  mutable std::mutex m_mutex;
  Status m_status = Status::Undefined;
  NameFileInfoMap m_diffs;
  LocalMapsInfo m_localMapsInfo;
  base::ObserverListUnsafe<Observer> m_observers;
  base::WorkerThread m_workerThread;
};
}  // namespace diffs
}  // namespace storage