提交 5391e33d authored 作者: blu's avatar blu

big refacting of communitation architect

上级 fdcf06ff
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
using namespace std; using namespace std;
int test_last_write_time(){ int test_last_write_time()
{
fs::path p = fs::current_path() / "example.bin"; fs::path p = fs::current_path() / "example.bin";
std::ofstream(p.c_str()).put('a'); // create file std::ofstream(p.c_str()).put('a'); // create file
auto ftime = fs::last_write_time(p); auto ftime = fs::last_write_time(p);
...@@ -29,19 +30,20 @@ int test_last_write_time(){ ...@@ -29,19 +30,20 @@ int test_last_write_time(){
return 0; return 0;
} }
void ftime2ctime(fs::file_time_type ftime){ void ftime2ctime(fs::file_time_type ftime)
{
std::time_t cftime = decltype(ftime)::clock::to_time_t(ftime); std::time_t cftime = decltype(ftime)::clock::to_time_t(ftime);
std::cout << "\t\twt: " << std::asctime(std::localtime(&cftime)) << std::endl; std::cout << "\t\twt: " << std::asctime(std::localtime(&cftime)) << std::endl;
} }
vector<long> LoadVideoFiles(string path, int days, map<long, string> &ts2fileName, list<long> &tsRing, list<long> &tsNeedProc) { vector<long> LoadVideoFiles(string path, int days, map<long, string> &ts2fileName, list<long> &tsRing, list<long> &tsNeedProc)
{
vector<long> v; vector<long> v;
// get current timestamp // get current timestamp
auto now = chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count(); auto now = chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count();
try{ try {
for (const auto & entry : fs::directory_iterator(path)) for (const auto & entry : fs::directory_iterator(path)) {
{
if(entry.file_size() == 0 || !entry.is_regular_file()||entry.path().extension() != ".mp4") { if(entry.file_size() == 0 || !entry.is_regular_file()||entry.path().extension() != ".mp4") {
spdlog::warn("LoasdVideoFiles skipped {} (empty/directory/!mp4)", entry.path().c_str()); spdlog::warn("LoasdVideoFiles skipped {} (empty/directory/!mp4)", entry.path().c_str());
continue; continue;
...@@ -49,38 +51,40 @@ vector<long> LoadVideoFiles(string path, int days, map<long, string> &ts2fileNam ...@@ -49,38 +51,40 @@ vector<long> LoadVideoFiles(string path, int days, map<long, string> &ts2fileNam
auto ftime = fs::last_write_time(entry.path()); auto ftime = fs::last_write_time(entry.path());
auto ts = decltype(ftime)::clock::to_time_t(ftime); auto ts = decltype(ftime)::clock::to_time_t(ftime);
// check it was processed already // check if processed already
if(ts2fileName.count(ts) != 0) { if(ts2fileName.count(ts) != 0) {
spdlog::warn("LoasdVideoFiles multiple files with same timestamp: {}, {}(skipped), ", ts2fileName[ts], entry.path().c_str()); spdlog::warn("LoasdVideoFiles multiple files with same timestamp: {}, {}(skipped), ", ts2fileName[ts], entry.path().c_str());
continue; continue;
} }
// check it was old files // check old files
if(ts - now > days * 24 * 60 * 60) { if(ts - now > days * 24 * 60 * 60) {
spdlog::info("file {} old that {} days", entry.path().c_str(), days); spdlog::info("file {} old that {} days", entry.path().c_str(), days);
tsNeedProc.push_back(ts); tsNeedProc.push_back(ts);
} }
else{ else {
tsRing.insert(std::lower_bound(tsRing.begin(), tsRing.end(), ts), ts); tsRing.insert(std::lower_bound(tsRing.begin(), tsRing.end(), ts), ts);
} }
// add to map // add to map
ts2fileName[ts] = entry.path(); ts2fileName[ts] = entry.path();
} }
}catch(exception &e) { }
catch(exception &e) {
spdlog::error("LoasdVideoFiles exception : {}", e.what()); spdlog::error("LoasdVideoFiles exception : {}", e.what());
} }
return v; return v;
} }
int main(int argc, const char *argv[]) { int main(int argc, const char *argv[])
{
std::string path = argv[1]; std::string path = argv[1];
list<long> tsRing; list<long> tsRing;
list<long> tsProcess; list<long> tsProcess;
map<long, string> ts2fileName; map<long, string> ts2fileName;
LoadVideoFiles(path, 2, ts2fileName, tsRing, tsProcess); LoadVideoFiles(path, 2, ts2fileName, tsRing, tsProcess);
for(auto &i:tsRing) { for(auto &i:tsRing) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论