Revision 41802ec1
Added by Marc Dequènes over 14 years ago
- ID 41802ec120851cf58a5f4d6a816de311a31f58d4
lib/cyborghood/cyborg/interface.rb | ||
---|---|---|
base.extend(ClassMethods)
|
||
end
|
||
|
||
def find_node_action(node_name)
|
||
next_node_name, other_nodes_names = node_name.split('.', 2)
|
||
|
||
next_node_klass = api_klasses[next_node_name]
|
||
if next_node_klass.nil?
|
||
if api_methods.include? next_node_name
|
||
next_node_method = self.method(next_node_name)
|
||
return next_node_method if other_nodes_names.nil?
|
||
next_node = next_node_method.call
|
||
else
|
||
return
|
||
end
|
||
else
|
||
next_node = next_node_klass.instance
|
||
return next_node.method('api_nodes') if other_nodes_names.nil?
|
||
end
|
||
|
||
next_node.find_node_action(other_nodes_names)
|
||
end
|
||
|
||
module ClassMethods
|
||
attr_accessor :exported_methods
|
||
attr_accessor :auto_export_public_instance_methods
|
||
... | ... | |
(api_klasses.keys + api_methods).sort
|
||
end
|
||
|
||
def find_node_action(node_name)
|
||
next_node_name, other_nodes_names = node_name.split('.', 2)
|
||
|
||
next_node_klass = api_klasses[next_node_name]
|
||
if next_node_klass.nil?
|
||
if api_methods.include? next_node_name
|
||
next_node_method = self.method(next_node_name)
|
||
return next_node_method if other_nodes_names.nil?
|
||
next_node = next_node_method.call
|
||
else
|
||
return
|
||
end
|
||
else
|
||
next_node = next_node_klass.instance
|
||
return next_node.method('api_nodes') if other_nodes_names.nil?
|
||
end
|
||
|
||
next_node.find_node_action(other_nodes_names)
|
||
end
|
||
|
||
def has_node?(cmd)
|
||
not find_node_action(cmd).nil?
|
||
end
|
||
|
||
# preliminary incoming message handling
|
||
def call(cmd, data)
|
||
action = find_node_action(cmd)
|
lib/cyborghood/cyborg/server.rb | ||
---|---|---|
|
||
if flags.index '?'
|
||
send_line "250+ ok"
|
||
send_line({'exists?' => @interface.find_node_action(cmd)}.to_yaml)
|
||
send_line({'exists?' => @interface.has_node?(cmd)}.to_yaml)
|
||
return
|
||
end
|
||
|
Also available in: Unified diff
[evol] work on cyborg server protocol and API #6 (refs #31)