String InspectorValue::toJSONString() const { Vector<UChar> result; result.reserveCapacity(512); writeJSON(&result); return String(result.data(), result.size()); }
String InspectorValue::toJSONString() const { StringBuilder result; result.reserveCapacity(512); writeJSON(&result); return result.toString(); }
void Server::startThreads() { int connection; socklen_t sockaddrClient; int i = 0; int j = 0; //processing HTTP requests processCount = 0; int iteration = 0; while (1) { sockaddrClient = sizeof(client); connection = accept(socketServer, (struct sockaddr*) &client, &sockaddrClient); if (connection == -1) { perror("accept"); if (errno == EINTR) { cout << "Manager out" << endl; return; } exit(1); } if (processCount == TABLE_SIZE){ string json = ""; int HTTPcode = 503; writeJSON(connection, json, HTTPcode); continue; } if(iteration == 0){ struct package pack; pack.delegate = reinterpret_cast<void*>(this); pack.connection = connection; pthread_create(&childThread[i], NULL, childThreadFunctionDel, reinterpret_cast<void*>(&pack)); processCount++; } else for (j=0; j<TABLE_SIZE; j++) { printf("\nBIERZEMY NOWE\n"); if (pthread_kill(childThread[j], 0) != 0) { pthread_join(childThread[j], NULL); struct package pack; pack.delegate = reinterpret_cast<void*>(this); pack.connection = connection; pthread_create(&childThread[j], NULL, childThreadFunctionDel, reinterpret_cast<void*>(&pack)); processCount++; break; } } i++; if (i == TABLE_SIZE) { printf("\nCZYSCIMY!\n"); i=0; iteration = 1; } } }
void testWriteJSON(){ std::string buffer; NOTIFICATION_ITEM item; item.type = PROGRESSVALUE; item.value = 66; item.infomation.hwnd = 50; item.infomation.pid = 4500; memcpy(item.infomation.pname, "chrome.exe", 11); writeJSON(item, buffer); //TRACE_WIN32A("json1: %s", buffer.c_str()); }
void testSocket(){ init(); connectExpandable(); std::string buffer; NOTIFICATION_ITEM item; item.type = PROGRESSVALUE; item.value = 66; item.infomation.hwnd = 50; item.infomation.pid = 4500; memcpy(item.infomation.pname, "chrome.exe", 11); writeJSON(item, buffer); if (isConnected() && isAvailable()){ sendData(buffer); char output[1024] = { 0, }; recvData(output); TRACE_WIN32A("output: %s", output); } disconnectExpandable(); clean(); }
void AppManager::begin(size_t N, float T){ std::cout << "Simulation starting with [" << results.Nx << "x" << results.Ny << "] grid" << std::endl; results.total_sim_time = 0; size_t c = 0; while (!glfwWindowShouldClose(visualizer->getWindow()) && c < N) { /* Poll for and process events */ glfwPollEvents(); SimDetail details = simulator->simulate(); visualizer->render(); results.total_sim_time += details.sim_time; results.time = details.time; results.max_sim_time = glm::max(results.max_sim_time, (float)details.sim_time); results.min_sim_time = glm::min(results.min_sim_time, (float)details.sim_time); /* Swap front and back buffers */ glfwSwapBuffers(visualizer->getWindow()); c++; if (details.time > T) { break; } } results.average_timestep = results.total_sim_time/c; results.N = c; writeJSON(); /* Clean up everything */ quit(); }
// CommunicationCenter reads HTTP message and writes the HTTP answer to client void Server::communicationCenter(int connection) { //first read, then respond appriopiately try { string dataReceived=reading(connection); string json; int HTTPcode; if (dataReceived[0] == 'P') { // POST Document document; cout << "parsuje" << endl; parsingJSONToDocument(document, dataReceived); if (document.HasMember("addresses")) { Task task; parsingAddressesJSONToTask(document, task); cout << "CommunicationCenter, Task nr: " << task.taskNumber << endl; for (int i=0; i<task.size; i++) { cout << "ip[" << i << "]: " <<task.ip[i] << endl; Packet packet; packet.ip_address =task.ip[i]; packet.identifier = task.taskNumber; packet.iterator = i; if (i+1 == task.size) packet.isLast = true; else packet.isLast = false; queueInto->push(packet); } json = createResponseToAddressesJSON(task.taskNumber, HTTPcode); writeJSON(connection, json, HTTPcode); } else if (document.HasMember("tasks")) { list<long long int> tasksList; cout << "parsujetoTask" << endl; parsingTasksJSONToParsedData(document, tasksList); list<Result> results; cout << "tworze resulty" << endl; while (!tasksList.empty()) { cout << tasksList.front() << endl; results.push_back(dataReciver->getData(tasksList.front())); tasksList.pop_front(); } cout << "creatuje" << endl; json = createResponseToTasksJSON(results, HTTPcode); cout << "wysylam" << endl; writeJSON(connection, json, HTTPcode); cout << "wyslalem" << endl; } } else if (dataReceived[0] == 'G') { // GET writing(connection); } else { writing(connection); } } catch (string e) { if(e==string("MESSAGE TOO LARGE")) { string json = "{\"error\":\"MESSAGE TOO LARGE\"}"; writeJSON(connection,json,400); } else { string json = "{\"error\":\"WRONG JSON STRUCTURE\"}"; writeJSON(connection, json, 400); } } return; }
void Arena::generateArenaSetup(QList<QVariant> places, QList<QString> objects, QList<QString> configurations, QList<QString> rotations, QList<QString> orientations, int objectsPerPlace){ clearList(); if(objects.length() >= 0 && configurations.length() > 0 && rotations.length() > 0 && orientations.length() > 0 ){ while(0 < places.length()){ int rdmConfiguration = rand() % configurations.length(); ArenaPlace* currentPlace = new ArenaPlace(); int rdmPlace = rand() % places.length(); QMap<QString, QVariant> qPlace = places[rdmPlace].toMap(); currentPlace->setConfiguration(configurations[rdmConfiguration]); currentPlace->setPlace(qPlace["text"].toString()); currentPlace->setNavigation(qPlace["navigation"].toBool()); currentPlace->setPickUp(qPlace["pickup"].toBool()); currentPlace->setPutDown(qPlace["putdown"].toBool()); if(qPlace["putdown"].toBool()){ ++numberOfPlaceAreas_; } places.removeAt(rdmPlace); if(qPlace["pickup"].toBool()){ for( int i = 0; i < objectsPerPlace && objects.length() > 0; ++i){ int rdmObject = rand() % objects.length(); int rdmOrientation = rand() % orientations.length(); int rdmRotation = rand() % rotations.length(); ArenaObject* currentObject = new ArenaObject(); currentObject->setObject(objects[rdmObject]); objects.removeAt(rdmObject); currentObject->setOrientation(orientations[rdmOrientation]); currentObject->setRotation(rotations[rdmRotation]); currentPlace->append(currentObject); ++numberObjectsArena_; } addItem(currentPlace); } } QJsonObject arenaSpec; writeJSON(arenaSpec); qDebug() << arenaSpec; } }
void JSONValue::prettyWriteJSONInternal(StringBuilder* output, int depth) const { writeJSON(output); }