root/juggler/tags/1.0.7/Environment/vjConnect.h

Revision 8789, 5.0 kB (checked in by patrickh, 7 years ago)

Copyright update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
2  *
3  * VR Juggler is (C) Copyright 1998, 1999, 2000, 2001, 2002
4  *   by Iowa State University
5  *
6  * Original Authors:
7  *   Allen Bierbaum, Christopher Just,
8  *   Patrick Hartling, Kevin Meinert,
9  *   Carolina Cruz-Neira, Albert Baker
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Library General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Library General Public License for more details.
20  *
21  * You should have received a copy of the GNU Library General Public
22  * License along with this library; if not, write to the
23  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24  * Boston, MA 02111-1307, USA.
25  *
26  * -----------------------------------------------------------------
27  * File:          $RCSfile$
28  * Date modified: $Date$
29  * Version:       $Revision$
30  * -----------------------------------------------------------------
31  *
32  *************** <auto-copyright.pl END do not edit this line> ***************/
33
34
35 #ifndef _VJ_CONNECT_H_
36 #define _VJ_CONNECT_H_
37
38 #include <vjConfig.h>
39 #include <queue>
40 #include <Environment/vjSocket.h>
41 #include <Threads/vjThread.h>
42 #include <Performance/vjTimeStamp.h>
43 #include <Environment/vjCommand.h>
44
45
46 class vjTimedUpdate;
47 class vjConfigChunk;
48
49 enum vjConnectMode { VJC_INTERACTIVE, VJC_INPUT, VJC_OUTPUT };
50
51 //--------------------------------------------------
52 //: vjConnect reads/writes to a file, pipe, or socket.
53 //
54 // @author  Christopher Just
55 //
56 //---------------------------------------
57 class vjConnect {
58  public:
59
60     vjConnect (vjSocket* s, const std::string& _name="unnamed",
61                vjConnectMode _mode = VJC_INTERACTIVE);
62
63
64
65     vjConnect (vjConfigChunk* c);
66
67
68     //: destructor
69     //! PRE:  True
70     //! POST: all dynamically-allocated memory associated
71     //+       with self is freed.
72     //+       If ControlPID is non-NULL, the process it refers
73     //+       to is stopped.
74     ~vjConnect();
75
76
77
78     //: returns the name of this connection
79     //! NOTE: The name is the same as the name of the ConfigChunk that
80     //+       represents it.
81     std::string getName () {
82         //cout << "name of this thing is " << name << endl;
83         return name;
84     }
85
86
87
88     //: Starts the file connection process.
89     //! PRE:  None
90     //! POST: A thread has been created to read from the file/pipe
91     //+       connection (or an error has occurred while
92     //+       attempting to do so).
93     //+       controlPID is set to the PID of the generated process.
94     //! RETURNS: True - successfully created the thread.
95     //! RETURNS: False - unable to create thread.
96     bool startProcess();
97
98
99
100     //: Stops file connection process.
101     //! PRE:  None
102     //! POST: If self had a thread associated with it, that
103     //+       thread is terminated.
104     //! RETURNS: always True
105     bool stopProcess();
106
107
108     void sendDescDB (vjChunkDescDB* db);
109     void sendChunkDB (vjConfigChunkDB* db, bool all);
110     void sendRefresh ();
111     void sendDisconnect();
112
113     //: Attaches a timed update object to this connection
114     //! ARGS: _tu - a vjTimedUpdate*
115     //! ARGS: _refresh_time - time between refreshes, in milliseconds
116     void addTimedUpdate (vjTimedUpdate* _tu, float _refresh_time);
117
118
119     //: Detaches a timed update object from this connection
120     void removeTimedUpdate (vjTimedUpdate* _tu);
121
122
123 private:
124
125
126     std::ostream*     outstream;
127     std::istream*      instream;
128     bool                    shutdown;        // set to stop procs
129     std::string             name;
130     std::string             filename;
131     vjThread*               read_connect_thread;
132     vjThread*               write_connect_thread;
133     vjSocket*               sock;
134     vjConnectMode           mode;
135     bool                    read_die;    // if true, thread suicide
136     bool                    write_die;   // if true, thread suicide
137     bool                    write_alive; // true when thread running
138
139     //: used for storing vjCommand* in a priority queue
140     struct vjCommandPtrCmp {
141         bool operator() (const vjCommand* a, const vjCommand* b) {
142             return (a->next_fire_time > b->next_fire_time);
143         }
144     };
145
146
147     std::priority_queue<vjCommand*, std::vector<vjCommand*>, vjCommandPtrCmp>
148                                timed_commands; // used as heap
149     std::queue<vjCommand*>     commands;
150
151     //: controls access to commands & timed_commands queues.
152     //  could we dispense with this???
153     vjMutex                    commands_mutex;
154
155     //: used to see if it's time to spring a timed_command
156     vjTimeStamp             current_time;
157
158     //: body of network process.
159     void readControlLoop (void* nullParam);
160     void writeControlLoop (void* nullParam);
161
162     //: utility for controlLoop()
163     bool readCommand (std::istream& fin);
164
165
166 }; // end vjConnect
167
168
169 #endif
Note: See TracBrowser for help on using the browser.