[4] | 1 | /****************************************************************************** |
---|
| 2 | * SAGE - Scalable Adaptive Graphics Environment |
---|
| 3 | * |
---|
| 4 | * Module: bridgeConsole.cpp - experimental user console for SAGE Bridge |
---|
| 5 | * Author : Byungil Jeong |
---|
| 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 | #include "sageVersion.h" |
---|
| 42 | #include "messageInterface.h" |
---|
| 43 | #include "misc.h" |
---|
| 44 | #include <pthread.h> |
---|
| 45 | |
---|
| 46 | void* readThread(void *args) |
---|
| 47 | { |
---|
| 48 | messageInterface *msgInf = (messageInterface *)args; |
---|
| 49 | |
---|
| 50 | while(1) { |
---|
| 51 | sageMessage msg; |
---|
| 52 | //msg.init(READ_BUF_SIZE); |
---|
| 53 | if (msgInf->readMsg(&msg) > 0) |
---|
| 54 | std::cout << "Message : " << msg.getCode() << std::endl << (char *)msg.getData() |
---|
| 55 | << std::endl << std::endl; |
---|
| 56 | sage::usleep(100000); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | return NULL; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | int initInterface(messageInterface &inf, const char *configFile) |
---|
| 63 | { |
---|
| 64 | msgInfConfig conf; |
---|
| 65 | conf.master = false; |
---|
| 66 | |
---|
| 67 | |
---|
| 68 | data_path path; |
---|
| 69 | std::string found = path.get_file(configFile); |
---|
| 70 | if (found.empty()) { |
---|
| 71 | sage::printLog("bridgeConsole: cannot find the file [%s]", configFile); |
---|
| 72 | return -1; |
---|
| 73 | } |
---|
| 74 | const char *bridgeConfigFile = found.c_str(); |
---|
| 75 | sage::printLog("bridgeConsole: SAGE version [%s]", SAGE_VERSION); |
---|
| 76 | sage::printLog("bridgeConsole: using [%s] configuration file", bridgeConfigFile); |
---|
| 77 | |
---|
| 78 | FILE *fileBridgeConf = fopen(bridgeConfigFile, "r"); |
---|
| 79 | |
---|
| 80 | if (!fileBridgeConf) { |
---|
| 81 | sage::printLog("bridgeConsole: fail to open SAGE Bridge config file [%s]\n", bridgeConfigFile); |
---|
| 82 | return -1; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | char token[TOKEN_LEN]; |
---|
| 86 | int tokenIdx = getToken(fileBridgeConf, token); |
---|
| 87 | |
---|
| 88 | while(tokenIdx != EOF) { |
---|
| 89 | if (strcmp(token, "masterIP") == 0) { |
---|
| 90 | getToken(fileBridgeConf, conf.serverIP); |
---|
| 91 | } |
---|
| 92 | else if (strcmp(token, "msgPort") == 0) { |
---|
| 93 | getToken(fileBridgeConf, token); |
---|
| 94 | conf.serverPort = atoi(token); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | tokenIdx = getToken(fileBridgeConf, token); |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | inf.init(conf); |
---|
| 101 | |
---|
| 102 | return 0; |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | int main(int argc, char *argv[]) |
---|
| 106 | { |
---|
| 107 | char token[TOKEN_LEN]; |
---|
| 108 | bool flag = true; |
---|
| 109 | int code; |
---|
| 110 | |
---|
| 111 | messageInterface msgInf; |
---|
| 112 | |
---|
| 113 | if (argc == 2) |
---|
| 114 | initInterface(msgInf, argv[1]); |
---|
| 115 | else |
---|
| 116 | initInterface(msgInf, "sageBridge.conf"); |
---|
| 117 | |
---|
| 118 | //msgInf.msgToServer(0, BRIDGE_UI_REG); |
---|
| 119 | |
---|
| 120 | pthread_t thId; |
---|
| 121 | |
---|
| 122 | if (pthread_create(&thId, 0, readThread, (void*)&msgInf) != 0){ |
---|
| 123 | return -1; |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | while(flag) { |
---|
| 127 | std::cin >> token; |
---|
| 128 | |
---|
| 129 | if (strcmp(token, "exit") == 0 || strcmp(token, "quit") == 0) { |
---|
| 130 | flag = false; |
---|
| 131 | } |
---|
| 132 | else if (strcmp(token, "share") == 0) { |
---|
| 133 | fgets(token, TOKEN_LEN, stdin); |
---|
| 134 | msgInf.msgToServer(0, SAGE_APP_SHARE, token); |
---|
| 135 | } |
---|
| 136 | else if (strcmp(token, "perf") == 0) { |
---|
| 137 | char cmd[TOKEN_LEN]; |
---|
| 138 | fgets(cmd, TOKEN_LEN, stdin); |
---|
| 139 | msgInf.msgToServer(0, PERF_INFO_REQ, cmd); |
---|
| 140 | } |
---|
| 141 | else if (strcmp(token, "stopperf") == 0) { |
---|
| 142 | fgets(token, TOKEN_LEN, stdin); |
---|
| 143 | msgInf.msgToServer(0, STOP_PERF_INFO, token); |
---|
| 144 | } |
---|
| 145 | else if (strcmp(token, "kill") == 0) { |
---|
| 146 | fgets(token, TOKEN_LEN, stdin); |
---|
| 147 | msgInf.msgToServer(0, SHUTDOWN_APP, token); |
---|
| 148 | } |
---|
| 149 | else if (strcmp(token, "shutdown") == 0) { |
---|
| 150 | msgInf.msgToServer(0, BRIDGE_SHUTDOWN); |
---|
| 151 | _exit(0); |
---|
| 152 | } |
---|
| 153 | else if (strcmp(token, "exec") == 0) { |
---|
| 154 | fgets(token, TOKEN_LEN, stdin); |
---|
| 155 | msgInf.msgToServer(0, EXEC_APP, token); |
---|
| 156 | } |
---|
| 157 | else if (strcmp(token, "move") == 0) { |
---|
| 158 | fgets(token, TOKEN_LEN, stdin); |
---|
| 159 | msgInf.msgToServer(0, MOVE_WINDOW, token); |
---|
| 160 | } |
---|
| 161 | else if (strcmp(token, "resize") == 0) { |
---|
| 162 | fgets(token, TOKEN_LEN, stdin); |
---|
| 163 | msgInf.msgToServer(0, RESIZE_WINDOW, token); |
---|
| 164 | } |
---|
| 165 | else if (strcmp(token, "bg") == 0) { |
---|
| 166 | fgets(token, TOKEN_LEN, stdin); |
---|
| 167 | msgInf.msgToServer(0, SAGE_BG_COLOR, token); |
---|
| 168 | } |
---|
| 169 | else if (strcmp(token, "depth") == 0) { |
---|
| 170 | char cmd[TOKEN_LEN]; |
---|
| 171 | fgets(cmd, TOKEN_LEN, stdin); |
---|
| 172 | msgInf.msgToServer(0, SAGE_Z_VALUE, cmd); |
---|
| 173 | } |
---|
| 174 | else if (strcmp(token, "admin") == 0) { |
---|
| 175 | msgInf.msgToServer(0, SAGE_ADMIN_CHECK); |
---|
| 176 | } |
---|
| 177 | else if (strcmp(token, "rate") == 0) { |
---|
| 178 | fgets(token, TOKEN_LEN, stdin); |
---|
| 179 | msgInf.msgToServer(0, APP_FRAME_RATE, token); |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | |
---|
| 183 | else if (strcmp(token, "help") == 0) { |
---|
| 184 | std::cout << std::endl; |
---|
| 185 | std::cout << "exec app_name config_num (init_x init_y) : execute an app" << std::endl; |
---|
| 186 | std::cout << "move app_id dx dy : move window of an app" << std::endl; |
---|
| 187 | std::cout << "resize app_id left right bottom top : resize window of an app" << std::endl; |
---|
| 188 | std::cout << "bg red green blue : change background color" << std::endl; |
---|
| 189 | std::cout << "depth num_of_change app_id zVal... : change z-order of windows" << std::endl; |
---|
| 190 | std::cout << "perf app_id report_period(sec) : request performance info" << std::endl; |
---|
| 191 | std::cout << "stopperf app_id : stop performance info report" << std::endl; |
---|
| 192 | std::cout << "kill app_id : shutdown an app" << std::endl; |
---|
| 193 | std::cout << "shutdown : shutdown SAGE" << std::endl; |
---|
| 194 | std::cout << "admin : get administrative info" << std::endl; |
---|
| 195 | } |
---|
| 196 | |
---|
| 197 | std::cout << std::endl; |
---|
| 198 | } |
---|
| 199 | } |
---|