21 #include "config/FileManagerConfig.hpp" 56 void FileManager ::CreateDirectory_cmdHandler(
const FwOpcodeType opCode,
61 bool errorIfDirExists =
true;
68 this->emitTelemetry(status);
69 this->sendCommandResponse(opCode, cmdSeq, status);
72 void FileManager ::RemoveFile_cmdHandler(
const FwOpcodeType opCode,
75 const bool ignoreErrors) {
81 if (ignoreErrors ==
true) {
90 this->emitTelemetry(status);
91 this->sendCommandResponse(opCode, cmdSeq, status);
94 void FileManager ::MoveFile_cmdHandler(
const FwOpcodeType opCode,
107 this->emitTelemetry(status);
108 this->sendCommandResponse(opCode, cmdSeq, status);
111 void FileManager ::RemoveDirectory_cmdHandler(
const FwOpcodeType opCode,
122 this->emitTelemetry(status);
123 this->sendCommandResponse(opCode, cmdSeq, status);
126 void FileManager ::AppendFile_cmdHandler(
const FwOpcodeType opCode,
142 this->emitTelemetry(status);
143 this->sendCommandResponse(opCode, cmdSeq, status);
157 this->emitTelemetry(status);
158 this->sendCommandResponse(opCode, cmdSeq, status);
161 void FileManager ::ListDirectory_cmdHandler(
const FwOpcodeType opCode,
165 if (m_listState == LISTING_IN_PROGRESS) {
185 m_listState = LISTING_IN_PROGRESS;
186 m_currentDirName = dirName;
187 m_currentOpCode = opCode;
188 m_currentCmdSeq = cmdSeq;
217 void FileManager ::GenerateDp_cmdHandler(
FwOpcodeType opCode,
224 const FileManager_GenerateDpMode& mode) {
228 if (this->m_dpState != DP_IDLE) {
242 U32 effectiveChunkSize = chunkSize;
255 status = this->m_dpFile.
size(fileSize);
257 this->m_dpFile.
close();
266 U64 effectiveEnd = endOffset;
267 if ((effectiveEnd == 0) || (effectiveEnd > static_cast<U64>(fileSize))) {
268 effectiveEnd =
static_cast<U64
>(fileSize);
271 const bool emptyFile = (fileSize == 0);
272 const bool badRange = (beginOffset >
static_cast<U64
>(fileSize)) || (!emptyFile && (beginOffset >= effectiveEnd));
274 this->m_dpFile.
close();
281 if (beginOffset > 0) {
282 status = this->m_dpFile.
seek(static_cast<FwSignedSizeType>(beginOffset), Os::File::SeekType::ABSOLUTE);
284 this->m_dpFile.
close();
286 static_cast<U32>(status));
293 this->m_dpFileSize = fileSize;
294 this->m_dpOffset = beginOffset;
295 this->m_dpEndOffset = effectiveEnd;
296 this->m_dpChunkSize = effectiveChunkSize;
297 this->m_dpChunkCount = 0;
298 this->m_dpOpCode = opCode;
299 this->m_dpCmdSeq = cmdSeq;
303 this->m_dpState = DP_IN_PROGRESS;
310 if (this->m_dpOffset >= this->m_dpEndOffset) {
312 this->finishDpGeneration();
320 this->processDpChunks(0);
324 void FileManager ::processDpChunks(U32 chunkLimit) {
328 const bool paced = (chunkLimit > 0);
330 for (U32 chunk = 0; !paced || (chunk < chunkLimit); chunk++) {
335 const FwSizeType requestedSize = (remaining < static_cast<FwSizeType>(this->m_dpChunkSize))
337 :
static_cast<FwSizeType>(this->m_dpChunkSize);
344 static_cast<U32>(status));
345 this->finishDpGeneration();
351 DpContainer container;
355 this->finishDpGeneration();
358 container.setPriority(this->m_dpPriority);
362 const FileManager_FileChunkHeader header(this->m_dpFileName, this->m_dpOffset, static_cast<U32>(readSize));
363 Fw::SerializeStatus serializeStatus = container.serializeRecord_FileChunkHeaderRecord(header);
365 serializeStatus = container.serializeRecord_FileChunkDataRecord(this->m_dpBuffer, readSize);
369 static_cast<U32>(serializeStatus));
370 this->finishDpGeneration();
376 this->m_dpOffset +=
static_cast<U64
>(readSize);
377 this->m_dpChunkCount++;
380 if (this->m_dpOffset >= this->m_dpEndOffset) {
382 this->finishDpGeneration();
388 void FileManager ::finishDpGeneration() {
389 this->m_dpFile.
close();
390 this->m_dpState = DP_IDLE;
391 this->m_dpOffset = 0;
392 this->m_dpEndOffset = 0;
393 this->m_dpFileSize = 0;
399 void FileManager ::pingIn_handler(
const FwIndexType portNum, U32 key) {
404 void FileManager ::schedIn_handler(
const FwIndexType portNum, U32 context) {
405 bool isQueued =
false;
409 bool expects_enqueue = this->m_runQueued.compare_exchange_strong(isQueued,
true);
410 if (expects_enqueue) {
415 void FileManager ::run_internalInterfaceHandler() {
417 this->m_runQueued =
false;
419 if (this->m_dpState == DP_IN_PROGRESS) {
424 if (m_listState == LISTING_IN_PROGRESS) {
432 m_currentDir.
close();
453 static_cast<Fw::StringFormatStatus::T>(formatStatus));
459 m_currentDirName, filename,
473 m_currentDir.
close();
491 ++this->commandCount;
499 void FileManager ::sendCommandResponse(
const FwOpcodeType opCode,
bool isConnected_productSendOut_OutputPort(FwIndexType portNum) const
Serialization/Deserialization operation was successful.
A request arrived while another was in progress.
void log_WARNING_HI_ListDirectoryError(const Fw::StringBase &dirName, U32 status) const
void log_ACTIVITY_HI_DirectoryListingSubdir(const Fw::StringBase &dirName, const Fw::StringBase &subdirName) const
void log_ACTIVITY_HI_CreateDirectoryStarted(const Fw::StringBase &dirName) const
static constexpr FwSizeType SIZE_OF_FileChunkDataRecord_RECORD(FwSizeType arraySize)
Record sizes.
FwIdType FwOpcodeType
The type of a command opcode.
Fw::Success::T dpGet_FileDpContainer(FwSizeType dataSize, DpContainer &container)
Status calculateCrc(U32 &crc)
calculate the CRC32 of the entire file
void log_ACTIVITY_HI_RemoveDirectorySucceeded(const Fw::StringBase &dirName) const
void log_ACTIVITY_HI_DirectoryListing(const Fw::StringBase &dirName, const Fw::StringBase &fileName, FwSizeType fileSize) const
PlatformSizeType FwSizeType
static Status moveFile(const char *sourcePath, const char *destPath)
Move a file from sourcePath to destPath.
U32 FwDpPriorityType
The type of a data product priority.
void log_ACTIVITY_HI_CalculateCrcStarted(const Fw::StringBase &fileName) const
static constexpr U32 CHUNKS_PER_RATE_TICK
void log_WARNING_HI_FileSizeError(const Fw::StringBase &fileName, U32 status) const
void run_internalInterfaceInvoke()
Internal interface base-class function for run.
FileManager(const char *const compName)
Reading a chunk from the source file.
void log_ACTIVITY_HI_GenerateDpStarted(const Fw::StringBase &fileName, U64 bytesToWrite) const
static Status removeDirectory(const char *path)
Remove a directory at the specified path.
StringTemplate< FW_FIXED_LENGTH_STRING_SIZE > String
void log_ACTIVITY_HI_FileSizeSucceeded(const Fw::StringBase &fileName, FwSizeType size) const
static Status appendFile(const char *sourcePath, const char *destPath, bool createMissingDest=false)
Append the source file to the destination file.
void log_ACTIVITY_HI_ListDirectorySucceeded(const Fw::StringBase &dirName, U32 fileCount) const
Auto-generated base for FileManager component.
Status size(FwSizeType &size_result) override
get size of currently open file
bool isConnected_productGetOut_OutputPort(FwIndexType portNum) const
void log_ACTIVITY_HI_CalculateCrcSucceeded(const Fw::StringBase &fileName, U32 crc) const
void log_ACTIVITY_HI_ListDirectoryStarted(const Fw::StringBase &dirName) const
void log_ACTIVITY_HI_MoveFileStarted(const Fw::StringBase &sourceFileName, const Fw::StringBase &destFileName) const
void log_WARNING_HI_GenerateDpInvalidRange(const Fw::StringBase &fileName, U64 beginOffset, U64 endOffset, U64 fileSize) const
void pingOut_out(FwIndexType portNum, U32 key) const
Invoke output port pingOut.
void log_ACTIVITY_HI_AppendFileSucceeded(const Fw::StringBase &source, const Fw::StringBase &target) const
SerializeStatus
forward declaration for string
void log_WARNING_HI_GenerateDpBufferFailed(const Fw::StringBase &fileName) const
void log_ACTIVITY_HI_CreateDirectorySucceeded(const Fw::StringBase &dirName) const
Os::FileInterface::Status open(const char *path, Mode mode)
open file with supplied path and mode
A catch-all for other errors. Have to look in implementation-specific code.
void log_WARNING_HI_GenerateDpFailed(const Fw::StringBase &fileName, const Svc::FileManager_GenerateDpStage &stage, U32 status) const
void log_ACTIVITY_HI_RemoveDirectoryStarted(const Fw::StringBase &dirName) const
void close() override
Close directory.
Status seek(FwSignedSizeType offset, SeekType seekType) override
seek the file pointer to the given offset
Status read(char *fileNameBuffer, FwSizeType buffSize) override
Get next filename from directory stream.
Querying the size of the source file.
static constexpr U32 GENERATE_DP_MAX_CHUNK_SIZE
void close() override
close the file, if not opened then do nothing
void cmdResponse_out(FwOpcodeType opCode, U32 cmdSeq, Fw::CmdResponse response)
Emit command response.
Directory stream has no more files.
const char * toChar() const
Convert to a C-style char*.
void log_ACTIVITY_HI_FileSizeStarted(const Fw::StringBase &fileName) const
void log_WARNING_HI_FileNameFormatError(const Fw::StringBase &fileName, const Fw::StringFormatStatus &status) const
FormatStatus format(const CHAR *formatString,...)
write formatted string to buffer
Command successfully executed.
void log_ACTIVITY_HI_GenerateDpComplete(const Fw::StringBase &fileName, U32 chunks) const
void log_ACTIVITY_HI_MoveFileSucceeded(const Fw::StringBase &sourceFileName, const Fw::StringBase &destFileName) const
static Status getFileSize(const char *path, FwSizeType &size)
Get the size of the file (in bytes) at the specified path.
static Status createDirectory(const char *path, bool errorIfAlreadyExists=false)
Create a new directory at the specified path.
static constexpr FwSizeType SIZE_OF_FileChunkHeaderRecord_RECORD
Status read(U8 *buffer, FwSizeType &size)
read data from this file into supplied buffer bounded by size
Seeking to the requested begin offset.
void log_WARNING_HI_DirectoryRemoveError(const Fw::StringBase &dirName, U32 status) const
Command had execution error.
static PathType getPathType(const char *path)
Return the type of the path (file, directory, or doesn't exist)
void log_ACTIVITY_HI_AppendFileStarted(const Fw::StringBase &source, const Fw::StringBase &target) const
Operation was successful.
void tlmWrite_Errors(U32 arg, Fw::Time _tlmTime=Fw::Time()) const
void log_ACTIVITY_HI_RemoveFileStarted(const Fw::StringBase &fileName) const
PlatformIndexType FwIndexType
Operation was successful.
void log_WARNING_HI_AppendFileFailed(const Fw::StringBase &source, const Fw::StringBase &target, U32 status) const
Status open(const char *path, OpenMode mode) override
Open or create a directory.
RateGroupDivider component implementation.
Emit all chunks in the command handler, completing immediately.
void log_WARNING_HI_CalculateCrcFailed(const Fw::StringBase &fileName, U32 status) const
Operation was successful.
static constexpr U32 FILES_PER_RATE_TICK
void log_WARNING_HI_DirectoryCreateError(const Fw::StringBase &dirName, U32 status) const
void log_ACTIVITY_HI_RemoveFileSucceeded(const Fw::StringBase &fileName) const
void log_WARNING_HI_FileMoveError(const Fw::StringBase &sourceFileName, const Fw::StringBase &destFileName, U32 status) const
void tlmWrite_CommandsExecuted(U32 arg, Fw::Time _tlmTime=Fw::Time()) const
static Status removeFile(const char *path)
Remove a file at the specified path.
Serializing a chunk into the container.
void log_WARNING_HI_FileRemoveError(const Fw::StringBase &fileName, U32 status) const
void dpSend(DpContainer &container, Fw::Time timeTag=Fw::ZERO_TIME)
Send a data product.
FormatStatus
status of string format calls