1 | /****************************************************************************** |
---|
2 | * SAGE - Scalable Adaptive Graphics Environment |
---|
3 | * |
---|
4 | * Module: fsCore.cpp - the core part of the Free Space Manager processing |
---|
5 | * user commands to run applications or send appropriate orders |
---|
6 | * to each part of SAGE. |
---|
7 | * Author : Byungil Jeong |
---|
8 | * |
---|
9 | * Copyright (C) 2004 Electronic Visualization Laboratory, |
---|
10 | * University of Illinois at Chicago |
---|
11 | * |
---|
12 | * All rights reserved. |
---|
13 | * |
---|
14 | * Redistribution and use in source and binary forms, with or without |
---|
15 | * modification, are permitted provided that the following conditions are met: |
---|
16 | * |
---|
17 | * * Redistributions of source code must retain the above copyright |
---|
18 | * notice, this list of conditions and the following disclaimer. |
---|
19 | * * Redistributions in binary form must reproduce the above |
---|
20 | * copyright notice, this list of conditions and the following disclaimer |
---|
21 | * in the documentation and/or other materials provided with the distribution. |
---|
22 | * * Neither the name of the University of Illinois at Chicago nor |
---|
23 | * the names of its contributors may be used to endorse or promote |
---|
24 | * products derived from this software without specific prior written permission. |
---|
25 | * |
---|
26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
27 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
28 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
29 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
---|
30 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
---|
31 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
32 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
---|
33 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
---|
34 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
---|
35 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
36 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
37 | * |
---|
38 | * Direct questions, comments etc about SAGE to sage_users@listserv.uic.edu or |
---|
39 | * http://www.evl.uic.edu/cavern/forum/ |
---|
40 | * |
---|
41 | *****************************************************************************/ |
---|
42 | |
---|
43 | #include "fsCore.h" |
---|
44 | #include "fsManager.h" |
---|
45 | #include "streamInfo.h" |
---|
46 | #include "misc.h" |
---|
47 | #include "displayInstance.h" |
---|
48 | #include "sageVirtualDesktop.h" |
---|
49 | #include "streamProtocol.h" |
---|
50 | #include "sageDrawObject.h" |
---|
51 | |
---|
52 | FILE *logFile; |
---|
53 | |
---|
54 | fsCore::fsCore() |
---|
55 | { |
---|
56 | fsm = NULL; |
---|
57 | } |
---|
58 | |
---|
59 | fsCore::~fsCore() |
---|
60 | { |
---|
61 | } |
---|
62 | |
---|
63 | int fsCore::init(fsManager *m) |
---|
64 | { |
---|
65 | fsm = m; |
---|
66 | winSteps = (int)ceil(m->winTime/20.0); |
---|
67 | logFile = fopen("window.log","w+"); |
---|
68 | return 0; |
---|
69 | } |
---|
70 | |
---|
71 | int fsCore::initDisp(appInExec* app) |
---|
72 | { |
---|
73 | displayInstance *disp = new displayInstance(fsm, fsm->m_execIndex, app); |
---|
74 | fsm->dispList.push_back(disp); |
---|
75 | |
---|
76 | return 0; |
---|
77 | } |
---|
78 | |
---|
79 | int fsCore::initAudio() |
---|
80 | { |
---|
81 | appInExec *appExec; |
---|
82 | int execNum = fsm->execList.size(); |
---|
83 | |
---|
84 | //int msgLen = 8 + SAGE_IP_LEN * execNum; |
---|
85 | int msgLen = 8 + SAGE_IP_LEN * fsm->vdtList[0]->getNodeNum(); |
---|
86 | char *msgStr = new char[msgLen]; |
---|
87 | memset(msgStr, 0, msgLen); |
---|
88 | |
---|
89 | int i = execNum -1; |
---|
90 | i = fsm->m_execIndex; |
---|
91 | appExec = fsm->execList[i]; |
---|
92 | if (!appExec) { |
---|
93 | //continue; |
---|
94 | } |
---|
95 | else |
---|
96 | { |
---|
97 | fsm->vdtList[0]->generateAudioRcvInfo(fsm->rInfo.audioPort, msgStr); |
---|
98 | //printf("initaudio --> %s\n", msgStr); |
---|
99 | char conMessage[TOKEN_LEN]; |
---|
100 | sprintf(conMessage, "%s %d", msgStr, i); |
---|
101 | if (fsm->sendMessage(appExec->sailClient, SAIL_CONNECT_TO_ARCV, conMessage) < 0) { |
---|
102 | sage::printLog("fsCore : %s(%d) is stuck or shutdown", appExec->appName, i); |
---|
103 | clearAppInstance(i); |
---|
104 | } |
---|
105 | } |
---|
106 | |
---|
107 | return 0; |
---|
108 | } |
---|
109 | |
---|
110 | void fsCore::clearAppInstance(int id) |
---|
111 | { |
---|
112 | int index = 0; |
---|
113 | appInExec* app = findApp(id, index); |
---|
114 | if (!app) |
---|
115 | { |
---|
116 | std::cout << "fsCore::clearAppInstance() : ERROR : " << id << " app instance is not found" << std::endl; |
---|
117 | return; |
---|
118 | } |
---|
119 | |
---|
120 | // clear app instance on display nodes |
---|
121 | fsm->sendToAllRcvs(RCV_SHUTDOWN_APP, id); |
---|
122 | |
---|
123 | // clear app instance on audio nodes |
---|
124 | if (app->audioOn) { |
---|
125 | std::vector<int> arcvList = fsm->vdtList[0]->getAudioRcvClientList(); |
---|
126 | int arcvNum = arcvList.size(); |
---|
127 | for(int i=0; i<arcvNum; i++) |
---|
128 | fsm->sendMessage(arcvList[i], ARCV_SHUTDOWN_APP, id); |
---|
129 | } |
---|
130 | |
---|
131 | // clear app instace on ui clients |
---|
132 | int uiNum = fsm->uiList.size(); |
---|
133 | for (int j=0; j<uiNum; j++) { |
---|
134 | if (fsm->uiList[j] < 0) |
---|
135 | continue; |
---|
136 | |
---|
137 | if (fsm->sendMessage(fsm->uiList[j], UI_APP_SHUTDOWN, id) < 0) { |
---|
138 | sage::printLog("fsCore::clearAppInstance() : uiClient(%d) is stuck or shutdown", j); |
---|
139 | fsm->uiList[j] = -1; |
---|
140 | } |
---|
141 | } |
---|
142 | |
---|
143 | // RE-GENERATING ID (1/2) |
---|
144 | //fsm->m_execIDList[id] = 0; |
---|
145 | // release data structure |
---|
146 | delete app; |
---|
147 | app = NULL; |
---|
148 | fsm->execList.erase(fsm->execList.begin() + index); |
---|
149 | |
---|
150 | displayInstance* temp_disp = (displayInstance*) fsm->dispList[index]; |
---|
151 | if (temp_disp) { |
---|
152 | delete temp_disp; |
---|
153 | fsm->dispList.erase(fsm->dispList.begin() + index); |
---|
154 | } |
---|
155 | //std::cout << "FsCore : " << id << " app instance is cleared (index: " << index << ")" << std::endl; |
---|
156 | |
---|
157 | } |
---|
158 | |
---|
159 | int fsCore::getAvailableInstID(void) |
---|
160 | { |
---|
161 | for(int i=0; i<MAX_INST_NUM; i++) |
---|
162 | { |
---|
163 | if (fsm->m_execIDList[i] == 0) |
---|
164 | return i; |
---|
165 | } |
---|
166 | return -1; |
---|
167 | } |
---|
168 | |
---|
169 | appInExec* fsCore::findApp(int id, int& index) |
---|
170 | { |
---|
171 | std::vector<appInExec*>::iterator iter_exec; |
---|
172 | appInExec* temp_exec = NULL; |
---|
173 | index = 0; |
---|
174 | for(iter_exec = fsm->execList.begin(); iter_exec != fsm->execList.end(); iter_exec++, index++) |
---|
175 | { |
---|
176 | if ((*iter_exec)->fsInstID == id) |
---|
177 | { |
---|
178 | temp_exec = (appInExec*) *iter_exec; |
---|
179 | break; |
---|
180 | } |
---|
181 | } |
---|
182 | return temp_exec; |
---|
183 | } |
---|
184 | |
---|
185 | |
---|
186 | //#define MAX_SAGE_WINDOW_SIZE 4096 |
---|
187 | #define MAX_SAGE_WINDOW_SIZE 8192 |
---|
188 | |
---|
189 | int fsCore::parseMessage(sageMessage &msg, int clientID) |
---|
190 | { |
---|
191 | appInExec *app; |
---|
192 | displayInstance *disp; |
---|
193 | |
---|
194 | char token[TOKEN_LEN], dataStr[TOKEN_LEN]; |
---|
195 | int tokenNum; |
---|
196 | |
---|
197 | if (msg.getData()) |
---|
198 | strcpy(dataStr, (char *)msg.getData()); |
---|
199 | |
---|
200 | switch(msg.getCode()) { |
---|
201 | case REG_APP : { |
---|
202 | app = new appInExec; |
---|
203 | memset(app->launcherID, 0, SAGE_NAME_LEN); |
---|
204 | sscanf((char *)msg.getData(), "%s %d %d %d %d %d %s %d %d %d %d %d %d %s %d", app->appName, &app->x, &app->y, |
---|
205 | &app->width, &app->height, &app->bandWidth, app->renderNodeIP, &app->imageWidth, |
---|
206 | &app->imageHeight, (int *)&app->audioOn, (int *)&app->protocol, &app->frameRate, |
---|
207 | &app->instID, app->launcherID, &app->portForwarding ); |
---|
208 | |
---|
209 | // adjust app window size considering image resolution |
---|
210 | float ar = (float)(app->imageWidth) / (float)(app->imageHeight); |
---|
211 | if ((app->imageWidth > MAX_SAGE_WINDOW_SIZE && app->width < MAX_SAGE_WINDOW_SIZE) || |
---|
212 | (app->imageHeight > MAX_SAGE_WINDOW_SIZE && app->height < MAX_SAGE_WINDOW_SIZE)) { |
---|
213 | if (ar > 1) { |
---|
214 | app->width = MAX_SAGE_WINDOW_SIZE; |
---|
215 | app->height = (int)(MAX_SAGE_WINDOW_SIZE/ar); |
---|
216 | } |
---|
217 | else { |
---|
218 | app->height = MAX_SAGE_WINDOW_SIZE; |
---|
219 | app->width = (int)(MAX_SAGE_WINDOW_SIZE*ar); |
---|
220 | } |
---|
221 | } |
---|
222 | |
---|
223 | app->sailClient = clientID; |
---|
224 | |
---|
225 | char sailInitMsg[TOKEN_LEN]; |
---|
226 | memset(sailInitMsg, 0, TOKEN_LEN); |
---|
227 | |
---|
228 | // RE-GENERATING ID (2/2) |
---|
229 | //fsm->m_execIndex = getAvailableInstID(); |
---|
230 | //fsm->m_execIDList[fsm->m_execIndex] = 1; |
---|
231 | app->fsInstID = fsm->m_execIndex; |
---|
232 | std::cout << "[fsCore::parseMessage] REG_APP inst id : " << app->fsInstID << std::endl; |
---|
233 | |
---|
234 | sprintf(sailInitMsg, "%d %d %d %d", fsm->m_execIndex, fsm->nwInfo->rcvBufSize, |
---|
235 | fsm->nwInfo->sendBufSize, fsm->nwInfo->mtuSize); |
---|
236 | |
---|
237 | if (fsm->sendMessage(clientID, SAIL_INIT_MSG, sailInitMsg) < 0) { |
---|
238 | sage::printLog("fsCore::parseMessage() : REG_APP : %s is stuck or shutdown", app->appName); |
---|
239 | } |
---|
240 | else |
---|
241 | fsm->execList.push_back(app); |
---|
242 | |
---|
243 | if (fsm->NRM) { |
---|
244 | char rcvIP[SAGE_IP_LEN]; |
---|
245 | fsm->vdtList[0]->getNodeIPs(0, rcvIP); |
---|
246 | char msgStr[TOKEN_LEN]; |
---|
247 | memset(msgStr, 0, TOKEN_LEN); |
---|
248 | sprintf(msgStr, "%s %s %d %d", app->renderNodeIP, rcvIP, app->bandWidth, |
---|
249 | fsm->m_execIndex); |
---|
250 | |
---|
251 | int uiNum = fsm->uiList.size(); |
---|
252 | for (int j=0; j<uiNum; j++) { |
---|
253 | if (fsm->uiList[j] < 0) |
---|
254 | continue; |
---|
255 | |
---|
256 | if (fsm->sendMessage(fsm->uiList[j], REQUEST_BANDWIDTH, msgStr) < 0) { |
---|
257 | sage::printLog("fsCore : uiClient(%d) is stuck or shutdown", j); |
---|
258 | fsm->uiList[j] = -1; |
---|
259 | } |
---|
260 | } |
---|
261 | } |
---|
262 | else { |
---|
263 | initDisp(app); |
---|
264 | if (app->audioOn) { |
---|
265 | std::cout << "initAudio is called" << std::endl; |
---|
266 | initAudio(); |
---|
267 | } |
---|
268 | |
---|
269 | //windowChanged(fsm->execList.size()-1); |
---|
270 | //bringToFront(fsm->execList.size()-1); |
---|
271 | fsm->m_execIndex++; |
---|
272 | } |
---|
273 | |
---|
274 | break; |
---|
275 | } |
---|
276 | |
---|
277 | case NOTIFY_APP_SHUTDOWN : { |
---|
278 | /* |
---|
279 | getToken((char *)msg.getData(), token); |
---|
280 | int appID = atoi(token); |
---|
281 | */ |
---|
282 | int appID; |
---|
283 | sscanf((char *)msg.getData(), "%d", &appID); |
---|
284 | |
---|
285 | #ifdef DEBUG_KILL |
---|
286 | fprintf(stderr, "fsCore::parseMsg() : NOTIFY_APP_SHUTDOWN. app %d\n", appID); |
---|
287 | #endif |
---|
288 | int index =0; |
---|
289 | app = findApp(appID, index); |
---|
290 | if (!app) { |
---|
291 | std::cout << "FsCore : app "<< appID << " doesn't exist" << std::endl; |
---|
292 | break; |
---|
293 | } |
---|
294 | |
---|
295 | clearAppInstance(appID); |
---|
296 | break; |
---|
297 | } |
---|
298 | |
---|
299 | case NETWORK_RESERVED : { |
---|
300 | //std::cout << "network_reserved is called ------------------- " << std::endl; |
---|
301 | if (fsm->NRM) { |
---|
302 | int appID = fsm->execList.size()-1; |
---|
303 | app = fsm->execList[appID]; |
---|
304 | |
---|
305 | int success = atoi(dataStr); |
---|
306 | if (success) { |
---|
307 | initDisp(app); |
---|
308 | if (app->audioOn) |
---|
309 | initAudio(); |
---|
310 | windowChanged(fsm->execList.size()-1); |
---|
311 | bringToFront(fsm->execList.size()-1); |
---|
312 | } |
---|
313 | else { |
---|
314 | if (fsm->sendMessage(app->sailClient, APP_QUIT) < 0) { |
---|
315 | //sage::printLog("fsCore : %s(%d) is stuck or shutdown", app->appName, app->fsInstID); |
---|
316 | //clearAppInstance(appID); |
---|
317 | clearAppInstance(app->fsInstID); |
---|
318 | } |
---|
319 | |
---|
320 | fsm->execList.pop_back(); |
---|
321 | } |
---|
322 | } |
---|
323 | break; |
---|
324 | } |
---|
325 | |
---|
326 | case REG_GRCV : { |
---|
327 | int nodeID, dispID; |
---|
328 | sscanf((char *)msg.getData(), "%d %d", &nodeID, &dispID); |
---|
329 | /* |
---|
330 | getToken((char *)msg.getData(), token); |
---|
331 | int nodeID = atoi(token); |
---|
332 | getToken((char *)msg.getData(), token); |
---|
333 | int dispID = atoi(token); |
---|
334 | */ |
---|
335 | // store client ID of receivers |
---|
336 | fsm->vdtList[dispID]->regRcv(clientID, nodeID); |
---|
337 | |
---|
338 | char info[TOKEN_LEN]; |
---|
339 | // get the tile config info of display node |
---|
340 | fsm->vdtList[dispID]->getRcvInfo(nodeID, info); |
---|
341 | int streamPort = fsm->vdtList[dispID]->getLocalPort(nodeID); |
---|
342 | if (streamPort < 1024) |
---|
343 | streamPort = fsm->rInfo.streamPort; |
---|
344 | else |
---|
345 | fsm->useLocalPort = true; |
---|
346 | |
---|
347 | char msgStr[TOKEN_LEN]; |
---|
348 | memset(msgStr, 0, TOKEN_LEN); |
---|
349 | sprintf(msgStr, "%d %d %d %d %d %d %d %s", fsm->nwInfo->rcvBufSize, |
---|
350 | fsm->nwInfo->sendBufSize, fsm->nwInfo->mtuSize, |
---|
351 | streamPort, fsm->rInfo.bufSize, (int)fsm->rInfo.fullScreen, |
---|
352 | fsm->vdtList[dispID]->getNodeNum(), info); |
---|
353 | |
---|
354 | if (fsm->sendMessage(clientID, RCV_INIT, msgStr) < 0) { |
---|
355 | sage::printLog("fsCore : displaynode(%d) doesn't respond", nodeID); |
---|
356 | } |
---|
357 | break; |
---|
358 | } |
---|
359 | |
---|
360 | case REG_ARCV : { |
---|
361 | int nodeID; |
---|
362 | sscanf((char *)msg.getData(), "%d", &nodeID); |
---|
363 | /* |
---|
364 | getToken((char *)msg.getData(), token); |
---|
365 | int nodeID = atoi(token); |
---|
366 | */ |
---|
367 | // store client ID of receivers |
---|
368 | fsm->vdtList[0]->regAudioRcv(clientID, nodeID); |
---|
369 | |
---|
370 | char info[TOKEN_LEN]; |
---|
371 | // get the tile config info of display node |
---|
372 | fsm->vdtList[0]->getAudioRcvInfo(nodeID, info); |
---|
373 | char msgStr[TOKEN_LEN]; |
---|
374 | sprintf(msgStr, "%d %d %d %d %d %d %d %d %s", fsm->nwInfo->rcvBufSize, |
---|
375 | fsm->nwInfo->sendBufSize, fsm->nwInfo->mtuSize, fsm->rInfo.audioSyncPort, |
---|
376 | fsm->rInfo.audioPort, fsm->rInfo.agSyncPort, fsm->rInfo.bufSize, fsm->vdtList[0]->getNodeNum(), info); |
---|
377 | |
---|
378 | //cout << " ----> fsCore : " << msgStr << endl; |
---|
379 | fsm->sendMessage(clientID, ARCV_AUDIO_INIT, msgStr); |
---|
380 | break; |
---|
381 | } |
---|
382 | |
---|
383 | /*case SYNC_INIT_ARCV : { |
---|
384 | // find gStreamRcvs connected to this aStreamRcv |
---|
385 | getToken((char *)msg.getData(), token); |
---|
386 | int nodeID = atoi(token); |
---|
387 | //fsm->vdt->getgRcvs(nodeID); |
---|
388 | char info[TOKEN_LEN]; |
---|
389 | fsm->vdt->getAudioNodeIPs(nodeID, info); |
---|
390 | |
---|
391 | // send message to gStreamRcvs |
---|
392 | |
---|
393 | // for testing |
---|
394 | std::vector<int> rcvList = fsm->vdt->getRcvClientList(); |
---|
395 | int rcvNum = rcvList.size(); |
---|
396 | for(int i=0; i<rcvNum; i++) { |
---|
397 | fsm->sendMessage(rcvList[i], RCV_SYNC_INIT, info); |
---|
398 | } |
---|
399 | |
---|
400 | break; |
---|
401 | }*/ |
---|
402 | |
---|
403 | case SHUTDOWN_APP : { |
---|
404 | int appID = -1; |
---|
405 | //tokenNum = getToken((char *)msg.getData(), token); |
---|
406 | //appID = atoi(token); |
---|
407 | sscanf((char *)msg.getData(), "%d", &appID); |
---|
408 | fprintf(stderr, "fsCore::parseMessage() : SHUTDOWN_APP : %d\n", appID); |
---|
409 | |
---|
410 | int index = 0; |
---|
411 | app = findApp(appID, index); |
---|
412 | if (!app) { |
---|
413 | fprintf(stderr, "fsCore::parseMessage() : SHUTDOWN_APP : appID %d doesn't exist in the app vector\n", appID); |
---|
414 | break; |
---|
415 | } |
---|
416 | |
---|
417 | #ifdef DEBUG_KILL |
---|
418 | fprintf(stderr, "fsCore::parseMsg() : SHUTDOWN_APP : sendMessage(%d, APP_QUIT)\n", app->sailClient); |
---|
419 | #endif |
---|
420 | if (fsm->sendMessage(app->sailClient, APP_QUIT) < 0) { |
---|
421 | sage::printLog("fsCore::parseMessage() : SHUTDOWN_APP : %s(%d) exist in the app vector but fsClient doesn't exist\n", app->appName, appID); |
---|
422 | } |
---|
423 | |
---|
424 | clearAppInstance(appID); |
---|
425 | |
---|
426 | break; |
---|
427 | } |
---|
428 | |
---|
429 | case SAGE_APP_SHARE : { |
---|
430 | /* |
---|
431 | tokenNum = getToken((char *)msg.getData(), token); |
---|
432 | int appID = atoi(token); |
---|
433 | */ |
---|
434 | |
---|
435 | int appID, fsPort, index=0; |
---|
436 | char fsIP[SAGE_IP_LEN]; |
---|
437 | sscanf((char *)msg.getData(), "%d %s %d", &appID, &fsIP[0], &fsPort); |
---|
438 | |
---|
439 | app = findApp(appID, index); |
---|
440 | if (!app) { |
---|
441 | std::cout << "FsCore : app "<< appID << " doesn't exist" << std::endl; |
---|
442 | break; |
---|
443 | } |
---|
444 | |
---|
445 | /* |
---|
446 | getToken((char *)msg.getData(), fsIP); |
---|
447 | getToken((char *)msg.getData(), token); |
---|
448 | */ |
---|
449 | //int fsPort = atoi(token); |
---|
450 | char msgData[TOKEN_LEN]; |
---|
451 | memset(msgData, 0, TOKEN_LEN); |
---|
452 | sprintf(msgData, "%s %d", fsIP, fsPort); |
---|
453 | |
---|
454 | //std::cout << fsIP << ":" << fsPort << std::endl; |
---|
455 | |
---|
456 | if (fsm->sendMessage(app->sailClient, SAGE_APP_SHARE, msgData) < 0) { |
---|
457 | sage::printLog("fsCore : %s(%d) is stuck or shutdown", app->appName, appID); |
---|
458 | clearAppInstance(appID); |
---|
459 | } |
---|
460 | |
---|
461 | break; |
---|
462 | } |
---|
463 | |
---|
464 | case MOVE_WINDOW : { |
---|
465 | sageRect devRect; |
---|
466 | int winID, index; |
---|
467 | float x,y; |
---|
468 | sscanf((char *)msg.getData(), "%d %f %f", &winID, &x, &y); |
---|
469 | devRect.x = int(x); |
---|
470 | devRect.y = int(y); |
---|
471 | /* |
---|
472 | tokenNum = getToken((char *)msg.getData(), token); |
---|
473 | int winID = atoi(token); |
---|
474 | int index =0; |
---|
475 | */ |
---|
476 | app = findApp(winID, index); |
---|
477 | if (!app) { |
---|
478 | std::cout << "FsCore : app "<< winID << " doesn't exist" << std::endl; |
---|
479 | break; |
---|
480 | } |
---|
481 | /* |
---|
482 | // change x position(left) of app window |
---|
483 | if (tokenNum < 1) { |
---|
484 | std::cout << "More arguments are needed for this command " << std::endl; |
---|
485 | break; |
---|
486 | } |
---|
487 | |
---|
488 | tokenNum = getToken((char *)msg.getData(), token); |
---|
489 | devRect.x = atoi(token); |
---|
490 | |
---|
491 | // change y position(bottom) of app windows |
---|
492 | if (tokenNum < 1) { |
---|
493 | std::cout << "More arguments are needed for this command " << std::endl; |
---|
494 | break; |
---|
495 | } |
---|
496 | |
---|
497 | tokenNum = getToken((char *)msg.getData(), token); |
---|
498 | devRect.y = atoi(token); |
---|
499 | */ |
---|
500 | //fsm->dispList[index]->modifyStream(); |
---|
501 | |
---|
502 | startTime = sage::getTime(); |
---|
503 | if (fsm->winStep > 0) |
---|
504 | winSteps = fsm->winStep; |
---|
505 | |
---|
506 | if (fsm->dispList[index]->changeWindow(devRect, winSteps) < 0) |
---|
507 | clearAppInstance(winID); |
---|
508 | else |
---|
509 | windowChanged(winID); |
---|
510 | |
---|
511 | break; |
---|
512 | } |
---|
513 | |
---|
514 | case ADD_OBJECT : { |
---|
515 | if (!msg.getData()) |
---|
516 | break; |
---|
517 | |
---|
518 | sageRect *obj = new sageRect; |
---|
519 | char objectName[SAGE_NAME_LEN]; |
---|
520 | sscanf(dataStr, "%s %d %d %d %d", objectName, &obj->x, &obj->y, |
---|
521 | &obj->width, &obj->height); |
---|
522 | int objectID = fsm->drawObjectList.size(); |
---|
523 | fsm->drawObjectList.push_back(obj); |
---|
524 | |
---|
525 | char msgStr[TOKEN_LEN]; |
---|
526 | sprintf(msgStr, "%d %s", objectID, dataStr); |
---|
527 | fsm->sendToAllRcvs(ADD_OBJECT, msgStr); |
---|
528 | fsm->sendMessage(clientID, UI_OBJECT_INFO, msgStr); |
---|
529 | |
---|
530 | break; |
---|
531 | } |
---|
532 | |
---|
533 | case MOVE_OBJECT : { |
---|
534 | if (!msg.getData()) |
---|
535 | break; |
---|
536 | |
---|
537 | int id, dx, dy; |
---|
538 | sscanf(dataStr, "%d %d %d", &id, &dx, &dy); |
---|
539 | |
---|
540 | if (id >= fsm->drawObjectList.size()) |
---|
541 | break; |
---|
542 | |
---|
543 | sageRect *obj = fsm->drawObjectList[id]; |
---|
544 | obj->x += dx; |
---|
545 | obj->y += dy; |
---|
546 | |
---|
547 | char msgStr[TOKEN_LEN]; |
---|
548 | sprintf(msgStr, "%d %d %d", id, obj->x, obj->y); |
---|
549 | fsm->sendToAllRcvs(UPDATE_OBJECT_POSITION, msgStr); |
---|
550 | |
---|
551 | break; |
---|
552 | } |
---|
553 | |
---|
554 | case REMOVE_OBJECT : { |
---|
555 | if (!msg.getData()) |
---|
556 | break; |
---|
557 | |
---|
558 | int id; |
---|
559 | sscanf(dataStr, "%d", &id); |
---|
560 | |
---|
561 | if (id >= fsm->drawObjectList.size()) { |
---|
562 | std::cout << "fsCore: invalid object ID " << id << std::endl; |
---|
563 | break; |
---|
564 | } |
---|
565 | |
---|
566 | fsm->sendToAllRcvs(REMOVE_OBJECT, dataStr); |
---|
567 | |
---|
568 | break; |
---|
569 | } |
---|
570 | |
---|
571 | case OBJECT_MESSAGE : { |
---|
572 | if (!msg.getData()) |
---|
573 | break; |
---|
574 | |
---|
575 | int id; |
---|
576 | sscanf(dataStr, "%d", &id); |
---|
577 | |
---|
578 | if (id >= fsm->drawObjectList.size()) { |
---|
579 | std::cout << "fsCore: invalid object ID " << id << std::endl; |
---|
580 | break; |
---|
581 | } |
---|
582 | |
---|
583 | fsm->sendToAllRcvs(OBJECT_MESSAGE, dataStr); |
---|
584 | |
---|
585 | break; |
---|
586 | } |
---|
587 | |
---|
588 | case SHOW_OBJECT : { |
---|
589 | if (!msg.getData()) |
---|
590 | break; |
---|
591 | |
---|
592 | int id; |
---|
593 | sscanf(dataStr, "%d", &id); |
---|
594 | |
---|
595 | if (id >= fsm->drawObjectList.size()) { |
---|
596 | std::cout << "fsCore: invalid object ID " << id << std::endl; |
---|
597 | break; |
---|
598 | } |
---|
599 | |
---|
600 | fsm->sendToAllRcvs(SHOW_OBJECT, dataStr); |
---|
601 | |
---|
602 | break; |
---|
603 | } |
---|
604 | |
---|
605 | case FS_TIME_MSG : { |
---|
606 | double endTime = sage::getTime(); |
---|
607 | double bigTime = floor(endTime/1000000.0)*1000000.0; |
---|
608 | endTime = (endTime - bigTime)/1000.0; |
---|
609 | double sageLatency = (endTime - startTime)/1000.0; |
---|
610 | //std::cout << "total latency = " << sageLatency << "ms" << std::endl; |
---|
611 | std::cout << "Time Block received at " << endTime << "ms" << std::endl; |
---|
612 | |
---|
613 | /* |
---|
614 | double endTime = sageGetTime(); |
---|
615 | double winTime = (endTime - startTime)/1000.0; |
---|
616 | double singleLatency = winTime / winSteps; |
---|
617 | |
---|
618 | //std::cout << winTime << std::endl; |
---|
619 | |
---|
620 | //std::cout << "total time = " << winTime << "ms for " << winSteps << " move/resizing" << std::endl; |
---|
621 | //std::cout << "single move/resizing time = " << singleLatency << "ms" << std::endl; |
---|
622 | winSteps = (int)(ceil)(fsm->winTime /singleLatency); |
---|
623 | //std::cout << "# of window change steps changed to " << winSteps << std::endl; |
---|
624 | */ |
---|
625 | |
---|
626 | break; |
---|
627 | } |
---|
628 | |
---|
629 | case RESIZE_WINDOW : { |
---|
630 | /* |
---|
631 | tokenNum = getToken((char *)msg.getData(), token); |
---|
632 | int winID = atoi(token); |
---|
633 | sageRect devRect; |
---|
634 | int index =0; |
---|
635 | */ |
---|
636 | int winID, index, left, right, bottom, top; |
---|
637 | sscanf((char *)msg.getData(), "%d %d %d %d %d", &winID, &left, &right, &bottom, &top); |
---|
638 | |
---|
639 | app = findApp(winID, index); |
---|
640 | |
---|
641 | if (!app) { |
---|
642 | std::cout << "FsCore : app "<< winID << " doesn't exist" << std::endl; |
---|
643 | break; |
---|
644 | } |
---|
645 | |
---|
646 | sageRect devRect; |
---|
647 | /* |
---|
648 | // change x position(left) of app window |
---|
649 | if (tokenNum < 1) { |
---|
650 | std::cout << "More arguments are needed for this command " << std::endl; |
---|
651 | break; |
---|
652 | } |
---|
653 | |
---|
654 | int left, right, bottom, top; |
---|
655 | |
---|
656 | tokenNum = getToken((char *)msg.getData(), token); |
---|
657 | left = atoi(token); |
---|
658 | |
---|
659 | // change width of app window |
---|
660 | if (tokenNum < 1) { |
---|
661 | std::cout << "More arguments are needed for this command " << std::endl; |
---|
662 | break; |
---|
663 | } |
---|
664 | |
---|
665 | tokenNum = getToken((char *)msg.getData(), token); |
---|
666 | right = atoi(token); |
---|
667 | |
---|
668 | // change y position(bottom) of app window |
---|
669 | if (tokenNum < 1) { |
---|
670 | std::cout << "More arguments are needed for this command " << std::endl; |
---|
671 | break; |
---|
672 | } |
---|
673 | |
---|
674 | tokenNum = getToken((char *)msg.getData(), token); |
---|
675 | bottom = atoi(token); |
---|
676 | |
---|
677 | // change height of app windows |
---|
678 | if (tokenNum < 1) { |
---|
679 | std::cout << "More arguments are needed for this command " << std::endl; |
---|
680 | break; |
---|
681 | } |
---|
682 | |
---|
683 | tokenNum = getToken((char *)msg.getData(), token); |
---|
684 | top = atoi(token); |
---|
685 | **/ |
---|
686 | |
---|
687 | // adjust app window size considering image resolution |
---|
688 | float ar = (float)(right - left) / (float)(top - bottom); |
---|
689 | if (ar > 1 && app->imageWidth > MAX_SAGE_WINDOW_SIZE && right - left < MAX_SAGE_WINDOW_SIZE) { |
---|
690 | right = left + MAX_SAGE_WINDOW_SIZE; |
---|
691 | top = bottom + (int)(MAX_SAGE_WINDOW_SIZE/ar); |
---|
692 | } |
---|
693 | |
---|
694 | if (ar <= 1 && app->imageHeight > MAX_SAGE_WINDOW_SIZE && top - bottom < MAX_SAGE_WINDOW_SIZE) { |
---|
695 | top = bottom + MAX_SAGE_WINDOW_SIZE; |
---|
696 | right = left + (int)(MAX_SAGE_WINDOW_SIZE*ar); |
---|
697 | } |
---|
698 | |
---|
699 | devRect.x = left - app->x; |
---|
700 | devRect.width = right - (app->width+app->x) - devRect.x; |
---|
701 | devRect.y = bottom - app->y; |
---|
702 | devRect.height = top - (app->y+app->height) - devRect.y; |
---|
703 | |
---|
704 | startTime = sage::getTime(); |
---|
705 | |
---|
706 | if (fsm->winStep > 0) |
---|
707 | winSteps = fsm->winStep; |
---|
708 | |
---|
709 | if (fsm->dispList[index]->changeWindow(devRect, winSteps) < 0) |
---|
710 | clearAppInstance(winID); |
---|
711 | else |
---|
712 | windowChanged(winID); |
---|
713 | |
---|
714 | break; |
---|
715 | } |
---|
716 | |
---|
717 | case ROTATE_WINDOW : { |
---|
718 | rotateWindow((char *)msg.getData()); |
---|
719 | break; |
---|
720 | } |
---|
721 | |
---|
722 | case SAGE_UI_REG : { |
---|
723 | fsm->uiList.push_back(clientID); |
---|
724 | sendDisplayInfo(clientID); |
---|
725 | sendSageStatus(clientID); |
---|
726 | sendAppInfo(clientID); |
---|
727 | break; |
---|
728 | } |
---|
729 | |
---|
730 | case APP_UI_REG : { |
---|
731 | fsm->appUiList.push_back(clientID); |
---|
732 | fprintf(stderr,"fsCore::%s() : APP_UI_REG : %s\n", __FUNCTION__, (char *)msg.getData()); |
---|
733 | tokenNum = getToken((char *)msg.getData(), token); |
---|
734 | |
---|
735 | if (strlen(token) > 0) { |
---|
736 | sendAppStatus(clientID, token); |
---|
737 | } |
---|
738 | else { |
---|
739 | std::cout << "More arguments are needed for this command " << std::endl; |
---|
740 | } |
---|
741 | break; |
---|
742 | } |
---|
743 | |
---|
744 | case APP_FRAME_RATE : { |
---|
745 | /* |
---|
746 | tokenNum = getToken((char *)msg.getData(), token); |
---|
747 | int appID = atoi(token); |
---|
748 | int index =0; |
---|
749 | */ |
---|
750 | int appID, index; |
---|
751 | char msgData[TOKEN_LEN]; |
---|
752 | sscanf((char *)msg.getData(), "%d %s", &appID, msgData); |
---|
753 | |
---|
754 | app = findApp(appID, index); |
---|
755 | |
---|
756 | if (!app) { |
---|
757 | std::cout << "FsCore : app "<< appID << " doesn't exist" << std::endl; |
---|
758 | break; |
---|
759 | } |
---|
760 | |
---|
761 | //getToken((char *)msg.getData(), token); |
---|
762 | if (fsm->sendMessage(app->sailClient, SAIL_FRAME_RATE, token) < 0) { |
---|
763 | sage::printLog("fsCore : %s(%d) is stuck or shutdown", app->appName, appID); |
---|
764 | clearAppInstance(appID); |
---|
765 | } |
---|
766 | |
---|
767 | break; |
---|
768 | } |
---|
769 | |
---|
770 | case PERF_INFO_REQ : { |
---|
771 | //int dispNum = fsm->dispList.size(); |
---|
772 | /* |
---|
773 | tokenNum = getToken((char *)msg.getData(), token); |
---|
774 | int appID = atoi(token); |
---|
775 | int index =0; |
---|
776 | */ |
---|
777 | int appID, sendingRate, index; |
---|
778 | sscanf((char *)msg.getData(), "%d %d", &appID, &sendingRate); |
---|
779 | |
---|
780 | app = findApp(appID, index); |
---|
781 | if (!app) { |
---|
782 | std::cout << "FsCore : app "<< appID << " doesn't exist" << std::endl; |
---|
783 | break; |
---|
784 | } |
---|
785 | disp = fsm->dispList[index]; |
---|
786 | /* |
---|
787 | int sendingRate; |
---|
788 | |
---|
789 | if (tokenNum < 1) { |
---|
790 | std::cout << "More arguments are needed for this command " << std::endl; |
---|
791 | break; |
---|
792 | } |
---|
793 | |
---|
794 | tokenNum = getToken((char *)msg.getData(), token); |
---|
795 | sendingRate = atoi(token); |
---|
796 | */ |
---|
797 | |
---|
798 | if (disp->requestPerformanceInfo(sendingRate) < 0) |
---|
799 | clearAppInstance(appID); |
---|
800 | |
---|
801 | break; |
---|
802 | } |
---|
803 | |
---|
804 | case STOP_PERF_INFO : { |
---|
805 | //int dispNum = fsm->dispList.size(); |
---|
806 | /* |
---|
807 | tokenNum = getToken((char *)msg.getData(), token); |
---|
808 | int appID = atoi(token); |
---|
809 | int index =0; |
---|
810 | */ |
---|
811 | int appID, index; |
---|
812 | sscanf((char *)msg.getData(), "%d", &appID); |
---|
813 | |
---|
814 | app = findApp(appID, index); |
---|
815 | if (!app) { |
---|
816 | std::cout << "FsCore : app "<< appID << " doesn't exist" << std::endl; |
---|
817 | break; |
---|
818 | } |
---|
819 | disp = fsm->dispList[index]; |
---|
820 | |
---|
821 | if (disp->stopPerformanceInfo() < 0) |
---|
822 | clearAppInstance(appID); |
---|
823 | break; |
---|
824 | } |
---|
825 | |
---|
826 | case SAGE_BG_COLOR : { |
---|
827 | int red, green, blue; |
---|
828 | sscanf((char *)msg.getData(), "%d %d %d", &red, &green, &blue); |
---|
829 | /* |
---|
830 | tokenNum = getToken((char *)msg.getData(), token); |
---|
831 | red = atoi(token); |
---|
832 | |
---|
833 | if (tokenNum < 1) { |
---|
834 | std::cout << "More arguments are needed for this command " << std::endl; |
---|
835 | _exit(0); |
---|
836 | } |
---|
837 | |
---|
838 | tokenNum = getToken((char *)msg.getData(), token); |
---|
839 | green = atoi(token); |
---|
840 | |
---|
841 | if (tokenNum < 1) { |
---|
842 | std::cout << "More arguments are needed for this command " << std::endl; |
---|
843 | _exit(0); |
---|
844 | } |
---|
845 | |
---|
846 | tokenNum = getToken((char *)msg.getData(), token); |
---|
847 | blue = atoi(token); |
---|
848 | */ |
---|
849 | |
---|
850 | for (int i=0; i<fsm->vdtList.size(); i++) |
---|
851 | fsm->vdtList[i]->changeBGColor(red, green, blue); |
---|
852 | |
---|
853 | break; |
---|
854 | } |
---|
855 | |
---|
856 | case UPDATE_WIN_PROP : { |
---|
857 | //int dispNum = fsm->dispList.size(); |
---|
858 | /* |
---|
859 | tokenNum = getToken((char *)msg.getData(), token); |
---|
860 | int appID = atoi(token); |
---|
861 | int index =0; |
---|
862 | */ |
---|
863 | int appID, index; |
---|
864 | sscanf((char *)msg.getData(), "%d", &appID); |
---|
865 | |
---|
866 | app = findApp(appID, index); |
---|
867 | if (!app) { |
---|
868 | std::cout << "FsCore : app "<< appID << " doesn't exist" << std::endl; |
---|
869 | break; |
---|
870 | } |
---|
871 | //disp = fsm->dispList[index]; |
---|
872 | |
---|
873 | //disp->updateWinProp((char *)msg.getData()); |
---|
874 | windowChanged(appID); |
---|
875 | break; |
---|
876 | } |
---|
877 | |
---|
878 | case BRING_TO_FRONT : { |
---|
879 | /* |
---|
880 | tokenNum = getToken((char *)msg.getData(), token); |
---|
881 | int winID = atoi(token); |
---|
882 | */ |
---|
883 | int winID; |
---|
884 | sscanf((char *)msg.getData(), "%d", &winID); |
---|
885 | bringToFront(winID); |
---|
886 | break; |
---|
887 | } |
---|
888 | |
---|
889 | case SAGE_FLIP_WINDOW : { |
---|
890 | //int execNum = fsm->execList.size(); |
---|
891 | /* |
---|
892 | tokenNum = getToken((char *)msg.getData(), token); |
---|
893 | int appID = atoi(token); |
---|
894 | */ |
---|
895 | int appID; |
---|
896 | sscanf((char *)msg.getData(), "%d", &appID); |
---|
897 | |
---|
898 | int index =0; |
---|
899 | app = findApp(appID, index); |
---|
900 | |
---|
901 | if (!app) { |
---|
902 | std::cout << "FsCore : app "<< appID << " doesn't exist" << std::endl; |
---|
903 | break; |
---|
904 | } |
---|
905 | |
---|
906 | if (fsm->sendMessage(app->sailClient, SAIL_FLIP_WINDOW) < 0) { |
---|
907 | sage::printLog("fsCore : %s(%d) is stuck or shutdown", app->appName, appID); |
---|
908 | clearAppInstance(appID); |
---|
909 | } |
---|
910 | |
---|
911 | break; |
---|
912 | } |
---|
913 | |
---|
914 | case SAGE_CHECK_LATENCY : { |
---|
915 | //int execNum = fsm->execList.size(); |
---|
916 | /* |
---|
917 | tokenNum = getToken((char *)msg.getData(), token); |
---|
918 | int appID = atoi(token); |
---|
919 | */ |
---|
920 | int appID; |
---|
921 | sscanf((char *)msg.getData(), "%d", &appID); |
---|
922 | |
---|
923 | int index =0; |
---|
924 | app = findApp(appID, index); |
---|
925 | |
---|
926 | if (!app) { |
---|
927 | std::cout << "FsCore : app "<< appID << " doesn't exist" << std::endl; |
---|
928 | break; |
---|
929 | } |
---|
930 | |
---|
931 | if (fsm->sendMessage(app->sailClient, SAIL_SEND_TIME_BLOCK) < 0) { |
---|
932 | sage::printLog("fsCore : %s(%d) is stuck or shutdown", app->appName, appID); |
---|
933 | clearAppInstance(appID); |
---|
934 | } |
---|
935 | startTime = sage::getTime(); |
---|
936 | |
---|
937 | break; |
---|
938 | } |
---|
939 | |
---|
940 | case SAGE_Z_VALUE : { |
---|
941 | fsm->sendToAllRcvs(RCV_CHANGE_DEPTH, dataStr); |
---|
942 | |
---|
943 | int uiNum = fsm->uiList.size(); |
---|
944 | |
---|
945 | for (int j=0; j<uiNum; j++) { |
---|
946 | if (fsm->uiList[j] < 0) |
---|
947 | continue; |
---|
948 | |
---|
949 | if (fsm->sendMessage(fsm->uiList[j], Z_VALUE_RETURN, dataStr) < 0) { |
---|
950 | sage::printLog("fsCore : uiClient(%d) is stuck or shutdown", j); |
---|
951 | fsm->uiList[j] = -1; |
---|
952 | } |
---|
953 | } |
---|
954 | |
---|
955 | char *tokenbuf; |
---|
956 | getToken((char *)msg.getData(), token, &tokenbuf); |
---|
957 | int numOfChange = atoi(token); |
---|
958 | |
---|
959 | int index =0; |
---|
960 | int appID, zValue; |
---|
961 | for (int i=0; i<numOfChange; i++) { |
---|
962 | /* |
---|
963 | if (tokenNum > 0) { |
---|
964 | tokenNum = getToken((char *)msg.getData(), token); |
---|
965 | appID = atoi(token); |
---|
966 | } |
---|
967 | else { |
---|
968 | std::cout << "More arguments are needed for this command " << std::endl; |
---|
969 | _exit(0); |
---|
970 | } |
---|
971 | |
---|
972 | if (tokenNum > 0) { |
---|
973 | tokenNum = getToken((char *)msg.getData(), token); |
---|
974 | zValue = atoi(token); |
---|
975 | } |
---|
976 | else { |
---|
977 | std::cout << "More arguments are needed for this command " << std::endl; |
---|
978 | _exit(0); |
---|
979 | } |
---|
980 | */ |
---|
981 | getToken(NULL, token, &tokenbuf); |
---|
982 | appID = atoi(token); |
---|
983 | getToken(NULL, token, &tokenbuf); |
---|
984 | zValue = atoi(token); |
---|
985 | |
---|
986 | app = findApp(appID, index); |
---|
987 | if(!app) continue; |
---|
988 | |
---|
989 | fsm->dispList[index]->setZValue(zValue); |
---|
990 | } |
---|
991 | |
---|
992 | break; |
---|
993 | } |
---|
994 | |
---|
995 | case SAGE_ADMIN_CHECK : { |
---|
996 | int execNum = fsm->execList.size(); |
---|
997 | |
---|
998 | for (int i=0; i<execNum; i++) { |
---|
999 | app = fsm->execList[i]; |
---|
1000 | if (!app) |
---|
1001 | continue; |
---|
1002 | |
---|
1003 | displayInstance *disp = fsm->dispList[i]; |
---|
1004 | |
---|
1005 | int left = app->x; |
---|
1006 | int bottom = app->y; |
---|
1007 | int right = app->x + app->width; |
---|
1008 | int top = app->y + app->height; |
---|
1009 | |
---|
1010 | int dispNodes = 0; //disp->getReceiverNum(); |
---|
1011 | int renderNodes = 0;//app->nodeNum; |
---|
1012 | int numStream = 0; //disp->getStreamNum(); |
---|
1013 | |
---|
1014 | char msgStr[512]; |
---|
1015 | memset(msgStr, 0, 512); |
---|
1016 | sprintf(msgStr, "App Name : %s\n App Instance ID : %d\n", |
---|
1017 | app->appName, app->fsInstID); |
---|
1018 | sprintf(token, " position (left, right, bottom, top) : ( %d , %d , %d , %d )\n", |
---|
1019 | left, right, bottom, top); |
---|
1020 | strcat(msgStr, token); |
---|
1021 | sprintf(token, " Z-Value : %d\n", disp->getZValue()); |
---|
1022 | strcat(msgStr, token); |
---|
1023 | sprintf(token, " %d Rendering Nodes %d Display Nodes %d Streams\n", |
---|
1024 | renderNodes, dispNodes, numStream ); |
---|
1025 | strcat(msgStr, token); |
---|
1026 | |
---|
1027 | fsm->sendMessage(clientID, UI_ADMIN_INFO, msgStr); |
---|
1028 | } |
---|
1029 | |
---|
1030 | break; |
---|
1031 | } |
---|
1032 | |
---|
1033 | case SAGE_SHUTDOWN : { |
---|
1034 | std::cout << "shutdown SAGE" << std::endl; |
---|
1035 | int execNum = fsm->execList.size(); |
---|
1036 | |
---|
1037 | for (int i=0; i<execNum; i++) { |
---|
1038 | app = fsm->execList[i]; |
---|
1039 | if (!app) |
---|
1040 | continue; |
---|
1041 | |
---|
1042 | fsm->sendMessage(app->sailClient, APP_QUIT); |
---|
1043 | } |
---|
1044 | |
---|
1045 | fsm->sendToAllRcvs(SHUTDOWN_RECEIVERS); |
---|
1046 | |
---|
1047 | std::vector<int> arcvList = fsm->vdtList[0]->getAudioRcvClientList(); |
---|
1048 | int arcvNum = arcvList.size(); |
---|
1049 | for(int i=0; i<arcvNum; i++) |
---|
1050 | fsm->sendMessage(arcvList[i], SHUTDOWN_RECEIVERS); |
---|
1051 | |
---|
1052 | fsm->fsmClose = true; |
---|
1053 | break; |
---|
1054 | } |
---|
1055 | } |
---|
1056 | |
---|
1057 | return 0; |
---|
1058 | } |
---|
1059 | |
---|
1060 | int fsCore::rotateWindow(char *msgStr) |
---|
1061 | { |
---|
1062 | //char token[TOKEN_LEN]; |
---|
1063 | //int tokenNum = getToken(msgStr, token); |
---|
1064 | //int winID = atoi(token); |
---|
1065 | |
---|
1066 | int winID, rotation; |
---|
1067 | sscanf( msgStr, "%d %d", &winID, &rotation); |
---|
1068 | |
---|
1069 | appInExec *app = NULL; |
---|
1070 | int index =0; |
---|
1071 | app = findApp(winID, index); |
---|
1072 | if (!app) { |
---|
1073 | sage::printLog("fsCore::rotateWindow : app %d doesn't exist", winID); |
---|
1074 | return -1; |
---|
1075 | } |
---|
1076 | /* |
---|
1077 | if (tokenNum < 1) { |
---|
1078 | sage::printLog("fsCore::rotateWindow : more arguments are needed for this command"); |
---|
1079 | return -1; |
---|
1080 | } |
---|
1081 | |
---|
1082 | getToken(msgStr, token); |
---|
1083 | int rotation = atoi(token); |
---|
1084 | */ |
---|
1085 | switch(rotation) { |
---|
1086 | case 90: |
---|
1087 | app->rotate(CCW_90); |
---|
1088 | break; |
---|
1089 | case 180: |
---|
1090 | app->rotate(CCW_180); |
---|
1091 | break; |
---|
1092 | case 270: |
---|
1093 | app->rotate(CCW_270); |
---|
1094 | break; |
---|
1095 | case -90: |
---|
1096 | app->rotate(CCW_270); |
---|
1097 | break; |
---|
1098 | case -180: |
---|
1099 | app->rotate(CCW_180); |
---|
1100 | break; |
---|
1101 | case -270: |
---|
1102 | app->rotate(CCW_90); |
---|
1103 | break; |
---|
1104 | default: |
---|
1105 | sage::printLog("rotation commnad error : invalid rotation degree"); |
---|
1106 | break; |
---|
1107 | } |
---|
1108 | |
---|
1109 | if (fsm->dispList[index]->modifyStream() < 0) |
---|
1110 | clearAppInstance(winID); |
---|
1111 | else |
---|
1112 | windowChanged(winID); |
---|
1113 | |
---|
1114 | return 0; |
---|
1115 | } |
---|
1116 | |
---|
1117 | int fsCore::windowChanged(int appId) |
---|
1118 | { |
---|
1119 | int uiNum = fsm->uiList.size(); |
---|
1120 | for (int j=0; j<uiNum; j++) { |
---|
1121 | if (fsm->uiList[j] < 0) |
---|
1122 | continue; |
---|
1123 | |
---|
1124 | if (sendAppInfo(appId, fsm->uiList[j]) < 0) { |
---|
1125 | sage::printLog("fsCore : uiClient(%d) is stuck or shutdown", j); |
---|
1126 | fsm->uiList[j] = -1; |
---|
1127 | } |
---|
1128 | } |
---|
1129 | |
---|
1130 | return 0; |
---|
1131 | } |
---|
1132 | |
---|
1133 | int fsCore::sendSageStatus(int clientID) |
---|
1134 | { |
---|
1135 | /* |
---|
1136 | int numApps = fsm->appDataList.size(); |
---|
1137 | |
---|
1138 | char statusStr[SAGE_MESSAGE_SIZE], token[TOKEN_LEN]; |
---|
1139 | |
---|
1140 | memset(statusStr, 0, SAGE_MESSAGE_SIZE); |
---|
1141 | sprintf(statusStr, "%d\n", numApps); |
---|
1142 | |
---|
1143 | for (int i=0; i<numApps; i++) { |
---|
1144 | appDataNode *dataNode = fsm->appDataList[i]; |
---|
1145 | int instNum = dataNode->instList.size(); |
---|
1146 | int execNum = dataNode->execs.size(); |
---|
1147 | |
---|
1148 | sprintf(token, "%s %d %d ", dataNode->app, execNum, instNum); |
---|
1149 | strcat(statusStr, token); |
---|
1150 | |
---|
1151 | for (int j=0; j<instNum; j++) { |
---|
1152 | sprintf(token, "%d ", dataNode->instList[j]); |
---|
1153 | strcat(statusStr, token); |
---|
1154 | } |
---|
1155 | strcat(statusStr, "\n"); |
---|
1156 | } |
---|
1157 | |
---|
1158 | fsm->sendMessage(clientID, SAGE_STATUS, statusStr); |
---|
1159 | |
---|
1160 | memset(statusStr, 0, SAGE_MESSAGE_SIZE); |
---|
1161 | |
---|
1162 | for (int i=0; i<numApps; i++) { |
---|
1163 | appDataNode *dataNode = fsm->appDataList[i]; |
---|
1164 | int execNum = dataNode->execs.size(); |
---|
1165 | |
---|
1166 | sprintf(statusStr, "%s\n", dataNode->app); |
---|
1167 | |
---|
1168 | for(int j=0; j<execNum; j++) { |
---|
1169 | sprintf(token, "config %s : nodeNum=%d initX=%d initY=%d dimX=%d dimY=%d\n", |
---|
1170 | dataNode->execs[j].name, dataNode->execs[j].nodeNum, dataNode->execs[j].posX, |
---|
1171 | dataNode->execs[j].posY, dataNode->execs[j].dimX, |
---|
1172 | dataNode->execs[j].dimY); |
---|
1173 | strcat(statusStr, token); |
---|
1174 | |
---|
1175 | int cmdNum = dataNode->execs[j].cmdList.size(); |
---|
1176 | for (int k=0; k<cmdNum; k++) { |
---|
1177 | sprintf(token, "exec %s %s\n", dataNode->execs[j].cmdList[k].ip, |
---|
1178 | dataNode->execs[j].cmdList[k].cmd); |
---|
1179 | strcat(statusStr, token); |
---|
1180 | } |
---|
1181 | sprintf(token, "nwProtocol=%s\n", dataNode->execs[j].nwProtocol); |
---|
1182 | strcat(statusStr, token); |
---|
1183 | sprintf(token, "bufNum=%d\n", dataNode->execs[j].bufNum); |
---|
1184 | strcat(statusStr, token); |
---|
1185 | sprintf(token, "syncMode=%d\n", dataNode->execs[j].syncMode); |
---|
1186 | strcat(statusStr, token); |
---|
1187 | } |
---|
1188 | |
---|
1189 | fsm->sendMessage(clientID, APP_EXEC_CONFIG, statusStr); |
---|
1190 | } |
---|
1191 | */ |
---|
1192 | return 0; |
---|
1193 | } |
---|
1194 | |
---|
1195 | int fsCore::sendDisplayInfo(int clientID) |
---|
1196 | { |
---|
1197 | char displayStr[STRBUF_SIZE]; |
---|
1198 | memset(displayStr, 0, STRBUF_SIZE); |
---|
1199 | displayStr[0] = '\0'; |
---|
1200 | |
---|
1201 | for (int i=0; i<fsm->vdtList.size(); i++) { |
---|
1202 | int tileNum = fsm->vdtList[i]->getTileNum(); |
---|
1203 | int dimX = fsm->vdtList[i]->dimX; |
---|
1204 | int dimY = fsm->vdtList[i]->dimY; |
---|
1205 | int vdtWidth = fsm->vdtList[i]->width; |
---|
1206 | int vdtHeight = fsm->vdtList[i]->height; |
---|
1207 | int tileWidth = fsm->vdtList[i]->tileList[0]->width; |
---|
1208 | int tileHeight = fsm->vdtList[i]->tileList[0]->height; |
---|
1209 | int id = fsm->vdtList[i]->displayID; |
---|
1210 | |
---|
1211 | char info[STRBUF_SIZE]; |
---|
1212 | memset(info, 0, STRBUF_SIZE); |
---|
1213 | sprintf(info, "%d %d %d\n%d %d\n%d %d %d\n", tileNum, dimX, dimY, vdtWidth, vdtHeight, |
---|
1214 | tileWidth, tileHeight, id); |
---|
1215 | strcat(displayStr, info); |
---|
1216 | } |
---|
1217 | |
---|
1218 | fsm->sendMessage(clientID, SAGE_DISPLAY_INFO, displayStr); |
---|
1219 | |
---|
1220 | memset(displayStr, 0, STRBUF_SIZE); |
---|
1221 | displayStr[0] = '\0'; |
---|
1222 | |
---|
1223 | for (int i=0; i<fsm->dispConnectionList.size(); i++) { |
---|
1224 | int disp0 = fsm->dispConnectionList[i]->displays[0]->displayID; |
---|
1225 | int disp1 = fsm->dispConnectionList[i]->displays[1]->displayID; |
---|
1226 | int edge0 = fsm->dispConnectionList[i]->edges[0]; |
---|
1227 | int edge1 = fsm->dispConnectionList[i]->edges[1]; |
---|
1228 | int offset = fsm->dispConnectionList[i]->offset; |
---|
1229 | |
---|
1230 | char info[STRBUF_SIZE]; |
---|
1231 | memset(info, 0, STRBUF_SIZE); |
---|
1232 | sprintf(info, "%d %d %d %d %d\n", disp0, edge0, disp1, edge1, offset); |
---|
1233 | strcat(displayStr, info); |
---|
1234 | } |
---|
1235 | |
---|
1236 | if (fsm->dispConnectionList.size() > 0) |
---|
1237 | fsm->sendMessage(clientID, DISP_CONNECTION_INFO, displayStr); |
---|
1238 | |
---|
1239 | return 0; |
---|
1240 | } |
---|
1241 | |
---|
1242 | int fsCore::sendAppInfo(int appID, int clientID) |
---|
1243 | { |
---|
1244 | appInExec *app; |
---|
1245 | int index =0; |
---|
1246 | app = findApp(appID, index); |
---|
1247 | if(!app) |
---|
1248 | { |
---|
1249 | std::cout << "FsCore::Invalid App ID " << appID << std::endl; |
---|
1250 | return 1; |
---|
1251 | } |
---|
1252 | |
---|
1253 | |
---|
1254 | int zValue = 0; |
---|
1255 | char appInfoStr[TOKEN_LEN]; |
---|
1256 | zValue = fsm->dispList[index]->getZValue(); |
---|
1257 | |
---|
1258 | int left = app->x; |
---|
1259 | int bottom = app->y; |
---|
1260 | int right = app->x + app->width; |
---|
1261 | int top = app->y + app->height; |
---|
1262 | int sailID = app->sailClient; |
---|
1263 | int degree = 90 * (int)app->getOrientation(); |
---|
1264 | |
---|
1265 | memset(appInfoStr, 0, TOKEN_LEN); |
---|
1266 | sprintf(appInfoStr, "%s %d %d %d %d %d %d %d %d %d %d %s %s", app->appName, appID, |
---|
1267 | left, right, bottom, top, sailID, zValue, degree, app->displayID, |
---|
1268 | app->fsInstID, app->launcherID, fsm->dispList[index]->winTitle); |
---|
1269 | |
---|
1270 | return fsm->sendMessage(clientID, APP_INFO_RETURN, appInfoStr); |
---|
1271 | } |
---|
1272 | |
---|
1273 | int fsCore::sendAppInfo(int clientID) |
---|
1274 | { |
---|
1275 | int appInstNum = fsm->execList.size(); |
---|
1276 | appInExec *app = NULL; |
---|
1277 | |
---|
1278 | int retVal = 0; |
---|
1279 | for (int i=0; i<appInstNum; i++) |
---|
1280 | { |
---|
1281 | app = (appInExec*) fsm->execList[i]; |
---|
1282 | if (!app) continue; |
---|
1283 | if (sendAppInfo(app->fsInstID, clientID) < 0) |
---|
1284 | retVal = 1; |
---|
1285 | } |
---|
1286 | |
---|
1287 | return retVal; |
---|
1288 | } |
---|
1289 | |
---|
1290 | int fsCore::sendAppStatus(int clientID, char *appName) |
---|
1291 | { |
---|
1292 | int appInstNum = fsm->execList.size(); |
---|
1293 | appInExec *app; |
---|
1294 | int instNum = 0; |
---|
1295 | char statusMsg[TOKEN_LEN]; |
---|
1296 | statusMsg[0] = '\0'; |
---|
1297 | |
---|
1298 | for (int i=0; i<appInstNum; i++) { |
---|
1299 | app = fsm->execList[i]; |
---|
1300 | if (!app) |
---|
1301 | return -1; |
---|
1302 | if (strcmp(app->appName, appName) == 0) { |
---|
1303 | instNum++; |
---|
1304 | char instStr[TOKEN_LEN]; |
---|
1305 | sprintf(instStr, " %d %d", app->fsInstID, app->sailClient); |
---|
1306 | strcat(statusMsg, instStr); |
---|
1307 | } |
---|
1308 | } |
---|
1309 | |
---|
1310 | char msgStr[TOKEN_LEN]; |
---|
1311 | memset(msgStr, 0, TOKEN_LEN); |
---|
1312 | sprintf(msgStr, "%d%s", instNum, statusMsg); |
---|
1313 | fsm->sendMessage(clientID, APP_STATUS, msgStr); |
---|
1314 | |
---|
1315 | return 0; |
---|
1316 | } |
---|
1317 | |
---|
1318 | int fsCore::bringToFront(int winID) |
---|
1319 | { |
---|
1320 | appInExec *app; |
---|
1321 | |
---|
1322 | int execNum = fsm->execList.size(); |
---|
1323 | int numOfWin = 0; |
---|
1324 | char depthStr[TOKEN_LEN]; |
---|
1325 | depthStr[0] = '\0'; |
---|
1326 | |
---|
1327 | for (int i=0; i<execNum; i++) { |
---|
1328 | app = fsm->execList[i]; |
---|
1329 | if (!app) |
---|
1330 | continue; |
---|
1331 | |
---|
1332 | displayInstance *disp = fsm->dispList[i]; |
---|
1333 | if (app->fsInstID != winID) |
---|
1334 | disp->increaseZ(); |
---|
1335 | else |
---|
1336 | disp->setZValue(0); |
---|
1337 | |
---|
1338 | numOfWin++; |
---|
1339 | char zVal[TOKEN_LEN]; |
---|
1340 | sprintf(zVal, "%d %d ", app->fsInstID, disp->getZValue()); |
---|
1341 | strcat(depthStr, zVal); |
---|
1342 | } |
---|
1343 | |
---|
1344 | char msgStr[TOKEN_LEN]; |
---|
1345 | memset(msgStr, 0, TOKEN_LEN); |
---|
1346 | sprintf(msgStr, "%d %s", numOfWin, depthStr); |
---|
1347 | |
---|
1348 | fsm->sendToAllRcvs(RCV_CHANGE_DEPTH, msgStr); |
---|
1349 | |
---|
1350 | int uiNum = fsm->uiList.size(); |
---|
1351 | |
---|
1352 | for (int j=0; j<uiNum; j++) { |
---|
1353 | if (fsm->uiList[j] < 0) |
---|
1354 | continue; |
---|
1355 | |
---|
1356 | if (fsm->sendMessage(fsm->uiList[j], Z_VALUE_RETURN, msgStr) < 0) { |
---|
1357 | sage::printLog("fsCore : uiClient(%d) is stuck or shutdown", j); |
---|
1358 | fsm->uiList[j] = -1; |
---|
1359 | } |
---|
1360 | } |
---|
1361 | |
---|
1362 | return 0; |
---|
1363 | } |
---|