// {{{ Message Management // {{{ handleMessage int handleMessage(msg_t msg) { switch (type(msg)) { case HELLO: return handleHello(msg); case HELLOREP: return handleHelloRep(msg, NULL); case RESOURCE: return handleResource(msg); case SOLUTION: return handleSolution(msg); default: if (_verbose) fprintf(stderr, "======> Uknown message type <======\n"); return -1; } }
//{{{ waitForHellorep int waitForHellorep(int waitingPeriod) { struct sockaddr_in netParamsNeighbour; time_t timeStart, timeCur; timeStart = time(&timeStart); timeCur = time(&timeCur); msg_t msg; int flags = fcntl(this_site.sdRecv, F_GETFL); int flags2 = flags | O_NONBLOCK; fcntl(this_site.sdRecv, F_SETFL, flags2); fprintf (stdout, "Expecting HELLOREP for network discover.\n"); //while((this_site.nbNeighbours < 2) || (timeCur - timeStart < waitingPeriod)) while(timeCur - timeStart < waitingPeriod) { timeCur = time(&timeCur); memset (&msg, 0, SIZE); if(recvMessage(&msg, &netParamsNeighbour) == -1) continue; switch (type(msg)) { case HELLO: handleHello(msg); break; case HELLOREP: handleHelloRep(msg, &netParamsNeighbour); break; case RESOURCE: handleResource(msg); break; default: fprintf(stderr, "======> Unknown message type <======\n"); break; } } fcntl(this_site.sdRecv, F_SETFL, flags); printf("End of network discovery : %ld sites found.\n", (long int)this_site.nbNeighbours); return 0; }
void Config::handleMessage(const QByteArray &message) { QDomDocument xml; bool ok = xml.setContent(message, true); assert(ok); /* * We don't check the namespace here. Qt seems to return empty string * (I must be doing something wrong, obviously), and this is dirty * test tool only anyway. */ const QString &name(xml.documentElement().tagName()); if (name == "hello") { handleHello(xml); return; } else if (name == "rpc-reply") { handleRpc(xml); return; } assert(false); }