Project

General

Profile

« Previous | Next » 

Revision a3483167

Added by Marc Dequènes over 14 years ago

  • ID a3483167a0b6fddcb6f827079e469e1fc2c8e23c

[evol] work on cyborg server protocol and API #4 (refs #31)

View differences:

bin/mapmaker
class DNS
include CyborgServerInterface
def api_zone_exists?(data)
def zone_exists?(data)
pp data
"coucou"
end
lib/cyborghood/cyborg/interface.rb
[klass, method]
end
def api_method_name?(method)
method =~ /^api_(.+)$/
$1
end
def api_method_to_class_method_name(method)
"api_#{method}".to_sym
end
def has_node?(cmd)
klass, method = self.decompose_command(cmd)
return false if klass.nil?
......
inst = klass.instance
inst.api_methods.include?(method)
end
attr_accessor :exported_methods
attr_accessor :auto_export_public_instance_methods
def export_method(syms)
syms = [syms] unless syms.is_a? Array
self.exported_methods ||= []
self.exported_methods += syms.collect{|m| m.to_s }
end
end
def initialize
@config = Config.instance
self.class.exported_methods ||= []
self.class.auto_export_public_instance_methods = true
end
def api_modules
......
end
def api_methods
@methods ||= self.methods.collect{|m| self.class.api_method_name?(m) }.compact
methods = self.class.exported_methods
methods += self.class.public_instance_methods(false) if self.class.auto_export_public_instance_methods
methods & self.methods
end
# preliminary incoming message handling
......
return "551 this object has no such method"
end
begin
formated_data = YAML.load(data) unless data.nil?
rescue
return "552 unreadable data for arguments"
end
if data.nil?
formated_data = []
else
begin
formated_data = YAML.load(data) unless data.nil?
rescue
return "552 unreadable data for arguments"
end
return "552 wrong format for arguments" unless formated_data.is_a? Array
return "552 wrong format for arguments" unless formated_data.is_a? Array
end
begin
# preliminary outgoing message handling
real_method = self.class.api_method_to_class_method_name(method)
#if inst.method(real_method).arity > 0
r = inst.send(real_method, *formated_data)
#else
# return "552 method does not take any argument" if formated_data
# r = inst.send(real_method)
#end
r.to_yaml
inst.send(method, *formated_data).to_yaml
rescue
return "550 method call failed"
end
......
module CyborgServerDefaultInterface
PROTOCOL_VERSION = "0.1~"
def api_product
def self.included(base)
list = self.public_instance_methods(false)
base.class_eval do
export_method list
end
end
def product_name
PRODUCT
end
def api_version
def product_version
VERSION
end
def api_protocol_version
def protocol_version
PROTOCOL_VERSION
end
def api_bot_name
def bot_name
@config.bot_name
end
end

Also available in: Unified diff