Module: Roby::Transaction::Proxying

Defined in:
lib/roby/transaction/proxying.rb

Defined Under Namespace

Modules: Cache

Constant Summary collapse

@@proxy_for =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#__getobj__Object (readonly)

Returns the value of attribute getobj.



111
112
113
# File 'lib/roby/transaction/proxying.rb', line 111

def __getobj__
  @__getobj__
end

Class Method Details

.create_forwarder_module(methods) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/roby/transaction/proxying.rb', line 70

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) ⇒ Object



45
46
47
48
# File 'lib/roby/transaction/proxying.rb', line 45

def self.define_proxying_module(proxying_module, mod)
    @@proxy_for[mod] = proxying_module
    nil
end

.forwarder_module_for(klass) ⇒ Object

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



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/roby/transaction/proxying.rb', line 90

def self.forwarder_module_for(klass)
    if (m = klass.transaction_forwarder_module)
        return m
    end

    methods = klass.instance_methods(true)
    parent_class = klass.superclass
    if parent_class.respond_to?(:transaction_forwarder_module)
        parent_module = forwarder_module_for(parent_class)
        methods -= parent_class.instance_methods(true)
    end

    if methods.empty?
        klass.transaction_forwarder_module = parent_module || Module.new
    else
        mod = create_forwarder_module(methods)
        mod.include(parent_module) if parent_module
        klass.transaction_forwarder_module = mod
    end
end

.proxying_module_for(klass) ⇒ Object

Returns the proxying module for object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/roby/transaction/proxying.rb', line 51

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

Instance Method Details

#has_sibling?(peer) ⇒ Boolean

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.

Returns:

  • (Boolean)


142
143
144
# File 'lib/roby/transaction/proxying.rb', line 142

def has_sibling?(peer)
    plan.has_sibling?(peer)
end

#pretty_print(pp) ⇒ Object



123
124
125
126
127
128
129
130
131
132
# File 'lib/roby/transaction/proxying.rb', line 123

def pretty_print(pp)
    if plan
        plan.disable_proxying do
            pp.text "TProxy:"
            __getobj__.pretty_print(pp)
        end
    else
        super
    end
end

#proxying?Boolean

Returns:

  • (Boolean)


134
135
136
# File 'lib/roby/transaction/proxying.rb', line 134

def proxying?
    plan&.proxying?
end

#setup_proxy(object, plan) ⇒ Object



117
118
119
# File 'lib/roby/transaction/proxying.rb', line 117

def setup_proxy(object, plan)
    @__getobj__ = object
end

#to_sObject



41
42
43
# File 'lib/roby/transaction/proxying.rb', line 41

def to_s
    "tProxy(#{__getobj__})"
end

#transaction_proxy?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/roby/transaction/proxying.rb', line 113

def transaction_proxy?
    true
end