Merge remote-tracking branch 'upstream/v0.10'
[platform/upstream/nodejs.git] / src / async-wrap.h
1 // Copyright Joyent, Inc. and other Node contributors.
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a
4 // copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to permit
8 // persons to whom the Software is furnished to do so, subject to the
9 // following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included
12 // in all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 // USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22 #ifndef SRC_ASYNC_WRAP_H_
23 #define SRC_ASYNC_WRAP_H_
24
25 #include "base-object.h"
26 #include "env.h"
27 #include "v8.h"
28
29 namespace node {
30
31 class AsyncWrap : public BaseObject {
32  public:
33   enum AsyncFlags {
34     NO_OPTIONS = 0,
35     HAS_ASYNC_LISTENER = 1
36   };
37
38   inline AsyncWrap(Environment* env, v8::Handle<v8::Object> object);
39
40   inline ~AsyncWrap();
41
42   template <typename Type>
43   static inline void AddMethods(v8::Handle<v8::FunctionTemplate> t);
44
45   inline uint32_t async_flags() const;
46
47   inline void set_flag(unsigned int flag);
48
49   inline void remove_flag(unsigned int flag);
50
51   inline bool has_async_listener();
52
53   // Only call these within a valid HandleScope.
54   inline v8::Handle<v8::Value> MakeCallback(const v8::Handle<v8::Function> cb,
55                                             int argc,
56                                             v8::Handle<v8::Value>* argv);
57   inline v8::Handle<v8::Value> MakeCallback(const v8::Handle<v8::String> symbol,
58                                             int argc,
59                                             v8::Handle<v8::Value>* argv);
60   inline v8::Handle<v8::Value> MakeCallback(uint32_t index,
61                                             int argc,
62                                             v8::Handle<v8::Value>* argv);
63
64  private:
65   inline AsyncWrap();
66
67   // TODO(trevnorris): BURN IN FIRE! Remove this as soon as a suitable
68   // replacement is committed.
69   inline v8::Handle<v8::Value> MakeDomainCallback(
70       const v8::Handle<v8::Function> cb,
71       int argc,
72       v8::Handle<v8::Value>* argv);
73
74   // Add an async listener to an existing handle.
75   template <typename Type>
76   static inline void AddAsyncListener(
77       const v8::FunctionCallbackInfo<v8::Value>& args);
78
79   // Remove an async listener to an existing handle.
80   template <typename Type>
81   static inline void RemoveAsyncListener(
82       const v8::FunctionCallbackInfo<v8::Value>& args);
83
84   uint32_t async_flags_;
85 };
86
87 }  // namespace node
88
89
90 #endif  // SRC_ASYNC_WRAP_H_