module Roby::Transaction::Proxying

Attributes

__getobj__[R]

Public Class Methods

create_forwarder_module(methods) click to toggle source
# File lib/roby/transaction/proxying.rb, line 67
def self.create_forwarder_module(methods)
    Module.new do
        attr_accessor :__getobj__
        def transaction_proxy?; true end
        methods.each do |name|
            next if name =~ /^__.*__$/
            next if name == :object_id
            define_method(name) do |*args, &block|
                __getobj__.send(name, *args, &block)
            end
        end
    end
end
define_proxying_module(proxying_module, mod) click to toggle source
# File lib/roby/transaction/proxying.rb, line 42
def self.define_proxying_module(proxying_module, mod)
    @@proxy_for[mod] = proxying_module
    nil
end
forwarder_module_for(klass) click to toggle source

Returns a module that, when used to extend an object, will forward all the calls to the object's @__getobj__

# File lib/roby/transaction/proxying.rb, line 83
def self.forwarder_module_for(klass)
    klass.transaction_forwarder_module ||=
        create_forwarder_module(klass.instance_methods(true)) 
end
proxying_module_for(klass) click to toggle source

Returns the proxying module for object

# File lib/roby/transaction/proxying.rb, line 48
def self.proxying_module_for(klass)
    if proxying_module = klass.transaction_proxy_module
        return proxying_module
    end

    modules = klass.ancestors.map do |ancestor|
        if mod_proxy = @@proxy_for[ancestor]
            mod_proxy
        end
    end.compact
    modules << Transaction::Proxying

    proxying_module = Module.new
    modules.reverse.each do |mod|
        proxying_module.include mod
    end
    klass.transaction_proxy_module = proxying_module
end

Public Instance Methods

has_sibling?(peer) click to toggle source

True if peer has a representation of this object

In the case of transaction proxies, we know they have siblings if the transaction is present on the other peer.

# File lib/roby/transaction/proxying.rb, line 114
def has_sibling?(peer)
    plan.has_sibling?(peer)
end
pretty_print(pp) click to toggle source
Calls superclass method
# File lib/roby/transaction/proxying.rb, line 98
def pretty_print(pp)
    if plan
        plan.disable_proxying do
            pp.text "TProxy:"
            __getobj__.pretty_print(pp)
        end
    else super
    end
end
proxying?() click to toggle source
# File lib/roby/transaction/proxying.rb, line 108
def proxying?; plan && plan.proxying? end
setup_proxy(object, plan) click to toggle source
# File lib/roby/transaction/proxying.rb, line 92
def setup_proxy(object, plan)
    @__getobj__  = object
end
to_s() click to toggle source
# File lib/roby/transaction/proxying.rb, line 40
def to_s; "tProxy(#{__getobj__.to_s})" end
transaction_proxy?() click to toggle source
# File lib/roby/transaction/proxying.rb, line 70
def transaction_proxy?; true end