11#include " node.h"
2- #include " process .h"
2+ #include " child_process .h"
33
44#include < assert.h>
55#include < stdlib.h>
@@ -13,65 +13,65 @@ using namespace node;
1313
1414#define PID_SYMBOL String::NewSymbol (" pid" )
1515
16- Persistent<FunctionTemplate> Process ::constructor_template;
16+ Persistent<FunctionTemplate> ChildProcess ::constructor_template;
1717
1818void
19- Process ::Initialize (Handle<Object> target)
19+ ChildProcess ::Initialize (Handle<Object> target)
2020{
2121 HandleScope scope;
2222
23- Local<FunctionTemplate> t = FunctionTemplate::New (Process ::New);
23+ Local<FunctionTemplate> t = FunctionTemplate::New (ChildProcess ::New);
2424 constructor_template = Persistent<FunctionTemplate>::New (t);
2525 constructor_template->Inherit (EventEmitter::constructor_template);
2626 constructor_template->InstanceTemplate ()->SetInternalFieldCount (1 );
2727
28- NODE_SET_PROTOTYPE_METHOD (constructor_template, " spawn" , Process ::Spawn);
29- NODE_SET_PROTOTYPE_METHOD (constructor_template, " write" , Process ::Write);
30- NODE_SET_PROTOTYPE_METHOD (constructor_template, " close" , Process ::Close);
31- NODE_SET_PROTOTYPE_METHOD (constructor_template, " kill" , Process ::Kill);
28+ NODE_SET_PROTOTYPE_METHOD (constructor_template, " spawn" , ChildProcess ::Spawn);
29+ NODE_SET_PROTOTYPE_METHOD (constructor_template, " write" , ChildProcess ::Write);
30+ NODE_SET_PROTOTYPE_METHOD (constructor_template, " close" , ChildProcess ::Close);
31+ NODE_SET_PROTOTYPE_METHOD (constructor_template, " kill" , ChildProcess ::Kill);
3232
33- target->Set (String::NewSymbol (" Process " ), constructor_template->GetFunction ());
33+ target->Set (String::NewSymbol (" ChildProcess " ), constructor_template->GetFunction ());
3434}
3535
3636Handle<Value>
37- Process ::New (const Arguments& args)
37+ ChildProcess ::New (const Arguments& args)
3838{
3939 HandleScope scope;
4040
41- Process *p = new Process ();
41+ ChildProcess *p = new ChildProcess ();
4242 p->Wrap (args.Holder ());
4343
4444 return args.This ();
4545}
4646
4747Handle<Value>
48- Process ::Spawn (const Arguments& args)
48+ ChildProcess ::Spawn (const Arguments& args)
4949{
5050 if (args.Length () == 0 || !args[0 ]->IsString ()) {
5151 return ThrowException (String::New (" Bad argument." ));
5252 }
5353
5454 HandleScope scope;
55- Process *process = ObjectWrap::Unwrap<Process >(args.Holder ());
55+ ChildProcess *child = ObjectWrap::Unwrap<ChildProcess >(args.Holder ());
5656
5757 String::Utf8Value command (args[0 ]->ToString ());
5858
59- int r = process ->Spawn (*command);
59+ int r = child ->Spawn (*command);
6060 if (r != 0 ) {
6161 return ThrowException (String::New (" Error spawning" ));
6262 }
6363
64- process ->handle_ ->Set (PID_SYMBOL, Integer::New (process ->pid_ ));
64+ child ->handle_ ->Set (PID_SYMBOL, Integer::New (child ->pid_ ));
6565
6666 return Undefined ();
6767}
6868
6969Handle<Value>
70- Process ::Write (const Arguments& args)
70+ ChildProcess ::Write (const Arguments& args)
7171{
7272 HandleScope scope;
73- Process *process = ObjectWrap::Unwrap<Process >(args.Holder ());
74- assert (process );
73+ ChildProcess *child = ObjectWrap::Unwrap<ChildProcess >(args.Holder ());
74+ assert (child );
7575
7676 ssize_t len;
7777
@@ -109,69 +109,69 @@ Process::Write (const Arguments& args)
109109 }
110110 }
111111
112- return process ->Write (buf, len) == 0 ? True () : False ();
112+ return child ->Write (buf, len) == 0 ? True () : False ();
113113}
114114
115115Handle<Value>
116- Process ::Kill (const Arguments& args)
116+ ChildProcess ::Kill (const Arguments& args)
117117{
118118 HandleScope scope;
119- Process *process = ObjectWrap::Unwrap<Process >(args.Holder ());
120- assert (process );
119+ ChildProcess *child = ObjectWrap::Unwrap<ChildProcess >(args.Holder ());
120+ assert (child );
121121
122122 int sig = SIGTERM;
123123 if (args[0 ]->IsInt32 ()) sig = args[0 ]->Int32Value ();
124124
125- if (process ->Kill (sig) != 0 ) {
126- return ThrowException (String::New (" Process already dead" ));
125+ if (child ->Kill (sig) != 0 ) {
126+ return ThrowException (String::New (" ChildProcess already dead" ));
127127 }
128128
129129 return Undefined ();
130130}
131131
132132Handle<Value>
133- Process ::Close (const Arguments& args)
133+ ChildProcess ::Close (const Arguments& args)
134134{
135135 HandleScope scope;
136- Process *process = ObjectWrap::Unwrap<Process >(args.Holder ());
137- assert (process );
138- return process ->Close () == 0 ? True () : False ();
136+ ChildProcess *child = ObjectWrap::Unwrap<ChildProcess >(args.Holder ());
137+ assert (child );
138+ return child ->Close () == 0 ? True () : False ();
139139}
140140
141141void
142- Process ::reader_closed (evcom_reader *r)
142+ ChildProcess ::reader_closed (evcom_reader *r)
143143{
144- Process *process = static_cast <Process *> (r->data );
145- if (r == &process ->stdout_reader_ ) {
146- process ->stdout_fd_ = -1 ;
144+ ChildProcess *child = static_cast <ChildProcess *> (r->data );
145+ if (r == &child ->stdout_reader_ ) {
146+ child ->stdout_fd_ = -1 ;
147147 } else {
148- assert (r == &process ->stderr_reader_ );
149- process ->stderr_fd_ = -1 ;
148+ assert (r == &child ->stderr_reader_ );
149+ child ->stderr_fd_ = -1 ;
150150 }
151151 evcom_reader_detach (r);
152- process ->MaybeShutdown ();
152+ child ->MaybeShutdown ();
153153}
154154
155155void
156- Process ::stdin_closed (evcom_writer *w)
156+ ChildProcess ::stdin_closed (evcom_writer *w)
157157{
158- Process *process = static_cast <Process *> (w->data );
159- assert (w == &process ->stdin_writer_ );
160- process ->stdin_fd_ = -1 ;
158+ ChildProcess *child = static_cast <ChildProcess *> (w->data );
159+ assert (w == &child ->stdin_writer_ );
160+ child ->stdin_fd_ = -1 ;
161161 evcom_writer_detach (w);
162- process ->MaybeShutdown ();
162+ child ->MaybeShutdown ();
163163}
164164
165165void
166- Process ::on_read (evcom_reader *r, const void *buf, size_t len)
166+ ChildProcess ::on_read (evcom_reader *r, const void *buf, size_t len)
167167{
168- Process *process = static_cast <Process *> (r->data );
168+ ChildProcess *child = static_cast <ChildProcess *> (r->data );
169169 HandleScope scope;
170170
171- bool isSTDOUT = (r == &process ->stdout_reader_ );
171+ bool isSTDOUT = (r == &child ->stdout_reader_ );
172172 Local<Value> argv[1 ];
173173
174- enum encoding encoding = isSTDOUT ? process ->stdout_encoding_ : process ->stderr_encoding_ ;
174+ enum encoding encoding = isSTDOUT ? child ->stdout_encoding_ : child ->stderr_encoding_ ;
175175
176176 if (len == 0 ) {
177177 argv[0 ] = Local<Value>::New (Null ());
@@ -190,11 +190,11 @@ Process::on_read (evcom_reader *r, const void *buf, size_t len)
190190 argv[0 ] = String::New ((const char *)buf, len);
191191 }
192192
193- process ->Emit (isSTDOUT ? " output" : " error" , 1 , argv);
194- process ->MaybeShutdown ();
193+ child ->Emit (isSTDOUT ? " output" : " error" , 1 , argv);
194+ child ->MaybeShutdown ();
195195}
196196
197- Process::Process ()
197+ ChildProcess::ChildProcess ()
198198 : EventEmitter()
199199{
200200 evcom_reader_init (&stdout_reader_);
@@ -211,7 +211,7 @@ Process::Process ()
211211 stdin_writer_.data = this ;
212212 stdin_writer_.on_close = stdin_closed;
213213
214- ev_init (&child_watcher_, Process ::OnCHLD);
214+ ev_init (&child_watcher_, ChildProcess ::OnCHLD);
215215 child_watcher_.data = this ;
216216
217217 stdout_fd_ = -1 ;
@@ -227,13 +227,13 @@ Process::Process ()
227227 pid_ = 0 ;
228228}
229229
230- Process ::~Process ()
230+ ChildProcess ::~ChildProcess ()
231231{
232232 Shutdown ();
233233}
234234
235235void
236- Process ::Shutdown ()
236+ ChildProcess ::Shutdown ()
237237{
238238 if (stdin_fd_ >= 0 ) {
239239 evcom_writer_close (&stdin_writer_);
@@ -269,7 +269,7 @@ SetNonBlocking (int fd)
269269}
270270
271271int
272- Process ::Spawn (const char *command)
272+ ChildProcess ::Spawn (const char *command)
273273{
274274 assert (pid_ == 0 );
275275 assert (stdout_fd_ == -1 );
@@ -345,48 +345,48 @@ Process::Spawn (const char *command)
345345}
346346
347347void
348- Process ::OnCHLD (EV_P_ ev_child *watcher, int revents)
348+ ChildProcess ::OnCHLD (EV_P_ ev_child *watcher, int revents)
349349{
350350 ev_child_stop (EV_A_ watcher);
351- Process *process = static_cast <Process *>(watcher->data );
351+ ChildProcess *child = static_cast <ChildProcess *>(watcher->data );
352352
353353 assert (revents == EV_CHILD);
354- assert (process ->pid_ == watcher->rpid );
355- assert (&process ->child_watcher_ == watcher);
354+ assert (child ->pid_ == watcher->rpid );
355+ assert (&child ->child_watcher_ == watcher);
356356
357- process ->got_chld_ = true ;
358- process ->exit_code_ = watcher->rstatus ;
357+ child ->got_chld_ = true ;
358+ child ->exit_code_ = watcher->rstatus ;
359359
360- if (process ->stdin_fd_ >= 0 ) evcom_writer_close (&process ->stdin_writer_ );
360+ if (child ->stdin_fd_ >= 0 ) evcom_writer_close (&child ->stdin_writer_ );
361361
362- process ->MaybeShutdown ();
362+ child ->MaybeShutdown ();
363363}
364364
365365int
366- Process ::Write (const char *str, size_t len)
366+ ChildProcess ::Write (const char *str, size_t len)
367367{
368368 if (stdin_fd_ < 0 || got_chld_) return -1 ;
369369 evcom_writer_write (&stdin_writer_, str, len);
370370 return 0 ;
371371}
372372
373373int
374- Process ::Close (void )
374+ ChildProcess ::Close (void )
375375{
376376 if (stdin_fd_ < 0 || got_chld_) return -1 ;
377377 evcom_writer_close (EV_DEFAULT_UC_ &stdin_writer_);
378378 return 0 ;
379379}
380380
381381int
382- Process ::Kill (int sig)
382+ ChildProcess ::Kill (int sig)
383383{
384384 if (got_chld_ || pid_ == 0 ) return -1 ;
385385 return kill (pid_, sig);
386386}
387387
388388void
389- Process ::MaybeShutdown (void )
389+ ChildProcess ::MaybeShutdown (void )
390390{
391391 if (stdout_fd_ < 0 && stderr_fd_ < 0 && got_chld_) {
392392 HandleScope scope;
0 commit comments