src: deduplicate CHECK_EQ/CHECK_NE macros
[platform/upstream/nodejs.git] / src / handle_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_HANDLE_WRAP_H_
23 #define SRC_HANDLE_WRAP_H_
24
25 #include "async-wrap.h"
26 #include "env.h"
27 #include "node.h"
28 #include "queue.h"
29 #include "uv.h"
30 #include "v8.h"
31
32 namespace node {
33
34 // Rules:
35 //
36 // - Do not throw from handle methods. Set errno.
37 //
38 // - MakeCallback may only be made directly off the event loop.
39 //   That is there can be no JavaScript stack frames underneath it.
40 //   (Is there any way to assert that?)
41 //
42 // - No use of v8::WeakReferenceCallback. The close callback signifies that
43 //   we're done with a handle - external resources can be freed.
44 //
45 // - Reusable?
46 //
47 // - The uv_close_cb is used to free the c++ object. The close callback
48 //   is not made into javascript land.
49 //
50 // - uv_ref, uv_unref counts are managed at this layer to avoid needless
51 //   js/c++ boundary crossing. At the javascript layer that should all be
52 //   taken care of.
53
54 class HandleWrap : public AsyncWrap {
55  public:
56   static void Close(const v8::FunctionCallbackInfo<v8::Value>& args);
57   static void Ref(const v8::FunctionCallbackInfo<v8::Value>& args);
58   static void Unref(const v8::FunctionCallbackInfo<v8::Value>& args);
59
60   inline uv_handle_t* GetHandle() { return handle__; }
61
62  protected:
63   HandleWrap(Environment* env,
64              v8::Handle<v8::Object> object,
65              uv_handle_t* handle,
66              AsyncWrap::ProviderType provider);
67   virtual ~HandleWrap();
68
69  private:
70   friend void GetActiveHandles(const v8::FunctionCallbackInfo<v8::Value>&);
71   static void OnClose(uv_handle_t* handle);
72   QUEUE handle_wrap_queue_;
73   unsigned int flags_;
74   // Using double underscore due to handle_ member in tcp_wrap. Probably
75   // tcp_wrap should rename it's member to 'handle'.
76   uv_handle_t* handle__;
77
78   static const unsigned int kUnref = 1;
79   static const unsigned int kCloseCallback = 2;
80 };
81
82
83 }  // namespace node
84
85
86 #endif  // SRC_HANDLE_WRAP_H_