1 // Copyright Joyent, Inc. and other Node contributors.
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:
11 // The above copyright notice and this permission notice shall be included
12 // in all copies or substantial portions of the Software.
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.
22 #ifndef SRC_HANDLE_WRAP_H_
23 #define SRC_HANDLE_WRAP_H_
25 #include "async-wrap.h"
36 // - Do not throw from handle methods. Set errno.
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?)
42 // - No use of v8::WeakReferenceCallback. The close callback signifies that
43 // we're done with a handle - external resources can be freed.
47 // - The uv_close_cb is used to free the c++ object. The close callback
48 // is not made into javascript land.
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
54 class HandleWrap : public AsyncWrap {
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);
60 inline uv_handle_t* GetHandle() { return handle__; }
63 HandleWrap(Environment* env,
64 v8::Handle<v8::Object> object,
66 AsyncWrap::ProviderType provider);
67 virtual ~HandleWrap();
70 friend void GetActiveHandles(const v8::FunctionCallbackInfo<v8::Value>&);
71 static void OnClose(uv_handle_t* handle);
72 QUEUE handle_wrap_queue_;
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__;
78 static const unsigned int kUnref = 1;
79 static const unsigned int kCloseCallback = 2;
86 #endif // SRC_HANDLE_WRAP_H_