FireBreath  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
OneShotManager.h
1 
2 /**********************************************************\
3  Original Author: Georg Fritzsche
4 
5  Created: Nov 6, 2010
6  License: Dual license model; choose one of two:
7  New BSD License
8  http://www.opensource.org/licenses/bsd-license.php
9  - or -
10  GNU Lesser General Public License, version 2.1
11  http://www.gnu.org/licenses/lgpl-2.1.html
12 
13  Copyright 2010 Georg Fritzsche and the Firebreath development team
14  \**********************************************************/
15 
16 #pragma once
17 #ifndef FB_H_ONESHOTMANAGER
18 #define FB_H_ONESHOTMANAGER
19 
20 #include <map>
21 #include <boost/utility.hpp>
22 
23 #include "APITypes.h"
24 #include "SafeQueue.h"
25 
26 
27 namespace FB
28 {
29  typedef void (*OneShotCallback)(void*);
30  typedef std::pair<void*, OneShotCallback> SinkPair;
31  typedef std::deque<SinkPair> SinkQueue;
32  typedef std::map<void*,SinkQueue*> Sinks;
33 
34  class OneShotManager : public boost::noncopyable
35  {
36  public:
37  ~OneShotManager();
38 
39  void npp_register(void* instance);
40  void npp_unregister(void* instance);
41 
42  void npp_scheduleAsyncCallback(void* instance, OneShotCallback func, void *userData);
43 
44  void npp_asyncCallback();
45 
46  static OneShotManager& getInstance();
47 
48  private:
49  OneShotManager();
50  bool npp_nextCallback(SinkPair& callback);
51 
52  mutable boost::mutex m_mutex;
53  Sinks m_sinks;
54  void* m_helper;
55  uint32_t m_shots;
56  };
57 }
58 
59 #endif
60