Project

General

Profile

« Previous | Next » 

Revision bc473567

Added by Marc Dequènes over 14 years ago

  • ID bc47356707084cec2c04c9974442601746e860ea

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

View differences:

bin/mapmaker
end
end
class MapMakerInterface < CyborgServerDefaultInterface
class DNS < CyborgServerInterface
class MapMakerInterface
include CyborgServerInterface
include CyborgServerDefaultInterface
class DNS
include CyborgServerInterface
def api_zone_exists?(data)
pp data
"coucou"
lib/cyborghood/cyborg/interface.rb
module CyborgHood
class CyborgServerInterface
include Singleton
module CyborgServerInterface
def self.included(base)
base.class_eval("include Singleton")
base.extend(ClassMethods)
end
def self.decompose_command(cmd)
object, method = cmd.split('.', 2)
module ClassMethods
def decompose_command(cmd)
object, method = cmd.split('.', 2)
if method
begin
klass = object.split('::').inject(self) {|scope, const_name| scope.const_get(const_name)}
rescue
return
end
else
if object.index("::")
return
if method
begin
klass = object.split('::').inject(self) {|scope, const_name| scope.const_get(const_name)}
rescue
return
end
else
klass = self
method = cmd
if object.index("::")
return
else
klass = self
method = cmd
end
end
[klass, method]
end
[klass, method]
end
def api_method_name?(method)
method =~ /^api_(.+)$/
$1
end
def self.api_method_name?(method)
method =~ /^api_(.+)$/
$1
end
def api_method_to_class_method_name(method)
"api_#{method}".to_sym
end
def self.api_method_to_class_method_name(method)
"api_#{method}".to_sym
def has_node?(cmd)
klass, method = self.decompose_command(cmd)
return false if klass.nil?
return true if method.nil?
inst = klass.instance
inst.api_methods.include?(method)
end
end
def initialize
......
@methods ||= self.methods.collect{|m| self.class.api_method_name?(m) }.compact
end
def self.has_node?(cmd)
klass, method = self.decompose_command(cmd)
return false if klass.nil?
return true if method.nil?
inst = klass.instance
inst.api_methods.include?(method)
end
# preliminary incoming message handling
def call(cmd, data)
klass, method = self.class.decompose_command(cmd)
......
end
end
class CyborgServerDefaultInterface < CyborgServerInterface
module CyborgServerDefaultInterface
PROTOCOL_VERSION = "0.1~"
def api_product
lib/cyborghood/cyborg/server.rb
end
end
class EmptyInterface
include CyborgServerInterface
include CyborgServerDefaultInterface
end
module SimpleServer
def setup
super
......
end
def interface
CyborgServerInterface
EmptyInterface
end
end
end

Also available in: Unified diff