1 // Copyright 2014 The Chromium 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.
5 #ifndef COMPONENTS_COPRESENCE_HANDLERS_DIRECTIVE_HANDLER_H_
6 #define COMPONENTS_COPRESENCE_HANDLERS_DIRECTIVE_HANDLER_H_
12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "components/copresence/handlers/audio/audio_directive_handler_impl.h"
15 #include "components/copresence/public/copresence_constants.h"
17 namespace copresence {
19 class AudioDirectiveHandler;
21 class WhispernetClient;
23 // The directive handler manages transmit and receive directives.
24 // TODO(ckehoe): Turn this into an interface.
25 class DirectiveHandler {
27 explicit DirectiveHandler(scoped_ptr<AudioDirectiveHandler> audio_handler =
28 make_scoped_ptr(new AudioDirectiveHandlerImpl));
29 virtual ~DirectiveHandler();
31 // Starts processing directives with the provided Whispernet client.
32 // Directives will be queued until this function is called.
33 // |whispernet_client| is owned by the caller and must outlive the
35 // |tokens_cb| is called for all audio tokens found in recorded audio.
36 virtual void Start(WhispernetClient* whispernet_client,
37 const TokensCallback& tokens_cb);
39 // Adds a directive to handle.
40 virtual void AddDirective(const Directive& directive);
42 // Removes any directives associated with the given operation id.
43 virtual void RemoveDirectives(const std::string& op_id);
45 // TODO(rkc): Too many audio specific functions here, find a better way to
46 // get this information to the copresence manager.
47 virtual const std::string GetCurrentAudioToken(AudioType type) const;
48 virtual bool IsAudioTokenHeard(AudioType type) const;
51 // Starts actually running a directive.
52 void StartDirective(const std::string& op_id, const Directive& directive);
54 scoped_ptr<AudioDirectiveHandler> audio_handler_;
55 std::map<std::string, std::vector<Directive>> pending_directives_;
59 DISALLOW_COPY_AND_ASSIGN(DirectiveHandler);
62 } // namespace copresence
64 #endif // COMPONENTS_COPRESENCE_HANDLERS_DIRECTIVE_HANDLER_H_