Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/device/clientBase.h

Go to the documentation of this file.
00001 // Filename: clientBase.h
00002 // Created by:  jason (04Aug00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef CLIENTBASE_H
00020 #define CLIENTBASE_H
00021 
00022 #include "pandabase.h"
00023 
00024 #include "clientDevice.h"
00025 
00026 #include "typedReferenceCount.h"
00027 #include "luse.h"
00028 #include "vector_string.h"
00029 #include "vector_int.h"
00030 #include "clockObject.h"
00031 #include "pointerTo.h"
00032 #include "coordinateSystem.h"
00033 
00034 #ifdef OLD_HAVE_IPC
00035 #include "ipc_thread.h"
00036 #endif
00037 
00038 #include "pmap.h"
00039 
00040 ////////////////////////////////////////////////////////////////////
00041 //       Class : ClientBase
00042 // Description : An abstract base class for a family of client
00043 //               device interfaces--including trackers, buttons,
00044 //               dials, and other analog inputs.
00045 //
00046 //               This provides a common interface to connect to such
00047 //               devices and extract their data; it is used by
00048 //               TrackerNode etc. to put these devices in the data
00049 //               graph.
00050 ////////////////////////////////////////////////////////////////////
00051 class EXPCL_PANDA ClientBase : public TypedReferenceCount {
00052 protected:
00053   ClientBase();
00054 
00055 PUBLISHED:
00056   ~ClientBase();
00057 
00058   bool fork_asynchronous_thread(double poll_time);
00059   INLINE bool is_forked() const;
00060   INLINE bool poll();
00061   INLINE double get_last_poll_time() const;
00062 
00063   INLINE void set_coordinate_system(CoordinateSystem cs);
00064   INLINE CoordinateSystem get_coordinate_system() const;
00065 
00066 public:
00067   PT(ClientDevice) get_device(TypeHandle device_type,
00068                               const string &device_name);
00069 
00070 protected:
00071   virtual PT(ClientDevice) make_device(TypeHandle device_type,
00072                                        const string &device_name)=0;
00073 
00074   virtual bool disconnect_device(TypeHandle device_type,
00075                                  const string &device_name,
00076                                  ClientDevice *device);
00077 
00078   virtual void do_poll();
00079 
00080 private:
00081   typedef pmap<string, ClientDevice *> DevicesByName;
00082   typedef pmap<TypeHandle, DevicesByName> Devices;
00083   Devices _devices;
00084 
00085   bool _forked;
00086   double _last_poll_time;
00087   int _last_poll_frame;
00088   CoordinateSystem _cs;
00089 
00090 #ifdef OLD_HAVE_IPC
00091   int _sleep_time;
00092   thread *_client_thread;
00093   bool _shutdown;
00094 
00095   static void* st_callback(void *arg);
00096   void callback();
00097 #endif
00098 
00099 
00100 public:
00101   static TypeHandle get_class_type() {
00102     return _type_handle;
00103   }
00104   static void init_type() {
00105     TypedReferenceCount::init_type();
00106     register_type(_type_handle, "ClientBase",
00107                   TypedReferenceCount::get_class_type());
00108   }
00109   virtual TypeHandle get_type() const {
00110     return get_class_type();
00111   }
00112   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00113 
00114 private:
00115   static TypeHandle _type_handle;
00116 
00117   friend class ClientDevice;
00118 };
00119 
00120 #include "clientBase.I"
00121 
00122 #endif

Generated on Fri May 2 00:36:09 2003 for Panda by doxygen1.3