Browse Source

cpplint.js file.{cc,h}

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
8a5194b7cf
  1. 73
      src/file.cc
  2. 71
      src/file.h

73
src/file.cc

@ -1,7 +1,5 @@
#include "node.h" // Copyright 2009 Ryan Dahl <ry@tinyclouds.org>
#include "file.h" #include <file.h>
#include "events.h"
#include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -9,9 +7,11 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <assert.h> #include <assert.h>
#include <string.h>
namespace node {
using namespace v8; using namespace v8;
using namespace node;
#define DEV_SYMBOL String::NewSymbol("dev") #define DEV_SYMBOL String::NewSymbol("dev")
#define INO_SYMBOL String::NewSymbol("ino") #define INO_SYMBOL String::NewSymbol("ino")
@ -28,21 +28,17 @@ using namespace node;
#define CTIME_SYMBOL String::NewSymbol("ctime") #define CTIME_SYMBOL String::NewSymbol("ctime")
#define BAD_ARGUMENTS Exception::TypeError(String::New("Bad argument")) #define BAD_ARGUMENTS Exception::TypeError(String::New("Bad argument"))
void void EIOPromise::Attach(void) {
EIOPromise::Attach (void)
{
ev_ref(EV_DEFAULT_UC); ev_ref(EV_DEFAULT_UC);
Promise::Attach(); Promise::Attach();
} }
void void EIOPromise::Detach(void) {
EIOPromise::Detach (void)
{
Promise::Detach(); Promise::Detach();
ev_unref(EV_DEFAULT_UC); ev_unref(EV_DEFAULT_UC);
} }
Handle<Value> EIOPromise::New (const v8::Arguments& args) { Handle<Value> EIOPromise::New(const v8::Arguments& args) {
HandleScope scope; HandleScope scope;
EIOPromise *promise = new EIOPromise(); EIOPromise *promise = new EIOPromise();
@ -64,9 +60,7 @@ EIOPromise* EIOPromise::Create() {
static Persistent<FunctionTemplate> stats_constructor_template; static Persistent<FunctionTemplate> stats_constructor_template;
static Local<Object> static Local<Object> BuildStatsObject(struct stat * s) {
BuildStatsObject (struct stat * s)
{
HandleScope scope; HandleScope scope;
Local<Object> stats = Local<Object> stats =
@ -114,9 +108,7 @@ BuildStatsObject (struct stat * s)
return scope.Close(stats); return scope.Close(stats);
} }
int int EIOPromise::After(eio_req *req) {
EIOPromise::After (eio_req *req)
{
HandleScope scope; HandleScope scope;
EIOPromise *promise = reinterpret_cast<EIOPromise*>(req->data); EIOPromise *promise = reinterpret_cast<EIOPromise*>(req->data);
@ -202,9 +194,7 @@ EIOPromise::After (eio_req *req)
return 0; return 0;
} }
static Handle<Value> static Handle<Value> Close(const Arguments& args) {
Close (const Arguments& args)
{
HandleScope scope; HandleScope scope;
if (args.Length() < 1 || !args[0]->IsInt32()) { if (args.Length() < 1 || !args[0]->IsInt32()) {
@ -216,9 +206,7 @@ Close (const Arguments& args)
return scope.Close(EIOPromise::Close(fd)); return scope.Close(EIOPromise::Close(fd));
} }
static Handle<Value> static Handle<Value> Stat(const Arguments& args) {
Stat (const Arguments& args)
{
HandleScope scope; HandleScope scope;
if (args.Length() < 1 || !args[0]->IsString()) { if (args.Length() < 1 || !args[0]->IsString()) {
@ -230,9 +218,7 @@ Stat (const Arguments& args)
return scope.Close(EIOPromise::Stat(*path)); return scope.Close(EIOPromise::Stat(*path));
} }
static Handle<Value> static Handle<Value> Rename(const Arguments& args) {
Rename (const Arguments& args)
{
HandleScope scope; HandleScope scope;
if (args.Length() < 2 || !args[0]->IsString() || !args[1]->IsString()) { if (args.Length() < 2 || !args[0]->IsString() || !args[1]->IsString()) {
@ -248,8 +234,7 @@ Rename (const Arguments& args)
return scope.Close(promise->Handle()); return scope.Close(promise->Handle());
} }
static Handle<Value> Unlink (const Arguments& args) static Handle<Value> Unlink(const Arguments& args) {
{
HandleScope scope; HandleScope scope;
if (args.Length() < 1 || !args[0]->IsString()) { if (args.Length() < 1 || !args[0]->IsString()) {
@ -260,9 +245,7 @@ static Handle<Value> Unlink (const Arguments& args)
return scope.Close(EIOPromise::Unlink(*path)); return scope.Close(EIOPromise::Unlink(*path));
} }
static Handle<Value> static Handle<Value> RMDir(const Arguments& args) {
RMDir (const Arguments& args)
{
HandleScope scope; HandleScope scope;
if (args.Length() < 1 || !args[0]->IsString()) { if (args.Length() < 1 || !args[0]->IsString()) {
@ -273,9 +256,7 @@ RMDir (const Arguments& args)
return scope.Close(EIOPromise::RMDir(*path)); return scope.Close(EIOPromise::RMDir(*path));
} }
static Handle<Value> static Handle<Value> MKDir(const Arguments& args) {
MKDir (const Arguments& args)
{
HandleScope scope; HandleScope scope;
if (args.Length() < 2 || !args[0]->IsString() || !args[1]->IsInt32()) { 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)); return scope.Close(EIOPromise::MKDir(*path, mode));
} }
static Handle<Value> static Handle<Value> ReadDir(const Arguments& args) {
ReadDir (const Arguments& args)
{
HandleScope scope; HandleScope scope;
if (args.Length() < 1 || !args[0]->IsString()) { if (args.Length() < 1 || !args[0]->IsString()) {
@ -301,9 +280,7 @@ ReadDir (const Arguments& args)
return scope.Close(EIOPromise::ReadDir(*path)); return scope.Close(EIOPromise::ReadDir(*path));
} }
static Handle<Value> static Handle<Value> Open(const Arguments& args) {
Open (const Arguments& args)
{
HandleScope scope; HandleScope scope;
if ( args.Length() < 3 if ( args.Length() < 3
@ -328,9 +305,7 @@ Open (const Arguments& args)
* if null, write from the current position * if null, write from the current position
* 3 encoding * 3 encoding
*/ */
static Handle<Value> static Handle<Value> Write(const Arguments& args) {
Write (const Arguments& args)
{
HandleScope scope; HandleScope scope;
if (args.Length() < 2 || !args[0]->IsInt32()) { if (args.Length() < 2 || !args[0]->IsInt32()) {
@ -363,9 +338,7 @@ Write (const Arguments& args)
* if null, read from the current position * if null, read from the current position
* 3 encoding * 3 encoding
*/ */
static Handle<Value> static Handle<Value> Read(const Arguments& args) {
Read (const Arguments& args)
{
HandleScope scope; HandleScope scope;
if (args.Length() < 2 || !args[0]->IsInt32() || !args[1]->IsNumber()) { if (args.Length() < 2 || !args[0]->IsInt32() || !args[1]->IsNumber()) {
@ -383,9 +356,7 @@ Read (const Arguments& args)
Persistent<FunctionTemplate> EIOPromise::constructor_template; Persistent<FunctionTemplate> EIOPromise::constructor_template;
void void File::Initialize(Handle<Object> target) {
File::Initialize (Handle<Object> target)
{
HandleScope scope; HandleScope scope;
NODE_SET_METHOD(target, "close", Close); NODE_SET_METHOD(target, "close", Close);
@ -414,3 +385,5 @@ File::Initialize (Handle<Object> target)
target->Set(String::NewSymbol("EIOPromise"), target->Set(String::NewSymbol("EIOPromise"),
EIOPromise::constructor_template->GetFunction()); EIOPromise::constructor_template->GetFunction());
} }
} // end namespace node

71
src/file.h

@ -1,8 +1,9 @@
#ifndef node_file_h // Copyright 2009 Ryan Dahl <ry@tinyclouds.org>
#define node_file_h #ifndef SRC_FILE_H_
#define SRC_FILE_H_
#include "node.h" #include <node.h>
#include "events.h" #include <events.h>
#include <v8.h> #include <v8.h>
namespace node { namespace node {
@ -18,11 +19,11 @@ namespace node {
*/ */
#define NODE_V8_METHOD_DECLARE(name) \ #define NODE_V8_METHOD_DECLARE(name) \
static v8::Handle<v8::Value> name (const v8::Arguments& args) static v8::Handle<v8::Value> name(const v8::Arguments& args)
class File { class File {
public: public:
static void Initialize (v8::Handle<v8::Object> target); static void Initialize(v8::Handle<v8::Object> target);
}; };
class EIOPromise : public Promise { class EIOPromise : public Promise {
@ -31,33 +32,31 @@ class EIOPromise : public Promise {
static v8::Persistent<v8::FunctionTemplate> constructor_template; static v8::Persistent<v8::FunctionTemplate> constructor_template;
static v8::Handle<v8::Value> New(const v8::Arguments& args); static v8::Handle<v8::Value> New(const v8::Arguments& args);
static v8::Handle<v8::Object> static v8::Handle<v8::Object> Open(const char *path, int flags, mode_t mode) {
Open (const char *path, int flags, mode_t mode)
{
EIOPromise *p = Create(); EIOPromise *p = Create();
p->req_ = eio_open(path, flags, mode, EIO_PRI_DEFAULT, After, p); p->req_ = eio_open(path, flags, mode, EIO_PRI_DEFAULT, After, p);
return p->handle_; return p->handle_;
} }
static v8::Handle<v8::Object> static v8::Handle<v8::Object> Close(int fd) {
Close (int fd)
{
EIOPromise *p = Create(); EIOPromise *p = Create();
p->req_ = eio_close(fd, EIO_PRI_DEFAULT, After, p); p->req_ = eio_close(fd, EIO_PRI_DEFAULT, After, p);
return p->handle_; return p->handle_;
} }
static v8::Handle<v8::Object> static v8::Handle<v8::Object> Write(int fd,
Write (int fd, void *buf, size_t count, off_t offset) void *buf,
{ size_t count,
off_t offset) {
EIOPromise *p = Create(); EIOPromise *p = Create();
p->req_ = eio_write(fd, buf, count, offset, EIO_PRI_DEFAULT, After, p); p->req_ = eio_write(fd, buf, count, offset, EIO_PRI_DEFAULT, After, p);
return p->handle_; return p->handle_;
} }
static v8::Handle<v8::Object> static v8::Handle<v8::Object> Read(int fd,
Read (int fd, size_t count, off_t offset, enum encoding encoding) size_t count,
{ off_t offset,
enum encoding encoding) {
EIOPromise *p = Create(); EIOPromise *p = Create();
p->encoding_ = encoding; p->encoding_ = encoding;
// NOTE: 2nd param: NULL pointer tells eio to allocate it itself // NOTE: 2nd param: NULL pointer tells eio to allocate it itself
@ -65,49 +64,37 @@ class EIOPromise : public Promise {
return p->handle_; return p->handle_;
} }
static v8::Handle<v8::Object> static v8::Handle<v8::Object> Stat(const char *path) {
Stat (const char *path)
{
EIOPromise *p = Create(); EIOPromise *p = Create();
p->req_ = eio_stat(path, EIO_PRI_DEFAULT, After, p); p->req_ = eio_stat(path, EIO_PRI_DEFAULT, After, p);
return p->handle_; return p->handle_;
} }
static v8::Handle<v8::Object> static v8::Handle<v8::Object> Rename(const char *path, const char *new_path) {
Rename (const char *path, const char *new_path)
{
EIOPromise *p = Create(); EIOPromise *p = Create();
p->req_ = eio_rename(path, new_path, EIO_PRI_DEFAULT, After, p); p->req_ = eio_rename(path, new_path, EIO_PRI_DEFAULT, After, p);
return p->handle_; return p->handle_;
} }
static v8::Handle<v8::Object> static v8::Handle<v8::Object> Unlink(const char *path) {
Unlink (const char *path)
{
EIOPromise *p = Create(); EIOPromise *p = Create();
p->req_ = eio_unlink(path, EIO_PRI_DEFAULT, After, p); p->req_ = eio_unlink(path, EIO_PRI_DEFAULT, After, p);
return p->handle_; return p->handle_;
} }
static v8::Handle<v8::Object> static v8::Handle<v8::Object> RMDir(const char *path) {
RMDir (const char *path)
{
EIOPromise *p = Create(); EIOPromise *p = Create();
p->req_ = eio_rmdir(path, EIO_PRI_DEFAULT, After, p); p->req_ = eio_rmdir(path, EIO_PRI_DEFAULT, After, p);
return p->handle_; return p->handle_;
} }
static v8::Handle<v8::Object> static v8::Handle<v8::Object> MKDir(const char *path, mode_t mode) {
MKDir (const char *path, mode_t mode)
{
EIOPromise *p = Create(); EIOPromise *p = Create();
p->req_ = eio_mkdir(path, mode, EIO_PRI_DEFAULT, After, p); p->req_ = eio_mkdir(path, mode, EIO_PRI_DEFAULT, After, p);
return p->handle_; return p->handle_;
} }
static v8::Handle<v8::Object> static v8::Handle<v8::Object> ReadDir(const char *path) {
ReadDir (const char *path)
{
EIOPromise *p = Create(); EIOPromise *p = Create();
// By using EIO_READDIR_DENTS (or other flags), more complex results can // 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. // be had from eio_readdir. Doesn't seem that we need that though.
@ -117,18 +104,18 @@ class EIOPromise : public Promise {
protected: protected:
void Attach (); void Attach();
void Detach (); void Detach();
EIOPromise () : Promise() { } EIOPromise() : Promise() { }
private: private:
static int After (eio_req *req); static int After(eio_req *req);
eio_req *req_; eio_req *req_;
enum encoding encoding_; enum encoding encoding_;
}; };
} // namespace node } // namespace node
#endif // node_file_h #endif // SRC_FILE_H_

Loading…
Cancel
Save