Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / components / copresence / handlers / directive_handler.h
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.
4
5 #ifndef COMPONENTS_COPRESENCE_HANDLERS_DIRECTIVE_HANDLER_H_
6 #define COMPONENTS_COPRESENCE_HANDLERS_DIRECTIVE_HANDLER_H_
7
8 #include <map>
9 #include <string>
10 #include <vector>
11
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"
16
17 namespace copresence {
18
19 class AudioDirectiveHandler;
20 class Directive;
21 class WhispernetClient;
22
23 // The directive handler manages transmit and receive directives.
24 // TODO(ckehoe): Turn this into an interface.
25 class DirectiveHandler {
26  public:
27   explicit DirectiveHandler(scoped_ptr<AudioDirectiveHandler> audio_handler =
28       make_scoped_ptr(new AudioDirectiveHandlerImpl));
29   virtual ~DirectiveHandler();
30
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
34   // DirectiveHandler.
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);
38
39   // Adds a directive to handle.
40   virtual void AddDirective(const Directive& directive);
41
42   // Removes any directives associated with the given operation id.
43   virtual void RemoveDirectives(const std::string& op_id);
44
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;
49
50  private:
51   // Starts actually running a directive.
52   void StartDirective(const std::string& op_id, const Directive& directive);
53
54   scoped_ptr<AudioDirectiveHandler> audio_handler_;
55   std::map<std::string, std::vector<Directive>> pending_directives_;
56
57   bool is_started_;
58
59   DISALLOW_COPY_AND_ASSIGN(DirectiveHandler);
60 };
61
62 }  // namespace copresence
63
64 #endif  // COMPONENTS_COPRESENCE_HANDLERS_DIRECTIVE_HANDLER_H_