Class: Orocos::CORBA::NameService

Inherits:
NameServiceBase show all
Includes:
Namespace
Defined in:
lib/orocos/name_service.rb,
ext/rorocos/corba.cc

Overview

Name service client to access the CORBA name service and retrieve an handle to registered Orocos Tasks. By default there is one global instance accessible via name_service which is also by default added to Orocos.name_service

The default name_service is used to register all Orocos Tasks started by the ruby instance no matter if it was removed from Orocos.name_service or not.

See Also:

Author:

  • Alexander Duda

Constant Summary

Constants included from Namespace

Namespace::DELIMATOR

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Namespace

#basename, #map_to_namespace, #namespace=, #same_namespace?, #split_name, split_name, validate_namespace_name, #verify_same_namespace

Methods inherited from NameServiceBase

#each_task, #find_one_running, #get_provides, #reachable?, #same_namespace?, #task_reachable?

Constructor Details

#initialize(host = "") ⇒ NameService

Returns a new instance of NameService



534
535
536
# File 'lib/orocos/name_service.rb', line 534

def initialize(host = "")
    self.ip = host
end

Class Method Details

.new(*args) ⇒ Object



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'ext/rorocos/corba.cc', line 160

static VALUE name_service_create(int argc, VALUE *argv,VALUE klass)
{
    // all parametes are forwarded to ruby initialize
    std::string ip;
    std::string port;

    if(argc > 0)
    {
        if(TYPE(argv[0]) == T_STRING)
            ip = StringValueCStr(argv[0]);
    }
    if(argc > 1)
    {
        if(TYPE(argv[1]) == T_STRING)
            port = StringValueCStr(argv[1]);
    }

    std::auto_ptr<NameServiceClient> new_name_service(new NameServiceClient(ip,port));
    VALUE obj = simple_wrap(cNameService, new_name_service.release());
    rb_obj_call_init(obj,argc,argv);
    return obj;
}

Instance Method Details

#bind(task, name) ⇒ Object

Bind an existing task under an alternative name

Parameters:

  • task (TaskContext)

    the task context

  • name (String)

    the name



568
569
570
# File 'lib/orocos/name_service.rb', line 568

def bind(task, name)
    do_bind(task, name)
end

#cleanupObject

Removes dangling references from the name service

This method removes objects that are not accessible anymore from the name service



656
657
658
659
660
661
662
663
664
665
666
667
# File 'lib/orocos/name_service.rb', line 656

def cleanup
    names = names().dup
    names.each do |n|
        begin
            CORBA.info "trying task context #{n}"
            get(n)
        rescue Orocos::NotFound => e
            deregister(n)
            CORBA.warn "deregistered dangling CORBA name #{n}: #{e.message}"
        end
    end
end

#deregister(name) ⇒ Object

Deregisters the given name or task from the name service.

Parameters:



633
634
635
636
637
638
639
640
641
642
643
# File 'lib/orocos/name_service.rb', line 633

def deregister(name)
    name = if name.respond_to? :name
               name.name
           else
               name
           end
    verify_same_namespace(name)
    CORBA.refine_exceptions("corba naming service #{ip}") do
        do_unbind(basename(name))
    end
end

#do_bind(task, task_name) ⇒ Object



246
247
248
249
250
251
252
253
254
255
256
# File 'ext/rorocos/corba.cc', line 246

static VALUE name_service_bind(VALUE self,VALUE task,VALUE task_name)
{
    corba_must_be_initialized();
    
    std::string name = StringValueCStr(task_name);
    NameServiceClient& name_service = get_wrapped<NameServiceClient>(self);
    RTaskContext& context = get_wrapped<RTaskContext>(task);
    CORBA::Object_var obj = CORBA::Object::_duplicate(context.task);
    corba_blocking_fct_call(boost::bind(&NameServiceClient::bind,&name_service,obj,name));
    return Qnil;
}

#do_ior(task_name) ⇒ Object



258
259
260
261
262
263
264
265
266
# File 'ext/rorocos/corba.cc', line 258

static VALUE name_service_ior(VALUE self,VALUE task_name)
{
    corba_must_be_initialized();

    std::string name = StringValueCStr(task_name);
    NameServiceClient& name_service = get_wrapped<NameServiceClient>(self);
    std::string ior = corba_blocking_fct_call_with_result(boost::bind(&NameServiceClient::getIOR,&name_service,name));
    return rb_str_new2(ior.c_str());
}

#do_ipObject



183
184
185
186
187
# File 'ext/rorocos/corba.cc', line 183

static VALUE name_service_ip(VALUE self)
{
    NameServiceClient& name_service = get_wrapped<NameServiceClient>(self);
    return rb_str_new2(name_service.getIp().c_str());
}

#do_portObject



189
190
191
192
193
# File 'ext/rorocos/corba.cc', line 189

static VALUE name_service_port(VALUE self)
{
    NameServiceClient& name_service = get_wrapped<NameServiceClient>(self);
    return rb_str_new2(name_service.getPort().c_str());
}

#do_reset(ip, port) ⇒ Object



195
196
197
198
199
200
201
202
# File 'ext/rorocos/corba.cc', line 195

static VALUE name_service_reset(VALUE self,VALUE ip, VALUE port)
{
    std::string sip = StringValueCStr(ip);
    std::string sport = StringValueCStr(port);
    NameServiceClient& name_service = get_wrapped<NameServiceClient>(self);
    name_service.reset(sip,sport);
    return self;
}

#do_task_context_namesObject



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'ext/rorocos/corba.cc', line 210

static VALUE name_service_task_context_names(VALUE self)
{
    corba_must_be_initialized();

    NameServiceClient& name_service = get_wrapped<NameServiceClient>(self);
    std::vector<std::string> names;

    names = corba_blocking_fct_call_with_result(boost::bind(&NameServiceClient::getTaskContextNames,&name_service),
                              boost::bind(&NameServiceClient::abort,&name_service));

    VALUE result = rb_ary_new();
    for (vector<string>::const_iterator it = names.begin(); it != names.end(); ++it)
        rb_ary_push(result, rb_str_new2(it->c_str()));
    return result;
}

#do_unbind(task_name) ⇒ Object



227
228
229
230
231
232
233
234
235
# File 'ext/rorocos/corba.cc', line 227

static VALUE name_service_unbind(VALUE self,VALUE task_name)
{
    corba_must_be_initialized();

    std::string name = StringValueCStr(task_name);
    NameServiceClient& name_service = get_wrapped<NameServiceClient>(self);
    bool result = corba_blocking_fct_call_with_result(boost::bind(&NameServiceClient::unbind,&name_service,name));
    return result ? Qtrue : Qfalse;
}

#do_validateObject



237
238
239
240
241
242
243
244
# File 'ext/rorocos/corba.cc', line 237

static VALUE name_service_validate(VALUE self)
{
    corba_must_be_initialized();

    NameServiceClient& name_service = get_wrapped<NameServiceClient>(self);
    corba_blocking_fct_call(boost::bind(&NameServiceClient::validate,&name_service));
    return Qnil;
}

#get(name = nil, namespace: nil, process: nil, ior: nil) ⇒ Orocos::TaskContext, Orocos::Log::TaskContext

Gets an handle to a local/remote Orocos Task having the given name.

Parameters:

  • name (String) (defaults to: nil)

    the name of the TaskContext

  • options (Hash)

    the options used by the name service to find the TaskContext

Returns:

Raises:

See Also:



604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
# File 'lib/orocos/name_service.rb', line 604

def get(name = nil, namespace: nil, process: nil, ior: nil)
    if ior
        Orocos::TaskContext.new(ior, namespace: namespace, process: process)
    else
        ns,_ = split_name(name)
        ns = if !ns || ns.empty?
                 self.namespace
             else
                 ns
             end
        namespace ||= (ns || "")
        Orocos::TaskContext.new(ior(name), namespace: namespace, process: process)
    end
rescue ComError => e
    raise Orocos::NotFound, "task context #{name} is registered but cannot be reached."
end

#ior(name) ⇒ String

Gets the IOR for the given Orocos Task having the given name.

Parameters:

  • name (String)

    the name of the TaskContext

Returns:

  • (String)

Raises:



588
589
590
591
592
593
# File 'lib/orocos/name_service.rb', line 588

def ior(name)
    verify_same_namespace(name)
    CORBA.refine_exceptions("corba naming service(#{ip})") do
        do_ior(basename(name))
    end
end

#ipString

Returns The ip where the client tries to reach the CORBA name service

Returns:

  • (String)

    The ip where the client tries to reach the CORBA name service



555
556
557
# File 'lib/orocos/name_service.rb', line 555

def ip
    do_ip
end

#ip=(host) ⇒ Object

Sets the ip address or host name where the CORBA name service is running

Parameters:

  • host (String)

    The ip address or host name



550
551
552
# File 'lib/orocos/name_service.rb', line 550

def ip=(host)
    reset(host)
end

#nameObject

return [String] the name of the name service



539
540
541
# File 'lib/orocos/name_service.rb', line 539

def name
    "CORBA:#{namespace}"
end

#namesArray<String>

Returns all Orocos Task names known by the name service inclusive the namespace of the NameService instance.

Returns:

  • (Array<String>)


596
597
598
599
600
601
# File 'lib/orocos/name_service.rb', line 596

def names
    result = CORBA.refine_exceptions("corba naming service(#{ip})") do
        do_task_context_names.find_all { |n| n !~ /^orocosrb_(\d+)$/ }
    end
    map_to_namespace(result)
end

#namespaceObject



543
544
545
# File 'lib/orocos/name_service.rb', line 543

def namespace
    ip
end

#portString

Returns The port where the client tries to reach the CORBA name service

Returns:

  • (String)

    The port where the client tries to reach the CORBA name service



560
561
562
# File 'lib/orocos/name_service.rb', line 560

def port
    do_port
end

#register(task, name = task.name) ⇒ Object

Registers the IOR of the given TaskContext on the CORBA name service.

Parameters:

  • task (Orocos::TaskContext)

    The task.

  • name (String) (defaults to: task.name)

    The name which is used to register the task.



625
626
627
628
# File 'lib/orocos/name_service.rb', line 625

def register(task,name=task.name)
    verify_same_namespace(name)
    do_bind(task,basename(name))
end

#reset(ip = ip(), port = port()) ⇒ Object

Resets the CORBA name service client.

Parameters:

  • ip (String) (defaults to: ip())

    The ip address or host name where the CORBA name service is running

  • port (String) (defaults to: port())

    The port of the CORBA name service



583
584
585
# File 'lib/orocos/name_service.rb', line 583

def reset(ip=ip(),port=port())
    do_reset(ip,port)
end

#to_async(reconnect: true) ⇒ Orocos::Async::CORBA::NameService

The async-access object for this name service



575
576
577
# File 'lib/orocos/name_service.rb', line 575

def to_async(reconnect: true)
    Orocos::Async::CORBA::NameService.new(ip, reconnect: reconnect)
end

#validatenil

Checks if the name service is reachable if not it raises a ComError.

Returns:

  • (nil)

Raises:



646
647
648
649
650
# File 'lib/orocos/name_service.rb', line 646

def validate
    CORBA.refine_exceptions("corba naming service #{ip}") do
        do_validate
    end
end