示例#1
0
void deployments_route(mg_connection* conn, const mg_request_info* request_info)
{
	mg_printf(conn, "%s", ajax_reply_start);
	mg_printf(conn, "[");

	PolypeerServer* server = PolypeerServer::getInstance();
	ServerData& data = server->getServerData();
	vector<File*>* files = data.getDeployFiles();
	vector<File*>::const_iterator it = files->begin();
	
	for (; it != files->end(); ++it) 
	{
		if ((*it)->getFileState() != F_ERROR)
		{
			FileManager* fm = (*it)->getFileManager();
			
			struct tm * timeinfo;
			time_t rawtime = (time_t)((*it)->getDate());
			char buffer[80];
			timeinfo = localtime(&rawtime);
			strftime (buffer,80,"%c",timeinfo);
			
			mg_printf(conn, "{\"id\":%i, \"name\":\"%s\", \"date\":\"%s\", \"state\":\"%s\"}"
				, fm->getIdFile()
				, (*it)->getName().c_str()
				, buffer
				, getStringFileState((*it)->getFileState()).c_str()
			);
	
			if ((it + 1) != files->end()) 
			{
				mg_printf(conn, ",");
			}
		}
		else 
		{
			mg_printf(conn, "{\"id\":%i, \"name\":\"%s\", \"state\":\"%s\"}"
				, 0
				, (*it)->getName().c_str()
				, getStringFileState((*it)->getFileState()).c_str()
			);
		}
	}
	
	mg_printf(conn, "]");
}
示例#2
0
void deployment_route(mg_connection* conn, const mg_request_info* request_info)
{
	char qid[16];
	int id;
	
	get_qsvar(request_info, "id", qid, sizeof(qid));
	
	mg_printf(conn, "%s", ajax_reply_start);	
	
	if (strcmp(qid, "undefined") == 0) 
	{
		mg_printf(conn, "{\"state\":\"error\"}");	
	} 
	else
	{
		istringstream iss(qid);
		iss >> id;
	
		PolypeerServer* server = PolypeerServer::getInstance();
		ServerData& data = server->getServerData();
		File* file = data.getFile(id);
		
		if (file == NULL)
		{
			mg_printf(conn, "{\"state\":\"error\"}");	
		}
		else
		{
			FileManager* fm = file->getFileManager();
			std::vector<std::vector<Entity*>* >* pp = file->getSortedHosts();
			
			// gestion affichage de la date de déploiement
			struct tm * timeinfo;
			time_t rawtime = (time_t)(file->getDate());
			char buffer[80];
			timeinfo = localtime(&rawtime);
			
			strftime (buffer,80,"%c",timeinfo);
			
			mg_printf(conn, "{\"id\":\"%i\", \"name\":\"%s\", \"date\":\"%s\", \"filename\":\"%s\", \"state\":\"%s\", \
				\"nbchunk\":%lu, \"chunksize\":%lu, \"size\":%lu, \"hosts\":["
				, id, file->getName().c_str(), buffer
				, fm->getFileName().c_str()
				, getStringFileState(file->getFileState()).c_str()
				, fm->getNumberChunk()
				, fm->getChunkSize(), fm->getFileSize()
			);
	
			for (vector<vector<Entity*>* >::const_iterator itZone = pp->begin(); itZone != pp->end(); ++itZone) 
			{
				for (vector<Entity*>::const_iterator it = (*itZone)->begin(); it != (*itZone)->end(); ++it)
				{
					mg_printf(conn, "{\"name\":\"%s\", \"ip\":\"%s\", \"host_state\":\"%s\", \"state\":\"%s\", \"current\":\"%i\", \"total\":\"%lu\"}"
						, (*it)->getName().c_str(), (*it)->getIP().c_str()
						, getStringHostState((*it)->getHostState()).c_str()
						, getStringHostDeployState((*it)->getDeploymentState(fm->getIdFile())->getCurrentState()).c_str()
						, (*it)->getDeploymentState(fm->getIdFile())->getCurrentIdChunk()
						, fm->getNumberChunk()
					);
			
					if ((it + 1) != (*itZone)->end()) 
					{
						mg_printf(conn, ",");
					}
				}
		
				if ((itZone + 1) != pp->end()) 
				{
					mg_printf(conn, ",");
				}
			}
	
			File::deleteSortedHost(pp); // Nécessaire, des allocations dynamiques sont faite lors du listing précédent
	
			mg_printf(conn, "]}");
		}
	}
}