Commit fec8ab2a authored by Renato Figueiro Maia's avatar Renato Figueiro Maia

[OPENBUS-1535] Refatorar os Serviços Básicos.

[OPENBUS-1538] Implementar a nova proposta do SDK OpenBus em Lua.
- Movendo no SVN arquivos da implementação dos serviços básicos para o SDK-Lua.
- Descartando a biblioteca de maniputação de bits em strings.

git-svn-id: https://subversion.tecgraf.puc-rio.br/engdist/openbus/sdk/lua/branches/openbus_v2_proto@128575 ae0415b3-e90b-0410-900d-d0be9363c56b
parent ea6c392a
local _G = require "_G"
local ipairs = _G.ipairs
local unpack = _G.unpack
local makeaux = require "openbus.core.idl.makeaux"
local parsed = require "openbus.core.legacy.parsed"
local types, values, throw = {}, {}, {}
for _, parsed in ipairs(parsed) do
if parsed.name == "tecgraf" then
makeaux(parsed, types, values, throw)
end
end
local idl = {
types = types.tecgraf.openbus.core.v1_05,
values = values.tecgraf.openbus.core.v1_05,
throw = throw.tecgraf.openbus.core.v1_05,
typesFT = types.tecgraf.openbus.fault_tolerance.v1_05,
}
function idl.loadto(orb)
orb.TypeRepository.registry:register(unpack(parsed))
end
return idl
local _G = require "_G"
local assert = _G.assert
local io = require "io"
local stderr = io.stderr
local luaidl = require "luaidl"
local parse = luaidl.parse
local idlspec = [[
#include "fault_tolerance.idl"
#include "access_control_service.idl"
#include "registry_service.idl"
]]
local idlpath = os.getenv("OPENBUS_IDLPATH")
if idlpath == nil then
stderr:write("OPENBUS_IDLPATH is not defined! Using '.' as default.\n")
idlpath = "."
end
local Compiler = require "oil.corba.idl.Compiler"
local options = Compiler().defaults
options.incpath = {
idlpath.."/legacy",
idlpath.."/scs",
}
return { assert(parse(idlspec, options)) }
......@@ -413,7 +413,6 @@ static int pmain (lua_State *L) {
lua_pushcfunction(L,luaopen_vararg);lua_setfield(L,-2,"vararg");
lua_pushcfunction(L,luaopen_struct);lua_setfield(L,-2,"struct");
lua_pushcfunction(L,luaopen_socket_core);lua_setfield(L,-2,"socket.core");
lua_pushcfunction(L,luaopen_string_bitwise);lua_setfield(L,-2,"string.bitwise");
lua_pop(L, 1); /* pop 'package.preload' table */
/* preload other C libraries */
luapreload_lce(L);
......
PROJNAME= luaopenbus
LIBNAME= $(PROJNAME)
SRC= \
$(PRELOAD_DIR)/$(LIBNAME).c \
strbitwise.c
OPENBUSIDL= ${OPENBUS_HOME}/idl/v2_00
LUAMOD= \
openbus.core.Access \
openbus.core.idl.makeaux \
openbus.core.idl.parsed \
openbus.core.idl \
openbus.core.messages \
openbus.multiplexed \
openbus.util.argcheck \
openbus.util.autotable \
openbus.util.database \
openbus.util.logger \
openbus.util.messages \
openbus.util.oo \
openbus.util.server \
openbus.util.sysex \
openbus.util.tickets \
openbus
SRC= $(PRELOAD_DIR)/$(LIBNAME).c
OPENBUSOLDIDL= ${OPENBUS_HOME}/idl/v1_05
OPENBUSNEWIDL= ${OPENBUS_HOME}/idl/v2_00
LUADIR= ../lua
LUASRC=$(addprefix $(LUADIR)/,$(addsuffix .lua,$(subst .,/,$(LUAMOD))))
LUASRC= \
$(LUADIR)/openbus/core/Access.lua \
$(LUADIR)/openbus/core/idl/makeaux.lua \
$(LUADIR)/openbus/core/idl/parsed.lua \
$(LUADIR)/openbus/core/idl.lua \
$(LUADIR)/openbus/core/legacy/parsed.lua \
$(LUADIR)/openbus/core/legacy/idl.lua \
$(LUADIR)/openbus/core/messages.lua \
$(LUADIR)/openbus/multiplexed.lua \
$(LUADIR)/openbus/util/argcheck.lua \
$(LUADIR)/openbus/util/autotable.lua \
$(LUADIR)/openbus/util/database.lua \
$(LUADIR)/openbus/util/logger.lua \
$(LUADIR)/openbus/util/messages.lua \
$(LUADIR)/openbus/util/oo.lua \
$(LUADIR)/openbus/util/server.lua \
$(LUADIR)/openbus/util/sysex.lua \
$(LUADIR)/openbus/util/tickets.lua \
$(LUADIR)/openbus.lua
IDL= \
$(OPENBUSIDL)/access_control.idl \
$(OPENBUSIDL)/offer_registry.idl
NEWIDL= \
$(OPENBUSNEWIDL)/access_control.idl \
$(OPENBUSNEWIDL)/offer_registry.idl
OLDIDL= \
$(OPENBUSOLDIDL)/access_control_service.idl \
$(OPENBUSOLDIDL)/registry_service.idl \
$(OPENBUSOLDIDL)/fault_tolerance.idl
include ${OIL_HOME}/openbus/base.mak
$(LUADIR)/openbus/core/idl/parsed.lua: $(IDL2LUA) $(IDL)
$(OILBIN) $(IDL2LUA) -o $@ $(IDL)
$(LUADIR)/openbus/core/idl/parsed.lua: $(IDL2LUA) $(NEWIDL)
$(OILBIN) $(IDL2LUA) -o $@ $(NEWIDL)
$(LUADIR)/openbus/core/legacy/parsed.lua: $(IDL2LUA) $(OLDIDL)
$(OILBIN) $(IDL2LUA) -o $@ $(OLDIDL)
$(PRELOAD_DIR)/$(LIBNAME).c: $(LUAPRELOADER) $(LUASRC)
$(LOOPBIN) $(LUAPRELOADER) -m -n \
$(LOOPBIN) $(LUAPRELOADER) -m \
-l "$(LUADIR)/?.lua" \
-d $(PRELOAD_DIR) \
-h $(LIBNAME).h \
-o $(LIBNAME).c \
string.bitwise $(LUAMOD)
$(LUASRC)
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
#define BINARY_BITOP(name, op) \
static int name(lua_State *L) \
{ \
luaL_Buffer b; \
size_t i, sz, osz; \
char res[LUAL_BUFFERSIZE]; \
const char *op1 = luaL_checklstring(L, 1, &sz); \
const char *op2 = luaL_checklstring(L, 2, &osz); \
luaL_argcheck(L, sz==osz, 2, "must be the same length of argument #1"); \
luaL_buffinit(L, &b); \
while (sz>LUAL_BUFFERSIZE) { \
for(i=0; i<LUAL_BUFFERSIZE; ++i) res[i] = op1[i] op op2[i]; \
luaL_addlstring(&b, res, LUAL_BUFFERSIZE); \
op1 += LUAL_BUFFERSIZE; \
op2 += LUAL_BUFFERSIZE; \
sz -= LUAL_BUFFERSIZE; \
} \
for(i=0; i<sz; ++i) res[i] = op1[i] op op2[i]; \
luaL_addlstring(&b, res, sz); \
luaL_pushresult(&b); \
return 1; \
}
static int str_not(lua_State *L)
{
luaL_Buffer b;
size_t i, sz;
char res[LUAL_BUFFERSIZE];
const char *op = luaL_checklstring(L, 1, &sz);
luaL_buffinit(L, &b);
while (sz>LUAL_BUFFERSIZE) {
for(i=0; i<LUAL_BUFFERSIZE; ++i) res[i] = ~op[i];
luaL_addlstring(&b, res, LUAL_BUFFERSIZE);
op += LUAL_BUFFERSIZE;
sz -= LUAL_BUFFERSIZE;
}
for(i=0; i<sz; ++i) res[i] = ~op[i];
luaL_addlstring(&b, res, sz);
luaL_pushresult(&b);
return 1;
}
BINARY_BITOP(str_and, &)
BINARY_BITOP(str_or, |)
BINARY_BITOP(str_xor, ^)
static const luaL_Reg strbitlib[] = {
{"bnot", str_not},
{"band", str_and},
{"bor", str_or},
{"bxor", str_xor},
{NULL, NULL}
};
LUALIB_API int luaopen_string_bitwise(lua_State *L) {
luaL_register(L, LUA_STRLIBNAME, strbitlib);
return 1;
}
local string = require "string.bitwise"
local large = 10000
local op1 = "\000\255\000\255\085"
local op2 = "\000\255\255\000\170"
local res = {
bnot = "\255\000\255\000\170",
band = "\000\255\000\000\000",
bor = "\000\255\255\255\255",
bxor = "\000\000\255\255\255",
}
for op, res in pairs(res) do
op = string[op]
assert(op(op1, op2) == res)
assert(op(op1:rep(large), op2:rep(large)) == res:rep(large))
assert(op("", "") == "")
if op ~= string.bnot then
local ok, err = pcall(op, "123", "1234")
assert(ok == false)
assert(err:match("bad argument #2 to '.-' %(must be the same length of argument #1%)$"))
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment