summaryrefslogtreecommitdiffstats
path: root/components/copresence/handlers/directive_handler_impl.h
blob: 01eb27ba45926e96a020c64e784ef7a7f448322d (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
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_COPRESENCE_HANDLERS_DIRECTIVE_HANDLER_IMPL_H_
#define COMPONENTS_COPRESENCE_HANDLERS_DIRECTIVE_HANDLER_IMPL_H_

#include "components/copresence/handlers/directive_handler.h"

#include <map>
#include <string>
#include <vector>

#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "components/copresence/handlers/audio/audio_directive_handler_impl.h"
#include "components/copresence/public/copresence_constants.h"

namespace copresence {

// The directive handler manages transmit and receive directives.
class DirectiveHandlerImpl final : public DirectiveHandler {
 public:
  DirectiveHandlerImpl();
  explicit DirectiveHandlerImpl(
      const DirectivesCallback& update_directives_callback);
  DirectiveHandlerImpl(
      scoped_ptr<AudioDirectiveHandler> audio_handler);
  ~DirectiveHandlerImpl() override;

  // DirectiveHandler overrides.
  void Start(audio_modem::WhispernetClient* whispernet_client,
             const audio_modem::TokensCallback& tokens_cb) override;
  void AddDirective(const Directive& directive) override;
  void RemoveDirectives(const std::string& op_id) override;
  const std::string
  GetCurrentAudioToken(audio_modem::AudioType type) const override;
  bool IsAudioTokenHeard(audio_modem::AudioType type) const override;

 private:
  // Starts actually running a directive.
  void StartDirective(const std::string& op_id, const Directive& directive);

  scoped_ptr<AudioDirectiveHandler> audio_handler_;
  std::map<std::string, std::vector<Directive>> pending_directives_;

  bool is_started_;

  DISALLOW_COPY_AND_ASSIGN(DirectiveHandlerImpl);
};

}  // namespace copresence

#endif  // COMPONENTS_COPRESENCE_HANDLERS_DIRECTIVE_HANDLER_IMPL_H_