00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "../msg/msg.h"
00025 #include "../utils/utils.h"
00026 #include <dashel/dashel.h>
00027 #include <time.h>
00028 #include <iostream>
00029 #include <cstring>
00030
00031 namespace Aseba
00032 {
00033 using namespace Dashel;
00034 using namespace std;
00035
00040
00043 class Recorder : public Hub
00044 {
00045 protected:
00046
00047 void incomingData(Stream *stream)
00048 {
00049 Message *message = Message::receive(stream);
00050 UserMessage *userMessage = dynamic_cast<UserMessage *>(message);
00051 if (userMessage)
00052 {
00053 dumpTime(cout, true);
00054 cout << userMessage->source << " ";
00055 cout << userMessage->type << " ";
00056 cout << userMessage->data.size() << " ";
00057 for (UserMessage::DataVector::const_iterator it = userMessage->data.begin(); it != userMessage->data.end(); ++it)
00058 cout << *it << " ";
00059 cout << endl;
00060 }
00061 }
00062 };
00063
00065 }
00066
00067
00069 void dumpHelp(std::ostream &stream, const char *programName)
00070 {
00071 stream << "Aseba rec, record the user messages to stdout for later replay, usage:\n";
00072 stream << programName << " [options] [targets]*\n";
00073 stream << "Options:\n";
00074 stream << "-h, --help : shows this help\n";
00075 stream << "Targets are any valid Dashel targets." << std::endl;
00076 }
00077
00078 int main(int argc, char *argv[])
00079 {
00080 std::vector<std::string> targets;
00081
00082 int argCounter = 1;
00083
00084 while (argCounter < argc)
00085 {
00086 const char *arg = argv[argCounter];
00087
00088 if ((strcmp(arg, "-h") == 0) || (strcmp(arg, "--help") == 0))
00089 {
00090 dumpHelp(std::cout, argv[0]);
00091 return 0;
00092 }
00093 else
00094 {
00095 targets.push_back(argv[argCounter]);
00096 }
00097 argCounter++;
00098 }
00099
00100 if (targets.empty())
00101 targets.push_back(ASEBA_DEFAULT_TARGET);
00102
00103 try
00104 {
00105 Aseba::Recorder recorder;
00106 for (size_t i = 0; i < targets.size(); i++)
00107 recorder.connect(targets[i]);
00108 recorder.run();
00109 }
00110 catch(Dashel::DashelException e)
00111 {
00112 std::cerr << e.what() << std::endl;
00113 }
00114
00115 return 0;
00116 }