Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make general structure, expose the first class, finish building

  • Loading branch information...
commit a355af5ec88be3239bd8309d8aae7b184f59722b 1 parent 7f51f57
@jmendeth authored
View
80 src/Context.cpp
@@ -0,0 +1,80 @@
+/* ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This file is part of node-openni.
+ *
+ * node-openni is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * node-openni is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with node-openni. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * node-openni is Copyright (C) 2012, Xavier Mendez (jmendeth).
+ *
+ * ***** END GPL LICENSE BLOCK ***** */
+
+#include "Context.h"
+
+namespace node_xn {
+
+ using namespace v8;
+ using namespace node;
+
+ Context Context::Init() {
+ XnContext* ptr;
+ xnInit(&ptr);
+ return Context(ptr);
+ }
+
+ void Context::OnConstruct() {
+ //FIXME: we should check if ptr == NULL
+ xnContextAddRef(this->ptr);
+ }
+
+ Context::~Context() {
+ xnContextRelease(this->ptr);
+ }
+
+
+ /** WRAPPED METHODS **/
+
+ /* Initializer */
+ void Context::INIT(Handle<Object> ctx) {
+ HandleScope scope;
+
+ //1. Declare the class prototype
+ Local<FunctionTemplate> protoL = FunctionTemplate::New(new_default);
+ Persistent<FunctionTemplate> proto = v8::Persistent<FunctionTemplate>::New(protoL);
+ proto->InstanceTemplate()->SetInternalFieldCount(1);
+ proto->SetClassName(v8::String::NewSymbol("Context"));
+
+ //2. Add accessors
+
+ //3. Bind methods
+
+ //4. Declare static functions' templates
+ Local<FunctionTemplate> initSyncL = FunctionTemplate::New(initSync, proto->GetFunction());
+ Persistent<FunctionTemplate> initSyncP = Persistent<FunctionTemplate>::New(initSyncL);
+
+ //5. Finally, add the things to the target
+ ctx->Set(v8::String::NewSymbol("initSync"), initSyncP->GetFunction());
+ ctx->Set(v8::String::NewSymbol("Context"), proto->GetFunction());
+ }
+
+ /* Static factory methods */
+ Handle<Value> Context::initSync(const Arguments& args) {
+ HandleScope scope;
+
+ Handle<Object> instH = ((Function*)(*args.Data()))->NewInstance();
+ (new Context(Init()))->Wrap(instH);
+
+ return instH;
+ }
+
+}
View
55 src/Context.h
@@ -0,0 +1,55 @@
+/* ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This file is part of node-openni.
+ *
+ * node-openni is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * node-openni is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with node-openni. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * node-openni is Copyright (C) 2012, Xavier Mendez (jmendeth).
+ *
+ * ***** END GPL LICENSE BLOCK ***** */
+
+#ifndef NODE_XN_CONTEXT_H
+#define NODE_XN_CONTEXT_H
+
+#include "wrapperUtils.h"
+
+namespace node_xn {
+
+ using namespace v8;
+ using namespace node;
+
+ class Context: public ObjectWrap {
+ public:
+ /* Factory method(s) */
+ static Context Init();
+
+ /* Core methods */
+ inline Context(XnContext* const handle) : ptr(handle) {OnConstruct();}
+ ~Context();
+
+ /* Copy ctor. */
+ inline Context(const Context& orig) : ptr(orig.ptr) {OnConstruct();}
+ inline Context operator=(const Context& orig) {return Context(orig);}
+
+ /** WRAPPED METHODS **/
+ static void INIT(Handle<Object> ctx);
+ static Handle<Value> initSync(const Arguments& args);
+ private:
+ XnContext* const ptr;
+ void OnConstruct();
+ };
+
+}
+
+#endif /* NODE_XN_CONTEXT_H */
View
30 src/wrapper.cpp
@@ -22,19 +22,25 @@
#include <v8.h>
#include <node.h>
-using namespace v8;
-using namespace node;
+#include "Context.h"
-extern "C" {
+namespace node_xn {
- static void init(Handle<Object> module) {
- //Declare global objects (version, ...)
- //TODO
-
- //Initialize every exposed class
- //TODO
+ using namespace v8;
+ using namespace node;
+
+ extern "C" {
+
+ static void init(Handle<Object> module) {
+ //Declare global objects (version, ...)
+ //TODO
+
+ //Initialize every exposed class
+ Context::INIT(module);
+ }
+
+ /** Finally, let Node.JS know about our module **/
+ NODE_MODULE(openni, init);
}
-
- /** Finally, let Node.JS know about our module **/
- NODE_MODULE(openni, init);
+
}
View
38 src/wrapperUtils.cpp
@@ -0,0 +1,38 @@
+/* ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This file is part of node-openni.
+ *
+ * node-openni is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * node-openni is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with node-openni. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * node-openni is Copyright (C) 2012, Xavier Mendez (jmendeth).
+ *
+ * ***** END GPL LICENSE BLOCK ***** */
+
+#include "wrapperUtils.h"
+
+namespace node_xn {
+
+ using namespace v8;
+ using namespace node;
+
+ //wrap
+ //check
+ //checkValid
+
+ Handle<Value> new_default(const Arguments& args) {
+ HandleScope scope;
+ return args.This();
+ }
+
+}
View
45 src/wrapperUtils.h
@@ -0,0 +1,45 @@
+/* ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This file is part of node-openni.
+ *
+ * node-openni is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * node-openni is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with node-openni. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * node-openni is Copyright (C) 2012, Xavier Mendez (jmendeth).
+ *
+ * ***** END GPL LICENSE BLOCK ***** */
+
+#ifndef NODE_XN_WRAPPERUTILS_H
+#define NODE_XN_WRAPPERUTILS_H
+
+//OpenNI includes
+#include <XnOpenNI.h>
+
+//Node.JS includes
+#include <v8.h>
+#include <node.h>
+
+namespace node_xn {
+
+ using namespace v8;
+ using namespace node;
+
+ //wrap
+ //check
+ //checkValid
+
+ Handle<Value> new_default(const Arguments& args);
+
+}
+
+#endif /* NODE_XN_WRAPPERUTILS_H */
View
13 wscript
@@ -4,12 +4,15 @@
def set_options(opt):
opt.tool_options("compiler_cxx")
-def configure(conf):
- conf.check_tool("compiler_cxx")
- conf.check_tool("node_addon")
+def configure(cnf):
+ cnf.check_tool("compiler_cxx")
+ cnf.check_tool("node_addon")
+ cnf.check(features="cxx", lib=["OpenNI"], includes=["/usr/include/ni"], uselib_store="OpenNI")
def build(bld):
obj = bld.new_task_gen("cxx", "shlib", "node_addon")
- obj.cxxflags = ["-g", "-D_FILE_OFFSET_BITS=64", "-D_LARGEFILE_SOURCE", "-Wall"]
+ obj.cxxflags = ["-g","-D_FILE_OFFSET_BITS=64","-D_LARGEFILE_SOURCE","-Wall"]
obj.target = "openni"
- obj.source = "src/wrapper.cpp"
+ obj.source = ["src/wrapper.cpp","src/wrapperUtils.cpp",
+ "src/Context.cpp"]
+ obj.uselib = ["OpenNI"]
Please sign in to comment.
Something went wrong with that request. Please try again.