summaryrefslogtreecommitdiff
path: root/i/marvin/src/proto/test_proto.cc
diff options
context:
space:
mode:
authorhaller2006-05-21 20:14:02 +0000
committerhaller2006-05-21 20:14:02 +0000
commit080f4918a072c8677c52d33eda2c32d087889209 (patch)
treeb3603fcfde2f9ee310e4d9e51624dc49dda61a84 /i/marvin/src/proto/test_proto.cc
parentf04316bb1b0bab00bd08a355ca0e3d0ab996ec4a (diff)
* 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
Diffstat (limited to 'i/marvin/src/proto/test_proto.cc')
-rw-r--r--i/marvin/src/proto/test_proto.cc98
1 files changed, 46 insertions, 52 deletions
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 <iostream>
#include <stdexcept>
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<std::string>("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<std::string>("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<char> (*it);
+ // format des arguments
+ std::string format = any_cast<std::string> (*++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<int> (*++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