|
| 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 NODE_WRAP_H |
| 23 | +#define NODE_WRAP_H |
| 24 | + |
| 25 | +#include "pipe_wrap.h" |
| 26 | +#include "tty_wrap.h" |
| 27 | +#include "tcp_wrap.h" |
| 28 | +#include "udp_wrap.h" |
| 29 | + |
| 30 | +#include "v8.h" |
| 31 | +#include "uv.h" |
| 32 | + |
| 33 | +namespace node { |
| 34 | + |
| 35 | +extern v8::Persistent<v8::FunctionTemplate> pipeConstructorTmpl; |
| 36 | +extern v8::Persistent<v8::FunctionTemplate> ttyConstructorTmpl; |
| 37 | +extern v8::Persistent<v8::FunctionTemplate> tcpConstructorTmpl; |
| 38 | + |
| 39 | +#define WITH_GENERIC_STREAM(obj, BODY) \ |
| 40 | + do { \ |
| 41 | + if (!tcpConstructorTmpl.IsEmpty() && \ |
| 42 | + tcpConstructorTmpl->HasInstance(obj)) { \ |
| 43 | + PipeWrap* wrap = PipeWrap::Unwrap(obj); \ |
| 44 | + BODY \ |
| 45 | + } else if (!ttyConstructorTmpl.IsEmpty() && \ |
| 46 | + ttyConstructorTmpl->HasInstance(obj)) { \ |
| 47 | + TTYWrap* wrap = TTYWrap::Unwrap(obj); \ |
| 48 | + BODY \ |
| 49 | + } else if (!pipeConstructorTmpl.IsEmpty() && \ |
| 50 | + pipeConstructorTmpl->HasInstance(obj)) { \ |
| 51 | + TCPWrap* wrap = TCPWrap::Unwrap(obj); \ |
| 52 | + BODY \ |
| 53 | + } \ |
| 54 | + } while (0) |
| 55 | + |
| 56 | +inline uv_stream_t* HandleToStream(v8::Local<v8::Object> obj) { |
| 57 | + v8::HandleScope scope(node_isolate); |
| 58 | + |
| 59 | + WITH_GENERIC_STREAM(obj, { |
| 60 | + return reinterpret_cast<uv_stream_t*>(wrap->UVHandle()); |
| 61 | + }); |
| 62 | + |
| 63 | + return NULL; |
| 64 | +} |
| 65 | + |
| 66 | +} |
| 67 | + |
| 68 | +#endif |
0 commit comments