diff --git a/src/file.cc b/src/file.cc index 90a914ffb..3ff5a9883 100644 --- a/src/file.cc +++ b/src/file.cc @@ -1,7 +1,5 @@ -#include "node.h" -#include "file.h" -#include "events.h" -#include +// Copyright 2009 Ryan Dahl +#include #include #include @@ -9,9 +7,11 @@ #include #include #include +#include + +namespace node { using namespace v8; -using namespace node; #define DEV_SYMBOL String::NewSymbol("dev") #define INO_SYMBOL String::NewSymbol("ino") @@ -28,21 +28,17 @@ using namespace node; #define CTIME_SYMBOL String::NewSymbol("ctime") #define BAD_ARGUMENTS Exception::TypeError(String::New("Bad argument")) -void -EIOPromise::Attach (void) -{ +void EIOPromise::Attach(void) { ev_ref(EV_DEFAULT_UC); Promise::Attach(); } -void -EIOPromise::Detach (void) -{ +void EIOPromise::Detach(void) { Promise::Detach(); ev_unref(EV_DEFAULT_UC); } -Handle EIOPromise::New (const v8::Arguments& args) { +Handle EIOPromise::New(const v8::Arguments& args) { HandleScope scope; EIOPromise *promise = new EIOPromise(); @@ -64,9 +60,7 @@ EIOPromise* EIOPromise::Create() { static Persistent stats_constructor_template; -static Local -BuildStatsObject (struct stat * s) -{ +static Local BuildStatsObject(struct stat * s) { HandleScope scope; Local stats = @@ -114,9 +108,7 @@ BuildStatsObject (struct stat * s) return scope.Close(stats); } -int -EIOPromise::After (eio_req *req) -{ +int EIOPromise::After(eio_req *req) { HandleScope scope; EIOPromise *promise = reinterpret_cast(req->data); @@ -202,9 +194,7 @@ EIOPromise::After (eio_req *req) return 0; } -static Handle -Close (const Arguments& args) -{ +static Handle Close(const Arguments& args) { HandleScope scope; if (args.Length() < 1 || !args[0]->IsInt32()) { @@ -216,9 +206,7 @@ Close (const Arguments& args) return scope.Close(EIOPromise::Close(fd)); } -static Handle -Stat (const Arguments& args) -{ +static Handle Stat(const Arguments& args) { HandleScope scope; if (args.Length() < 1 || !args[0]->IsString()) { @@ -230,9 +218,7 @@ Stat (const Arguments& args) return scope.Close(EIOPromise::Stat(*path)); } -static Handle -Rename (const Arguments& args) -{ +static Handle Rename(const Arguments& args) { HandleScope scope; if (args.Length() < 2 || !args[0]->IsString() || !args[1]->IsString()) { @@ -248,8 +234,7 @@ Rename (const Arguments& args) return scope.Close(promise->Handle()); } -static Handle Unlink (const Arguments& args) -{ +static Handle Unlink(const Arguments& args) { HandleScope scope; if (args.Length() < 1 || !args[0]->IsString()) { @@ -260,9 +245,7 @@ static Handle Unlink (const Arguments& args) return scope.Close(EIOPromise::Unlink(*path)); } -static Handle -RMDir (const Arguments& args) -{ +static Handle RMDir(const Arguments& args) { HandleScope scope; if (args.Length() < 1 || !args[0]->IsString()) { @@ -273,9 +256,7 @@ RMDir (const Arguments& args) return scope.Close(EIOPromise::RMDir(*path)); } -static Handle -MKDir (const Arguments& args) -{ +static Handle MKDir(const Arguments& args) { HandleScope scope; if (args.Length() < 2 || !args[0]->IsString() || !args[1]->IsInt32()) { @@ -288,9 +269,7 @@ MKDir (const Arguments& args) return scope.Close(EIOPromise::MKDir(*path, mode)); } -static Handle -ReadDir (const Arguments& args) -{ +static Handle ReadDir(const Arguments& args) { HandleScope scope; if (args.Length() < 1 || !args[0]->IsString()) { @@ -301,9 +280,7 @@ ReadDir (const Arguments& args) return scope.Close(EIOPromise::ReadDir(*path)); } -static Handle -Open (const Arguments& args) -{ +static Handle Open(const Arguments& args) { HandleScope scope; if ( args.Length() < 3 @@ -328,9 +305,7 @@ Open (const Arguments& args) * if null, write from the current position * 3 encoding */ -static Handle -Write (const Arguments& args) -{ +static Handle Write(const Arguments& args) { HandleScope scope; if (args.Length() < 2 || !args[0]->IsInt32()) { @@ -363,9 +338,7 @@ Write (const Arguments& args) * if null, read from the current position * 3 encoding */ -static Handle -Read (const Arguments& args) -{ +static Handle Read(const Arguments& args) { HandleScope scope; if (args.Length() < 2 || !args[0]->IsInt32() || !args[1]->IsNumber()) { @@ -383,9 +356,7 @@ Read (const Arguments& args) Persistent EIOPromise::constructor_template; -void -File::Initialize (Handle target) -{ +void File::Initialize(Handle target) { HandleScope scope; NODE_SET_METHOD(target, "close", Close); @@ -414,3 +385,5 @@ File::Initialize (Handle target) target->Set(String::NewSymbol("EIOPromise"), EIOPromise::constructor_template->GetFunction()); } + +} // end namespace node diff --git a/src/file.h b/src/file.h index 28ec20102..d37429363 100644 --- a/src/file.h +++ b/src/file.h @@ -1,8 +1,9 @@ -#ifndef node_file_h -#define node_file_h +// Copyright 2009 Ryan Dahl +#ifndef SRC_FILE_H_ +#define SRC_FILE_H_ -#include "node.h" -#include "events.h" +#include +#include #include namespace node { @@ -18,11 +19,11 @@ namespace node { */ #define NODE_V8_METHOD_DECLARE(name) \ - static v8::Handle name (const v8::Arguments& args) + static v8::Handle name(const v8::Arguments& args) class File { -public: - static void Initialize (v8::Handle target); + public: + static void Initialize(v8::Handle target); }; class EIOPromise : public Promise { @@ -31,33 +32,31 @@ class EIOPromise : public Promise { static v8::Persistent constructor_template; static v8::Handle New(const v8::Arguments& args); - static v8::Handle - Open (const char *path, int flags, mode_t mode) - { + static v8::Handle Open(const char *path, int flags, mode_t mode) { EIOPromise *p = Create(); p->req_ = eio_open(path, flags, mode, EIO_PRI_DEFAULT, After, p); return p->handle_; } - static v8::Handle - Close (int fd) - { + static v8::Handle Close(int fd) { EIOPromise *p = Create(); p->req_ = eio_close(fd, EIO_PRI_DEFAULT, After, p); return p->handle_; } - static v8::Handle - Write (int fd, void *buf, size_t count, off_t offset) - { + static v8::Handle Write(int fd, + void *buf, + size_t count, + off_t offset) { EIOPromise *p = Create(); p->req_ = eio_write(fd, buf, count, offset, EIO_PRI_DEFAULT, After, p); return p->handle_; } - static v8::Handle - Read (int fd, size_t count, off_t offset, enum encoding encoding) - { + static v8::Handle Read(int fd, + size_t count, + off_t offset, + enum encoding encoding) { EIOPromise *p = Create(); p->encoding_ = encoding; // NOTE: 2nd param: NULL pointer tells eio to allocate it itself @@ -65,49 +64,37 @@ class EIOPromise : public Promise { return p->handle_; } - static v8::Handle - Stat (const char *path) - { + static v8::Handle Stat(const char *path) { EIOPromise *p = Create(); p->req_ = eio_stat(path, EIO_PRI_DEFAULT, After, p); return p->handle_; } - static v8::Handle - Rename (const char *path, const char *new_path) - { + static v8::Handle Rename(const char *path, const char *new_path) { EIOPromise *p = Create(); p->req_ = eio_rename(path, new_path, EIO_PRI_DEFAULT, After, p); return p->handle_; } - static v8::Handle - Unlink (const char *path) - { + static v8::Handle Unlink(const char *path) { EIOPromise *p = Create(); p->req_ = eio_unlink(path, EIO_PRI_DEFAULT, After, p); return p->handle_; } - static v8::Handle - RMDir (const char *path) - { + static v8::Handle RMDir(const char *path) { EIOPromise *p = Create(); p->req_ = eio_rmdir(path, EIO_PRI_DEFAULT, After, p); return p->handle_; } - static v8::Handle - MKDir (const char *path, mode_t mode) - { + static v8::Handle MKDir(const char *path, mode_t mode) { EIOPromise *p = Create(); p->req_ = eio_mkdir(path, mode, EIO_PRI_DEFAULT, After, p); return p->handle_; } - static v8::Handle - ReadDir (const char *path) - { + static v8::Handle ReadDir(const char *path) { EIOPromise *p = Create(); // By using EIO_READDIR_DENTS (or other flags), more complex results can // be had from eio_readdir. Doesn't seem that we need that though. @@ -117,18 +104,18 @@ class EIOPromise : public Promise { protected: - void Attach (); - void Detach (); + void Attach(); + void Detach(); - EIOPromise () : Promise() { } + EIOPromise() : Promise() { } private: - static int After (eio_req *req); + static int After(eio_req *req); eio_req *req_; enum encoding encoding_; }; -} // namespace node -#endif // node_file_h +} // namespace node +#endif // SRC_FILE_H_