client.lua 1.79 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
local utils = require "utils"
local openbus = require "openbus"


-- 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,
}


18 19 20 21 22 23 24 25 26 27
-- setup the ORB and connect to the bus
local OpenBusContext = openbus.initORB().OpenBusContext
OpenBusContext:setDefaultConnection(
  OpenBusContext:createConnection(bushost, busport))

-- call in protected mode
local ok, result = pcall(function ()
  -- login to the bus 
  OpenBusContext:getCurrentConnection():loginByPassword(entity, password
                                                                or entity)
28
  -- find the offered service
29 30 31
  local OfferRegistry = OpenBusContext:getCoreService("OfferRegistry")
  return OfferRegistry:findServices{{name="offer.domain",value="Hello Demo"}}
end)
32
if not ok then
33 34
  utils.showerror(result, params, utils.errmsg.LoginByPassword,
                                  utils.errmsg.BusCore)
35
else
36 37 38 39 40 41 42 43 44 45 46 47 48
  -- for each service offer found
  for _, offer in ipairs(result) do
    -- call in protected mode
    local ok, result = pcall(function ()
      -- get the facet providing the service
      local facet = assert(offer.service_ref:getFacetByName("Hello"),
        "o serviço encontrado não provê a faceta ofertada")
      -- invoke the service
      facet:__narrow():sayHello()
    end)
    if not ok then
      utils.showerror(result, params, utils.errmsg.Service)
    end
49 50 51 52
  end
end

-- free any resoures allocated
53
OpenBusContext:getCurrentConnection():logout()