Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "../common/consts.h"
00022 #include "../msg/msg.h"
00023 #include "../utils/utils.h"
00024 #include <dashel/dashel.h>
00025 #include "../transport/dashel_plugins/dashel-plugins.h"
00026 #include <time.h>
00027 #include <iostream>
00028 #include <cstring>
00029
00030 namespace Aseba
00031 {
00032 using namespace Dashel;
00033 using namespace std;
00034
00039
00042 class Dump : public Hub
00043 {
00044 private:
00045 bool rawTime;
00046
00047 public:
00048 Dump(bool rawTime) :
00049 rawTime(rawTime)
00050 {
00051 }
00052
00053 protected:
00054
00055 void connectionCreated(Stream *stream)
00056 {
00057 dumpTime(cout, rawTime);
00058 cout << stream->getTargetName() << " connection created." << endl;
00059 }
00060
00061 void incomingData(Stream *stream)
00062 {
00063 Message *message = Message::receive(stream);
00064
00065 dumpTime(cout, rawTime);
00066 cout << stream->getTargetName() << " ";
00067 if (message)
00068 message->dump(wcout);
00069 else
00070 cout << "unknown message received";
00071 cout << endl;
00072 }
00073
00074 void connectionClosed(Stream *stream, bool abnormal)
00075 {
00076 dumpTime(cout);
00077 cout << stream->getTargetName() << " connection closed";
00078 if (abnormal)
00079 cout << " : " << stream->getFailReason();
00080 cout << "." << endl;
00081 }
00082 };
00083
00085 }
00086
00087
00089 void dumpHelp(std::ostream &stream, const char *programName)
00090 {
00091 stream << "Aseba dump, print the content of aseba messages, usage:\n";
00092 stream << programName << " [options] [targets]*\n";
00093 stream << "Options:\n";
00094 stream << "--rawtime : shows time in the form of sec:usec since 1970\n";
00095 stream << "-h, --help : shows this help\n";
00096 stream << "-V, --version : shows the version number\n";
00097 stream << "Targets are any valid Dashel targets." << std::endl << std::endl;
00098 stream << "Report bugs to: aseba-dev@gna.org" << std::endl;
00099 }
00100
00102 void dumpVersion(std::ostream &stream)
00103 {
00104 stream << "Aseba dump " << ASEBA_VERSION << std::endl;
00105 stream << "Aseba protocol " << ASEBA_PROTOCOL_VERSION << std::endl;
00106 stream << "Licence LGPLv3: GNU LGPL version 3 <http://www.gnu.org/licenses/lgpl.html>\n";
00107 }
00108
00109 int main(int argc, char *argv[])
00110 {
00111 Dashel::initPlugins();
00112 bool rawTime = false;
00113 std::vector<std::string> targets;
00114
00115 int argCounter = 1;
00116
00117 while (argCounter < argc)
00118 {
00119 const char *arg = argv[argCounter];
00120
00121 if (strcmp(arg, "--rawtime") == 0)
00122 {
00123 rawTime = true;
00124 }
00125 else if ((strcmp(arg, "-h") == 0) || (strcmp(arg, "--help") == 0))
00126 {
00127 dumpHelp(std::cout, argv[0]);
00128 return 0;
00129 }
00130 else if ((strcmp(arg, "-V") == 0) || (strcmp(arg, "--version") == 0))
00131 {
00132 dumpVersion(std::cout);
00133 return 0;
00134 }
00135 else
00136 {
00137 targets.push_back(argv[argCounter]);
00138 }
00139 argCounter++;
00140 }
00141
00142 if (targets.empty())
00143 targets.push_back(ASEBA_DEFAULT_TARGET);
00144
00145 try
00146 {
00147 Aseba::Dump dump(rawTime);
00148 for (size_t i = 0; i < targets.size(); i++)
00149 dump.connect(targets[i]);
00150 dump.run();
00151 }
00152 catch(Dashel::DashelException e)
00153 {
00154 std::cerr << e.what() << std::endl;
00155 }
00156
00157 return 0;
00158 }