Skip to content

Commit e0cf403

Browse files
author
Jason Kridner
committed
Saving off temporary workspace
misctest.js will currently immediately read the file without waiting. I'm looking to add an EventEmitter next.
1 parent 84d8d4f commit e0cf403

3 files changed

Lines changed: 41 additions & 26 deletions

File tree

.settings.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<settings version="0.0.4" ><auto><configurations debug="0" ><config path="blinkled.js" name="blinkled" extension="js" args="" /><config path="bone101.js" name="bone101" extension="js" args="" /><config path="footest.js" name="footest" extension="" args="" /><config path="input.js" name="input" extension="" args="" /></configurations><panel>{"ext/editors/editors":{"parent":{"visible":2,"flex":1},"visible":2,"flex":1},"ext/tree/tree":{"parent":{"visible":true,"width":"200"},"visible":true,"flex":1,"state":"normal"},"ext/console/console":{"parent":{"visible":2,"height":200},"visible":true,"flex":1},"ext/settings/settings":{"parent":{"visible":true,"width":"200"},"visible":false,"flex":1,"state":"normal"},"ext/openfiles/openfiles":{"parent":{"visible":true,"width":"200"},"visible":false,"flex":1,"state":"normal"}}</panel><tree_selection path="/workspace/bonescript/misctest.js" type="file"/><tree>["folder[1]","folder[1]/folder[2]"]</tree><console><input>this.subdir
1+
<settings version="0.0.4" ><auto><configurations debug="0" ><config path="blinkled.js" name="blinkled" extension="js" args="" /><config path="bone101.js" name="bone101" extension="js" args="" /><config path="footest.js" name="footest" extension="" args="" /><config path="input.js" name="input" extension="" args="" /></configurations><panel>{"ext/editors/editors":{"parent":{"visible":2,"flex":1},"visible":2,"flex":1},"ext/tree/tree":{"parent":{"visible":true,"width":"200"},"visible":true,"flex":1,"state":"normal"},"ext/console/console":{"parent":{"visible":2,"height":200},"visible":true,"flex":1},"ext/settings/settings":{"parent":{"visible":true,"width":"200"},"visible":false,"flex":1,"state":"normal"},"ext/openfiles/openfiles":{"parent":{"visible":true,"width":"200"},"visible":false,"flex":1,"state":"normal"}}</panel><tree_selection path="/workspace/bonescript/misctest.js" type="file"/><tree>["folder[1]","folder[1]/folder[2]"]</tree><console><input>this.subdir
22

33

4-
</input></console><customtypes/><zen>0.7</zen><recentfiles>[{"caption":"misc.cpp","value":"/workspace/bonescript/misc.cpp"},{"caption":"misctest.js","value":"/workspace/bonescript/misctest.js"},{"caption":"footest.js","value":"/workspace/footest.js"},{"caption":"input.js","value":"/workspace/input.js"},{"caption":"index.js","value":"/workspace/bonescript/index.js"},{"caption":"epolltest.c","value":"/workspace/epolltest.c"},{"caption":"blinkled.js","value":"/workspace/blinkled.js"},{"caption":"polltest.c","value":"/workspace/polltest.c"},{"caption":"wscript","value":"/workspace/bonescript/wscript"},{"caption":"LICENSE","value":"/workspace/LICENSE"}]</recentfiles><extensions/><files active="/workspace/bonescript/misc.cpp"><file path="/workspace/bonescript/index.js" type="file" size="19586" name="index.js" contenttype="application/javascript; charset=utf-8" modifieddate="Fri, 04 May 2012 02:29:54 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/bonescript/index.js"/><file path="/workspace/input.js" type="file" size="745" name="input.js" contenttype="application/javascript; charset=utf-8" modifieddate="Fri, 04 May 2012 02:29:54 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/input.js" state="{&quot;scrolltop&quot;:775,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:0,&quot;column&quot;:0},&quot;end&quot;:{&quot;row&quot;:0,&quot;column&quot;:0}}}"/><file path="/workspace/blinkled.js" type="file" size="364" name="blinkled.js" contenttype="application/javascript; charset=utf-8" modifieddate="Fri, 04 May 2012 02:29:54 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/blinkled.js"/><file path="/workspace/bonescript/misc.cpp" type="file" size="1372" name="misc.cpp" contenttype="text/x-c; charset=utf-8" modifieddate="Fri, 04 May 2012 03:22:37 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/bonescript/misc.cpp" changed="1" state="{&quot;scrolltop&quot;:775,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:71,&quot;column&quot;:11},&quot;end&quot;:{&quot;row&quot;:71,&quot;column&quot;:11}}}"/><file path="/workspace/epolltest.c" type="file" size="1012" name="epolltest.c" contenttype="text/x-c; charset=utf-8" modifieddate="Fri, 04 May 2012 02:29:54 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/epolltest.c" state="{&quot;scrolltop&quot;:775,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:20,&quot;column&quot;:20},&quot;end&quot;:{&quot;row&quot;:20,&quot;column&quot;:20}}}"/><file type="file" name="misctest.js" path="/workspace/bonescript/misctest.js" scriptname="/var/lib/cloud9/bonescript/misctest.js" changed="0" modifieddate="Fri, 04 May 2012 03:04:13 +0100" state="{&quot;scrolltop&quot;:775,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:3,&quot;column&quot;:42},&quot;end&quot;:{&quot;row&quot;:3,&quot;column&quot;:42}}}"/></files></auto><general name="General" saveallbeforerun="true" openfiles="true"/><beautify name="Beautify"><jsbeautify name="JS Beautify" preserveemptylines="true" keeparrayindentation="false" braces="end-expand"/></beautify><editors name="Editor"><code name="Code Editor" overwrite="false" selectstyle="line" activeline="true" showinvisibles="false" showprintmargin="true" printmargincolumn="80" softtabs="true" tabsize="4" scrollspeed="2" fontsize="12" wrapmode="false" wraplimitmin="" wraplimitmax="" gutter="true" highlightselectedword="true" autohidehorscrollbar="true"/></editors><search><word key="attachInterrupt"/><word key="rx"/><word key="analogRead"/><word key="digitalWrite"/><word key="HIGH"/><word key="output"/><word key="socket"/><word key="readFile"/><word key="pinmode"/><word key="eeproms"/><word key="eeprom"/><word key="eeproms"/><word key="socket.emit"/><word key="muxOption"/><word key="ex"/><word key="export"/><word key="getpinmode"/><word key="omap_mux"/><word key="readout"/><word key="omap_mux"/><word key="muxstruct"/><word key="socket.emit"/><word key="mode"/><word key="socket"/><word key="spawn"/><word key="socket.on"/><word key="fibers"/><word key="pinObject"/><word key="pull"/><word key="pinmode"/><word key="events"/><word key="gpmc_ben1"/><word key="opensync"/></search><breakpoints /></settings>
4+
</input></console><customtypes/><zen>0.7</zen><recentfiles>[{"caption":"misc.cpp","value":"/workspace/bonescript/misc.cpp"},{"caption":"misctest.js","value":"/workspace/bonescript/misctest.js"},{"caption":"epolltest.c","value":"/workspace/epolltest.c"},{"caption":"blinkled.js","value":"/workspace/blinkled.js"},{"caption":"input.js","value":"/workspace/input.js"},{"caption":"index.js","value":"/workspace/bonescript/index.js"},{"caption":"footest.js","value":"/workspace/footest.js"},{"caption":"polltest.c","value":"/workspace/polltest.c"},{"caption":"wscript","value":"/workspace/bonescript/wscript"},{"caption":"LICENSE","value":"/workspace/LICENSE"}]</recentfiles><extensions/><files active="/workspace/bonescript/misc.cpp"><file path="/workspace/bonescript/index.js" type="file" size="19586" name="index.js" contenttype="application/javascript; charset=utf-8" modifieddate="Fri, 04 May 2012 16:41:38 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/bonescript/index.js" state="{&quot;scrolltop&quot;:200,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:0,&quot;column&quot;:0},&quot;end&quot;:{&quot;row&quot;:0,&quot;column&quot;:0}}}"/><file path="/workspace/input.js" type="file" size="745" name="input.js" contenttype="application/javascript; charset=utf-8" modifieddate="Fri, 04 May 2012 16:41:38 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/input.js" state="{&quot;scrolltop&quot;:200,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:0,&quot;column&quot;:0},&quot;end&quot;:{&quot;row&quot;:0,&quot;column&quot;:0}}}"/><file path="/workspace/blinkled.js" type="file" size="364" name="blinkled.js" contenttype="application/javascript; charset=utf-8" modifieddate="Fri, 04 May 2012 16:41:38 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/blinkled.js"/><file path="/workspace/bonescript/misc.cpp" type="file" size="1372" name="misc.cpp" contenttype="text/x-c; charset=utf-8" modifieddate="Fri, 04 May 2012 17:24:24 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/bonescript/misc.cpp" changed="0" state="{&quot;scrolltop&quot;:200,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:24,&quot;column&quot;:34},&quot;end&quot;:{&quot;row&quot;:24,&quot;column&quot;:34}}}"/><file path="/workspace/epolltest.c" type="file" size="1012" name="epolltest.c" contenttype="text/x-c; charset=utf-8" modifieddate="Fri, 04 May 2012 16:41:38 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/epolltest.c" changed="0" state="{&quot;scrolltop&quot;:200,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:28,&quot;column&quot;:0},&quot;end&quot;:{&quot;row&quot;:29,&quot;column&quot;:0}}}"/><file type="file" name="misctest.js" path="/workspace/bonescript/misctest.js" scriptname="/var/lib/cloud9/bonescript/misctest.js" changed="0" modifieddate="Fri, 04 May 2012 17:10:17 +0100" state="{&quot;scrolltop&quot;:200,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:7,&quot;column&quot;:64},&quot;end&quot;:{&quot;row&quot;:7,&quot;column&quot;:64}}}"/></files></auto><general name="General" saveallbeforerun="true" openfiles="true"/><beautify name="Beautify"><jsbeautify name="JS Beautify" preserveemptylines="true" keeparrayindentation="false" braces="end-expand"/></beautify><editors name="Editor"><code name="Code Editor" overwrite="false" selectstyle="line" activeline="true" showinvisibles="false" showprintmargin="true" printmargincolumn="80" softtabs="true" tabsize="4" scrollspeed="2" fontsize="12" wrapmode="false" wraplimitmin="" wraplimitmax="" gutter="true" highlightselectedword="true" autohidehorscrollbar="true"/></editors><search><word key="attachInterrupt"/><word key="rx"/><word key="analogRead"/><word key="digitalWrite"/><word key="HIGH"/><word key="output"/><word key="socket"/><word key="readFile"/><word key="pinmode"/><word key="eeproms"/><word key="eeprom"/><word key="eeproms"/><word key="socket.emit"/><word key="muxOption"/><word key="ex"/><word key="export"/><word key="getpinmode"/><word key="omap_mux"/><word key="readout"/><word key="omap_mux"/><word key="muxstruct"/><word key="socket.emit"/><word key="mode"/><word key="socket"/><word key="spawn"/><word key="socket.on"/><word key="fibers"/><word key="pinObject"/><word key="pull"/><word key="pinmode"/><word key="events"/><word key="gpmc_ben1"/><word key="opensync"/></search><breakpoints /></settings>

bonescript/misc.cpp

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,22 @@ using namespace std;
1313
using namespace node;
1414
using namespace v8;
1515

16-
static Handle<Value> PollpriAsync(const Arguments&);
17-
static int Pollpri(eio_req *);
18-
//static int PollpriAfter(eio_req *);
19-
static void PollpriAfter(ev_io* req, int revents);
16+
static Handle<Value> pollpri(const Arguments&);
17+
static int pollpri_thread(eio_req *);
18+
static int pollpri_after(eio_req *);
19+
//extern "C" void pollpri_event(struct ev_loop* loop, ev_io* req, int revents);
20+
extern "C" void pollpri_event(ev_io* req, int revents);
2021
extern "C" void init(Handle<Object>);
2122

2223
struct pollpri_request {
23-
Persistent<Function> cb;
24+
Persistent<Function> callback;
2425
char path[1];
2526
};
2627

27-
static Handle<Value> PollpriAsync(const Arguments& args) {
28+
class Pollpri : public ObjectWrap {
29+
};
30+
31+
static Handle<Value> pollpri(const Arguments& args) {
2832
HandleScope scope;
2933
const char *usage = "usage: pollpri(path, cb)";
3034
if(args.Length() != 2) {
@@ -39,36 +43,42 @@ static Handle<Value> PollpriAsync(const Arguments& args) {
3943
pr->cb = Persistent<Function>::New(cb);
4044
strncpy(pr->path, *path, path.length() + 1);
4145

46+
eio_custom(pollpri_thread, EIO_PRI_DEFAULT, pollpri_after, pr);
47+
ev_ref(EV_DEFAULT_UC);
48+
printf("Leaving pollpri\n");
49+
return(Undefined());
50+
}
51+
52+
static int pollpri_thread(eio_req *req) {
53+
printf("Entered pollpri_thread\n");
54+
struct pollpri_request * pr = (struct pollpri_request *)req->data;
4255
int epfd = epoll_create(1);
4356
int fd = open(pr->path, O_RDWR | O_NONBLOCK);
4457
printf("open(%s) returned %d: %s\n", pr->path, fd, strerror(errno));
4558
struct epoll_event ev;
46-
struct epoll_event events;
4759
ev.events = EPOLLPRI;
4860
ev.data.fd = fd;
4961
int n = epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &ev);
5062
printf("epoll_ctl(%d) returned %d (%d): %s\n", fd, n, epfd, strerror(errno));
5163
ev_io pollpri_watcher;
52-
ev_init(&pollpri_watcher, PollpriAfter);
64+
ev_init(&pollpri_watcher, pollpri_event);
5365
pollpri_watcher.data = pr;
54-
ev_io_set(&pollpri_watcher, epfd, EV_READ);
66+
ev_io_set(&pollpri_watcher, epfd, EV_READ | EV_WRITE);
5567
ev_io_start(EV_DEFAULT_ &pollpri_watcher);
56-
57-
//eio_custom(Pollpri, EIO_PRI_DEFAULT, PollpriAfter, pr);
58-
//ev_ref(EV_DEFAULT_UC);
59-
printf("Leaving PollpriAsync\n");
60-
return(Undefined());
68+
//struct epoll_event events;
69+
//n = epoll_wait(epfd, &events, 1, -1);
70+
//printf("epoll_wait(%d) returned %d: %s\n", epfd, n, strerror(errno));
71+
printf("Leaving pollpri_thread\n");
72+
return(0);
6173
}
6274

63-
static int Pollpri(eio_req *req) {
64-
struct pollpri_request * pr = (struct pollpri_request *)req->data;
65-
printf("Entered Pollpri\n");
66-
return(0);
75+
extern "C" void pollpri_event(ev_io* req, int revents) {
76+
printf("Entered pollpri_event\n");
77+
printf("Leaving pollpri_event\n");
6778
}
6879

69-
//static int PollpriAfter(eio_req *req) {
70-
static void PollpriAfter(ev_io* req, int revents) {
71-
printf("Entered PollpriAfter\n");
80+
static int pollpri_after(eio_req *req) {
81+
printf("Entered pollpri_after\n");
7282
HandleScope scope;
7383
//ev_unref(EV_DEFAULT_UC);
7484
struct pollpri_request * pr = (struct pollpri_request *)req->data;
@@ -78,9 +88,11 @@ static void PollpriAfter(ev_io* req, int revents) {
7888
pr->cb->Call(Context::GetCurrent()->Global(), 2, argv);
7989
//pr->cb.Dispose();
8090
//free(pr);
91+
printf("Leaving pollpri_after\n");
92+
return(0);
8193
}
8294

8395
extern "C" void init(Handle<Object> target) {
8496
HandleScope scope;
85-
NODE_SET_METHOD(target, "pollpri", PollpriAsync);
97+
NODE_SET_METHOD(target, "pollpri", pollpri);
8698
}

bonescript/misctest.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
var misc = require('./misc');
2+
var fs = require('fs');
3+
4+
var filename = '/sys/class/gpio/gpio34/value';
25

36
console.log('Calling pollpri');
4-
misc.pollpri('/sys/class/gpio/gpio34/value', function(err, data) {
5-
console.log(''+data);
7+
misc.pollpri(filename, function(err, data) {
8+
console.log(data + ': ' + fs.readFileSync(filename, 'utf-8'));
69
});

0 commit comments

Comments
 (0)