src: deduplicate CHECK_EQ/CHECK_NE macros
[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   enum ProviderType {
39     PROVIDER_NONE               = 1 << 0,
40     PROVIDER_CARES              = 1 << 1,
41     PROVIDER_CONNECTWRAP        = 1 << 2,
42     PROVIDER_CRYPTO             = 1 << 3,
43     PROVIDER_FSEVENTWRAP        = 1 << 4,
44     PROVIDER_GETADDRINFOREQWRAP = 1 << 5,
45     PROVIDER_PIPEWRAP           = 1 << 6,
46     PROVIDER_PROCESSWRAP        = 1 << 7,
47     PROVIDER_REQWRAP            = 1 << 8,
48     PROVIDER_SHUTDOWNWRAP       = 1 << 9,
49     PROVIDER_SIGNALWRAP         = 1 << 10,
50     PROVIDER_STATWATCHER        = 1 << 11,
51     PROVIDER_TCPWRAP            = 1 << 12,
52     PROVIDER_TIMERWRAP          = 1 << 13,
53     PROVIDER_TLSWRAP            = 1 << 14,
54     PROVIDER_TTYWRAP            = 1 << 15,
55     PROVIDER_UDPWRAP            = 1 << 16,
56     PROVIDER_ZLIB               = 1 << 17
57   };
58
59   inline AsyncWrap(Environment* env,
60                    v8::Handle<v8::Object> object,
61                    ProviderType provider);
62
63   inline ~AsyncWrap();
64
65   inline bool has_async_listener();
66
67   inline uint32_t provider_type() const;
68
69   // Only call these within a valid HandleScope.
70   inline v8::Handle<v8::Value> MakeCallback(const v8::Handle<v8::Function> cb,
71                                             int argc,
72                                             v8::Handle<v8::Value>* argv);
73   inline v8::Handle<v8::Value> MakeCallback(const v8::Handle<v8::String> symbol,
74                                             int argc,
75                                             v8::Handle<v8::Value>* argv);
76   inline v8::Handle<v8::Value> MakeCallback(uint32_t index,
77                                             int argc,
78                                             v8::Handle<v8::Value>* argv);
79
80  private:
81   inline AsyncWrap();
82
83   // TODO(trevnorris): BURN IN FIRE! Remove this as soon as a suitable
84   // replacement is committed.
85   inline v8::Handle<v8::Value> MakeDomainCallback(
86       const v8::Handle<v8::Function> cb,
87       int argc,
88       v8::Handle<v8::Value>* argv);
89
90   uint32_t async_flags_;
91   uint32_t provider_type_;
92 };
93
94 }  // namespace node
95
96
97 #endif  // SRC_ASYNC_WRAP_H_