Homepage Demos Overview Downloads Tutorials Reference
Credits

WMMonitorBehavior.h

Go to the documentation of this file.
00001 //-*-c++-*-
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 //! gets input from the GUI
00017 int wmmonitorcmd_callback(char *buf, int bytes);
00018 class WMMonitorBehavior;
00019 
00020 //! so wmmonitorcmd_callback knows where to send the input from the GUI
00021 extern WMMonitorBehavior *wmMonitorBehavior;
00022 
00023 class WMitem_base;
00024 
00025 //! Listens to wmmonitor control commands coming in from the command port.
00026 class WMMonitorBehavior : public BehaviorBase {
00027  protected:
00028   //! The input command stream socket
00029   Socket *cmdsock;
00030 
00031  private:
00032   WMMonitorBehavior(const WMMonitorBehavior&); //!< don't call
00033   WMMonitorBehavior operator=(const WMMonitorBehavior&); //!< don't call
00034 
00035  public:
00036   //! constructor
00037   WMMonitorBehavior() :
00038     BehaviorBase(),
00039     cmdsock(wireless->socket(SocketNS::SOCK_STREAM, 2048, 8192))
00040   { wmMonitorBehavior = this;
00041     wireless->setDaemon(cmdsock); }
00042   //! destructor
00043   virtual ~WMMonitorBehavior() { wmMonitorBehavior = NULL; }
00044 
00045   //! processes input from the GUI
00046   void registerData(const std::string& s);
00047 
00048   //! Finds the item with the corresponding name
00049   WMitem_base* find (std::string& s);
00050 
00051   //! Writes out the passed information to #cmdsock
00052   void report (const std::string& var_type,
00053                const std::string& var_name,
00054                const std::string& value);
00055 
00056   //! Writes out the passed information to #cmdsock
00057   void report (const std::string& var_type,
00058                const std::string& var_name,
00059                const char* value, int value_length);
00060 
00061   //! Writes out the passed information to #cmdsock
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     // Behavior startup
00068     BehaviorBase::DoStart();
00069     // Turn on wireless
00070     wireless->setReceiver(cmdsock->sock, wmmonitorcmd_callback);
00071     wireless->listen(cmdsock->sock, config->main.wmmonitor_port);
00072     // open gui
00073     // GUI is opened by separate behavior ViewWMVarsBehavior
00074     // until bug with clearing wmvars when restarting this is fixed
00075     erouter->addListener(this,EventBase::wmVarEGID);
00076   }
00077 
00078   virtual void DoStop() {
00079 //    Controller::closeGUI(getGUIType());
00080     erouter->forgetListener(this);
00081     // Close socket; turn wireless off
00082     wireless->close(cmdsock);
00083     // Total behavior stop
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"; } //!< returns name of behavior
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 //! interfaces with wireless to pass information from the gui to the monitor
00109 int wmmonitorcmd_callback(char *buf, int bytes);
00110 
00111 /*! @file
00112  * @brief Defines WMMonitorBehavior, which listens to commands from the Aibo3D gui and shows current state
00113  * @author alokl (Creator)
00114  *
00115  * $Author: ejt $
00116  * $Name: tekkotsu-1_5 $
00117  * $Revision: 1.3 $
00118  * $State: Rel $
00119  * $Date: 2003/10/10 17:50:10 $
00120  */
00121 
00122 #endif 

Tekkotsu v1.5
Generated Fri Oct 10 15:52:00 2003 by Doxygen 1.3.4