# HG changeset patch # User Thinker K.F. Li # Date 1275822801 -28800 # Node ID c9d23f7279a42528ade03d9c7b8504d18a61863b # Parent 962d8436a303510d3b11a4d79a994d79e374abb7 The first testcase that nodejs code can show a MadButterfly window. This testcase call MadButterfly from Javascript with nodejs framework. The testcase show a MadButterfly window in X. diff -r 962d8436a303 -r c9d23f7279a4 nodejs/Makefile.am --- a/nodejs/Makefile.am Sun Jun 06 15:27:28 2010 +0800 +++ b/nodejs/Makefile.am Sun Jun 06 19:13:21 2010 +0800 @@ -1,7 +1,10 @@ mbfly_node_SRCS = mbfly_njs.cc X_supp_njs.c -mbfly_node_CFLAGS= -I$(abs_top_srcdir)/include -I$(prefix)/include \ +mbfly_node_CFLAGS= -I$(abs_top_builddir)/include \ + -I$(abs_top_srcdir)/include \ + -I$(prefix)/include \ @pangocairo_CFLAGS@ $(CFLAGS) +mbfly_node_LDFLAGS = -L$(abs_top_builddir)/src/.libs @pangocairo_LIBS@ all: mbfly.node clean: clean-mbfly-node @@ -9,6 +12,8 @@ mbfly.node: wscript $(mbfly_node_SRCS) cd $(srcdir); \ CFLAGS="$(mbfly_node_CFLAGS)" \ + LDFLAGS="$(mbfly_node_LDFLAGS)" \ + TOP_BUILDDIR="$(abs_top_builddir)" \ WAFLOCK=$(abs_builddir)/.lock-wscript \ $(NODE_WAF) configure build --blddir=$(abs_builddir) diff -r 962d8436a303 -r c9d23f7279a4 nodejs/X_supp_njs.c --- a/nodejs/X_supp_njs.c Sun Jun 06 15:27:28 2010 +0800 +++ b/nodejs/X_supp_njs.c Sun Jun 06 19:13:21 2010 +0800 @@ -68,7 +68,7 @@ mb_tman_t *tman; redraw_man_t *rdman; mb_timeval_t now; - extern int _X_MB_flush_x_conn_nodejs(void *rt); + extern int _X_MB_flush_x_conn_for_nodejs(void *rt); tman = X_MB_tman(rt->xrt); get_now(&now); @@ -76,7 +76,7 @@ rdman = X_MB_rdman(rt->xrt); rdman_redraw_changed(rdman); - _X_MB_flush_x_conn_nodejs(rt->xrt); + _X_MB_flush_x_conn_for_nodejs(rt->xrt); set_next_timeout(rt); } @@ -86,7 +86,7 @@ * \param rt is a runtime object for X. */ void -X_njs_MB_handle_connection(njs_runtime_t *rt) { +X_njs_MB_init_handle_connection(njs_runtime_t *rt) { void *xrt = rt->xrt; mb_tman_t *tman; mb_timeval_t now, tmo; diff -r 962d8436a303 -r c9d23f7279a4 nodejs/X_supp_njs.h --- a/nodejs/X_supp_njs.h Sun Jun 06 15:27:28 2010 +0800 +++ b/nodejs/X_supp_njs.h Sun Jun 06 19:13:21 2010 +0800 @@ -4,7 +4,7 @@ struct _njs_runtime; typedef struct _njs_runtime njs_runtime_t; -extern void X_njs_MB_handle_connection(njs_runtime_t *rt); +extern void X_njs_MB_init_handle_connection(njs_runtime_t *rt); extern void X_njs_MB_free(njs_runtime_t *rt); extern njs_runtime_t *X_njs_MB_new(char *display_name, int w, int h); extern void *_X_njs_MB_get_X_runtime(njs_runtime_t *rt); diff -r 962d8436a303 -r c9d23f7279a4 nodejs/mbfly_njs.cc --- a/nodejs/mbfly_njs.cc Sun Jun 06 15:27:28 2010 +0800 +++ b/nodejs/mbfly_njs.cc Sun Jun 06 19:13:21 2010 +0800 @@ -1,8 +1,62 @@ #include #include +extern "C" { +#include "X_supp_njs.h" +} + using namespace v8; +/*! \defgroup njs_template_cb Callback functions for v8 engine and nodejs. + * + * @{ + */ + +/*! \brief to Create a njs runtime object for MadButterfly. + * + * Three arguments are requried. They are + * - display name, + * - width, and + * - height. + */ +static Handle +xnjsmb_new(const Arguments &args) { + int argc; + Handle exc; + njs_runtime_t *rt; + char *display_name; + int width, height; + Handle self; + + argc = args.Length(); + if(argc != 3) { + exc = Exception::Error(String::New("Need 3 arguments.")); + return ThrowException(exc); + } + + if(!args[0]->IsString() || !args[1]->IsInt32() || !args[2]->IsInt32()) { + exc = Exception::Error(String::New("Invalid argument type.")); + return ThrowException(exc); + } + + String::Utf8Value disp_utf8(args[0]->ToString()); + display_name = *disp_utf8; + width = args[1]->Int32Value(); + height = args[2]->Int32Value(); + rt = X_njs_MB_new(display_name, width, height); + + self = args.This(); + self->Set(String::New("_njs_rt"), External::Wrap(rt)); + + X_njs_MB_init_handle_connection(rt); +} + +static Handle +xnjsmb_handle_connection(const Arguments &args) { +} + +/* @} */ + Handle hello_func(const Arguments &args) { HandleScope scope; @@ -17,4 +71,7 @@ func = FunctionTemplate::New(hello_func); target->Set(String::New("Hello"), func->GetFunction()); + + func = FunctionTemplate::New(xnjsmb_new); + target->Set(String::New("mb_rt"), func->GetFunction()); } diff -r 962d8436a303 -r c9d23f7279a4 nodejs/testcase.js --- a/nodejs/testcase.js Sun Jun 06 15:27:28 2010 +0800 +++ b/nodejs/testcase.js Sun Jun 06 19:13:21 2010 +0800 @@ -3,5 +3,6 @@ var sys = require("sys"); sys.puts(r); +var mb_rt = mbfly.mb_rt(":0.0", 300, 200); setTimeout(function() { sys.puts("timeout"); }, 1000); diff -r 962d8436a303 -r c9d23f7279a4 nodejs/wscript --- a/nodejs/wscript Sun Jun 06 15:27:28 2010 +0800 +++ b/nodejs/wscript Sun Jun 06 19:13:21 2010 +0800 @@ -9,18 +9,23 @@ def configure(conf): import Options + import os + conf.check_tool('compiler_cxx') conf.check_tool('compiler_cc') conf.check_tool('node_addon') conf.env.SRCDIR = Options.options.srcdir + conf.env.TOP_BUILDDIR = os.environ['TOP_BUILDDIR'] pass def build(conf): - import os + import Utils + obj = conf.new_task_gen('cxx', 'shlib', 'node_addon') obj.target = 'mbfly' obj.source = 'mbfly_njs.cc' obj.add_objects = 'X_supp_njs.o' + obj.staticlib = 'mbfly' obj = conf.new_task_gen('cc', 'shlib', 'node_addon') obj.target = 'X_supp_njs.o' diff -r 962d8436a303 -r c9d23f7279a4 src/X_supp.c --- a/src/X_supp.c Sun Jun 06 15:27:28 2010 +0800 +++ b/src/X_supp.c Sun Jun 06 19:13:21 2010 +0800 @@ -666,7 +666,7 @@ /*! \brief Flush buffer for the X connection of a runtime object. */ -int _X_MB_flush_x_conn_nodejs(void *rt) { +int _X_MB_flush_x_conn_for_nodejs(void *rt) { return XFlush(((X_MB_runtime_t *)rt)->display); }