Panda3D
Loading...
Searching...
No Matches
clientBase.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file clientBase.h
10 * @author jason
11 * @date 2000-08-04
12 */
13
14#ifndef CLIENTBASE_H
15#define CLIENTBASE_H
16
17#include "pandabase.h"
18
19#include "clientDevice.h"
20
21#include "typedReferenceCount.h"
22#include "luse.h"
23#include "vector_string.h"
24#include "vector_int.h"
25#include "clockObject.h"
26#include "pointerTo.h"
27#include "coordinateSystem.h"
28
29#ifdef OLD_HAVE_IPC
30#include <ipc_thread.h>
31#endif
32
33#include "pmap.h"
34
35/**
36 * An abstract base class for a family of client device interfaces--including
37 * trackers, buttons, dials, and other analog inputs.
38 *
39 * This provides a common interface to connect to such devices and extract
40 * their data; it is used by TrackerNode etc. to put these devices in the
41 * data graph.
42 */
43class EXPCL_PANDA_DEVICE ClientBase : public TypedReferenceCount {
44protected:
45 ClientBase();
46
47PUBLISHED:
48 ~ClientBase();
49
50 bool fork_asynchronous_thread(double poll_time);
51 INLINE bool is_forked() const;
52 INLINE bool poll();
53 INLINE double get_last_poll_time() const;
54
55 INLINE void set_coordinate_system(CoordinateSystem cs);
56 INLINE CoordinateSystem get_coordinate_system() const;
57
58public:
59 PT(ClientDevice) get_device(TypeHandle device_type,
60 const std::string &device_name);
61
62protected:
63 virtual PT(ClientDevice) make_device(TypeHandle device_type,
64 const std::string &device_name)=0;
65
66 virtual bool disconnect_device(TypeHandle device_type,
67 const std::string &device_name,
68 ClientDevice *device);
69
70 virtual void do_poll();
71
72private:
73 typedef pmap<std::string, ClientDevice *> DevicesByName;
74 typedef pmap<TypeHandle, DevicesByName> Devices;
75 Devices _devices;
76
77 bool _forked;
78 double _last_poll_time;
79 int _last_poll_frame;
80 CoordinateSystem _cs;
81
82#ifdef OLD_HAVE_IPC
83 int _sleep_time;
84 thread *_client_thread;
85 bool _shutdown;
86
87 static void* st_callback(void *arg);
88 void callback();
89#endif
90
91
92public:
93 static TypeHandle get_class_type() {
94 return _type_handle;
95 }
96 static void init_type() {
97 TypedReferenceCount::init_type();
98 register_type(_type_handle, "ClientBase",
99 TypedReferenceCount::get_class_type());
100 }
101 virtual TypeHandle get_type() const {
102 return get_class_type();
103 }
104 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
105
106private:
107 static TypeHandle _type_handle;
108
109 friend class ClientDevice;
110};
111
112#include "clientBase.I"
113
114#endif
PointerTo< ClientDevice > get_device(TypeHandle device_type, const std::string &device_name)
Returns a ClientDevice pointer that corresponds to the named device of the indicated device type.
bool is_forked() const
Returns true if the ClientBase has been forked (and, therefore, poll() does not need to be called),...
Definition clientBase.I:19
void set_coordinate_system(CoordinateSystem cs)
Specifies the coordinate system that all devices associated with this client will operate in.
Definition clientBase.I:53
bool poll()
Initiates a poll of the client devices, if we are not forked and if we have not already polled this f...
Definition clientBase.I:29
CoordinateSystem get_coordinate_system() const
Returns the coordinate system that all devices associated with this client will operate in.
Definition clientBase.I:62
bool fork_asynchronous_thread(double poll_time)
Forks a separate thread to do all the polling of connected devices.
double get_last_poll_time() const
Returns the time (according to the global ClockObject's get_real_time() method) of the last device po...
Definition clientBase.I:44
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.