00001
00002 #ifndef INCLUDED_WMMonitorBehavior_h_
00003 #define INCLUDED_WMMonitorBehavior_h_
00004
00005 #include <iostream>
00006 #include "Wireless/Wireless.h"
00007 #include "Behaviors/BehaviorBase.h"
00008 #include "Motion/MotionManager.h"
00009 #include "Events/EventRouter.h"
00010 #include "Events/EventBase.h"
00011 #include "Shared/RobotInfo.h"
00012 #include "Shared/Serializer.h"
00013 #include "Behaviors/Controller.h"
00014 #include "Shared/WMclass.h"
00015
00016
00017 int wmmonitorcmd_callback(char *buf, int bytes);
00018 class WMMonitorBehavior;
00019
00020
00021 extern WMMonitorBehavior *wmMonitorBehavior;
00022
00023 class WMitem_base;
00024
00025
00026 class WMMonitorBehavior : public BehaviorBase {
00027 protected:
00028
00029 Socket *cmdsock;
00030
00031 private:
00032 WMMonitorBehavior(const WMMonitorBehavior&);
00033 WMMonitorBehavior operator=(const WMMonitorBehavior&);
00034
00035 public:
00036
00037 WMMonitorBehavior() :
00038 BehaviorBase(),
00039 cmdsock(wireless->socket(SocketNS::SOCK_STREAM, 2048, 8192))
00040 { wmMonitorBehavior = this;
00041 wireless->setDaemon(cmdsock); }
00042
00043 virtual ~WMMonitorBehavior() { wmMonitorBehavior = NULL; }
00044
00045
00046 void registerData(const std::string& s);
00047
00048
00049 WMitem_base* find (std::string& s);
00050
00051
00052 void report (const std::string& var_type,
00053 const std::string& var_name,
00054 const std::string& value);
00055
00056
00057 void report (const std::string& var_type,
00058 const std::string& var_name,
00059 const char* value, int value_length);
00060
00061
00062 void report(const char* var_type, int var_type_length,
00063 const char* var_name, int var_name_length,
00064 const char* value, int value_length);
00065
00066 virtual void DoStart() {
00067
00068 BehaviorBase::DoStart();
00069
00070 wireless->setReceiver(cmdsock->sock, wmmonitorcmd_callback);
00071 wireless->listen(cmdsock->sock, config->main.wmmonitor_port);
00072
00073
00074
00075 erouter->addListener(this,EventBase::wmVarEGID);
00076 }
00077
00078 virtual void DoStop() {
00079
00080 erouter->forgetListener(this);
00081
00082 wireless->close(cmdsock);
00083
00084 BehaviorBase::DoStop();
00085 }
00086
00087 virtual void processEvent(const EventBase& e) {
00088 WMentry * entry = reinterpret_cast<WMentry*>(e.getSourceID());
00089 std::string s(entry->item_name);
00090 WMregistry *temp=entry->registry;
00091 while (temp!=&GlobalWM && temp!=NULL) {
00092 s=temp->name + "." + s;
00093 temp=temp->parent;
00094 }
00095 report(entry->type_name, s, entry->item->toString());
00096 }
00097
00098 virtual unsigned int getPort() const { return config->main.wmmonitor_port; }
00099
00100 virtual std::string getName() const { return "Watchable Memory Monitor"; }
00101 static std::string getClassDescription() {
00102 char tmp[20];
00103 sprintf(tmp,"%d",config->main.wmmonitor_port);
00104 return std::string("Bidirectional control communication with WMMonitor on port ")+tmp;
00105 }
00106 };
00107
00108
00109 int wmmonitorcmd_callback(char *buf, int bytes);
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 #endif