1 | /****************************************************************************** |
---|
2 | * SAGE - Scalable Adaptive Graphics Environment |
---|
3 | * |
---|
4 | * Module: sageDisplayManager.h |
---|
5 | * Author : Byungil Jeong, Rajvikram Singh |
---|
6 | * |
---|
7 | * Copyright (C) 2004 Electronic Visualization Laboratory, |
---|
8 | * University of Illinois at Chicago |
---|
9 | * |
---|
10 | * All rights reserved. |
---|
11 | * |
---|
12 | * Redistribution and use in source and binary forms, with or without |
---|
13 | * modification, are permitted provided that the following conditions are met: |
---|
14 | * |
---|
15 | * * Redistributions of source code must retain the above copyright |
---|
16 | * notice, this list of conditions and the following disclaimer. |
---|
17 | * * Redistributions in binary form must reproduce the above |
---|
18 | * copyright notice, this list of conditions and the following disclaimer |
---|
19 | * in the documentation and/or other materials provided with the distribution. |
---|
20 | * * Neither the name of the University of Illinois at Chicago nor |
---|
21 | * the names of its contributors may be used to endorse or promote |
---|
22 | * products derived from this software without specific prior written permission. |
---|
23 | * |
---|
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
27 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
---|
28 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
---|
29 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
30 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
---|
31 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
---|
32 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
---|
33 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
34 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
35 | * |
---|
36 | * Direct questions, comments etc about SAGE to sage_users@listserv.uic.edu or |
---|
37 | * http://www.evl.uic.edu/cavern/forum/ |
---|
38 | * |
---|
39 | *****************************************************************************/ |
---|
40 | |
---|
41 | #ifndef sageDisplayManager_H_ |
---|
42 | #define sageDisplayManager_H_ |
---|
43 | |
---|
44 | #include "fsClient.h" |
---|
45 | #include "streamProtocol.h" |
---|
46 | |
---|
47 | #define DISPLAY_REFRESH_INTERVAL 8333 // 1000000us/120frame = 8333 |
---|
48 | //#define DISPLAY_REFRESH_INTERVAL 16666 // 1000000us/60 = 16666 |
---|
49 | #define DISPLAY_MAX_FRAME_RATE MAX_FRAME_RATE |
---|
50 | |
---|
51 | class sageDisplayManager; |
---|
52 | class sageEvent; |
---|
53 | class sageReceiver; |
---|
54 | class sageTcpModule; |
---|
55 | class sageUdpModule; |
---|
56 | class dispSharedData; |
---|
57 | class pixelDownloader; |
---|
58 | |
---|
59 | |
---|
60 | class sageSyncBBServer; |
---|
61 | class sageSyncServer; |
---|
62 | |
---|
63 | typedef struct { |
---|
64 | sageDisplayManager *This; |
---|
65 | streamProtocol *nwObj; |
---|
66 | } nwCheckThreadParam; |
---|
67 | |
---|
68 | /** |
---|
69 | * class sageDisplayManager |
---|
70 | */ |
---|
71 | class sageDisplayManager : public fsClient { |
---|
72 | private: |
---|
73 | /** |
---|
74 | * This is the pointer that points eventQueue and syncClientObject which are shared to downloaderList<BR> |
---|
75 | * pixelDownloader also has pointer to sagePixelReceiver and it's created when pixelDownloader is created.<BR> |
---|
76 | * so, sageDisplayManger, pixelDownloader, and sagePixelReceiver all can access same dispSharedData |
---|
77 | */ |
---|
78 | dispSharedData *shared; |
---|
79 | sageNwConfig nwCfg; |
---|
80 | sageTcpModule *tcpObj; |
---|
81 | sageUdpModule *udpObj; |
---|
82 | |
---|
83 | |
---|
84 | bool syncMaster; /**< if syncMaster then syncBBServerObj is created */ |
---|
85 | sageSyncBBServer *syncBBServerObj; /**< instantiated if syncMaster is true */ |
---|
86 | sageSyncServer *syncServerObj; |
---|
87 | |
---|
88 | int syncPort; /**< syncServer's port */ |
---|
89 | int syncBarrierPort; /**< syncMaster's barrier port (2nd phase) */ |
---|
90 | int syncRefreshRate; /**< This is important parameter. It determines how frequent BBS should broadcast in Hz */ |
---|
91 | int syncMasterPollingInterval; /**< select return timer in usec */ |
---|
92 | int syncLevel; |
---|
93 | |
---|
94 | //sageReceiver *receiverList[MAX_INST_NUM]; |
---|
95 | std::vector<pixelDownloader *> downloaderList; /**< pixelDownloader object for each application */ |
---|
96 | std::vector<char *> reconfigStr; |
---|
97 | |
---|
98 | int streamPort; |
---|
99 | int totalRcvNum; /**< total number of node in the system */ |
---|
100 | bool rcvEnd; |
---|
101 | int displayID; /**< looks like ]always zero */ |
---|
102 | |
---|
103 | /** |
---|
104 | * called by the mainLoop().<BR> |
---|
105 | * It parses sageEvent then calls appropriate functions. |
---|
106 | */ |
---|
107 | int parseEvent(sageEvent *event); |
---|
108 | |
---|
109 | /** |
---|
110 | * called by parseEvent().<BR> |
---|
111 | * It parses sageMessage then calls appropriate functions. |
---|
112 | */ |
---|
113 | int parseMessage(sageMessage *msg); |
---|
114 | int perfReport(); /**< calls pixelDownloader::evalPerformance() for each element in the downloaderList */ |
---|
115 | int startPerformanceReport(sageMessage *msg); |
---|
116 | int stopPerformanceReport(sageMessage *msg); |
---|
117 | int changeBGColor(sageMessage *msg); |
---|
118 | int changeDepth(sageMessage *msg); |
---|
119 | |
---|
120 | /** |
---|
121 | * if appId is -1 then all applications are closed |
---|
122 | * |
---|
123 | * @param appId integer |
---|
124 | * @return 0 on success, -1 otherwise |
---|
125 | */ |
---|
126 | int shutdownApp(int appId); |
---|
127 | |
---|
128 | /** |
---|
129 | * creates sageTcpModule, sageUdpModule, and generates nwCheckThread |
---|
130 | */ |
---|
131 | int initNetworks(); |
---|
132 | |
---|
133 | /** |
---|
134 | * creates pixelDownloader object if it wasn't created for this instID before.<BR> |
---|
135 | * If pixelDownloader object already exist then just pixelDownloader::addStream() is called.<BR> |
---|
136 | * pixelDownloader (per application) reads pixel data from buffer and downloads into texture memory.<BR> |
---|
137 | * if stream type is SAGE_BLOCK_NO_SYNC then only pixelDownloader::init() is called.<br> |
---|
138 | * if stream type is SAGE_BLOCK_XXX_SYNC then a syncGroup object is created and syncGroup::init() is called followed by pixelDownloader::init()<br> |
---|
139 | * If syncMaster is true then the newly created syncGroup object is then added by syncServerObj->addSyncGroup() <br> |
---|
140 | * finally, pixelDownloader::addStream() is called and this pixelDownloader instance is added into the array downloaderList |
---|
141 | * |
---|
142 | * @param msg char * |
---|
143 | * @param nwObj streamProtocol * |
---|
144 | * @return 0 |
---|
145 | */ |
---|
146 | int initStreams(char *msg, streamProtocol *nwObj); |
---|
147 | |
---|
148 | /** |
---|
149 | * this function is called when EVENT_SYNC_MESSAGE arrives in the parseEvent() in this class. This event is generated in the syncCheckThread() which is started in the init()<BR> |
---|
150 | * It finds syncGroup id and syncframe from the msg |
---|
151 | * then calls pixelDownloader::processSync() of an element in the downloaderList array<BR> |
---|
152 | * if status of this group is PDL_WAIT_SYNC then, also calls pixelDownloader.fetchSageBlocks() |
---|
153 | */ |
---|
154 | //int processSync(char *msg); |
---|
155 | int processSync(sageEvent *e); |
---|
156 | |
---|
157 | |
---|
158 | |
---|
159 | /** |
---|
160 | * it's called when a message RCV_UPDATE_DISPLAY is received from fsManager |
---|
161 | */ |
---|
162 | int updateDisplay(char *msg); |
---|
163 | int clearDisplay(int instID); |
---|
164 | |
---|
165 | char CLEAR_STR[TOKEN_LEN]; |
---|
166 | |
---|
167 | /** |
---|
168 | * keeps checking network connection and generates EVENT_NEW_CONNECTION event if new connection has arrived. |
---|
169 | */ |
---|
170 | static void* nwCheckThread(void *args); |
---|
171 | |
---|
172 | /** |
---|
173 | * keeps checking message from fsManager(?) by calling fsClient::rcvMessageBlk()<BR> |
---|
174 | * generates EVENT_NEW_MESSAGE |
---|
175 | */ |
---|
176 | static void* msgCheckThread(void *args); |
---|
177 | |
---|
178 | /** |
---|
179 | * This thread creates sageEvent type syncEvent (EVENT_SYNC_MESSAGE) if sageSyncClient::waitForSync() is returned.<BR> |
---|
180 | * In other words, if it gets sync message from the syncMaster then it generates EVENT_SYNC_MESSAGE |
---|
181 | */ |
---|
182 | static void* syncCheckThread(void *args); |
---|
183 | |
---|
184 | /** |
---|
185 | * the constructor starts this thread.<br> |
---|
186 | * It keeps calling perfReport() |
---|
187 | */ |
---|
188 | static void* perfReportThread(void *args); |
---|
189 | |
---|
190 | /** |
---|
191 | * started by pthread_create in the init()<BR> |
---|
192 | * It keeps sending EVENT_REFRESH_SCREEN event. it causes calling sageDisplay::updateScreen() |
---|
193 | * refer DISPLAY_REFRESH_INTERVAL |
---|
194 | */ |
---|
195 | static void* refreshThread(void *args); |
---|
196 | |
---|
197 | pixelDownloader* findApp(int id, int& index); |
---|
198 | |
---|
199 | public: |
---|
200 | /** |
---|
201 | * if syncMaster is true, sageSyncServer object is created here, and sageSyncServer::init() is called.<BR> |
---|
202 | * if globalSync(which is argv[6]) is true, then both shared->nodeID and displayID must be zero to syncMaster be true.<BR> |
---|
203 | * Also starts msgCheckThread() and perfReportThread(). |
---|
204 | */ |
---|
205 | sageDisplayManager(int argc, char **argv); |
---|
206 | ~sageDisplayManager(); |
---|
207 | |
---|
208 | /** |
---|
209 | * sageSyncClient object is created here.<BR> |
---|
210 | * It starts syncCheckThread() and refreshThread()<BR> |
---|
211 | * Also, sageDisplay is instantiated here. It draws pixel data onto screen, and all OpenGL related code resides in the sageDisplay |
---|
212 | */ |
---|
213 | int init(char *msg); |
---|
214 | |
---|
215 | /** |
---|
216 | * It keeps getting an event from the eventQueue, and caliing parseEvent() with new event until rcvEnd is true |
---|
217 | */ |
---|
218 | void mainLoop(); |
---|
219 | }; |
---|
220 | |
---|
221 | #endif |
---|