client.lua 1.83 KB
Newer Older
1 2 3 4 5 6
local utils = require "utils"
local openbus = require "openbus"


-- process command-line arguments
local bushost, busport, entity, password = ...
7 8 9 10
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 nmero de porta")
entity = assert(entity, "o 3o. argumento  a entidade a ser autenticada")
11 12 13 14 15 16 17
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 offers of the required service
29
  local OfferRegistry = OpenBusContext:getOfferRegistry()
30
  return OfferRegistry:findServices{{name="offer.domain",value="Demo Hello"}}
31
end)
32 33

-- show eventual errors or call services found
34
if not ok then
35 36
  utils.showerror(result, params, utils.errmsg.LoginByPassword,
                                  utils.errmsg.BusCore)
37
else
38 39 40 41 42 43
  -- 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"),
44
        "o servio encontrado no prov a faceta ofertada")
45 46 47 48 49 50
      -- invoke the service
      facet:__narrow():sayHello()
    end)
    if not ok then
      utils.showerror(result, params, utils.errmsg.Service)
    end
51 52 53 54
  end
end

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