Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 128 lines (99 sloc) 4.245 kb
d6c9d31 @ry cpplint.py node.cc and node.h
ry authored
1 // Copyright 2009 Ryan Dahl <ry@tinyclouds.org>
2 #ifndef SRC_NODE_H_
3 #define SRC_NODE_H_
e02b71e @ry exit program on top level exceptions
ry authored
4
5 #include <ev.h>
0e9e927 @ry enable support for the thread pool
ry authored
6 #include <eio.h>
e02b71e @ry exit program on top level exceptions
ry authored
7 #include <v8.h>
44d5f21 @choonkeat Stat::Callback has 2 arguments for callback: current stat info and pr…
choonkeat authored
8 #include <sys/types.h> /* struct stat */
9 #include <sys/stat.h>
e02b71e @ry exit program on top level exceptions
ry authored
10
a5df0f6 @ry Prefix all source files with node_
ry authored
11 #include <node_object_wrap.h>
cf1c580 @ry Create a node namespace
ry authored
12
30dadfc @pquerna Register builtin extensions via a macro, rather than a manual strcmp
pquerna authored
13 #ifndef NODE_STRINGIFY
14 #define NODE_STRINGIFY(n) NODE_STRINGIFY_HELPER(n)
15 #define NODE_STRINGIFY_HELPER(n) #n
16 #endif
17
1fc4dce @ry Simplify and cleanup ObjectWrap.
ry authored
18 namespace node {
6697cd0 @ry small superficial clean-ups
ry authored
19
45a806a @ry Statically define symbols
ry authored
20 #define NODE_PSYMBOL(s) Persistent<String>::New(String::NewSymbol(s))
21
2f46540 @ry Create NODE_UNIXTIME macros
ry authored
22 /* Converts a unixtime to V8 Date */
23 #define NODE_UNIXTIME_V8(t) v8::Date::New(1000*static_cast<double>(t))
d6c9d31 @ry cpplint.py node.cc and node.h
ry authored
24 #define NODE_V8_UNIXTIME(v) (static_cast<double>((v)->IntegerValue())/1000.0);
2f46540 @ry Create NODE_UNIXTIME macros
ry authored
25
6697cd0 @ry small superficial clean-ups
ry authored
26 #define NODE_DEFINE_CONSTANT(target, constant) \
27 (target)->Set(v8::String::NewSymbol(#constant), \
28 v8::Integer::New(constant))
29
30 #define NODE_SET_METHOD(obj, name, callback) \
31 obj->Set(v8::String::NewSymbol(name), \
32 v8::FunctionTemplate::New(callback)->GetFunction())
63a9cd3 @ry everything is changed. i've waited much too long to commit.
ry authored
33
427e3f5 @ry Introduce NODE_SET_PROTOTYPE_METHOD which properly sets the signature.
ry authored
34 #define NODE_SET_PROTOTYPE_METHOD(templ, name, callback) \
35 do { \
d6c9d31 @ry cpplint.py node.cc and node.h
ry authored
36 v8::Local<v8::Signature> __callback##_SIG = v8::Signature::New(templ); \
37 v8::Local<v8::FunctionTemplate> __callback##_TEM = \
38 FunctionTemplate::New(callback, v8::Handle<v8::Value>(), \
39 __callback##_SIG); \
6697cd0 @ry small superficial clean-ups
ry authored
40 templ->PrototypeTemplate()->Set(v8::String::NewSymbol(name), \
41 __callback##_TEM); \
d6c9d31 @ry cpplint.py node.cc and node.h
ry authored
42 } while (0)
427e3f5 @ry Introduce NODE_SET_PROTOTYPE_METHOD which properly sets the signature.
ry authored
43
95638c9 @bnoordhuis Buffer: adjust buffer size so the base64-decoded input fits snugly.
bnoordhuis authored
44 enum encoding {ASCII, UTF8, BASE64, BINARY};
d6c9d31 @ry cpplint.py node.cc and node.h
ry authored
45 enum encoding ParseEncoding(v8::Handle<v8::Value> encoding_v,
07792af @ry Remove "raw" encoding. Rename "raws" to "binary".
ry authored
46 enum encoding _default = BINARY);
d6c9d31 @ry cpplint.py node.cc and node.h
ry authored
47 void FatalException(v8::TryCatch &try_catch);
63a9cd3 @ry everything is changed. i've waited much too long to commit.
ry authored
48
d6c9d31 @ry cpplint.py node.cc and node.h
ry authored
49 v8::Local<v8::Value> Encode(const void *buf, size_t len,
07792af @ry Remove "raw" encoding. Rename "raws" to "binary".
ry authored
50 enum encoding encoding = BINARY);
21a1b04 @ry Byte stream to V8 decoding and encoding.
ry authored
51
d6c9d31 @ry cpplint.py node.cc and node.h
ry authored
52 // Returns -1 if the handle was not valid for decoding
53 ssize_t DecodeBytes(v8::Handle<v8::Value>,
07792af @ry Remove "raw" encoding. Rename "raws" to "binary".
ry authored
54 enum encoding encoding = BINARY);
21a1b04 @ry Byte stream to V8 decoding and encoding.
ry authored
55
56 // returns bytes written.
d6c9d31 @ry cpplint.py node.cc and node.h
ry authored
57 ssize_t DecodeWrite(char *buf,
58 size_t buflen,
59 v8::Handle<v8::Value>,
07792af @ry Remove "raw" encoding. Rename "raws" to "binary".
ry authored
60 enum encoding encoding = BINARY);
21a1b04 @ry Byte stream to V8 decoding and encoding.
ry authored
61
44d5f21 @choonkeat Stat::Callback has 2 arguments for callback: current stat info and pr…
choonkeat authored
62 v8::Local<v8::Object> BuildStatsObject(struct stat * s);
63
21a1b04 @ry Byte stream to V8 decoding and encoding.
ry authored
64
3377a30 @ry Move cb_persist functions out of dns module
ry authored
65 static inline v8::Persistent<v8::Function>* cb_persist(
66 const v8::Local<v8::Value> &v) {
67 v8::Persistent<v8::Function> *fn = new v8::Persistent<v8::Function>();
68 *fn = v8::Persistent<v8::Function>::New(v8::Local<v8::Function>::Cast(v));
69 return fn;
70 }
71
72 static inline v8::Persistent<v8::Function>* cb_unwrap(void *data) {
73 v8::Persistent<v8::Function> *cb =
74 reinterpret_cast<v8::Persistent<v8::Function>*>(data);
75 assert((*cb)->IsFunction());
76 return cb;
77 }
78
79 static inline void cb_destroy(v8::Persistent<v8::Function> * cb) {
80 cb->Dispose();
81 delete cb;
82 }
83
c9e27b1 @ry Unify ErrnoException creation
ry authored
84 v8::Local<v8::Value> ErrnoException(int errorno,
85 const char *syscall = NULL,
45948e0 @tj Added better error messages for async and sync fs calls with paths
tj authored
86 const char *msg = "",
87 const char *path = NULL);
c9e27b1 @ry Unify ErrnoException creation
ry authored
88
f8a3cf9 @felixge Properly handle child process exit codes
felixge authored
89 const char *signo_string(int errorno);
4906604 @pquerna Add basic structure and macros for node modules.
pquerna authored
90
91 struct node_module_struct {
92 int version;
93 void *dso_handle;
30dadfc @pquerna Register builtin extensions via a macro, rather than a manual strcmp
pquerna authored
94 const char *filename;
4906604 @pquerna Add basic structure and macros for node modules.
pquerna authored
95 void (*register_func) (v8::Handle<v8::Object> target);
30dadfc @pquerna Register builtin extensions via a macro, rather than a manual strcmp
pquerna authored
96 const char *modname;
4906604 @pquerna Add basic structure and macros for node modules.
pquerna authored
97 };
98
30dadfc @pquerna Register builtin extensions via a macro, rather than a manual strcmp
pquerna authored
99 node_module_struct* get_builtin_module(const char *name);
100
4906604 @pquerna Add basic structure and macros for node modules.
pquerna authored
101 /**
102 * When this version number is changed, node.js will refuse
103 * to load older modules. This should be done whenever
104 * an API is broken in the C++ side, including in v8 or
105 * other dependencies
106 */
107 #define NODE_MODULE_VERSION (1)
108
109 #define NODE_STANDARD_MODULE_STUFF \
110 NODE_MODULE_VERSION, \
111 NULL, \
112 __FILE__
113
114 #define NODE_MODULE(modname, regfunc) \
115 node::node_module_struct modname ## _module = \
116 { \
117 NODE_STANDARD_MODULE_STUFF, \
30dadfc @pquerna Register builtin extensions via a macro, rather than a manual strcmp
pquerna authored
118 regfunc, \
119 NODE_STRINGIFY(modname) \
4906604 @pquerna Add basic structure and macros for node modules.
pquerna authored
120 };
121
30dadfc @pquerna Register builtin extensions via a macro, rather than a manual strcmp
pquerna authored
122 #define NODE_MODULE_DECL(modname) \
123 extern node::node_module_struct modname ## _module;
124
4906604 @pquerna Add basic structure and macros for node modules.
pquerna authored
125
d6c9d31 @ry cpplint.py node.cc and node.h
ry authored
126 } // namespace node
127 #endif // SRC_NODE_H_
Something went wrong with that request. Please try again.