void FileTransfer::Run() { std::cout << "File Transfer service started" << std::endl; while (true) { Command *cmd = DeQ(); if (cmd == 0) // termination signal break; if (cmd->Name() == "PutFile") { PutFile * pf = dynamic_cast<PutFile*>(cmd); std::string newpath = _saveDir + "\\" + pf->_fname; (void) DeleteFile(newpath.c_str()); // delete target file just in case bool status = MoveFile(pf->_path.c_str(), newpath.c_str()) ? true : false; StatusMessage * resp = new StatusMessage(status); resp->SetConn(cmd->Msg().Conn()); Dispatch(resp); } else { std::cout << "Command " << cmd->Name() << " is not known" << std::endl; } delete cmd; } std::cout << "File Transfer service stopped" << std::endl; }
void TextSearch::ProcessCompletedSearch(SearchString *ss) { if (ss->_completed != ss->_jobs) // ensure all jobs have been completed return; //std::cout << "Search Completed" << std::endl; StatusMessage * resp = new StatusMessage(true); resp->SetConn(ss->Msg().Conn()); std::chrono::milliseconds ms = std::chrono::duration_cast<std::chrono::milliseconds>(resp->CreateTime() - ss->CreateTime()); resp->AddHeader("ExecutionTime", ms.count()); while (ss->_matches.size()) { std::string *match = ss->_matches.deQ(); resp->WriteData(match->c_str(), match->size()); resp->WriteData("\n", 1); delete match; } Dispatch(resp); delete ss; }