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


-- process command-line arguments
6
local bushost, busport, entity, domain, 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
domain = assert(domain, "o 4o. argumento  o dominio da senha de autenticao")
12 13 14 15 16 17 18
local params = {
  bushost = bushost,
  busport = busport,
  entity = entity,
}


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

-- call in protected mode
local ok, result = pcall(function ()
  -- login to the bus 
28 29 30
  OpenBusContext:getCurrentConnection():loginByPassword(entity,
                                                        password or entity,
                                                        domain)
31
  -- find offers of the required service
32
  local OfferRegistry = OpenBusContext:getOfferRegistry()
33
  return OfferRegistry:findServices{{name="offer.domain",value="Demo Hello"}}
34
end)
35 36

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

-- free any resoures allocated
58
OpenBusContext:getCurrentConnection():logout()
59
orb:shutdown()