void tst_QXmlSchemaValidator::constructorQXmlNamePool() const { // test that the name pool from the schema is used by // the schema validator as well QXmlSchema schema; QXmlNamePool np = schema.namePool(); const QXmlName name(np, QLatin1String("localName"), QLatin1String("http://example.com/"), QLatin1String("prefix")); QXmlSchemaValidator validator(schema); QXmlNamePool np2(validator.namePool()); QCOMPARE(name.namespaceUri(np2), QString::fromLatin1("http://example.com/")); QCOMPARE(name.localName(np2), QString::fromLatin1("localName")); QCOMPARE(name.prefix(np2), QString::fromLatin1("prefix")); // make sure namePool() is const const QXmlSchemaValidator constValidator(schema); np = constValidator.namePool(); }
void NetworkPackageTests::networkPackageTest() { NetworkPackage np("com.test"); np.set("hello","hola"); QCOMPARE( (np.get<QString>("hello","bye")) , QString("hola") ); np.set("hello",""); QCOMPARE( (np.get<QString>("hello","bye")) , QString("") ); np.body().remove("hello"); QCOMPARE( (np.get<QString>("hello","bye")) , QString("bye") ); np.set("foo", "bar"); QByteArray ba = np.serialize(); //qDebug() << "Serialized package:" << ba; NetworkPackage np2(""); NetworkPackage::unserialize(ba,&np2); QCOMPARE( np.id(), np2.id() ); QCOMPARE( np.type(), np2.type() ); QCOMPARE( np.body(), np2.body() ); QByteArray json("{\"id\":\"123\",\"type\":\"test\",\"body\":{\"testing\":true}}"); //qDebug() << json; NetworkPackage::unserialize(json,&np2); QCOMPARE( np2.id(), QString("123") ); QCOMPARE( (np2.get<bool>("testing")), true ); QCOMPARE( (np2.get<bool>("not_testing")), false ); QCOMPARE( (np2.get<bool>("not_testing",true)), true ); //NetworkPackage::unserialize("this is not json",&np2); //QtTest::ignoreMessage(QtSystemMsg, "json_parser - syntax error found, forcing abort, Line 1 Column 0"); //QtTest::ignoreMessage(QtDebugMsg, "Unserialization error: 1 \"syntax error, unexpected string\""); }
void BezierMode::mouseReleaseEvent(QMouseEvent *m) { const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos()); undoManager->setUndoEnabled(true); PageItem *currItem; m_MouseButtonPressed = false; m_canvas->resetRenderMode(); m->accept(); // m_view->stopDragTimer(); m_canvas->setRenderModeUseBuffer(false); if ((m_doc->appMode == modeDrawBezierLine) && (m->button() == Qt::LeftButton)) { m_canvas->setRenderModeUseBuffer(true); currItem = m_doc->m_Selection->itemAt(0); currItem->ClipEdited = true; currItem->FrameType = 3; QTransform pm = currItem->getTransform(); FPoint npf = m_doc->ApplyGridF(mousePointDoc).transformPoint(pm, true); currItem->PoLine.addPoint(npf); bool ssiz = currItem->Sizing; currItem->Sizing = true; if ((currItem->PoLine.size() % 4 == 0) && (currItem->PoLine.size() > 3)) { FPoint lxy(currItem->PoLine.point(currItem->PoLine.size()-2)); FPoint lk(currItem->PoLine.point(currItem->PoLine.size()-1)); double dx = lxy.x() - lk.x(); double dy = lxy.y() - lk.y(); lk.setX(lk.x() + dx*2); lk.setY(lk.y() + dy*2); currItem->PoLine.addPoint(lxy); currItem->PoLine.addPoint(lk); } FPoint np2(getMinClipF(&currItem->PoLine)); if (np2.x() < 0) { currItem->PoLine.translate(-np2.x(), 0); m_doc->MoveItem(np2.x(), 0, currItem); } if (np2.y() < 0) { currItem->PoLine.translate(0, -np2.y()); m_doc->MoveItem(0, np2.y(), currItem); } if (FirstPoly) { FirstPoly = false; currItem->Sizing = ssiz; } else { m_doc->SizeItem(currItem->PoLine.WidthHeight().x(), currItem->PoLine.WidthHeight().y(), currItem, false, false, false); m_doc->AdjustItemSize(currItem); currItem->Sizing = ssiz; currItem->ContourLine = currItem->PoLine.copy(); m_canvas->setRenderModeUseBuffer(false); currItem->update(); } m_canvas->setRenderModeFillBuffer(); int newX = qRound(mousePointDoc.x()); //m_view->translateToDoc(m->x(), m->y()).x()); int newY = qRound(mousePointDoc.y()); //m_view->translateToDoc(m->x(), m->y()).y()); m_canvas->newRedrawPolygon() << QPoint(newX - qRound(currItem->xPos()), newY - qRound(currItem->yPos())); m_view->updateCanvas(); } if ((m_doc->appMode == modeDrawBezierLine) && (m->button() == Qt::RightButton)) { currItem = m_doc->m_Selection->itemAt(0); if (currItem!=0) { finalizeItem(currItem); } if (!PrefsManager::instance()->appPrefs.uiPrefs.stickyTools) { // qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor)); m_view->requestMode(modeNormal); // m_view->requestMode(submodePaintingDone); } else m_view->requestMode(m_doc->appMode); m_doc->changed(); // emit DocChanged(); FirstPoly = true; inItemCreation = false; m_canvas->setRenderModeUseBuffer(false); // m_view->updateContents(); } m_doc->DragP = false; m_doc->leaveDrag = false; // m_canvas->m_viewMode.operItemResizing = false; m_view->MidButt = false; shiftSelItems = false; // m_doc->SubMode = -1; if (m_view->groupTransactionStarted()) { for (int i = 0; i < m_doc->m_Selection->count(); ++i) m_doc->m_Selection->itemAt(i)->checkChanges(true); m_view->endGroupTransaction(); } //??? for (int i = 0; i < m_doc->m_Selection->count(); ++i) //??? m_doc->m_Selection->itemAt(i)->checkChanges(true); // //Commit drag created items to undo manager. // if (m_doc->m_Selection->itemAt(0)!=NULL) // { // m_doc->itemAddCommit(m_doc->m_Selection->itemAt(0)->ItemNr); // } //Make sure the Zoom spinbox and page selector dont have focus if we click on the canvas m_view->m_ScMW->zoomSpinBox->clearFocus(); m_view->m_ScMW->pageSelector->clearFocus(); if (m_doc->m_Selection->itemAt(0) != 0) // is there the old clip stored for the undo action { currItem = m_doc->m_Selection->itemAt(0); m_doc->nodeEdit.finishTransaction(currItem); } else { //delete oldClip; //oldClip = 0; } }
int main(int argc, char **argv) { int i; int ret = -1; int screen = -1; int usealpha = 0; int fullscreen = 0; SDL_SysWMinfo info; SDL_Window *window = NULL; SDL_GLContext *ctx = NULL; for (i = 0; i < argc; i++) { if (!SDL_strncasecmp(argv[i], "-h", 2) || !SDL_strncasecmp(argv[i], "-?", 2)) { usage(argv); exit(0); } if (!SDL_strncasecmp(argv[i], "-c", 2)) useci = 1; else if (!SDL_strncasecmp(argv[i], "-i", 2)) interactive = 1; else if (!SDL_strncasecmp(argv[i], "-l", 2)) locolor = 1; else if (!SDL_strncasecmp(argv[i], "-m", 2)) useimm = 1; else if (!SDL_strncasecmp(argv[i], "-32", 3)) usealpha = 1; else if (!SDL_strncasecmp(argv[i], "-w", 2) && i < argc - 1) { int w = 0, h = 0; if (sscanf(argv[++i], "%dx%d", &w, &h) == 2 && w > 0 && h > 0) { width = w; height = h; printf("Window dimensions: %d x %d\n", width, height); } } else if (!SDL_strncasecmp(argv[i], "-p", 2) && i < argc - 1) { int npolys = atoi(argv[++i]); if (npolys > 0) { slices = stacks = (int)(sqrt((double)npolys / ((double)(3 * NSPHERES + 1)))); if (slices < 1) slices = stacks = 1; } } else if (!SDL_strncasecmp(argv[i], "-fs", 3)) { fullscreen = 1; } else if (!SDL_strncasecmp(argv[i], "-f", 2) && i < argc - 1) { int mf = atoi(argv[++i]); if (mf > 0) { maxframes = mf; printf("Number of frames to render: %d\n", maxframes); } } else if (!SDL_strncasecmp(argv[i], "-bt", 3) && i < argc - 1) { double temp = atof(argv[++i]); if (temp > 0.0) benchtime = temp; } else if (!SDL_strncasecmp(argv[i], "-sc", 3) && i < argc - 1) { int sc = atoi(argv[++i]); if (sc > 0) { screen = sc; printf("Rendering to screen %d\n", screen); } } else if (!SDL_strncasecmp(argv[i], "-s", 2)) { usestereo = 1; } } if (useci) { SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, usealpha ? 8 : 0); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 1); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0); } else { SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, usealpha ? 8 : 0); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 1); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_STEREO, usestereo); } // Initialize SDL for video output. if (SDL_Init(SDL_INIT_VIDEO) < 0) _throw("Unable to initialize SDL"); // Create our OpenGL window. window = SDL_CreateWindow("vogltest", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE); if (!window) _throw("Unable to create OpenGL window"); ctx = SDL_GL_CreateContext(window); if (!ctx) _throw("Unable to create OpenGL context"); SDL_VERSION(&info.version); if (SDL_GetWindowWMInfo(window, &info) == SDL_TRUE) { const char *subsystem = "Unknown system"; switch(info.subsystem) { case SDL_SYSWM_UNKNOWN: break; case SDL_SYSWM_WINDOWS: subsystem = "Microsoft Windows(TM)"; break; case SDL_SYSWM_X11: subsystem = "X Window System"; break; case SDL_SYSWM_DIRECTFB: subsystem = "DirectFB"; break; case SDL_SYSWM_COCOA: subsystem = "Apple OS X"; break; case SDL_SYSWM_UIKIT: subsystem = "UIKit"; break; case SDL_SYSWM_WAYLAND: subsystem = "Wayland"; break; } printf("Running SDL version %d.%d.%d on '%s'\n", (int)info.version.major, (int)info.version.minor, (int)info.version.patch, subsystem); if (useci) { #ifdef __linux__ int n; XVisualInfo vinfo_template; XVisualInfo *vinfo; memset(&vinfo_template, 0, sizeof(vinfo_template)); vinfo_template.colormap_size = 256; vinfo = XGetVisualInfo(info.info.x11.display, VisualColormapSizeMask, &vinfo_template, &n); if (vinfo && (n > 0)) { ncolors = np2(vinfo->colormap_size); } #else // TODO: Just assume 256 for Windows? ncolors = 256; #endif if (ncolors < 32) _throw("Color map is not large enough"); _catch(setcolorscheme(window, ncolors, colorscheme)); } } fprintf(stderr, "Polygons in scene: %d\n", (NSPHERES * 3 + 1) * slices * stacks); if (fullscreen) { go_fullscreen(window, screen); } ret = event_loop(window); bailout: SDL_Quit(); return ret; }
int main(int argc,char *argv[]) { srand((unsigned)time(NULL)); int n,m; /* * make 2^n optimal vantage points set * vector<Gene> twoPowOptimalPoints */ makeTwoPowOptimalPoints(); #ifdef DEBUG for ( int i = 0 ; i < MAX_DIMENSION_POW ; i++ ) { puts(""); for ( int j = 0 ; j < twoPowOptimalPoints[i].m ; j++ ) { for ( int k = 0 ; k < twoPowOptimalPoints[i].n ; k++ ) printf("%d ",twoPowOptimalPoints[i].g[j][k]); puts(""); } } #endif for ( int tot = 11 ; tot <= 35; tot+= 1 ) { /* system("rm graph/g*.max"); system("rm graph/g*.out"); system("rm graph/g*"); */ n = m = tot; // scanf("%d %d",&n,&m); /* * make genes * vector<Gene> genes; */ vector<Gene> genes; for ( int i = 0 ; i < INIT_SIZE ; i++ ) genes.push_back(initializingGene(n,m,i)); #ifdef DEBUG for ( int i = 0 ; i < INIT_SIZE ; i++ ) genes[i].printGene(stdout); #endif for ( int generation = 1 ; generation <= MAX_GENERATION ; generation++ ) { printf("current generation : %d\n",generation); /* * print now generation information */ char *filename; FILE *fp; bool printOption = ( !(generation%50) ); // bool printOption = true; // bool printOption = ( !(generation%1000) || (1 <= generation && generation <= 10) || generation == MAX_GENERATION); if ( printOption ) { filename = (char*)malloc(sizeof(char)*222); sprintf(filename,"result/g_%d_%d.vp",n,generation); fp = fopen(filename,"w"); fprintf(fp,"now generation = %d tot f = %lf\n",generation,calculateNowGenesF(genes)); for ( int i = 0 ; i < genes.size() ; i++ ) genes[i].printGene(fp); fclose(fp); sprintf(filename,"result/g_%d_%d.result",n,generation); fp = fopen(filename,"w"); fprintf(fp,"now generation = %d tot f = %lf\n",generation,calculateNowGenesF(genes)); } /* * min heap based on ff */ priority_queue<Gene,vector<Gene>,greater<Gene> > pq; for ( int i = 0 ; i < genes.size() ; i++ ) { Gene now(genes[i].n,genes[i].m); for ( int j = 0 ; j < genes[i].m ; j++ ) for ( int k = 0 ; k < genes[i].n ; k++ ) now.g[j][k] = genes[i].g[j][k]; pq.push(now); } genes.clear(); if ( printOption ) { fprintf(fp,"min f = %lf\n",f(pq.top().g,pq.top().n,pq.top().m)); fclose(fp); free(filename); } for ( int i = 0 ; i < INIT_SIZE*DOMINANCE_SIZE ; i++ ) { Gene now = pq.top();pq.pop(); Gene insertGene(now.n,now.m); for ( int j = 0 ; j < now.m ; j++ ) for ( int k = 0 ; k < now.n ; k++ ) insertGene.g[j][k] = now.g[j][k]; genes.push_back(insertGene); } while ( !pq.empty() ) { if ( (int)pq.size() == 1 ) { Gene tp1 = pq.top();pq.pop(); Gene p1(tp1.n,tp1.m); for ( int i = 0 ; i < tp1.m; i++ ) for ( int j = 0 ; j < tp1.n ; j++ ) p1.g[i][j] = tp1.g[i][j]; genes.push_back(p1); continue; } Gene tp1 = pq.top();pq.pop(); Gene tp2 = pq.top();pq.pop(); Gene p1(tp1.n,tp1.m); Gene p2(tp2.n,tp2.m); for ( int i = 0 ; i < tp1.m ; i++ ) for ( int j = 0 ; j < tp1.n ; j++ ) p1.g[i][j] = tp1.g[i][j]; for ( int i = 0 ; i < tp2.m ; i++ ) for ( int j = 0 ; j < tp2.n ; j++ ) p2.g[i][j] = tp2.g[i][j]; vector<Gene> nextGenes; nextGenes.push_back(Gene(p1.n,p1.m)); nextGenes.push_back(Gene(p2.n,p2.m)); int pos[2]={}; Gene np1(p1.n,p1.m); Gene np2(p2.n,p2.m); int t_pos[2]={}; for ( int i = 0 ; i < p1.m ; i++ ) { if ( isSameVantagePointsInGene(p1,p2,i) ) { for ( int j = 0 ; j < p1.n ; j++ ) nextGenes[0].g[pos[0]][j] = p1.g[i][j]; pos[0]++; } else { for ( int j = 0 ; j < p1.n; j++ ) np1.g[t_pos[0]][j] = p1.g[i][j]; t_pos[0]++; } } np1.m = t_pos[0]; for ( int i = 0 ; i < p2.m ; i++ ) { if ( isSameVantagePointsInGene(p2,p1,i) ) { for ( int j = 0 ; j < p2.n ; j++ ) nextGenes[1].g[pos[1]][j] = p2.g[i][j]; pos[1]++; } else { for ( int j = 0 ; j < p2.n ; j++ ) np2.g[t_pos[1]][j] = p2.g[i][j]; t_pos[1]++; } } np2.m = t_pos[1]; vector<Graph> g1,g2; g1 = makeGraph(np1); vector<vector<int> > V1,V2; V1 = maxCut(generation,np1.m,g1); for ( int i = 0 ; i < V1[0].size() ; i++ ) { for ( int j = 0 ; j < np1.n ; j++ ) nextGenes[0].g[pos[0]][j] = np1.g[V1[0][i]][j]; pos[0]++; } for ( int i = 0 ; i < V1[1].size() ; i++ ) { for ( int j = 0 ; j < np2.n ; j++ ) nextGenes[1].g[pos[1]][j] = np1.g[V1[1][i]][j]; pos[1]++; } g2 = makeGraph(np2); V2 = maxCut(generation,np2.m,g2); for ( int i = 0 ; i < V2[0].size() ; i++ ) { for ( int j = 0 ; j < np2.n ; j++ ) nextGenes[0].g[pos[0]][j] = np2.g[V2[0][i]][j]; pos[0]++; } Gene now(np2.n,V2[1].size()); for ( int i = 0 ; i < V2[1].size() ; i++ ) { for ( int j = 0 ; j < np2.n; j++ ) now.g[i][j] = np2.g[V2[1][i]][j]; } if ( pos[0] == m ) { for ( int i = 0 ; i < now.m ; i++ ) { for ( int j = 0 ; j < now.n ; j++ ) nextGenes[1].g[pos[1]][j] = now.g[i][j]; pos[1]++; } } while ( pos[0] < m ) { vector<Graph> ng = makeGraph(now); vector<vector<int> > nV; nV = maxCut(generation,now.m,ng); for ( int i = 0 ; i < nV[0].size() ; i++ ) { if ( pos[0] < m ) { for ( int j = 0 ; j < now.n ; j++ ) nextGenes[0].g[pos[0]][j] = now.g[nV[0][i]][j]; pos[0]++; } else { nV[1].push_back(nV[0][i]); } } if ( pos[0] == m ) { for ( int i = 0 ; i < nV[1].size() ; i++ ) { for ( int j = 0 ; j < now.n ; j++ ) nextGenes[1].g[pos[1]][j] = now.g[nV[1][i]][j]; pos[1]++; } break; } else { Gene next(now.n,nV[1].size()); int nPos = 0; for ( int i = 0 ; i < nV[1].size() ; i++ ) { for ( int j = 0 ; j < now.n ; j++ ) next.g[nPos][j] = now.g[nV[1][i]][j]; nPos++; } now.m = nV[1].size(); for ( int i = 0 ; i < next.m ; i++ ) for ( int j = 0 ; j < now.n ; j++ ) now.g[i][j] = next.g[i][j]; } } if ( f(nextGenes[0].g,nextGenes[0].n,nextGenes[0].m) <= f(nextGenes[1].g,nextGenes[1].n,nextGenes[1].m) ) { genes.push_back(nextGenes[0]); pq.push(nextGenes[1]); } else { genes.push_back(nextGenes[1]); pq.push(nextGenes[0]); } g1.clear(); g2.clear(); for ( int i = 0 ; i < V1.size() ; i++ ) V1[i].clear(); V1.clear(); for ( int i = 0 ; i < V2.size() ; i++ ) V2[i].clear(); V2.clear(); } mutation(genes); } } return 0; }
static void tst3() { enable_trace("nlsat_interval"); unsynch_mpq_manager qm; anum_manager am(qm); small_object_allocator allocator; nlsat::interval_set_manager ism(am, allocator); scoped_anum sqrt2(am), m_sqrt2(am), two(am), m_two(am), three(am), one(am), zero(am); am.set(two, 2); am.set(m_two, -2); am.set(one, 1); am.root(two, 2, sqrt2); am.set(m_sqrt2, sqrt2); am.neg(m_sqrt2); am.set(three, 3); nlsat::literal p1(1, false); nlsat::literal p2(2, false); nlsat::literal p3(3, false); nlsat::literal p4(4, false); nlsat::literal np2(2, true); nlsat::interval_set_ref s1(ism), s2(ism), s3(ism), s4(ism); s1 = ism.mk_empty(); std::cout << "s1: " << s1 << "\n"; s2 = ism.mk(true, true, zero, false, false, sqrt2, np2); std::cout << "s2: " << s2 << "\n"; s3 = ism.mk(false, false, zero, false, false, two, p1); std::cout << "s3: " << s3 << "\n"; s4 = ism.mk_union(s2, s3); std::cout << "s4: " << s4 << "\n"; // Case // s1: [ ... ] // s2: [ ... ] s1 = ism.mk(false, false, zero, false, false, two, p1); s2 = ism.mk(false, false, zero, false, false, two, p2); tst_interval(s1, s2, 1); // Case // s1: [ ... ] // s2: [ ... ] s1 = ism.mk(false, false, zero, false, false, two, p1); s2 = ism.mk(false, false, m_sqrt2, false, false, one, p2); s3 = ism.mk_union(s1, s2); tst_interval(s1, s2, 2); // Case // s1: [ ... ] // s2: [ ... ] s1 = ism.mk(false, false, m_sqrt2, false, false, one, p1); s2 = ism.mk(false, false, zero, false, false, two, p2); tst_interval(s1, s2, 2); // Case // s1: [ ... ] // s2: [ ... ] s1 = ism.mk(false, false, m_sqrt2, false, false, one, p1); s2 = ism.mk(false, false, two, false, false, three, p2); tst_interval(s1, s2, 2); // Case // s1: [ ... ] // s2: [ ... ] s1 = ism.mk(false, false, m_sqrt2, false, false, three, p1); s2 = ism.mk(false, false, zero, false, false, two, p2); tst_interval(s1, s2, 1); // Case // s1: [ ... ] // s2: [ ... ] [ ... ] s1 = ism.mk(false, false, m_two, false, false, two, p1); s2 = ism.mk(false, false, m_sqrt2, false, false, zero, p2); s3 = ism.mk(false, false, one, false, false, three, p2); s2 = ism.mk_union(s2, s3); tst_interval(s1, s2, 2); // Case // s1: [ ... ] // s2: [ ... ] s1 = ism.mk(false, false, m_two, false, false, two, p1); s2 = ism.mk(false, false, two, false, false, three, p2); tst_interval(s1, s2, 2); s2 = ism.mk(true, false, two, false, false, three, p2); tst_interval(s1, s2, 2); s2 = ism.mk(true, false, two, false, false, three, p1); tst_interval(s1, s2, 1); s1 = ism.mk(false, false, m_two, true, false, two, p1); tst_interval(s1, s2, 2); s1 = ism.mk(false, false, two, false, false, two, p1); s2 = ism.mk(false, false, two, false, false, three, p2); tst_interval(s1, s2, 1); // Case // s1: [ ... ] [ ... ] // s2: [ .. ] [ ... ] [ ... ] s1 = ism.mk(false, false, m_two, false, false, zero, p1); s3 = ism.mk(false, false, one, false, false, three, p1); s1 = ism.mk_union(s1, s3); s2 = ism.mk(true, true, zero, false, false, m_sqrt2, p2); tst_interval(s1, s2, 3); s3 = ism.mk(false, false, one, false, false, sqrt2, p2); s2 = ism.mk_union(s2, s3); s3 = ism.mk(false, false, two, true, true, zero, p2); s2 = ism.mk_union(s2, s3); tst_interval(s1, s2, 4); // Case s1 = ism.mk(true, true, zero, false, false, one, p1); s2 = ism.mk(true, false, one, true, true, zero, p2); tst_interval(s1, s2, 2); s2 = ism.mk(true, false, one, false, false, two, p2); s3 = ism.mk(false, false, two, true, true, zero, p1); s2 = ism.mk_union(s2, s3); tst_interval(s1, s2, 3); }
void LanLinkProvider::connected() { qCDebug(KDECONNECT_CORE) << "Socket connected"; QSslSocket* socket = qobject_cast<QSslSocket*>(sender()); if (!socket) return; disconnect(socket, SIGNAL(connected()), this, SLOT(connected())); disconnect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(connectError())); configureSocket(socket); // If socket disconnects due to any reason after connection, link on ssl faliure connect(socket, SIGNAL(disconnected()), socket, SLOT(deleteLater())); NetworkPackage* receivedPackage = receivedIdentityPackages[socket].np; const QString& deviceId = receivedPackage->get<QString>("deviceId"); //qCDebug(KDECONNECT_CORE) << "Connected" << socket->isWritable(); // If network is on ssl, do not believe when they are connected, believe when handshake is completed NetworkPackage np2(""); NetworkPackage::createIdentityPackage(&np2); socket->write(np2.serialize()); bool success = socket->waitForBytesWritten(); if (success) { qCDebug(KDECONNECT_CORE) << "Handshaking done (i'm the existing device)"; // if ssl supported if (receivedPackage->get<int>("protocolVersion") >= NetworkPackage::ProtocolVersion) { // since I support ssl and remote device support ssl socket->setPeerVerifyName(deviceId); QString certString = KdeConnectConfig::instance()->getDeviceProperty(deviceId, "certificate", QString()); if (!certString.isEmpty()) { qCDebug(KDECONNECT_CORE) << "Device trusted"; socket->addCaCertificate(QSslCertificate(certString.toLatin1())); socket->setPeerVerifyMode(QSslSocket::VerifyPeer); connect(socket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslErrors(QList<QSslError>))); } else { qCDebug(KDECONNECT_CORE) << "Device untrusted"; // Do not care about ssl errors here, socket will not be closed due to errors because of query peer socket->setPeerVerifyMode(QSslSocket::QueryPeer); connect(socket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslErrorsLogButIgnore(QList<QSslError>))); } qCDebug(KDECONNECT_CORE) << "Starting server ssl (I'm the client TCP socket)"; connect(socket, SIGNAL(encrypted()), this, SLOT(encrypted())); socket->startServerEncryption(); return; // Return statement prevents from deleting received package, needed in slot "encrypted" } else { qWarning() << "Incompatible protocol version, this won't work"; //addLink(deviceId, socket, receivedPackage, LanDeviceLink::Remotely); } } else { //I think this will never happen, but if it happens the deviceLink //(or the socket that is now inside it) might not be valid. Delete them. qCDebug(KDECONNECT_CORE) << "Fallback (2), try reverse connection (send udp packet)"; mUdpSocket.writeDatagram(np2.serialize(), receivedIdentityPackages[socket].sender, port); } delete receivedIdentityPackages.take(socket).np; //We don't delete the socket because now it's owned by the LanDeviceLink }