-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SVCD::subdispatch [NOT READY] #34
base: master
Are you sure you want to change the base?
Changes from all commits
fe438a7
c3fd8f2
746d16f
133bc09
e211649
07a4476
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require "cord" | ||
sh = require "stormsh" | ||
|
||
-- start a coroutine that provides a REPL | ||
sh.start() | ||
|
||
require "svcd" | ||
require "pprint" | ||
|
||
storm.n.svcd_init("kavan", function() print("ready to go") end) | ||
-- SVCD.add_service(12) | ||
-- SVCD.add_attribute(12,1,function() print("someone wrote to attribute") end) | ||
|
||
-- enter the main event loop. This puts the processor to sleep | ||
-- in between events | ||
cord.enter_loop() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
//This file is included into native.c | ||
#include "libstormarray.h" | ||
#include "lrodefs.h" | ||
|
||
static int svcd_subdispatch(lua_State *L); | ||
|
||
#define SVCD_SYMBOLS \ | ||
{ LSTRKEY( "svcd_init"), LFUNCVAL ( svcd_init ) }, | ||
//This file is included into native.c | ||
|
||
#define SVCD_SYMBOLS \ | ||
{ LSTRKEY( "svcd_init"), LFUNCVAL ( svcd_init ) }, \ | ||
{ LSTRKEY( "svcd_subdispatch"), LFUNCVAL ( svcd_subdispatch ) }, | ||
|
||
//If this file is defining only specific functions, or if it | ||
//is defining the whole thing | ||
|
@@ -143,8 +147,7 @@ static int svcd_init( lua_State *L ) | |
lua_pushstring(L, "subsock"); | ||
lua_pushlightfunction(L, libstorm_net_udpsocket); | ||
lua_pushnumber(L, 2530); | ||
lua_pushstring(L, "subdispatch"); | ||
lua_gettable(L, 3); | ||
lua_pushlightfunction(L, svcd_subdispatch); | ||
lua_call(L, 2, 1); | ||
lua_settable(L, 3); //Store | ||
|
||
|
@@ -185,3 +188,82 @@ static int svcd_init( lua_State *L ) | |
|
||
return 0; | ||
} | ||
|
||
|
||
////////////////////////////////////////////////////////////////////////////// | ||
// SVCD.subdispatch() implementation | ||
// Maintainer: Running with scissors | ||
////////////////////////////////////////////////////////////////////////////// | ||
|
||
static int svcd_subdispatch(lua_State *L) { | ||
//local parr = storm.array.fromstr(pay) | ||
size_t len; | ||
uint8_t *parr __attribute__((aligned(2))) = lua_tolstring(L, 1, &len); | ||
uint8_t *srcip = lua_tostring(L, 2); | ||
uint32_t strcport = lua_tointeger(L, 3); | ||
|
||
//local cmd = parr:get(1); | ||
uint8_t cmd = parr[0]; | ||
//local svc_id = parr:get_as(storm.array.UINT16,1); | ||
int16_t svc_id = *(int16_t*)(parr+1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You cannot do an unaligned access like this on ARM. See my other ranty comments for people doing unaligned writes. |
||
//local attr_id = parr:get_as(storm.array.UINT16,3); | ||
int16_t attr_id = *(int16_t*)(parr+3); | ||
//local ivkid = parr:get_as(storm.array.UINT16, 5); | ||
int16_t ivkid = *(int16_t*)(parr+5); | ||
|
||
lua_getglobal(L, "SVCD"); | ||
lua_pushstring(L, "subscribers"); | ||
lua_gettable(L, -2); | ||
lua_pushinteger(L, svc_id); | ||
lua_gettable(L, -2); | ||
//stack: SVCD, SVCD[subscribers], SVCD[subscribers][svc_id] | ||
if (cmd == 1){ //subscribe command | ||
if (lua_isnil(L,-1)){ // if (SVCD.subscribers[svc_id] == nil){ | ||
lua_pop(L, 1); //stack: SVCD, SVCD[subscribers] | ||
//SVCD.subscribers[svc_id] = {}; | ||
lua_newtable(L); | ||
lua_pushinteger(L, svc_id); | ||
lua_pushvalue(L, -2); | ||
//stack: SVCD, SVCD[subscribers], <newTable>, svc_id, <newTable> | ||
lua_settable(L, -4); | ||
} | ||
//stack: SVCD, SVCD[subscribers], SVCD[subscribers][svc_id], | ||
//if (SVCD.subscribers[svc_id][attr_id] == nil){ | ||
lua_pushstring(L,"attr_id"); | ||
lua_gettable(L, -2); | ||
if (lua_isnil(L, -1)){ | ||
//SVCD.subscribers[svc_id][attr_id] = {} | ||
lua_pop(L, 1); | ||
lua_newtable(L); | ||
lua_pushinteger(L, attr_id); | ||
lua_pushvalue(L, -2); | ||
lua_settable(L, -4); | ||
} | ||
//stack: SVCD[subscribers], SVCD[subscribers][svc_id], SVCD[subscribers][svc_id][attr_id] | ||
|
||
//SVCD.subscribers[svc_id][attr_id][srcip] = ivkid; | ||
lua_pushstring(L, srcip); | ||
lua_pushnumber(L, ivkid); | ||
lua_settable(L, -3); | ||
|
||
}else if (cmd == 0){ //unsubscribe command | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in svcd.lua, 2 is the unsubscribe command, not 0. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, in subdispatch it is. But in SVCD.unsubscribe it is 0 so we changed it here so everything would work There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this a bug in unsubscribe? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it was a bug in the program as a whole, I'm not sure which they meant it to be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant it to be 2, but I will fix it when I merge, as this is my bad. |
||
//stack: SVCD, SVCD[subscribers], SVCD[subscribers][svc_id] | ||
|
||
//if (SVCD.subscribers[svc_id] == nil){ | ||
if (lua_isnil(L, -1)){ | ||
return 0; | ||
} | ||
//if (SVCD.subscribers[svc_id][attr_id] == nil){ | ||
lua_pushnumber(L, attr_id); | ||
lua_gettable(L, -2); | ||
if (lua_isnil(L, -1)){ | ||
return 0; | ||
} | ||
//stack: SVCD, SVCD[subscribers], SVCD[subscribers][svc_id], SVCD[subscribers][svc_id][attr_id] | ||
//SVCD.subscribers[svc_id][attr_id][srcip] = nil; | ||
lua_pushstring(L, srcip); | ||
lua_pushnil(L); | ||
lua_settable(L, -3); | ||
} | ||
return 0; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good. Good job on doing the comments. Line 224-228 is fantastic! Took me a while to understand the reasoning. Untitled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be included in native.c by #30
men in #000000