boost::shared_ptr<StorageMapping> resolve_storagemapping_info(FileMapping const& fm) { boost::shared_ptr<StorageMapping> result( new StorageMapping ); FileMapping::const_iterator file_it = fm.begin(); FileMapping::const_iterator const file_end = fm.end(); std::pair<boost::shared_ptr<void>, int> ret = ism::match_on_active_side(); // ++matching threads on the currently active ISM side, as ret.first increases // by one the reference counting on that ISM side; // this will not prevent the ISM from // switching over with pending matches // insisting onto the target slice, but before // starting yet another purchasing (in background), // no pending matching_threads must exist ism::ism_type const& the_ism = ism::get_ism(ism::se, ret.second /* side */); for ( ; file_it != file_end; ++file_it) { std::vector<std::string> const& sfns(file_it->second); std::vector<std::string>::const_iterator sfni = sfns.begin(); std::vector<std::string>::const_iterator const sfne = sfns.end(); for( ; sfni != sfne; ++sfni ) { std::string const name = resolve_storage_name(*sfni); if (name.empty()) { continue; } ism::ism_type::const_iterator it( the_ism.find(name) ); if (it != the_ism.end()) { boost::shared_ptr<classad::ClassAd> se_ad( boost::tuples::get<ism::ad_ptr_entry>(it->second) ); StorageInfo& info = (*result)[name]; info.links.push_back(file_it); insert_protocols(info.protocols, *se_ad); insert_ce_mount_points(info.ce_mounts, *se_ad); } } } return result; }
void Scenario::toFile(const string &fileName) const { using namespace xmlpp; using namespace Poco; // file mapping (for archives) FileMapping fileMapping; Document document; Element *root = document.create_root_node(ioConfig.rootName()); root->set_attribute("version",ioConfig.version().shortVersion()); root->set_attribute("interface",interfaceToString(uiInterface)); Element *tmp; if (ioConfig.hasMetadata()) { tmp = root->add_child("metadata"); mMetadata.toXML(*tmp); } tmp = root->add_child(ioConfig.plotName()); tPlot.toXML(ioConfig, *tmp, fileMapping); tmp = root->add_child("notes"); tmp->add_child_text(nMain.text()); tmp = root->add_child(ioConfig.propertiesName()); lProperties.toXML(ioConfig, *tmp); tmp = root->add_child("characters"); lCharacters.toXML(ioConfig, *tmp); tmp = root->add_child("history"); tHistory.toXML(ioConfig, *tmp, fileMapping); tmp = root->add_child("music"); tMusic.toXML(ioConfig, *tmp, fileMapping); tmp = root->add_child("effects"); tEffects.toXML(ioConfig, *tmp, fileMapping); // saved XML file and temporary directory (if needed) string xmlFile(fileName); File tempDir; if (ioConfig.isArchived()) { tempDir = TemporaryFile::tempName(); tempDir.createDirectory(); TemporaryFile::registerForDeletion(tempDir.path()); xmlFile = tempDir.path() + "/scenario.xml"; } document.write_to_file_formatted(xmlFile, "UTF-8"); if (ioConfig.isArchived()) { // adding files to the archive for (FileMapping::Iterator it = fileMapping.begin(); it != fileMapping.end(); it++) { File file(it.file()); // only if the file exists and is readable if (file.exists() && file.canRead()) { Path path(tempDir.path()); path.append(it.destination()); File(path.parent()).createDirectory(); file.copyTo(path.toString()); } } // compressing it FileOutputStream output(fileName.c_str()); Zip::Compress comp(output, true); comp.addRecursive(tempDir.path()); comp.close(); tempDir.remove(true); } }