bool CImageQuad::SetProperties(CParametersMap ¶msIn, CParametersMap ¶msOut) { CActor::SetProperties(paramsIn, paramsOut); double fValue; wxString strValue; ////-------- texture from file if (paramsIn.GetFloat(wxString::FromAscii("width"), &fValue)) fWidth = (float)fValue; if (paramsIn.GetFloat(wxString::FromAscii("height"), &fValue)) fHeight = (float)fValue; if (paramsIn.GetString(wxString::FromAscii("texture_file"), &strValue)) { wxImage image; if (!image.LoadFile(strValue)) paramsOut.AppendString(wxString::FromAscii("error"), wxString::FromAscii("Failed to load file")); else { SetTexture(image.GetWidth(), image.GetHeight(), 3, GL_UNSIGNED_BYTE, image.GetData()); } } ////-------- user-supplied texture CDoubleArray *pTexture = paramsIn.GetArray(wxString::FromAscii("texture")); if (pTexture) { int iTexW, iTexH; if (!paramsIn.GetInt(wxString::FromAscii("tex_width"), &iTexW) || !paramsIn.GetInt(wxString::FromAscii("tex_height"), &iTexH)) { paramsOut.AppendString(wxString::FromAscii("error"), wxString::FromAscii("'tex_width' and 'tex_height' parameters are required")); } else if ((pTexture->GetNumberOfDimensions() != 2) || ((pTexture->GetSizes()[0] != 3) && (pTexture->GetSizes()[0] != 4)) || (pTexture->GetSizes()[1] != iTexW*iTexH)) { paramsOut.AppendString(wxString::FromAscii("error"), wxString::FromAscii("Invalid size of 'texture' array")); } else { double *dTex = pTexture->GetPointer(); int nVals = iTexW*iTexH*pTexture->GetSizes()[0]; float *fTex = (float *)malloc(nVals*sizeof(float)); for(int i=0; i<nVals; i++) fTex[i] = (float)dTex[i]; SetTexture(iTexW, iTexH, pTexture->GetSizes()[0], GL_FLOAT, fTex); free(fTex); //SetTexture(iTexW, iTexH, pTexture->GetSizes()[0], GL_DOUBLE, pTexture->GetPointer()); } } return true; }
bool CServerConsole::CommandMessage(ClientIDData *pClient, CParametersMap ¶msIn, CParametersMap ¶msOut, CServerConsole *pThis) { wxString strMsg; if (!paramsIn.GetString(wxString::FromAscii("message"), &strMsg)) { paramsOut.SetString(wxString::FromAscii("error"), wxString::FromAscii("No 'message' field")); return false; } pClient->pWindow->Raise(); wxMessageDialog(pClient->pWindow, strMsg, wxString::FromAscii("Message"), wxOK | wxCENTRE).ShowModal(); return true; }
bool CServerConsole::ProcessClientCommand(ClientIDData *pClient, char *pCommand, CParametersMap ¶msIn, CParametersMap ¶msOut) { wxASSERT(pClient); HashMapCommandHandlers::iterator it; it = mapClientCommandHandlers.find(wxString::FromAscii(pCommand)); if (it == mapClientCommandHandlers.end()) { paramsOut.AppendString(wxString::FromAscii("error"), wxString::FromAscii("Unknown command")); Log(wxString::FromAscii("Unknown command\n")); return false; } /* // uncomment to check parser int iLen; char *pDump = paramsIn.FormatString(&iLen); Log(pDump); delete[] pDump; */ return it->second(pClient, paramsIn, paramsOut, this); }
bool CImageQuad::GetProperties(CParametersMap ¶msIn, CParametersMap ¶msOut) { CActor::GetProperties(paramsIn, paramsOut); if (paramsIn.GetInt(wxString::FromAscii("get_width"), FALSE) || paramsIn.GetInt(wxString::FromAscii("get_all"), FALSE)) paramsOut.SetFloat(wxString::FromAscii("width"), fWidth); if (paramsIn.GetInt(wxString::FromAscii("get_width"), FALSE) || paramsIn.GetInt(wxString::FromAscii("get_all"), FALSE)) paramsOut.SetFloat(wxString::FromAscii("width"), fWidth); return true; }
bool CServerConsole::CommandHelp(ClientIDData *pClient, CParametersMap ¶msIn, CParametersMap ¶msOut, CServerConsole *pThis){ HashMapCommandHandlers::iterator it; wxString strHelp; strHelp.Alloc(pThis->mapClientCommandHandlers.size()*10); for (it = pThis->mapClientCommandHandlers.begin(); it != pThis->mapClientCommandHandlers.end(); it++) strHelp += it->first + wxString::FromAscii("\n"); // wxString strViewCommands; // C3DView::GetCommandsList(strViewCommands); // strHelp += strViewCommands; paramsOut.SetString(wxString::FromAscii("Available commands"), strHelp); return true; }
bool CServerConsole::CommandGetNumWindows(ClientIDData *pClient, CParametersMap ¶msIn, CParametersMap ¶msOut, CServerConsole *pThis){ paramsOut.SetInt(wxString::FromAscii("n"), pThis->mapClients.size()); return true; }
bool CServerConsole::ReceiveClientCommand(int iID, wxSocketBase *sock){ HashMapClients::iterator it; ClientHeader client_header; ServerHeader server_header; char *pCommand = NULL; char *pParams = NULL; CParametersMap paramsIn; CParametersMap paramsOut; // check if ID is valid it = mapClients.find(iID); if (it == mapClients.end()){ wxASSERT(0); return false; } // receive message header sock->ReadMsg(&client_header, sizeof(client_header)); if (sock->Error()) { Log(wxString::FromAscii("Failed to receive client message")); return false; } Log(wxString::FromAscii("Received client message")); // receive command and parameters if (client_header.command_length){ pCommand = new char[client_header.command_length]; sock->ReadMsg(pCommand, client_header.command_length); //_strlwr(pCommand); for (char *s=pCommand; *s; s++){ if (*s >= 'A' && *s <= 'Z') *s = *s - 'A' + 'a'; } wxString wCommand(pCommand, wxConvUTF8); Log(wxString::Format(wxString::FromAscii("Command = %s"), wCommand.c_str())); //RK 12/21/09: fixed, pCommand is showing up now } if (client_header.params_length){ pParams = new char[client_header.params_length]; //sock->ReadMsg(pParams, client_header.params_length); bool bRes = ReceiveInParts(sock, pParams, client_header.params_length); if (!bRes) Log(wxString::FromAscii("Error receiving client data")); else{ if (client_header.params_length < 50) { wxString wParams(pParams, wxConvUTF8); Log(wxString::Format(wxString::FromAscii("Params\n********\n%s********"), wParams.c_str())); //RK 12/21/09: fixed } else Log(wxString::Format(wxString::FromAscii("Params : %d bytes\n"), client_header.params_length)); } } // parse parameters if (pParams){ if (!paramsIn.CreateFromString(pParams, client_header.params_length)) paramsOut.SetString(wxString::FromAscii("warning"), wxString::FromAscii("Invalid arguments string")); //<debug> //{ //int nLen = 0; //char *pData = paramsIn.FormatString(&nLen); //Dump("params_in", pParams, client_header.params_length); //Dump("params_fmt", pData, nLen); //delete[] pData; //} //</debug> } // Search string => command arrays and maps bool bHandlerRes = false; if (!pCommand) paramsOut.SetString(wxString::FromAscii("error"), wxString::FromAscii("No command")); else{ if (!it->second.pWindow->Get3DView()->ProcessCommand(pCommand, &bHandlerRes, paramsIn, paramsOut)){ // no handler in C3DView ProcessClientCommand(&it->second, pCommand, paramsIn, paramsOut); } } if (bHandlerRes) server_header.status = 1; else server_header.status = -1; // cleanup if (pCommand) delete[] pCommand; if (pParams) delete[] pParams; // reply char *pReplyData = paramsOut.FormatString(&server_header.data_length); if (server_header.data_length ==1) server_header.data_length = 0; sock->WriteMsg(&server_header, sizeof(server_header)); if (sock->Error()) { Log(wxString::FromAscii("Failed to respond")); if (pReplyData) delete[] pReplyData; return false; } if (server_header.data_length) { //Dump("outf", pReplyData, server_header.data_length); //sock->WriteMsg(pReplyData, server_header.data_length); //if (sock->Error()) //{ // wxASSERT(0); // Log(wxString::Format(wxString::FromAscii("Failed to send data (%d bytes)"), server_header.data_length)); //} if (!SendInParts(sock, pReplyData, server_header.data_length)) Log(wxString::Format(wxString::FromAscii("Failed to send data (%d bytes)"), server_header.data_length)); } if (pReplyData) delete[] pReplyData; Log(wxString::FromAscii("\n")); return true; }