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 Dump : public Hub
00044 {
00045 private:
00046 bool rawTime;
00047
00048 public:
00049 Dump(bool rawTime) :
00050 rawTime(rawTime)
00051 {
00052 }
00053
00054 protected:
00055
00056 void connectionCreated(Stream *stream)
00057 {
00058 dumpTime(cout, rawTime);
00059 cout << stream->getTargetName() << " connection created." << endl;
00060 }
00061
00062 void incomingData(Stream *stream)
00063 {
00064 Message *message = Message::receive(stream);
00065
00066 dumpTime(cout, rawTime);
00067 cout << stream->getTargetName() << " ";
00068 if (message)
00069 message->dump(cout);
00070 else
00071 cout << "unknown message received";
00072 cout << endl;
00073 }
00074
00075 void connectionClosed(Stream *stream, bool abnormal)
00076 {
00077 dumpTime(cout);
00078 cout << stream->getTargetName() << " connection closed";
00079 if (abnormal)
00080 cout << " : " << stream->getFailReason();
00081 cout << "." << endl;
00082 }
00083 };
00084
00086 }
00087
00088
00090 void dumpHelp(std::ostream &stream, const char *programName)
00091 {
00092 stream << "Aseba dump, print the content of aseba messages, usage:\n";
00093 stream << programName << " [options] [targets]*\n";
00094 stream << "Options:\n";
00095 stream << "--rawtime : shows time in the form of sec:usec since 1970\n";
00096 stream << "-h, --help : shows this help\n";
00097 stream << "Targets are any valid Dashel targets." << std::endl;
00098 }
00099
00100 int main(int argc, char *argv[])
00101 {
00102 bool rawTime = false;
00103 std::vector<std::string> targets;
00104
00105 int argCounter = 1;
00106
00107 while (argCounter < argc)
00108 {
00109 const char *arg = argv[argCounter];
00110
00111 if (strcmp(arg, "--rawtime") == 0)
00112 {
00113 rawTime = true;
00114 }
00115 else if ((strcmp(arg, "-h") == 0) || (strcmp(arg, "--help") == 0))
00116 {
00117 dumpHelp(std::cout, argv[0]);
00118 return 0;
00119 }
00120 else
00121 {
00122 targets.push_back(argv[argCounter]);
00123 }
00124 argCounter++;
00125 }
00126
00127 if (targets.empty())
00128 targets.push_back(ASEBA_DEFAULT_TARGET);
00129
00130 try
00131 {
00132 Aseba::Dump dump(rawTime);
00133 for (size_t i = 0; i < targets.size(); i++)
00134 dump.connect(targets[i]);
00135 dump.run();
00136 }
00137 catch(Dashel::DashelException e)
00138 {
00139 std::cerr << e.what() << std::endl;
00140 }
00141
00142 return 0;
00143 }