client.lua 1.86 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
-- setup the ORB and connect to the bus
19 20
local orb = openbus.initORB()
local OpenBusContext = orb.OpenBusContext
21 22 23 24 25 26 27 28
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)
29
  -- find offers of the required service
30
  local OfferRegistry = OpenBusContext:getOfferRegistry()
31
  return OfferRegistry:findServices{{name="offer.domain",value="Demo Hello"}}
32
end)
33 34

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

-- free any resoures allocated
56
OpenBusContext:getCurrentConnection():logout()
57
orb:shutdown()