Class: EverSdk::ClientContext

Inherits:
Object
  • Object
show all
Defined in:
lib/ever_sdk_client/client_context.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cfg_json) ⇒ ClientContext

Returns a new instance of ClientContext.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ever_sdk_client/client_context.rb', line 25

def initialize(cfg_json)
  cfg_json_tc_str = Interop::TcStringData::from_string(cfg_json)
  ptr = Interop::tc_create_context(cfg_json_tc_str)
  ctx_tc_str = Interop::tc_read_string(ptr)
  if (ctx_tc_str != nil) && (ctx_tc_str[:len] > 0)
    cont_str = ctx_tc_str[:content].read_string(ctx_tc_str[:len])
    ctx_json = JSON.parse(cont_str)
    ctx_val = ctx_json["result"]
    if ctx_val != nil
      @context = ctx_val
      @requests = Concurrent::Hash.new()
      ObjectSpace.define_finalizer(self, self.class.finalize(@context))
    else
      raise SdkError.new(message: "unable to create context: #{ctx_json}")
    end

    Interop::tc_destroy_string(ptr)
  else
    raise SdkError.new(message: "unable to create context")
  end
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



23
24
25
# File 'lib/ever_sdk_client/client_context.rb', line 23

def context
  @context
end

Class Method Details

.finalize(ctx) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/ever_sdk_client/client_context.rb', line 47

def self.finalize(ctx)
  Proc.new do
    if (ctx != nil) && (ctx > 0)
      Interop::tc_destroy_context(ctx)
    end
  end
end