void reorder_file_streams(std::vector<ArchiveWriter::FileQueueElement> &file_queue){ typedef std::pair<std::wstring, ArchiveWriter::FileQueueElement> pair_t; std::vector<pair_t> sortable; std::vector<decltype(file_queue[0].stream_id)> old_ids; for (auto &fqe : file_queue){ sortable.push_back(std::make_pair(get_extension(fqe.fso->get_name()), fqe)); old_ids.push_back(fqe.stream_id); } std::sort(sortable.begin(), sortable.end(), [](const pair_t &a, const pair_t &b){ if (extension_sort(a.first, b.first)) return true; if (extension_sort(b.first, a.first)) return false; return a.second.fso->get_size() < b.second.fso->get_size(); } ); std::sort(old_ids.begin(), old_ids.end()); file_queue.clear(); file_queue.reserve(sortable.size()); zekvok_assert(sortable.size() == old_ids.size()); for (size_t i = 0; i < sortable.size(); i++){ auto fso = sortable[i].second.fso; auto id = old_ids[i]; fso->set_stream_id(id); auto stream = fso->get_backup_stream(); zekvok_assert(stream); stream->set_unique_id(id); file_queue.push_back({ fso, id }); } }
std::shared_ptr<stream_profile_interface> software_sensor::add_video_stream(rs2_video_stream video_stream) { auto exist = (std::find_if(_profiles.begin(), _profiles.end(), [&](std::shared_ptr<stream_profile_interface> profile) { if (profile->get_unique_id() == video_stream.uid) { return true; } return false; } ) != _profiles.end()); if (exist) { LOG_WARNING("Stream unique ID already exist!"); throw rs2::error("Stream unique ID already exist!"); } auto profile = std::make_shared<video_stream_profile>( platform::stream_profile{ (uint32_t)video_stream.width, (uint32_t)video_stream.height, (uint32_t)video_stream.fps, 0 }); profile->set_dims(video_stream.width, video_stream.height); profile->set_format(video_stream.fmt); profile->set_framerate(video_stream.fps); profile->set_stream_index(video_stream.index); profile->set_stream_type(video_stream.type); profile->set_unique_id(video_stream.uid); profile->set_intrinsics([=]() {return video_stream.intrinsics; }); _profiles.push_back(profile); return profile; }
std::shared_ptr<stream_profile_interface> stream_profile_base::clone() const { auto res = std::make_shared<stream_profile_base>(get_backend_profile()); res->set_unique_id(environment::get_instance().generate_stream_id()); res->set_framerate(get_framerate()); return res; }
std::shared_ptr<stream_profile_interface> software_sensor::add_motion_stream(rs2_motion_stream motion_stream) { auto exist = (std::find_if(_profiles.begin(), _profiles.end(), [&](std::shared_ptr<stream_profile_interface> profile) { return profile->get_unique_id() == motion_stream.uid; }) != _profiles.end()); if (exist) { LOG_WARNING("Motion stream unique ID already exist!"); throw rs2::error("Stream unique ID already exist!"); } auto profile = std::make_shared<motion_stream_profile>( platform::stream_profile{ 0, 0, (uint32_t)motion_stream.fps, 0 }); profile->set_format(motion_stream.fmt); profile->set_framerate(motion_stream.fps); profile->set_stream_index(motion_stream.index); profile->set_stream_type(motion_stream.type); profile->set_unique_id(motion_stream.uid); profile->set_intrinsics([=]() {return motion_stream.intrinsics; }); _profiles.push_back(profile); return profile; }
std::shared_ptr<BackupStream> BackupSystem::check_and_maybe_add(FileSystemObject &fso, known_guids_t &known_guids){ std::shared_ptr<BackupStream> ret; if (!this->should_be_added(fso, known_guids)){ this->fix_up_stream_reference(fso, known_guids); return ret; } auto &filish = static_cast<FilishFso &>(fso); auto existing_version = invalid_version_number; if (filish.get_backup_mode() == BackupMode::Full && !this->file_has_changed(existing_version, filish)) filish.set_backup_mode(BackupMode::Unmodified); switch (filish.get_backup_mode()){ case BackupMode::Unmodified: { auto temp = make_unique(new UnmodifiedStream); temp->set_unique_id(filish.get_stream_id()); temp->set_containing_version(existing_version); temp->set_virtual_size(filish.get_size()); ret = std::move(temp); } ret->add_file_system_object(&filish); break; case BackupMode::ForceFull: case BackupMode::Full: { auto temp = make_unique(new FullStream); temp->set_unique_id(filish.get_stream_id()); temp->set_physical_size(filish.get_size()); temp->set_virtual_size(filish.get_size()); ret = std::move(temp); } ret->add_file_system_object(&filish); break; case BackupMode::Rsync: throw NotImplementedException(); default: throw InvalidSwitchVariableException(); } zekvok_assert(!!ret); auto &guid = filish.get_file_system_guid(); if (guid.valid) known_guids[guid.data] = ret; return ret; }
std::shared_ptr<BackupStream> BackupSystem::generate_initial_stream(FileSystemObject &fso, known_guids_t &known_guids){ if (!this->should_be_added(fso, known_guids)){ this->fix_up_stream_reference(fso, known_guids); return std::shared_ptr<BackupStream>(); } auto &filish = static_cast<FilishFso &>(fso); auto ret = make_shared(new FullStream); ret->set_unique_id(filish.get_stream_id()); ret->set_physical_size(filish.get_size()); ret->set_virtual_size(filish.get_size()); if (filish.get_file_system_guid().valid) known_guids[filish.get_file_system_guid().data] = ret; ret->add_file_system_object(&filish); return ret; }
BackupSystem::stream_dict_t BackupSystem::generate_streams(generate_archive_fp generator){ known_guids_t known_guids; stream_dict_t stream_dict; for (stream_index_t i = 0; i < this->base_objects.size(); i++){ auto fso = this->base_objects[i]; std::vector<std::shared_ptr<BackupStream>> streams; for (auto &child : fso->get_iterator()){ auto stream = (this->*generator)(*child, known_guids); if (!stream || !stream->has_data()) continue; child->set_unique_ids(*this); stream->set_unique_id(child->get_stream_id()); streams.push_back(stream); this->streams.push_back(stream); } stream_dict[i] = std::move(streams); } return stream_dict; }