ServerConnection::ServerConnection(QTcpSocket *connection, QObject *parent) : QObject(parent), m_connection(connection) { m_messageList = new QStringList(); m_connected = true; m_hostIp = m_connection->peerAddress().toString(); m_port = m_connection->peerPort(); m_active = true; m_activeTimer = startTimer(2*60000); kDebug() << m_port; connect( m_connection, SIGNAL(readyRead()), this, SLOT(gotNewData()) ); // let's see if we already got some data gotNewData(); }
void ULaserDevice::callGotNewDataWithObject() { if (pushData != NULL) { pushData->lock(); // start the push handling gotNewData(pushData); // finished with the data structure, so release. pushData->unlock(); } }
void UResPoly::handleNewData(USmlTag * tag) { // handle poly message const int MSL = 200; char att[MAX_SML_NAME_LENGTH]; char val[MSL]; USmlTag nTag; int cntItems = 0; const int MNL = 32; char name[MNL]; UPolyItem * pi; // while (tag->getNextAttribute(att, val, MSL)) { if ((strcasecmp(att, "warning") == 0) or (strcasecmp(att, "info") == 0)) { // no data printf("*** failed: %s\n", val); break; } // else if (strcasecmp(att, "cnt") == 0) // { // cnt = strtol(val, NULL, 10); // } } if (tag->isAStartTag()) { // there is nested structures while (tag->getNextTag(&nTag, 200)) { if (nTag.isTagA("polygon")) { // get all support data pi = NULL; if (nTag.getAttValue("name", name, MNL)) { // must have a name // get polygon item to unpack to pi = getItem(name); if (pi == NULL) pi = add(name); } if (pi != NULL) { // optional coordinate system nTag.getAttBool("valid", &pi->valid, true); if (pi->valid) { nTag.getAttInteger("cooSys", &pi->cooSys, 1); nTag.getAttDouble("x", &pi->relPose.x, 0.0); nTag.getAttDouble("y", &pi->relPose.y, 0.0); nTag.getAttDouble("h", &pi->relPose.h, 0.0); nTag.getAttBool("relPoseUse", &pi->relPoseUse, false); // get rest of polygon nTag.getPolygon(pi, NULL); } pi->updateTime.now(); cntItems++; } } else if (nTag.isAStartTag()) // is an unwanted tag goup - skip nTag.skipToEndTag(1000); // remember to test for endflag too else if (nTag.isTagAnEnd(tag->getTagName())) break; } } if (cntItems > 0) { /* if (polysCnt != cnt) printf("Has %d polyItems (%d updated), but sender has %d!\n", polysCnt, cntItems, cnt);*/ varPolyCnt->setInt(polysCnt); gotNewData(); } }
bool UResPoly::methodCallV(const char * name, const char * paramOrder, UVariable * params[], UDataBase ** returnStruct, int * returnStructCnt) { bool result = true; UPolyItem * pi; UPolygon * poly; UDataBase * db; int i; UPosition pos; UVariable buffer; UVariable * returnVar = NULL; bool isOK; UPose po1, po2; // evaluate standard functions if (returnStruct[0]->isA("var")) { returnVar = (UVariable*)returnStruct[0]; *returnStructCnt = 1; } else returnVar = &buffer; // // test available methods if ((strcasecmp(name, "addPoint") == 0) and (strcmp(paramOrder, "sc") == 0)) { pos = params[1]->get3D(); pi = add(params[0]->getValues(), pos.x, pos.y, pos.z); isOK = pi != NULL; returnVar->setBool(isOK); gotNewData(); } else if ((strcasecmp(name, "del") == 0) and (strcmp(paramOrder, "s") == 0)) { isOK = del(params[0]->getValues()); returnVar->setBool(isOK); gotNewData(); } else if ((strcasecmp(name, "delPoint") == 0) and (strcmp(paramOrder, "sd") == 0)) { pi = getItem(params[0]->getValues()); isOK = pi != NULL; if (isOK) pi->remove(params[1]->getInt()); returnVar->setBool(isOK); gotNewData(); } else if ((strcasecmp(name, "getPoint") == 0) and (strcmp(paramOrder, "sd") == 0)) { isOK = false; pi = getItem(params[0]->getValues()); if (pi != NULL) { // item is found, so get position i = roundi(params[1]->getInt()); if (i < pi->getPointsCnt() and i >= 0) { isOK = true; pos = pi->getPoint(i); } } if (not isOK) pos.clear(); returnVar->set3D(&pos); } else if ((strcasecmp(name, "isInside") == 0) and (strcmp(paramOrder, "sc") == 0)) { isOK = false; pos = params[1]->get3D(); pi = getItem(params[0]->getValues()); if (pi != NULL) { // item is found, test isOK = pi->isInsideConvex(pos.x, pos.y, 0.0); } returnVar->setBool(isOK); } else if ((strcasecmp(name, "isInside") == 0) and (strcmp(paramOrder, "scc") == 0)) { isOK = false; po1 = params[1]->getPose(); // pose of robot po2 = params[2]->getPose(); // position relative to robot po1 = po1 + po2; pi = getItem(params[0]->getValues()); if (pi != NULL) { // item is found, test isOK = pi->isInsideConvex(po1.x, po1.y, 0.0); } returnVar->setBool(isOK); } else if ((strcasecmp(name, "defined") == 0) and (strcmp(paramOrder, "s") == 0)) { pi = getItem(params[0]->getValues()); isOK = (pi != NULL); returnVar->setBool(isOK); } else if ((strcasecmp(name, "setRefCoord") == 0) and (strcmp(paramOrder, "sd") == 0)) { pi = getItem(params[0]->getValues()); isOK = pi != NULL; if (isOK) pi->cooSys = params[1]->getInt(); returnVar->setBool(isOK); } else if ((strcasecmp(name, "setOpen") == 0) and (strcmp(paramOrder, "s") == 0)) { pi = getItem(params[0]->getValues()); isOK = pi != NULL; if (isOK) pi->setAsPolyline(); returnVar->setBool(isOK); gotNewData(); } else if ((strcasecmp(name, "setClosed") == 0) and (strcmp(paramOrder, "s") == 0)) { pi = getItem(params[0]->getValues()); isOK = pi != NULL; if (isOK) pi->setAsPolygon(); returnVar->setBool(isOK); gotNewData(); } else if ((strcasecmp(name, "setPolygon") == 0) and (strcmp(paramOrder, "sc") == 0 or strcmp(paramOrder, "scd") == 0)) { isOK = false; pi = getItem(params[0]->getValues()); db = params[1]; if (db->isAlsoA("polygon")) poly = (UPolygon*) db; else poly = NULL; isOK = poly != NULL; if (isOK and pi == NULL) { // item is found, so get position pi = add(params[0]->getValues()); isOK = pi != NULL; } if (isOK) { isOK = poly->copyTo(pi); if (strlen(paramOrder) >= 3) // get also coordinate system reference pi->cooSys = params[2]->getInt(); pi->setUpdated(); } returnVar->setBool(isOK); gotNewData(); } else // call name is unknown result = false; // set result if just a boolean if (result) { // set return struct value to isOK if (returnStruct != NULL and returnStructCnt != NULL) *returnStructCnt = 1; } return result; }