Skip to content
This repository
Newer
Older
100644 187 lines (136 sloc) 5.109 kb
60818b95 » ry
2011-11-02 Add missing copyright headers
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
ff4a9d38 » bnoordhuis
2012-03-10 core: use proper #include directives
22 #include "node.h"
23 #include "node_buffer.h"
24 #include "req_wrap.h"
25 #include "handle_wrap.h"
26 #include "stream_wrap.h"
af98fc9d » indutny
2012-05-16 child_process: new stdio API for .spawn() method
27 #include "tty_wrap.h"
c1ae6ea2 » ry
2011-09-20 Add TTYWrap
28
29 namespace node {
30
31 using v8::Object;
32 using v8::Handle;
33 using v8::Local;
34 using v8::Persistent;
35 using v8::Value;
36 using v8::HandleScope;
37 using v8::FunctionTemplate;
38 using v8::String;
39 using v8::Function;
40 using v8::TryCatch;
41 using v8::Context;
42 using v8::Arguments;
43 using v8::Integer;
44 using v8::Undefined;
45
46
af98fc9d » indutny
2012-05-16 child_process: new stdio API for .spawn() method
47 void TTYWrap::Initialize(Handle<Object> target) {
48 StreamWrap::Initialize(target);
c1ae6ea2 » ry
2011-09-20 Add TTYWrap
49
af98fc9d » indutny
2012-05-16 child_process: new stdio API for .spawn() method
50 HandleScope scope;
c1ae6ea2 » ry
2011-09-20 Add TTYWrap
51
af98fc9d » indutny
2012-05-16 child_process: new stdio API for .spawn() method
52 Local<FunctionTemplate> t = FunctionTemplate::New(New);
53 t->SetClassName(String::NewSymbol("TTY"));
c1ae6ea2 » ry
2011-09-20 Add TTYWrap
54
af98fc9d » indutny
2012-05-16 child_process: new stdio API for .spawn() method
55 t->InstanceTemplate()->SetInternalFieldCount(1);
c1ae6ea2 » ry
2011-09-20 Add TTYWrap
56
af98fc9d » indutny
2012-05-16 child_process: new stdio API for .spawn() method
57 NODE_SET_PROTOTYPE_METHOD(t, "close", HandleWrap::Close);
58 NODE_SET_PROTOTYPE_METHOD(t, "unref", HandleWrap::Unref);
0e57aafb » piscisaureus
2012-05-07 Optimize writing strings with Socket.write
59
af98fc9d » indutny
2012-05-16 child_process: new stdio API for .spawn() method
60 NODE_SET_PROTOTYPE_METHOD(t, "readStart", StreamWrap::ReadStart);
61 NODE_SET_PROTOTYPE_METHOD(t, "readStop", StreamWrap::ReadStop);
c1ae6ea2 » ry
2011-09-20 Add TTYWrap
62
af98fc9d » indutny
2012-05-16 child_process: new stdio API for .spawn() method
63 NODE_SET_PROTOTYPE_METHOD(t, "writeBuffer", StreamWrap::WriteBuffer);
64 NODE_SET_PROTOTYPE_METHOD(t, "writeAsciiString", StreamWrap::WriteAsciiString);
65 NODE_SET_PROTOTYPE_METHOD(t, "writeUtf8String", StreamWrap::WriteUtf8String);
66 NODE_SET_PROTOTYPE_METHOD(t, "writeUcs2String", StreamWrap::WriteUcs2String);
74b6426e » ry
2011-09-20 Initial pass at new TTY js layer
67
af98fc9d » indutny
2012-05-16 child_process: new stdio API for .spawn() method
68 NODE_SET_PROTOTYPE_METHOD(t, "getWindowSize", TTYWrap::GetWindowSize);
69 NODE_SET_PROTOTYPE_METHOD(t, "setRawMode", SetRawMode);
c1ae6ea2 » ry
2011-09-20 Add TTYWrap
70
af98fc9d » indutny
2012-05-16 child_process: new stdio API for .spawn() method
71 NODE_SET_METHOD(target, "isTTY", IsTTY);
72 NODE_SET_METHOD(target, "guessHandleType", GuessHandleType);
c1ae6ea2 » ry
2011-09-20 Add TTYWrap
73
af98fc9d » indutny
2012-05-16 child_process: new stdio API for .spawn() method
74 target->Set(String::NewSymbol("TTY"), t->GetFunction());
75 }
1de156ab » ry
2011-09-22 Bind/use uv_guess_handle
76
77
af98fc9d » indutny
2012-05-16 child_process: new stdio API for .spawn() method
78 TTYWrap* TTYWrap::Unwrap(Local<Object> obj) {
79 assert(!obj.IsEmpty());
80 assert(obj->InternalFieldCount() > 0);
81 return static_cast<TTYWrap*>(obj->GetPointerFromInternalField(0));
82 }
1de156ab » ry
2011-09-22 Bind/use uv_guess_handle
83
84
af98fc9d » indutny
2012-05-16 child_process: new stdio API for .spawn() method
85 uv_tty_t* TTYWrap::UVHandle() {
86 return &handle_;
87 }
1de156ab » ry
2011-09-22 Bind/use uv_guess_handle
88
89
af98fc9d » indutny
2012-05-16 child_process: new stdio API for .spawn() method
90 Handle<Value> TTYWrap::GuessHandleType(const Arguments& args) {
91 HandleScope scope;
92 int fd = args[0]->Int32Value();
93 assert(fd >= 0);
94
95 uv_handle_type t = uv_guess_handle(fd);
c1ae6ea2 » ry
2011-09-20 Add TTYWrap
96
af98fc9d » indutny
2012-05-16 child_process: new stdio API for .spawn() method
97 switch (t) {
98 case UV_TTY:
99 return scope.Close(String::New("TTY"));
189dd8f8 » piscisaureus
2011-11-04 Fix line endings and trailing whitespace
100
af98fc9d » indutny
2012-05-16 child_process: new stdio API for .spawn() method
101 case UV_NAMED_PIPE:
102 return scope.Close(String::New("PIPE"));
74b6426e » ry
2011-09-20 Initial pass at new TTY js layer
103
af98fc9d » indutny
2012-05-16 child_process: new stdio API for .spawn() method
104 case UV_FILE:
105 return scope.Close(String::New("FILE"));
74b6426e » ry
2011-09-20 Initial pass at new TTY js layer
106
3a6314db » bnoordhuis
2012-07-12 net: fix net.Server.listen({fd:x}) error reporting
107 case UV_UNKNOWN_HANDLE:
108 return scope.Close(String::New("UNKNOWN"));
109
af98fc9d » indutny
2012-05-16 child_process: new stdio API for .spawn() method
110 default:
111 assert(0);
74b6426e » ry
2011-09-20 Initial pass at new TTY js layer
112 return v8::Undefined();
af98fc9d » indutny
2012-05-16 child_process: new stdio API for .spawn() method
113 }
114 }
74b6426e » ry
2011-09-20 Initial pass at new TTY js layer
115
116
af98fc9d » indutny
2012-05-16 child_process: new stdio API for .spawn() method
117 Handle<Value> TTYWrap::IsTTY(const Arguments& args) {
118 HandleScope scope;
119 int fd = args[0]->Int32Value();
120 assert(fd >= 0);
121 return uv_guess_handle(fd) == UV_TTY ? v8::True() : v8::False();
122 }
74b6426e » ry
2011-09-20 Initial pass at new TTY js layer
123
124
af98fc9d » indutny
2012-05-16 child_process: new stdio API for .spawn() method
125 Handle<Value> TTYWrap::GetWindowSize(const Arguments& args) {
126 HandleScope scope;
74b6426e » ry
2011-09-20 Initial pass at new TTY js layer
127
af98fc9d » indutny
2012-05-16 child_process: new stdio API for .spawn() method
128 UNWRAP(TTYWrap)
74b6426e » ry
2011-09-20 Initial pass at new TTY js layer
129
af98fc9d » indutny
2012-05-16 child_process: new stdio API for .spawn() method
130 int width, height;
131 int r = uv_tty_get_winsize(&wrap->handle_, &width, &height);
74b6426e » ry
2011-09-20 Initial pass at new TTY js layer
132
af98fc9d » indutny
2012-05-16 child_process: new stdio API for .spawn() method
133 if (r) {
134 SetErrno(uv_last_error(uv_default_loop()));
135 return v8::Undefined();
74b6426e » ry
2011-09-20 Initial pass at new TTY js layer
136 }
137
af98fc9d » indutny
2012-05-16 child_process: new stdio API for .spawn() method
138 Local<v8::Array> a = v8::Array::New(2);
139 a->Set(0, Integer::New(width));
140 a->Set(1, Integer::New(height));
c1ae6ea2 » ry
2011-09-20 Add TTYWrap
141
af98fc9d » indutny
2012-05-16 child_process: new stdio API for .spawn() method
142 return scope.Close(a);
143 }
c1ae6ea2 » ry
2011-09-20 Add TTYWrap
144
145
af98fc9d » indutny
2012-05-16 child_process: new stdio API for .spawn() method
146 Handle<Value> TTYWrap::SetRawMode(const Arguments& args) {
147 HandleScope scope;
c1ae6ea2 » ry
2011-09-20 Add TTYWrap
148
af98fc9d » indutny
2012-05-16 child_process: new stdio API for .spawn() method
149 UNWRAP(TTYWrap)
150
151 int r = uv_tty_set_mode(&wrap->handle_, args[0]->IsTrue());
c1ae6ea2 » ry
2011-09-20 Add TTYWrap
152
af98fc9d » indutny
2012-05-16 child_process: new stdio API for .spawn() method
153 if (r) {
154 SetErrno(uv_last_error(uv_default_loop()));
c1ae6ea2 » ry
2011-09-20 Add TTYWrap
155 }
156
af98fc9d » indutny
2012-05-16 child_process: new stdio API for .spawn() method
157 return scope.Close(Integer::New(r));
158 }
159
160
161 Handle<Value> TTYWrap::New(const Arguments& args) {
162 HandleScope scope;
163
164 // This constructor should not be exposed to public javascript.
165 // Therefore we assert that we are not trying to call this as a
166 // normal function.
167 assert(args.IsConstructCall());
168
169 int fd = args[0]->Int32Value();
170 assert(fd >= 0);
171
172 TTYWrap* wrap = new TTYWrap(args.This(), fd, args[1]->IsTrue());
173 assert(wrap);
174 wrap->UpdateWriteQueueSize();
175
176 return scope.Close(args.This());
177 }
178
179
180 TTYWrap::TTYWrap(Handle<Object> object, int fd, bool readable)
181 : StreamWrap(object, (uv_stream_t*)&handle_) {
182 uv_tty_init(uv_default_loop(), &handle_, fd, readable);
183 }
c1ae6ea2 » ry
2011-09-20 Add TTYWrap
184
185 } // namespace node
186
cdcb1118 » bnoordhuis
2011-11-09 Remove stray NODE_MODULE() semi-colons.
187 NODE_MODULE(node_tty_wrap, node::TTYWrap::Initialize)
Something went wrong with that request. Please try again.