Class: Runivedo::RemoteObject

Inherits:
Object
  • Object
show all
Defined in:
lib/runivedo/remote_object.rb

Direct Known Subclasses

Result, Statement

Defined Under Namespace

Modules: MethodMissing

Constant Summary collapse

OPERATION_CALL_ROM =
1
OPERATION_ANSWER_CALL =
2
OPERATION_NOTIFY =
3
OPERATION_DELETE =
4

Instance Method Summary collapse

Constructor Details

#initialize(connection, id) ⇒ RemoteObject

Returns a new instance of RemoteObject.



19
20
21
22
23
24
25
26
27
# File 'lib/runivedo/remote_object.rb', line 19

def initialize(connection, id)
  @connection = connection
  @open = true
  @id = id
  @call_id = 0
  @calls = {}
  @notifications = {}
  @mutex = Mutex.new
end

Instance Method Details

#call_rom(name, *args) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/runivedo/remote_object.rb', line 36

def call_rom(name, *args)
  call_result = nil
  @mutex.synchronize do
    check_open
    call_result = Future.new
    @calls[@call_id] = call_result
    @connection.send :send_message, [@id, OPERATION_CALL_ROM, @call_id, name, args]
    @call_id += 1
  end
  result = call_result.get
  if result.is_a?(RemoteObject) && block_given?
    begin
      yield result
    ensure
      result.close
    end
  else
    result
  end
end

#closeObject



65
66
67
68
69
# File 'lib/runivedo/remote_object.rb', line 65

def close
  @connection.send :delete_ro, @id
  onclose(Runivedo::ConnectionError.new("remote object closed"))
  @connection.send :send_message, [@id, OPERATION_DELETE]
end

#closed?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/runivedo/remote_object.rb', line 61

def closed?
  !@open
end

#on(notification_name, &block) ⇒ Object



57
58
59
# File 'lib/runivedo/remote_object.rb', line 57

def on(notification_name, &block)
  @notifications[notification_name.to_s] = block
end

#send_notification(name, *args) ⇒ Object



29
30
31
32
33
34
# File 'lib/runivedo/remote_object.rb', line 29

def send_notification(name, *args)
  @mutex.synchronize do
    check_open
    @connection.send :send_message, [@id, OPERATION_NOTIFY, name.to_s, args]
  end
end