Getting a Command through its name






Dear Orocos specialists,



I would like to get a command in C++ using its name. I managed to get
the command and execute it, but I did not succeed in giving arguments
to this command ... See the code below.



bool mySendMsg(std::string peerName, std::string cdeName,
std::string argValue) {

            //getting the peer

            TaskContext* peer = this->getPeer(peerName);



            //getting the command

            CommandRepository *cr = peer->commands();

            DispatchInterface *di =
cr->getCommand<bool(std::string)>(cdeName);



            //giving the command arguments ???????????



            //executing the command

            bool res = di->execute();



            //print results

            if(!res)

                log(Info) << "executeMsg not OK" <<
endlog();

            else

                log(Info) << "executeMsg OK" << endlog();



            return true;

}



Any idea ?

Thanks a lot,

Renaud


Ruben Smits's picture

Getting a Command through its name

On Wednesday November 5 2008 12:41:11 Renaud Heitz wrote:
> Dear Orocos specialists,
>
> I would like to get a command in C++ using its name. I managed to get the
> command and execute it, but I did not succeed in giving arguments to this
> command ... See the code below.
>
> bool mySendMsg(std::string peerName, std::string cdeName, std::string
> argValue) { //getting the peer
> TaskContext* peer = this->getPeer(peerName);
>
> //getting the command
> CommandRepository *cr = peer->commands();
> DispatchInterface *di =
> cr->getCommand(cdeName);
>
> //giving the command arguments ???????????
>
> //executing the command
> bool res = di->execute();
>
> //print results
> if(!res)
> log(Info) << "executeMsg not OK" << endlog();
> else
> log(Info) << "executeMsg OK" << endlog();
>
> return true;
> }

From the components-builder manual:

part of invoking commands in c++, try the following:

bool mySendMsg(std::string peerName, std::string cdeName, std::string argValue)
{
Command mycom = this->getPeer(peerName)->commands()->getCommand("cdeName");
//executing the command
if (mycom.ready() ){
bool res = mycom(argValue);

// next, use any of the following :
bool accepted = mycom.accepted(); // accepted by execution engine?
bool valid = mycom.valid(); // command was valid (well-formed)?
bool done = mycom.done(); // command was done?

//print results
if(!res)
log(Info) << "executeMsg not OK" << endlog();
else
log(Info) << "executeMsg OK" << endlog();
}
return true;
}

Ruben