OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_COPRESENCE_HANDLERS_DIRECTIVE_HANDLER_H_ | 5 #ifndef COMPONENTS_COPRESENCE_HANDLERS_DIRECTIVE_HANDLER_H_ |
6 #define COMPONENTS_COPRESENCE_HANDLERS_DIRECTIVE_HANDLER_H_ | 6 #define COMPONENTS_COPRESENCE_HANDLERS_DIRECTIVE_HANDLER_H_ |
7 | 7 |
8 #include <map> | |
8 #include <string> | 9 #include <string> |
10 #include <vector> | |
9 | 11 |
10 #include "base/callback.h" | |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
13 #include "components/copresence/handlers/audio/audio_directive_handler.h" | 14 #include "components/copresence/public/whispernet_client.h" |
14 #include "components/copresence/mediums/audio/audio_manager.h" | |
15 | 15 |
16 namespace copresence { | 16 namespace copresence { |
17 | 17 |
18 class AudioDirectiveHandler; | |
18 class Directive; | 19 class Directive; |
19 | 20 |
20 // The directive handler manages transmit and receive directives | 21 // The directive handler manages transmit and receive directives. |
21 // given to it by the manager. | 22 // TODO(ckehoe): Add tests for this class. |
rkc
2014/10/31 17:18:06
This class is now complex enough that this shouldn
Charlie
2014/10/31 17:47:06
I agree, but there's some refactoring required to
rkc
2014/10/31 18:06:15
That's fine, you can do them both in another CL. A
Charlie
2014/10/31 18:20:55
The CL is in progress already. And you know how mu
| |
23 // TODO(ckehoe): Turn this into an interface. | |
22 class DirectiveHandler { | 24 class DirectiveHandler { |
23 public: | 25 public: |
24 DirectiveHandler(); | 26 DirectiveHandler(); |
25 virtual ~DirectiveHandler(); | 27 virtual ~DirectiveHandler(); |
26 | 28 |
27 // Initialize the |audio_handler_| with the appropriate callbacks. | 29 // Starts processing directives with the provided Whispernet client. |
28 // This function must be called before any others. | 30 // Directives will be queued until this function is called. |
29 // TODO(ckehoe): Instead of this, use a static Create() method | 31 // |whispernet_client| is owned by the caller |
30 // and make the constructor private. | 32 // and must outlive the DirectiveHandler. |
31 virtual void Initialize(const AudioManager::DecodeSamplesCallback& decode_cb, | 33 virtual void Start(WhispernetClient* whispernet_client); |
32 const AudioManager::EncodeTokenCallback& encode_cb); | |
33 | 34 |
34 // Adds a directive to handle. | 35 // Adds a directive to handle. |
35 virtual void AddDirective(const copresence::Directive& directive); | 36 virtual void AddDirective(const Directive& directive); |
37 | |
36 // Removes any directives associated with the given operation id. | 38 // Removes any directives associated with the given operation id. |
37 virtual void RemoveDirectives(const std::string& op_id); | 39 virtual void RemoveDirectives(const std::string& op_id); |
38 | 40 |
39 const std::string GetCurrentAudioToken(AudioType type) const; | 41 virtual const std::string GetCurrentAudioToken(AudioType type) const; |
40 | 42 |
41 private: | 43 private: |
44 // Starts actually running a directive. | |
45 void StartDirective(const std::string& op_id, const Directive& directive); | |
46 | |
47 // Forwards the request to encode a token to whispernet, | |
48 // and instructs it to call samples_callback when encoding is complete. | |
49 void EncodeToken( | |
50 const std::string& token, | |
51 AudioType type, | |
52 const WhispernetClient::SamplesCallback& samples_callback); | |
53 | |
42 scoped_ptr<AudioDirectiveHandler> audio_handler_; | 54 scoped_ptr<AudioDirectiveHandler> audio_handler_; |
55 std::map<std::string, std::vector<Directive>> pending_directives_; | |
56 | |
57 // Belongs to the caller. | |
58 WhispernetClient* whispernet_client_; | |
43 | 59 |
44 DISALLOW_COPY_AND_ASSIGN(DirectiveHandler); | 60 DISALLOW_COPY_AND_ASSIGN(DirectiveHandler); |
45 }; | 61 }; |
46 | 62 |
47 } // namespace copresence | 63 } // namespace copresence |
48 | 64 |
49 #endif // COMPONENTS_COPRESENCE_HANDLERS_DIRECTIVE_HANDLER_H_ | 65 #endif // COMPONENTS_COPRESENCE_HANDLERS_DIRECTIVE_HANDLER_H_ |
OLD | NEW |