From 080f4918a072c8677c52d33eda2c32d087889209 Mon Sep 17 00:00:00 2001 From: haller Date: Sun, 21 May 2006 20:14:02 +0000 Subject: * Ajout d'une fonction exists dans Interpreter (Ni) * Patch de InterpreterParser::call, vérifie que la fonction _postcall existe avant d'essayer de la lancer * Refonte de test_proto en utilisant un AnyList dans TestProto::send --- i/marvin/src/proto/test_proto.cc | 98 +++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 52 deletions(-) (limited to 'i/marvin/src/proto') diff --git a/i/marvin/src/proto/test_proto.cc b/i/marvin/src/proto/test_proto.cc index a9f1fa8..01cac96 100644 --- a/i/marvin/src/proto/test_proto.cc +++ b/i/marvin/src/proto/test_proto.cc @@ -25,66 +25,60 @@ #include "proto.hh" #include "timer/timer.hh" #include "tester/tester.hh" +#include "parser/parser.hh" #include #include class TestProto : public Tester, Proto::Receiver { - private: - Proto proto_; - public: - // Constructor - TestProto (int argc, char ** argv) - : Tester (argc, argv), proto_(*this){} - void preRun (void) - { - Interpreter &interpreter = getInterpreter (); - // Récupère le tty de config - proto_.open(config_.get("testProto.tty")); - // Add functions. - interpreter.add ("s", Interpreter::memFunc ( *this, &TestProto::send ), - "Fonction send (string commande, string format, int arg...)"); - interpreter.add ("w", Interpreter::memFunc ( proto_, &Proto::wait ), "Fonction wait ()"); - } - void postRun(void) - { - proto_.close(); - } - void receive (char command, const Proto::Frame &frame) - { - std::cout << "received " << frame << std::endl; - } - void send (std::string str) + private: + Proto proto_; + public: + // Constructor + TestProto (int argc, char ** argv) + : Tester (argc, argv), proto_(*this){} + void preRun (void) + { + Interpreter &interpreter = getInterpreter (); + // Récupère le tty de config + proto_.open(config_.get("testProto.tty")); + // Add functions. + interpreter.add ("s", Interpreter::memFunc ( *this, &TestProto::send ), + "Fonction send (string commande, string format, " + "int arg...)"); + interpreter.add ("w", Interpreter::memFunc ( proto_, &Proto::wait ), + "Fonction wait ()"); + } + void postRun(void) + { + proto_.close(); + } + void receive (char command, const Proto::Frame &frame) + { + std::cout << "received " << frame << std::endl; + } + void send (const Parser::AnyList & al, bool dryrun) + { + Parser::AnyList::const_iterator it = al.begin(); + // arguments envoyé à la fonctions Proto::send + int arg[6]; + // command avr + char command = any_cast (*it); + // format des arguments + std::string format = any_cast (*++it); + // Récupération des arguments + for (unsigned i = 0; i < 6; ++i) { - // command avr - char command = str[0]; - // format des arguments - char *format; - // arguments envoyé à la fonctions Proto::send - int arg[6]; - int nbArg = 0; - char *temp; - char *string = new char[str.size() + 1]; - strcpy(string, str.c_str()); - // On fait un strtok qui sert à rien - strtok(string, " "); - // On récupère le format - format = strtok(0, " "); - // On récupère les arguments - for(; nbArg < 6; nbArg++) - { - if(!(temp = strtok(0, " "))) - break; - else - arg[nbArg] = atoi(temp); - } - for(;nbArg < 6; nbArg++) - arg[nbArg] = 0; - proto_.send(command, !format?"":format, arg[0], arg[1], arg[2], arg[3], arg[4], - arg[5]); - delete [] string; + if(i < al.size() - 2) + arg[i] = any_cast (*++it); + else + arg[i] = 0; } + if (!dryrun) + proto_.send(command, format.c_str(), arg[0], arg[1], arg[2], + arg[3], arg[4], arg[5]); + } }; int -- cgit v1.2.3