root/src/CopyManager.h @ master
| 2c54c4c3 | david.sorber | /********************************************************************
|
||
* CONFIDENTIAL - All source code is the propriety and confidential *
|
||||
* information of David Sorber. *
|
||||
* *
|
||||
* Copyright 2024 David Sorber *
|
||||
* Unpublished -- all rights reserved under the copyright laws *
|
||||
* of the United States. *
|
||||
********************************************************************/
|
||||
#ifndef __COPYTOOL_COPYMANAGER_H_
|
||||
#define __COPYTOOL_COPYMANAGER_H_
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <map>
|
||||
| 6248f75f | david.sorber | #include <mutex>
|
||
| 2c54c4c3 | david.sorber | #include <string>
|
||
#include <thread>
|
||||
#include <vector>
|
||||
#include "CopyManagerOptions.h"
|
||||
#include "ProtectedQueue.h"
|
||||
namespace sfs = std::filesystem;
|
||||
namespace DBS
|
||||
{
|
||||
class CopyManager
|
||||
{
|
||||
public:
|
||||
| eee13fa3 | david.sorber | // Maximum "count" size per sendfile() documentation
|
||
static inline size_t MAX_COPY_SIZE{0x7ffff000};
|
||||
| 2c54c4c3 | david.sorber | static inline const sfs::directory_entry ENTRY_TERMINATOR{};
|
||
| 6248f75f | david.sorber | CopyManager() = delete;
|
||
| 2c54c4c3 | david.sorber | CopyManager(CopyManagerOptions& options);
|
||
~CopyManager();
|
||||
| 6248f75f | david.sorber | /**
|
||
* Execute the copy operation described by the CopyManagerOptions instance.
|
||||
* @return
|
||||
*/
|
||||
void run();
|
||||
| dbbd2afa | david.sorber | inline void terminate()
|
||
{
|
||||
// TODO: something else???
|
||||
m_terminate = true;
|
||||
}
|
||||
| 6248f75f | david.sorber | /**
|
||
* Wait for the main thread to complete. Should be called after run().
|
||||
* @return
|
||||
*/
|
||||
int waitForComplete();
|
||||
inline bool isRunning() const
|
||||
{
|
||||
return m_running;
|
||||
}
|
||||
| dbbd2afa | david.sorber | inline bool iterationError() const
|
||
{
|
||||
return m_iterationError;
|
||||
}
|
||||
| 6248f75f | david.sorber | inline uint64_t getTotalEntries()
|
||
{
|
||||
return m_totalEntries;
|
||||
}
|
||||
inline uint64_t getInvalidEntries()
|
||||
{
|
||||
return m_invalidEntries;
|
||||
}
|
||||
inline uint64_t getProcessedEntries()
|
||||
{
|
||||
return m_processedEntries;
|
||||
}
|
||||
//--- Setters -------------------------------------------------------------
|
||||
inline void incTotalEntries()
|
||||
{
|
||||
++m_totalEntries;
|
||||
}
|
||||
inline void incInvalidEntries()
|
||||
{
|
||||
++m_invalidEntries;
|
||||
}
|
||||
inline void incProcessedEntries()
|
||||
{
|
||||
++m_processedEntries;
|
||||
}
|
||||
| 2c54c4c3 | david.sorber | |||
private:
|
||||
| 6248f75f | david.sorber | /**
|
||
* Body of the main thread spawned when run() is called.
|
||||
*/
|
||||
| 2c54c4c3 | david.sorber | void mainThreadBody();
|
||
| 6248f75f | david.sorber | /**
|
||
* Body of thread that does the actual copying and creating of directories.
|
||||
*/
|
||||
| eee13fa3 | david.sorber | void copyThreadBody();
|
||
| 2c54c4c3 | david.sorber | |||
| 6248f75f | david.sorber | /**
|
||
* Body of thread that counts directory entries in the source path.
|
||||
*/
|
||||
void counterThreadBody();
|
||||
| 2c54c4c3 | david.sorber | |||
CopyManagerOptions& r_options;
|
||||
ProtectedQueue<sfs::directory_entry> m_entryQueue;
|
||||
std::atomic_bool m_terminate;
|
||||
| 6248f75f | david.sorber | std::atomic_bool m_running;
|
||
| dbbd2afa | david.sorber | std::atomic_bool m_iterationError;
|
||
| 2c54c4c3 | david.sorber | |||
std::thread* p_mainThread;
|
||||
| eee13fa3 | david.sorber | std::vector<std::thread*> m_copyThreads;
|
||
| 6248f75f | david.sorber | std::thread* p_counterThread;
|
||
std::mutex m_mutex;
|
||||
std::atomic_uint64_t m_totalEntries;
|
||||
std::atomic_uint64_t m_invalidEntries;
|
||||
std::atomic_uint64_t m_processedEntries;
|
||||
| 2c54c4c3 | david.sorber | |||
};
|
||||
} // namespace DBS
|
||||
#endif //__COPYTOOL_COPYMANAGER_H_
|