Panda3D

clientBase.h

00001 // Filename: clientBase.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 CLIENTBASE_H
00016 #define CLIENTBASE_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "clientDevice.h"
00021 
00022 #include "typedReferenceCount.h"
00023 #include "luse.h"
00024 #include "vector_string.h"
00025 #include "vector_int.h"
00026 #include "clockObject.h"
00027 #include "pointerTo.h"
00028 #include "coordinateSystem.h"
00029 
00030 #ifdef OLD_HAVE_IPC
00031 #include "ipc_thread.h"
00032 #endif
00033 
00034 #include "pmap.h"
00035 
00036 ////////////////////////////////////////////////////////////////////
00037 //       Class : ClientBase
00038 // Description : An abstract base class for a family of client
00039 //               device interfaces--including trackers, buttons,
00040 //               dials, and other analog inputs.
00041 //
00042 //               This provides a common interface to connect to such
00043 //               devices and extract their data; it is used by
00044 //               TrackerNode etc. to put these devices in the data
00045 //               graph.
00046 ////////////////////////////////////////////////////////////////////
00047 class EXPCL_PANDA_DEVICE ClientBase : public TypedReferenceCount {
00048 protected:
00049   ClientBase();
00050 
00051 PUBLISHED:
00052   ~ClientBase();
00053 
00054   bool fork_asynchronous_thread(double poll_time);
00055   INLINE bool is_forked() const;
00056   INLINE bool poll();
00057   INLINE double get_last_poll_time() const;
00058 
00059   INLINE void set_coordinate_system(CoordinateSystem cs);
00060   INLINE CoordinateSystem get_coordinate_system() const;
00061 
00062 public:
00063   PT(ClientDevice) get_device(TypeHandle device_type,
00064                               const string &device_name);
00065 
00066 protected:
00067   virtual PT(ClientDevice) make_device(TypeHandle device_type,
00068                                        const string &device_name)=0;
00069 
00070   virtual bool disconnect_device(TypeHandle device_type,
00071                                  const string &device_name,
00072                                  ClientDevice *device);
00073 
00074   virtual void do_poll();
00075 
00076 private:
00077   typedef pmap<string, ClientDevice *> DevicesByName;
00078   typedef pmap<TypeHandle, DevicesByName> Devices;
00079   Devices _devices;
00080 
00081   bool _forked;
00082   double _last_poll_time;
00083   int _last_poll_frame;
00084   CoordinateSystem _cs;
00085 
00086 #ifdef OLD_HAVE_IPC
00087   int _sleep_time;
00088   thread *_client_thread;
00089   bool _shutdown;
00090 
00091   static void* st_callback(void *arg);
00092   void callback();
00093 #endif
00094 
00095 
00096 public:
00097   static TypeHandle get_class_type() {
00098     return _type_handle;
00099   }
00100   static void init_type() {
00101     TypedReferenceCount::init_type();
00102     register_type(_type_handle, "ClientBase",
00103                   TypedReferenceCount::get_class_type());
00104   }
00105   virtual TypeHandle get_type() const {
00106     return get_class_type();
00107   }
00108   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00109 
00110 private:
00111   static TypeHandle _type_handle;
00112 
00113   friend class ClientDevice;
00114 };
00115 
00116 #include "clientBase.I"
00117 
00118 #endif
 All Classes Functions Variables Enumerations