| 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 <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "components/copresence/handlers/audio/audio_directive_handler_impl.h" | 14 #include "components/copresence/handlers/audio/audio_directive_handler_impl.h" |
| 15 #include "components/copresence/public/whispernet_client.h" | 15 #include "components/copresence/public/copresence_constants.h" |
| 16 | 16 |
| 17 namespace copresence { | 17 namespace copresence { |
| 18 | 18 |
| 19 class AudioDirectiveHandler; | 19 class AudioDirectiveHandler; |
| 20 class Directive; | 20 class Directive; |
| 21 class WhispernetClient; |
| 21 | 22 |
| 22 // The directive handler manages transmit and receive directives. | 23 // The directive handler manages transmit and receive directives. |
| 23 // TODO(ckehoe): Turn this into an interface. | 24 // TODO(ckehoe): Turn this into an interface. |
| 24 class DirectiveHandler { | 25 class DirectiveHandler { |
| 25 public: | 26 public: |
| 26 explicit DirectiveHandler(scoped_ptr<AudioDirectiveHandler> audio_handler = | 27 explicit DirectiveHandler(scoped_ptr<AudioDirectiveHandler> audio_handler = |
| 27 make_scoped_ptr(new AudioDirectiveHandlerImpl)); | 28 make_scoped_ptr(new AudioDirectiveHandlerImpl)); |
| 28 virtual ~DirectiveHandler(); | 29 virtual ~DirectiveHandler(); |
| 29 | 30 |
| 30 // Starts processing directives with the provided Whispernet client. | 31 // Starts processing directives with the provided Whispernet client. |
| 31 // Directives will be queued until this function is called. | 32 // Directives will be queued until this function is called. |
| 32 // |whispernet_client| is owned by the caller | 33 // |whispernet_client| is owned by the caller and must outlive the |
| 33 // and must outlive the DirectiveHandler. | 34 // DirectiveHandler. |
| 34 virtual void Start(WhispernetClient* whispernet_client); | 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); |
| 35 | 38 |
| 36 // Adds a directive to handle. | 39 // Adds a directive to handle. |
| 37 virtual void AddDirective(const Directive& directive); | 40 virtual void AddDirective(const Directive& directive); |
| 38 | 41 |
| 39 // Removes any directives associated with the given operation id. | 42 // Removes any directives associated with the given operation id. |
| 40 virtual void RemoveDirectives(const std::string& op_id); | 43 virtual void RemoveDirectives(const std::string& op_id); |
| 41 | 44 |
| 45 // TODO(rkc): Too many audio specific functions here, find a better way to |
| 46 // get this information to the copresence manager. |
| 42 virtual const std::string GetCurrentAudioToken(AudioType type) const; | 47 virtual const std::string GetCurrentAudioToken(AudioType type) const; |
| 48 virtual bool IsAudioTokenHeard(AudioType type) const; |
| 43 | 49 |
| 44 private: | 50 private: |
| 45 // Starts actually running a directive. | 51 // Starts actually running a directive. |
| 46 void StartDirective(const std::string& op_id, const Directive& directive); | 52 void StartDirective(const std::string& op_id, const Directive& directive); |
| 47 | 53 |
| 48 // Forwards the request to encode a token to whispernet, | |
| 49 // and instructs it to call samples_callback when encoding is complete. | |
| 50 void EncodeToken( | |
| 51 const std::string& token, | |
| 52 AudioType type, | |
| 53 const WhispernetClient::SamplesCallback& samples_callback); | |
| 54 | |
| 55 scoped_ptr<AudioDirectiveHandler> audio_handler_; | 54 scoped_ptr<AudioDirectiveHandler> audio_handler_; |
| 56 std::map<std::string, std::vector<Directive>> pending_directives_; | 55 std::map<std::string, std::vector<Directive>> pending_directives_; |
| 57 | 56 |
| 58 // Belongs to the caller. | 57 bool is_started_; |
| 59 WhispernetClient* whispernet_client_; | |
| 60 | 58 |
| 61 DISALLOW_COPY_AND_ASSIGN(DirectiveHandler); | 59 DISALLOW_COPY_AND_ASSIGN(DirectiveHandler); |
| 62 }; | 60 }; |
| 63 | 61 |
| 64 } // namespace copresence | 62 } // namespace copresence |
| 65 | 63 |
| 66 #endif // COMPONENTS_COPRESENCE_HANDLERS_DIRECTIVE_HANDLER_H_ | 64 #endif // COMPONENTS_COPRESENCE_HANDLERS_DIRECTIVE_HANDLER_H_ |
| OLD | NEW |