Panda3D
 All Classes Functions Variables Enumerations
vrpnClient.h
00001 // Filename: vrpnClient.h
00002 // Created by:  jason (04Aug00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef VRPNCLIENT_H
00016 #define VRPNCLIENT_H
00017 
00018 #include "pandabase.h"
00019 #include "clientBase.h"
00020 
00021 #include "vrpn_interface.h"
00022 
00023 class VrpnTracker;
00024 class VrpnTrackerDevice;
00025 class VrpnButton;
00026 class VrpnButtonDevice;
00027 class VrpnAnalog;
00028 class VrpnAnalogDevice;
00029 class VrpnDial;
00030 class VrpnDialDevice;
00031 
00032 ////////////////////////////////////////////////////////////////////
00033 //       Class : VrpnClient
00034 // Description : A specific ClientBase that connects to a VRPN server
00035 //               and records information on the connected VRPN
00036 //               devices.
00037 ////////////////////////////////////////////////////////////////////
00038 class EXPCL_PANDA_VRPN VrpnClient : public ClientBase {
00039 PUBLISHED:
00040   VrpnClient(const string &server_name);
00041   ~VrpnClient();
00042 
00043   INLINE const string &get_server_name() const;
00044   INLINE bool is_valid() const;
00045   INLINE bool is_connected() const;
00046 
00047   void write(ostream &out, int indent_level = 0) const;
00048 
00049 public:
00050   INLINE static double convert_to_secs(struct timeval msg_time);
00051 
00052 protected:
00053   virtual PT(ClientDevice) make_device(TypeHandle device_type,
00054                                        const string &device_name);
00055 
00056   virtual bool disconnect_device(TypeHandle device_type,
00057                                  const string &device_name,
00058                                  ClientDevice *device);
00059 
00060   virtual void do_poll();
00061 
00062 private:
00063   PT(ClientDevice) make_tracker_device(const string &device_name);
00064   PT(ClientDevice) make_button_device(const string &device_name);
00065   PT(ClientDevice) make_analog_device(const string &device_name);
00066   PT(ClientDevice) make_dial_device(const string &device_name);
00067   void disconnect_tracker_device(VrpnTrackerDevice *device);
00068   void disconnect_button_device(VrpnButtonDevice *device);
00069   void disconnect_analog_device(VrpnAnalogDevice *device);
00070   void disconnect_dial_device(VrpnDialDevice *device);
00071 
00072   VrpnTracker *get_tracker(const string &tracker_name);
00073   void free_tracker(VrpnTracker *vrpn_tracker);
00074 
00075   VrpnButton *get_button(const string &button_name);
00076   void free_button(VrpnButton *vrpn_button);
00077 
00078   VrpnAnalog *get_analog(const string &analog_name);
00079   void free_analog(VrpnAnalog *vrpn_analog);
00080 
00081   VrpnDial *get_dial(const string &dial_name);
00082   void free_dial(VrpnDial *vrpn_dial);
00083 
00084 private:
00085   string _server_name;
00086   vrpn_Connection *_connection;
00087 
00088   typedef pmap<string, VrpnTracker *> Trackers;
00089   typedef pmap<string, VrpnButton *> Buttons;
00090   typedef pmap<string, VrpnAnalog *> Analogs;
00091   typedef pmap<string, VrpnDial *> Dials;
00092 
00093   Trackers _trackers;
00094   Buttons _buttons;
00095   Analogs _analogs;
00096   Dials _dials;
00097 
00098 
00099 public:
00100   static TypeHandle get_class_type() {
00101     return _type_handle;
00102   }
00103   static void init_type() {
00104     ClientBase::init_type();
00105     register_type(_type_handle, "VrpnClient",
00106                   ClientBase::get_class_type());
00107   }
00108   virtual TypeHandle get_type() const {
00109     return get_class_type();
00110   }
00111   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00112 
00113 private:
00114   static TypeHandle _type_handle;
00115 };
00116 
00117 #include "vrpnClient.I"
00118 
00119 #endif
00120 
00121 
 All Classes Functions Variables Enumerations