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

Relase tag of version 2.0.1.0

git-svn-id: https://subversion.tecgraf.puc-rio.br/engdist/openbus/sdk/lua/tags/02_00_01_00@165324 ae0415b3-e90b-0410-900d-d0be9363c56b
parents 6812c200 b2110ff8
# -*- coding: iso-8859-1-unix -*-
import os ;
import modules ;
path-constant here : . ;
lua-install-path = [ os.environ LUA_INSTALL_PATH ] ;
if ! $(lua-install-path)
{
lua-install-path = "$(here)/../../install/lua" ;
}
loop-root-path = [ os.environ LOOP_ROOT_PATH ] ;
if ! $(loop-root-path)
{
loop-root-path = "$(here)/../loop" ;
}
oil-root-path = [ os.environ OIL_ROOT_PATH ] ;
if ! $(oil-root-path)
{
oil-root-path = "$(here)/../oil" ;
}
scs-idl-path = [ os.environ SCS_IDL_PATH ] ;
if ! $(scs-idl-path)
{
scs-idl-path = "$(here)/../scs-idl" ;
}
openbus-idl-path = [ os.environ OPENBUS_IDL_PATH ] ;
if ! $(openbus-idl-path)
{
openbus-idl-path = "$(here)/../openbus-idl" ;
}
openbus-legacy-idl-path = [ os.environ OPENBUS_LEGACY_IDL_PATH ] ;
if ! $(openbus-legacy-idl-path)
{
openbus-legacy-idl-path = "$(here)/../openbus-legacy-idl" ;
}
openbus-lib-idl-path = [ os.environ OPENBUS_LIB_IDL_PATH ] ;
if ! $(openbus-lib-idl-path)
{
openbus-lib-idl-path = "$(here)/../openbus-lib-idl" ;
}
modules.load preloader : : $(loop-root-path) ;
import preloader ;
using preloader ;
project luaopenbus
: requirements
<target-os>windows:<pch>off
<target-os>windows,<link>shared:<runtime-link>shared
<target-os>windows,<link>static:<runtime-link>static
<target-os>windows:<debug-store>database
<target-os>windows:<define>_CRT_SECURE_NO_WARNINGS
<toolset>msvc-12.0:<cxxflags>/FS
<debug-symbols>on
;
make luaopenbus.c
: lua/openbus/assistant.lua
lua/openbus/assistant2.lua
lua/openbus/core/Access.lua
lua/openbus/core/idl/makeaux.lua
lua/openbus/core/idl/parsed.lua
lua/openbus/core/idl.lua
lua/openbus/core/legacy/idl.lua
lua/openbus/core/legacy/parsed.lua
lua/openbus/core/messages.lua
lua/openbus/idl/parsed.lua
lua/openbus/idl.lua
lua/openbus/util/argcheck.lua
lua/openbus/util/autotable.lua
lua/openbus/util/database.lua
lua/openbus/util/except.lua
lua/openbus/util/logger.lua
lua/openbus/util/messages.lua
lua/openbus/util/oo.lua
lua/openbus/util/sandbox.lua
lua/openbus/util/server.lua
lua/openbus/util/sysex.lua
lua/openbus/util/tickets.lua
lua/openbus.lua
: preloader.pre-compile
: <search>$(here)
;
modules.load idl2lua : : $(oil-root-path) ;
import idl2lua ;
using idl2lua ;
make lua/openbus/idl/parsed.lua
: $(openbus-lib-idl-path)/src/openbus.idl
: idl2lua.compile
: <include>$(openbus-lib-idl-path)/src
<include>$(openbus-idl-path)/src
<include>$(scs-idl-path)/src
;
make lua/openbus/core/idl/parsed.lua
: $(openbus-idl-path)/src/access_control.idl
$(openbus-idl-path)/src/offer_registry.idl
$(openbus-idl-path)/src/data_export.idl
$(openbus-idl-path)/src/core.idl
$(openbus-idl-path)/src/credential.idl
$(scs-idl-path)/src/scs.idl
: idl2lua.compile
: <include>$(openbus-idl-path)/src
<include>$(scs-idl-path)/src
;
make lua/openbus/core/legacy/parsed.lua
: $(openbus-legacy-idl-path)/src/access_control_service.idl
$(openbus-legacy-idl-path)/src/registry_service.idl
$(openbus-legacy-idl-path)/src/fault_tolerance.idl
$(openbus-legacy-idl-path)/src/core.idl
$(scs-idl-path)/src/scs.idl
: idl2lua.compile
: <include>$(openbus-legacy-idl-path)/src
<include>$(scs-idl-path)/src
;
lib luaopenbus
: luaopenbus.c
/lua//lua
: <include>src
<target-os>windows,<link>shared:<linkflags>"/def:$(here)/luaopenbus.def"
:
: <include>.
;
explicit luaopenbus ;
exe busconsole
: src/console.c
/lua//lua
/luuid//luuid
/lce//lce
/luafilesystem//lfs
/luavararg//luavararg
/luastruct//luastruct
/luasocket//luasocket
/loop//loop
/loop//luatuple
/loop//luacothread
/oil//oil
/oil//luaidl
/luascs//luascs
/luaopenbus//luaopenbus
: <dependency>/loop//loop
<dependency>/loop//luatuple
<dependency>/loop//luacothread
<dependency>/oil//oil
<dependency>/oil//luaidl
<dependency>/lce//lce
<dependency>/luascs//luascs
<dependency>/luaopenbus//luaopenbus
;
explicit busconsole ;
install stage
: luaopenbus
busconsole
: <location>install
;
\ No newline at end of file
local utils = require "utils"
local assistant = require "openbus.assistant"
-- process command-line arguments
local bushost, busport, entity, password = ...
bushost = assert(bushost, "o 1o. argumento é o host do barramento")
busport = assert(busport, "o 2o. argumento é a porta do barramento")
busport = assert(tonumber(busport), "o 2o. argumento é um número de porta")
entity = assert(entity, "o 3o. argumento é a entidade a ser autenticada")
local params = {
bushost = bushost,
busport = busport,
entity = entity,
}
-- obtain an assistant
local OpenBusAssistant = assistant.create{
bushost = bushost,
busport = busport,
entity = entity,
password = password or entity,
observer = utils.failureObserver(params),
}
local repID = "IDL:Messenger:1.0"
-- find offers of the required service
local offers = OpenBusAssistant:findServices{
{name="openbus.component.interface",value=repID},
{name="offer.domain",value="Demo Chain Validation"},
}
ok = nil
for _, offer in ipairs(offers) do
ok, result = pcall(function ()
-- get the facet providing the service
local facet = assert(offer.service_ref:getFacet(repID),
"o serviço encontrado não provê a faceta ofertada")
-- invoke the service
facet:__narrow():showMessage("Hello!")
end)
if not ok then
if result._repid == "IDL:Unauthorized:1.0" then
io.stderr:write("serviço com papel ",utils.getprop(offer, "offer.role"),
" não autorizou a chamada\n")
elseif result._repid == "IDL:Unavailable:1.0" then
io.stderr:write("serviço com papel ",utils.getprop(offer, "offer.role"),
" está indisponível\n")
else
utils.showerror(result, params, utils.errmsg.Service)
end
end
end
if ok == nil then
io.stderr:write("não foi possível encontrar o serviço esperado\n")
end
-- free any resoures allocated
OpenBusAssistant:shutdown()
OpenBusAssistant.orb:shutdown()
local utils = require "utils"
local openbus = require "openbus"
local assistant = require "openbus.assistant"
local ComponentContext = require "scs.core.ComponentContext"
-- process command-line arguments
local bushost, busport, entity, privatekeypath = ...
bushost = assert(bushost, "o 1o. argumento é o host do barramento")
busport = assert(busport, "o 2o. argumento é a porta do barramento")
busport = assert(tonumber(busport), "o 2o. argumento é um número de porta")
entity = assert(entity, "o 3o. argumento é a entidade a ser autenticada")
privatekeypath = assert(privatekeypath,
"o 4o. argumento é o caminho da chave privada de autenticação da entidade")
local privatekey = assert(openbus.readKeyFile(privatekeypath))
local params = {
bushost = bushost,
busport = busport,
entity = entity,
privatekeypath = privatekeypath,
}
-- create an assistant, the ORB, and the context manager
local OpenBusAssistant = assistant.create{
bushost = bushost,
busport = busport,
entity = entity,
privatekey = privatekey,
observer = utils.failureObserver(params),
}
-- setup and start the ORB
local OpenBusORB = OpenBusAssistant.orb
openbus.newThread(OpenBusORB.run, OpenBusORB)
-- get bus context manager
local OpenBusContext = OpenBusORB.OpenBusContext
-- load interface definitions
OpenBusORB:loadidlfile("callchain/messenger.idl")
local iface = OpenBusORB.types:lookup("Messenger")
params.interface = iface.name
-- create service implementation
local function chain2str(chain)
local entities = {}
for _, login in ipairs(chain.originators) do
entities[#entities+1] = login.entity
end
entities[#entities+1] = chain.caller.entity
return table.concat(entities, "->")
end
local function callService(offer, message)
local facet = assert(offer.service_ref:getFacet(iface.repID),
"o serviço encontrado não provê a faceta ofertada")
facet:__narrow():showMessage(message)
end
local messenger = {}
function messenger:showMessage(message)
local chain = OpenBusContext:getCallerChain()
print("repassando mensagem de "..chain2str(chain))
OpenBusContext:joinChain(chain)
for _, offer in ipairs(offers) do
local ok, result = pcall(callService, offer, message)
if not ok then
utils.showerror(result, params, utils.errmsg.Service)
else
return
end
end
io.stderr:write("serviços encontrados não estão disponíveis\n")
error{_repid="IDL:Unavailable:1.0"}
end
-- create service SCS component
local component = ComponentContext(OpenBusORB, {
name = iface.name,
major_version = 1,
minor_version = 0,
patch_version = 0,
platform_spec = "Lua",
})
component:addFacet(iface.name, iface.repID, messenger)
-- find offers of the required service
offers = OpenBusAssistant:findServices{
{name="openbus.component.interface",value=iface.repID},
{name="offer.domain",value="Demo Chain Validation"},
}
-- check if some offer was found
if #offers == 0 then
io.stderr:write("nenhum serviço encontrado para repassar mensagens\n")
return
end
-- register service offer
OpenBusAssistant:registerService(component.IComponent, {
{name="offer.role",value="proxy messenger"},
{name="offer.domain",value="Demo Chain Validation"},
})
local utils = require "utils"
local openbus = require "openbus"
local assistant = require "openbus.assistant"
local ComponentContext = require "scs.core.ComponentContext"
-- process command-line arguments
local bushost, busport, entity, privatekeypath = ...
bushost = assert(bushost, "o 1o. argumento é o host do barramento")
busport = assert(busport, "o 2o. argumento é a porta do barramento")
busport = assert(tonumber(busport), "o 2o. argumento é um número de porta")
entity = assert(entity, "o 3o. argumento é a entidade a ser autenticada")
privatekeypath = assert(privatekeypath,
"o 4o. argumento é o caminho da chave privada de autenticação da entidade")
local privatekey = assert(openbus.readKeyFile(privatekeypath))
local params = {
bushost = bushost,
busport = busport,
entity = entity,
privatekeypath = privatekeypath,
}
-- create an assistant, the ORB, and the context manager
local OpenBusAssistant = assistant.create{
bushost = bushost,
busport = busport,
entity = entity,
privatekey = privatekey,
observer = utils.failureObserver(params),
}
-- setup and start the ORB
local OpenBusORB = OpenBusAssistant.orb
openbus.newThread(OpenBusORB.run, OpenBusORB)
-- get bus context manager
local OpenBusContext = OpenBusORB.OpenBusContext
-- create service implementation
local function chain2str(chain)
local entities = {}
for _, login in ipairs(chain.originators) do
entities[#entities+1] = login.entity
end
entities[#entities+1] = chain.caller.entity
return table.concat(entities, "->")
end
local messenger = {}
function messenger:showMessage(message)
local chain = OpenBusContext:getCallerChain()
if chain.caller.entity ~= entity then
print("recusando mensagem de "..chain2str(chain))
error{_repid="IDL:Unauthorized:1.0"}
end
print("aceitando mensagem de "..chain2str(chain)..":", message)
end
-- load interface definitions
OpenBusORB:loadidlfile("callchain/messenger.idl")
local iface = OpenBusORB.types:lookup("Messenger")
params.interface = iface.name
-- create service SCS component
local component = ComponentContext(OpenBusORB, {
name = iface.name,
major_version = 1,
minor_version = 0,
patch_version = 0,
platform_spec = "Lua",
})
component:addFacet(iface.name, iface.repID, messenger)
-- register service offer
OpenBusAssistant:registerService(component.IComponent, {
{name="offer.role",value="actual messenger"},
{name="offer.domain",value="Demo Chain Validation"},
})
local utils = require "utils"
local assistant = require "openbus.assistant"
-- process command-line arguments
local bushost, busport, entity, password, interval, timeout = ...
bushost = assert(bushost, "o 1o. argumento é o host do barramento")
busport = assert(busport, "o 2o. argumento é a porta do barramento")
busport = assert(tonumber(busport), "o 2o. argumento é um número de porta")
entity = assert(entity, "o 3o. argumento é a entidade a ser autenticada")
interval = assert(tonumber(interval or 1), "o 5o. argumento é um tempo entre "..
"tentativas de acesso ao barramento em virtude de falhas")
retries = assert(tonumber(timeout or 10), "o 6o. argumento é o número máximo "..
"de tentativas de acesso ao barramento em virtude de falhas")
local params = {
bushost = bushost,
busport = busport,
entity = entity,
}
-- obtain an assistant
local OpenBusAssistant = assistant.create{
bushost = bushost,
busport = busport,
entity = entity,
password = password or entity,
observer = utils.failureObserver(params),
}
-- find offers of the required service
local props = {{name="offer.domain",value="Demo Dedicated Clock"}}
local offers = OpenBusAssistant:findServices(props, retries)
-- for each service offer found
local timestamp
for _, offer in ipairs(offers) do
local ok, result = pcall(function ()
-- get the facet providing the service
local facet = assert(offer.service_ref:getFacetByName("Clock"),
"o serviço encontrado não provê a faceta ofertada")
-- invoke the service
timestamp = facet:__narrow():getTime()
end)
if not ok then
utils.showerror(result, params, utils.errmsg.Service)
else
break
end
end
if timestamp == nil then
io.stderr:write("não foi possível utilizar os serviços encontrados\n")
end
-- show the obtained timestamp, if any
print(os.date(nil, timestamp))
-- free any resoures allocated
OpenBusAssistant:shutdown()
OpenBusAssistant.orb:shutdown()
local utils = require "utils"
local openbus = require "openbus"
local assistant = require "openbus.assistant"
local ComponentContext = require "scs.core.ComponentContext"
-- process command-line arguments
local bushost, busport, entity, privatekeypath, interval = ...
bushost = assert(bushost, "o 1o. argumento é o host do barramento")
busport = assert(busport, "o 2o. argumento é a porta do barramento")
busport = assert(tonumber(busport), "o 2o. argumento é um número de porta")
entity = assert(entity, "o 3o. argumento é a entidade a ser autenticada")
privatekeypath = assert(privatekeypath,
"o 4o. argumento é o caminho da chave privada de autenticação da entidade")
local privatekey = assert(openbus.readKeyFile(privatekeypath))
interval = assert(tonumber(interval or 1), "o 5o. argumento é um tempo entre "..
"tentativas de acesso ao barramento em virtude de falhas")
local params = {
bushost = bushost,
busport = busport,
entity = entity,
privatekeypath = privatekeypath,
}
-- create service implementation
local clock = {}
function clock:getTime()
return os.time() - 24*60*60 -- send the time of the same moment yesterday
end
-- create an assistant, the ORB, and the context manager
local OpenBusAssistant = assistant.create{
bushost = bushost,
busport = busport,
entity = entity,
privatekey = privatekey,
observer = utils.failureObserver(params),
}
-- setup and start the ORB
local OpenBusORB = OpenBusAssistant.orb
openbus.newThread(OpenBusORB.run, OpenBusORB)
-- load interface definition
local iface = OpenBusORB:loadidl("interface Clock { double getTime(); };")
params.interface = iface.name
-- create service SCS component
local component = ComponentContext(OpenBusORB, {
name = iface.name,
major_version = 1,
minor_version = 0,
patch_version = 0,
platform_spec = "Lua",
})
component:addFacet(iface.name, iface.repID, clock)
-- register service offer
OpenBusAssistant:registerService(component.IComponent, {
{name="offer.domain",value="Demo Dedicated Clock"},
})
local utils = require "utils"
local assistant = require "openbus.assistant"
-- process command-line arguments
local bushost, busport, entity, password, language = ...
bushost = assert(bushost, "o 1o. argumento é o host do barramento")
busport = assert(busport, "o 2o. argumento é a porta do barramento")
busport = assert(tonumber(busport), "o 2o. argumento é um número de porta")
entity = assert(entity, "o 3o. argumento é a entidade a ser autenticada")
language = assert(language or "Portuguese",
"o 4o. argumento deve ser uma das opções: English, Spanish, Portuguese")
local params = {
bushost = bushost,
busport = busport,
entity = entity,
}
-- obtain an assistant
local OpenBusAssistant = assistant.create{
bushost = bushost,
busport = busport,
entity = entity,
password = password or entity,
observer = utils.failureObserver(params),
}
-- find offers of the required service
local offers = OpenBusAssistant:findServices{
{name="offer.domain",value="Demo Greetings"},
{name="greetings.language",value=language},
}
-- for each service offer found
for _, offer in ipairs(offers) do