00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <stdlib.h>
00023 #include <tcl.h>
00024 #include "config.h"
00025 #include "VMDApp.h"
00026 #include "MobileInterface.h"
00027 #include "utilities.h"
00028
00029
00030 static void mobile_usage(Tcl_Interp *interp) {
00031 Tcl_AppendResult(interp, "mobile usage:\n",
00032 "mobile mode <mode>\n",
00033 " modes: off, move, animate, tracker, user\n",
00034 "mobile port <incoming network port number>\n",
00035 "mobile get <mode/port/clientList/APIsupported>\n",
00036 "mobile set activeClient {name} {ip}\n",
00037 "mobile sendMsg {name} {ip} msgType {msg}\n",
00038
00039
00040 NULL);
00041 }
00042
00043 int text_cmd_mobile(ClientData cd, Tcl_Interp *interp, int argc,
00044 const char *argv[]) {
00045
00046 VMDApp *app = (VMDApp *)cd;
00047
00048 if (argc < 3 || argc > 6) {
00049
00050 mobile_usage(interp);
00051 return TCL_ERROR;
00052 }
00053
00054 if (!strupncmp(argv[1], "mode", CMDLEN)) {
00055 int m1 = Mobile::OFF;
00056
00057 if (!strupncmp(argv[2], "off", CMDLEN)) m1 = Mobile::OFF;
00058 else if (!strupncmp(argv[2], "move", CMDLEN)) m1 = Mobile::MOVE;
00059 else if (!strupncmp(argv[2], "animate", CMDLEN)) m1 = Mobile::ANIMATE;
00060 else if (!strupncmp(argv[2], "tracker", CMDLEN)) m1 = Mobile::TRACKER;
00061 else if (!strupncmp(argv[2], "user", CMDLEN)) m1 = Mobile::USER;
00062 else mobile_usage(interp);
00063
00064 if (!app->mobile_set_mode(m1)) {
00065 Tcl_AppendResult(interp, "Unable to set Mobile mode to ",
00066 argv[2], argc > 3 ? argv[3] : NULL, NULL);
00067
00068
00069 mobile_usage(interp);
00070 return TCL_ERROR;
00071 }
00072 } else if(!strupncmp(argv[1], "port", CMDLEN)) {
00073 int port;
00074 if (sscanf(argv[2], "%d", &port) == 1) {
00075 if (!app->mobile_network_port(port)) {
00076
00077 mobile_usage(interp);
00078 return TCL_ERROR;
00079 }
00080 } else {
00081
00082 mobile_usage(interp);
00083 return TCL_ERROR;
00084 }
00085 } else if(!strupncmp(argv[1], "get", CMDLEN)) {
00086 if (!strupncmp(argv[2], "mode", CMDLEN))
00087 {
00088 Tcl_AppendResult(interp, Mobile::get_mode_str((Mobile::MoveMode)app->mobile_get_mode()), NULL);
00089 } else if (!strupncmp(argv[2], "clientList", CMDLEN)) {
00090 ResizeArray <JString *>* ip;
00091 ResizeArray <JString *>* nick;
00092 ResizeArray <bool>* active;
00093 app->mobile_get_client_list( nick, ip, active);
00094 for (int i=0; i<nick->num(); i++)
00095 {
00096 Tcl_AppendResult(interp, " {", NULL);
00097
00098 Tcl_AppendResult(interp, " {", NULL);
00099
00100
00101
00102
00103
00104
00105
00106 Tcl_AppendResult(interp, (const char *)(*(*nick)[i]), NULL);
00107 Tcl_AppendResult(interp, "}", NULL);
00108
00109 Tcl_AppendResult(interp, " {", NULL);
00110 Tcl_AppendResult(interp, (const char *)(*(*ip)[i]), NULL);
00111 Tcl_AppendResult(interp, "}", NULL);
00112
00113 Tcl_AppendResult(interp, " {", NULL);
00114 char tmp[10]; sprintf(tmp, "%d", (*active)[i]);
00115 Tcl_AppendResult(interp, tmp, NULL);
00116 Tcl_AppendResult(interp, "}", NULL);
00117
00118 Tcl_AppendResult(interp, " }", NULL);
00119 }
00120
00121 } else if (!strupncmp(argv[2], "port", CMDLEN)) {
00122 char tmpstr[20];
00123 sprintf(tmpstr, "%d", app->mobile_get_network_port());
00124 Tcl_AppendResult(interp, tmpstr, NULL);
00125 } else if (!strupncmp(argv[2], "APIsupported", CMDLEN)) {
00126 char tmpstr[20];
00127 sprintf(tmpstr, "%d", app->mobile_get_APIsupported());
00128 Tcl_AppendResult(interp, tmpstr, NULL);
00129 } else mobile_usage(interp);
00130
00131 } else if(!strupncmp(argv[1], "sendMsg", CMDLEN)) {
00132 if (argc >= 6)
00133 {
00134 if (!app->mobile_sendMsg(argv[2], argv[3], argv[4], argv[5])) {
00135
00136
00137 mobile_usage(interp);
00138 return TCL_ERROR;
00139 }
00140 } else mobile_usage(interp);
00141
00142 } else if(!strupncmp(argv[1], "set", CMDLEN)) {
00143 if (!strupncmp(argv[2], "activeClient", CMDLEN))
00144 {
00145 if (argc >= 5)
00146 {
00147 if (!app->mobile_set_activeClient(argv[3], argv[4])) {
00148
00149
00150
00151
00152 mobile_usage(interp);
00153 return TCL_ERROR;
00154 }
00155 } else mobile_usage(interp);
00156
00157 } else mobile_usage(interp);
00158
00159 } else {
00160
00161 mobile_usage(interp);
00162 return TCL_ERROR;
00163 }
00164
00165
00166 return TCL_OK;
00167 }
00168