DSFileStream *DSFileStream::makeFromPath(const Common::String &path, bool writeMode) { FILE *handle = std_fopen(path.c_str(), writeMode ? "wb" : "rb"); if (handle) return new DSFileStream(handle); return 0; }
void xml_topology_generate(const char *filename, int nnodes, float min_band, float max_band, int seed ){ float band; char hostname[20]; int c = 0; int event; int node_added = 0; long_vector_t elemstack = long_vector_create(1); FILE *fp = std_fopen(filename, "w"); srand(seed); push_element(fp, XML_TOPOLOGY_TAG_CLUSTER, elemstack, -2.0, NULL); push_element(fp, XML_TOPOLOGY_TAG_SWITCH, elemstack, -2.0, NULL); while(long_vector_size(elemstack)){ event = rand() % 3; /* kinda ad-hoc */ switch(event){ case 0: /* new host */ if(c == nnodes) continue; sprintf(hostname, "NODE:%d", c ++); band = (float)rand() / RAND_MAX * (max_band - min_band) + min_band; push_element(fp, XML_TOPOLOGY_TAG_NODE, elemstack, band, hostname); node_added = 1; break; case 1: /* new switch */ if(c == nnodes) continue; band = (float)rand() / RAND_MAX * (max_band - min_band) + min_band; push_element(fp, XML_TOPOLOGY_TAG_SWITCH, elemstack, band, "SWITCH"); node_added = 0; break; case 2: /* close switch */ if(node_added == 0) continue; if(long_vector_size(elemstack) <= 2 && c < nnodes) continue; pop_element(fp, elemstack); break; } } long_vector_destroy(elemstack); }