1
0

Event system changes

This commit is contained in:
Scott E. Graves
2017-04-12 00:36:21 -05:00
parent bf7fda99a6
commit 3f26144975
4 changed files with 395 additions and 14 deletions

View File

@@ -29,6 +29,7 @@ public:
virtual SString GetSingleLineMessage() const = 0; virtual SString GetSingleLineMessage() const = 0;
virtual std::shared_ptr<CEvent> Clone() const = 0; virtual std::shared_ptr<CEvent> Clone() const = 0;
virtual SString GetEventName() const = 0; virtual SString GetEventName() const = 0;
virtual json GetEventJson() const = 0;
}; };
typedef std::shared_ptr<CEvent> CEventPtr; typedef std::shared_ptr<CEvent> CEventPtr;

View File

@@ -50,6 +50,16 @@ public:
{ {
return "SiaCurlBegin"; return "SiaCurlBegin";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "type", _type },
{ "url", _url }
};
}
}; };
class SiaCurlEnd : class SiaCurlEnd :
@@ -105,6 +115,18 @@ public:
{ {
return "SiaCurlEnd"; return "SiaCurlEnd";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "type", _type },
{ "url", _url },
{ "code", _curlCode},
{ "reason", _siaCurlError.GetReason() }
};
}
}; };
CSiaCurl::CSiaCurl() CSiaCurl::CSiaCurl()

View File

@@ -45,6 +45,16 @@ public:
{ {
return "FileAddedToQueue"; return "FileAddedToQueue";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "sia_path", _siaPath },
{ "file_path", _filePath }
};
}
}; };
class ExternallyRemovedFileDetected : class ExternallyRemovedFileDetected :
@@ -84,6 +94,16 @@ public:
{ {
return "ExternallyRemovedFileDetected"; return "ExternallyRemovedFileDetected";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "sia_path", _siaPath },
{ "file_path", _filePath }
};
}
}; };
class UploadToSiaStarted : class UploadToSiaStarted :
@@ -123,6 +143,16 @@ public:
{ {
return "UploadToSiaStarted"; return "UploadToSiaStarted";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "sia_path", _siaPath },
{ "file_path", _filePath }
};
}
}; };
class UploadToSiaComplete : class UploadToSiaComplete :
@@ -162,6 +192,16 @@ public:
{ {
return "UploadToSiaComplete"; return "UploadToSiaComplete";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "sia_path", _siaPath },
{ "file_path", _filePath }
};
}
}; };
class FileRemovedFromSia : class FileRemovedFromSia :
@@ -201,6 +241,16 @@ public:
{ {
return "FileRemovedFromSia"; return "FileRemovedFromSia";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "sia_path", _siaPath },
{ "file_path", _filePath }
};
}
}; };
class FailedToRemoveFileFromSia : class FailedToRemoveFileFromSia :
@@ -243,6 +293,17 @@ public:
{ {
return "FailedToRemoveFileFromSia"; return "FailedToRemoveFileFromSia";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "sia_path", _siaPath },
{ "file_path", _filePath },
{ "curl_error", _curlError.GetReason() }
};
}
}; };
class ModifyUploadStatusFailed : class ModifyUploadStatusFailed :
@@ -288,6 +349,18 @@ public:
{ {
return "ModifyUploadStatusFailed"; return "ModifyUploadStatusFailed";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "sia_path", _siaPath },
{ "file_path", _filePath },
{ "status", CUploadManager::UploadStatusToString(_uploadStatus) },
{ "message", _errorMsg}
};
}
}; };
class DatabaseInsertFailed : class DatabaseInsertFailed :
@@ -297,7 +370,7 @@ public:
DatabaseInsertFailed(const SString& siaPath, const SString& filePath, const SString& errorMessage) : DatabaseInsertFailed(const SString& siaPath, const SString& filePath, const SString& errorMessage) :
_siaPath(siaPath), _siaPath(siaPath),
_filePath(filePath), _filePath(filePath),
_errorMessage(errorMessage) _errorMsg(errorMessage)
{ {
} }
@@ -310,7 +383,7 @@ public:
private: private:
const SString _siaPath; const SString _siaPath;
const SString _filePath; const SString _filePath;
const SString _errorMessage; const SString _errorMsg;
public: public:
virtual SString GetSingleLineMessage() const override virtual SString GetSingleLineMessage() const override
@@ -318,18 +391,29 @@ public:
return GetEventName() + return GetEventName() +
"|SP|" + _siaPath + "|SP|" + _siaPath +
"|FP|" + _filePath + "|FP|" + _filePath +
"|MSG|" + _errorMessage; "|MSG|" + _errorMsg;
} }
virtual std::shared_ptr<CEvent> Clone() const override virtual std::shared_ptr<CEvent> Clone() const override
{ {
return std::shared_ptr<CEvent>(new DatabaseInsertFailed(_siaPath, _filePath, _errorMessage)); return std::shared_ptr<CEvent>(new DatabaseInsertFailed(_siaPath, _filePath, _errorMsg));
} }
virtual SString GetEventName() const override virtual SString GetEventName() const override
{ {
return "DatabaseInsertFailed"; return "DatabaseInsertFailed";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "sia_path", _siaPath },
{ "file_path", _filePath },
{ "message", _errorMsg }
};
}
}; };
class DatabaseDeleteFailed : class DatabaseDeleteFailed :
@@ -339,7 +423,7 @@ public:
DatabaseDeleteFailed(const SString& siaPath, const SString& filePath, const SString& errorMessage) : DatabaseDeleteFailed(const SString& siaPath, const SString& filePath, const SString& errorMessage) :
_siaPath(siaPath), _siaPath(siaPath),
_filePath(filePath), _filePath(filePath),
_errorMessage(errorMessage) _errorMsg(errorMessage)
{ {
} }
@@ -352,7 +436,7 @@ public:
private: private:
const SString _siaPath; const SString _siaPath;
const SString _filePath; const SString _filePath;
const SString _errorMessage; const SString _errorMsg;
public: public:
virtual SString GetSingleLineMessage() const override virtual SString GetSingleLineMessage() const override
@@ -360,18 +444,29 @@ public:
return GetEventName() + return GetEventName() +
"|SP|" + _siaPath + "|SP|" + _siaPath +
"|FP|" + _filePath + "|FP|" + _filePath +
"|MSG|" + _errorMessage; "|MSG|" + _errorMsg;
} }
virtual std::shared_ptr<CEvent> Clone() const override virtual std::shared_ptr<CEvent> Clone() const override
{ {
return std::shared_ptr<CEvent>(new DatabaseDeleteFailed(_siaPath, _filePath, _errorMessage)); return std::shared_ptr<CEvent>(new DatabaseDeleteFailed(_siaPath, _filePath, _errorMsg));
} }
virtual SString GetEventName() const override virtual SString GetEventName() const override
{ {
return "DatabaseDeleteFailed"; return "DatabaseDeleteFailed";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "sia_path", _siaPath },
{ "file_path", _filePath },
{ "message", _errorMsg }
};
}
}; };
class SourceFileNotFound : class SourceFileNotFound :
@@ -411,6 +506,16 @@ public:
{ {
return "SourceFileNotFound"; return "SourceFileNotFound";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "sia_path", _siaPath },
{ "file_path", _filePath }
};
}
}; };
class DatabaseExceptionOccurred : class DatabaseExceptionOccurred :
@@ -450,6 +555,16 @@ public:
{ {
return "DatabaseExceptionOccurred"; return "DatabaseExceptionOccurred";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "message", _exception.getErrorStr() },
{ "operation", _duringOperation }
};
}
}; };
#define TABLE_CREATE L"create table if not exists %s (%s);" #define TABLE_CREATE L"create table if not exists %s (%s);"

View File

@@ -75,6 +75,17 @@ private:
{ {
return "DownloadToCacheBegin"; return "DownloadToCacheBegin";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "file_path", static_cast<SString>(_openFileInfo.CacheFilePath) },
{ "sia_path", _openFileInfo.SiaPath},
{ "temp_file_path", _tempFilePath}
};
}
}; };
class DownloadToCacheEnd : class DownloadToCacheEnd :
@@ -101,7 +112,7 @@ private:
virtual SString GetSingleLineMessage() const override virtual SString GetSingleLineMessage() const override
{ {
return GetEventName() + return GetEventName() +
"|FP|" + _openFileInfo.CacheFilePath + "|FP|" + static_cast<SString>(_openFileInfo.CacheFilePath) +
"|SP|" + _openFileInfo.SiaPath + "|SP|" + _openFileInfo.SiaPath +
"|TP|" + _tempFilePath + "|TP|" + _tempFilePath +
"|RES|" + SString::FromBool(_result); "|RES|" + SString::FromBool(_result);
@@ -116,6 +127,18 @@ private:
{ {
return "DownloadToCacheEnd"; return "DownloadToCacheEnd";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "file_path", static_cast<SString>(_openFileInfo.CacheFilePath) },
{ "sia_path", _openFileInfo.SiaPath },
{ "temp_file_path", _tempFilePath },
{ "result", _result}
};
}
}; };
class MoveTempToCacheResult : class MoveTempToCacheResult :
@@ -142,7 +165,7 @@ private:
virtual SString GetSingleLineMessage() const override virtual SString GetSingleLineMessage() const override
{ {
return GetEventName() + return GetEventName() +
"|FP|" + _openFileInfo.CacheFilePath + "|FP|" + static_cast<SString>(_openFileInfo.CacheFilePath) +
"|SP|" + _openFileInfo.SiaPath + "|SP|" + _openFileInfo.SiaPath +
"|TP|" + _tempFilePath + "|TP|" + _tempFilePath +
"|RES|" + SString::FromBool(_result); "|RES|" + SString::FromBool(_result);
@@ -157,6 +180,18 @@ private:
{ {
return "MoveTempToCacheResult"; return "MoveTempToCacheResult";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "file_path", static_cast<SString>(_openFileInfo.CacheFilePath) },
{ "sia_path", _openFileInfo.SiaPath },
{ "temp_file_path", _tempFilePath },
{ "result", _result }
};
}
}; };
class AddToCacheComplete : class AddToCacheComplete :
@@ -181,7 +216,7 @@ private:
virtual SString GetSingleLineMessage() const override virtual SString GetSingleLineMessage() const override
{ {
return GetEventName() + return GetEventName() +
"|FP|" + _openFileInfo.CacheFilePath + "|FP|" + static_cast<SString>(_openFileInfo.CacheFilePath) +
"|SP|" + _openFileInfo.SiaPath + "|SP|" + _openFileInfo.SiaPath +
"|RES|" + SString::FromBool(_result); "|RES|" + SString::FromBool(_result);
} }
@@ -195,6 +230,17 @@ private:
{ {
return "AddToCacheComplete"; return "AddToCacheComplete";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "file_path", static_cast<SString>(_openFileInfo.CacheFilePath) },
{ "sia_path", _openFileInfo.SiaPath },
{ "result", _result }
};
}
}; };
class DriveMountEnded : class DriveMountEnded :
@@ -226,13 +272,23 @@ private:
{ {
return GetEventName() + return GetEventName() +
"|LOC|" + _mountLocation + "|LOC|" + _mountLocation +
"|RET|" + SString::FromInt32(_result); "|RES|" + SString::FromInt32(_result);
} }
virtual SString GetEventName() const override virtual SString GetEventName() const override
{ {
return "DriveMountEnded"; return "DriveMountEnded";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "mount_location", _mountLocation },
{ "result", _result }
};
}
}; };
class DriveUnMounted : class DriveUnMounted :
@@ -269,6 +325,15 @@ private:
{ {
return "DriveUnMounted"; return "DriveUnMounted";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "mount_location", _mountLocation }
};
}
}; };
class DriveMounted : class DriveMounted :
@@ -305,6 +370,15 @@ private:
{ {
return "DriveMounted"; return "DriveMounted";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "mount_location", _mountLocation }
};
}
}; };
class DokanCreateFile : class DokanCreateFile :
@@ -347,13 +421,26 @@ private:
"|ATTR|" + SString::FromUInt32(_fileAttributesAndFlags) + "|ATTR|" + SString::FromUInt32(_fileAttributesAndFlags) +
"|DISP|" + SString::FromUInt32(_creationDisposition) + "|DISP|" + SString::FromUInt32(_creationDisposition) +
"|MASK|" + SString::FromUInt32(_genericDesiredAccess) + "|MASK|" + SString::FromUInt32(_genericDesiredAccess) +
"|RET|" + SString::FromUInt32(_result); "|RES|" + SString::FromUInt32(_result);
} }
virtual SString GetEventName() const override virtual SString GetEventName() const override
{ {
return "DokanCreateFile"; return "DokanCreateFile";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "file_path", _filePath },
{ "attributes", _fileAttributesAndFlags},
{ "create_disposition", _creationDisposition},
{ "access_mask", _genericDesiredAccess},
{ "result", _result }
};
}
}; };
class DokanFindFiles : class DokanFindFiles :
@@ -398,13 +485,27 @@ private:
"|QUERY|" + _siaQuery + "|QUERY|" + _siaQuery +
"|FIND|" + _findFile + "|FIND|" + _findFile +
"|FN|" + _fileName + "|FN|" + _fileName +
"|RET|" + SString::FromUInt32(_result); "|RES|" + SString::FromUInt32(_result);
} }
virtual SString GetEventName() const override virtual SString GetEventName() const override
{ {
return "DokanFindFiles"; return "DokanFindFiles";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "file_path", _cachePath },
{ "root_path", _rootPath },
{ "sia_query", _siaQuery },
{ "find", _findFile },
{ "file_name", _fileName },
{ "result", _result }
};
}
}; };
class DokanCloseFile : class DokanCloseFile :
@@ -441,6 +542,15 @@ private:
{ {
return "DokanCloseFile"; return "DokanCloseFile";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "file_path", _cachePath }
};
}
}; };
class DokanGetFileInformation : class DokanGetFileInformation :
@@ -486,6 +596,18 @@ private:
{ {
return "DokanGetFileInformation"; return "DokanGetFileInformation";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "file_path", _cachePath },
{ "file_name", _fileName },
{ "was_opened", _opened },
{ "result", _result }
};
}
}; };
class DokanReadFile : class DokanReadFile :
@@ -528,6 +650,17 @@ private:
{ {
return "DokanReadFile"; return "DokanReadFile";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "file_path", _cachePath },
{ "opened", _opened },
{ "result", _result }
};
}
}; };
class DokanWriteFile : class DokanWriteFile :
@@ -570,6 +703,17 @@ private:
{ {
return "DokanWriteFile"; return "DokanWriteFile";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "file_path", _cachePath },
{ "opened", _opened },
{ "result", _result }
};
}
}; };
class DokanSetEndOfFile : class DokanSetEndOfFile :
@@ -609,6 +753,16 @@ private:
{ {
return "DokanSetEndOfFile"; return "DokanSetEndOfFile";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "file_path", _cachePath },
{ "result", _result }
};
}
}; };
class DokanFlushFileBuffers : class DokanFlushFileBuffers :
@@ -648,6 +802,16 @@ private:
{ {
return "DokanFlushFileBuffers"; return "DokanFlushFileBuffers";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "file_path", _cachePath },
{ "result", _result }
};
}
}; };
class DokanDeleteDirectory : class DokanDeleteDirectory :
@@ -686,6 +850,16 @@ private:
{ {
return "DokanDeleteDirectory"; return "DokanDeleteDirectory";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "file_path", _cachePath },
{ "result", _result }
};
}
}; };
class DokanDeleteFileW : class DokanDeleteFileW :
@@ -725,6 +899,16 @@ private:
{ {
return "DokanDeleteFileW"; return "DokanDeleteFileW";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "file_path", _cachePath },
{ "result", _result }
};
}
}; };
class DokanSetFileAttributesW : class DokanSetFileAttributesW :
@@ -764,6 +948,16 @@ private:
{ {
return "DokanSetFileAttributesW"; return "DokanSetFileAttributesW";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "file_path", _cachePath },
{ "result", _result }
};
}
}; };
class DokanGetFileAttributesW : class DokanGetFileAttributesW :
@@ -800,6 +994,15 @@ private:
{ {
return "DokanGetFileAttributesW"; return "DokanGetFileAttributesW";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "file_path", _cachePath }
};
}
}; };
class DokanSetFileSecurityW : class DokanSetFileSecurityW :
@@ -836,6 +1039,15 @@ private:
{ {
return "DokanSetFileSecurityW"; return "DokanSetFileSecurityW";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "file_path", _cachePath }
};
}
}; };
class DokanSetFileTime : class DokanSetFileTime :
@@ -875,6 +1087,16 @@ private:
{ {
return "DokanSetFileTime"; return "DokanSetFileTime";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "file_path", _cachePath },
{ "result", _result }
};
}
}; };
class DokanSetAllocationSize : class DokanSetAllocationSize :
@@ -914,6 +1136,16 @@ private:
{ {
return "DokanSetAllocationSize"; return "DokanSetAllocationSize";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "file_path", _cachePath },
{ "result", _result }
};
}
}; };
class DokanMoveFileW : class DokanMoveFileW :
@@ -956,6 +1188,17 @@ private:
{ {
return "DokanMoveFileW"; return "DokanMoveFileW";
} }
virtual json GetEventJson() const override
{
return
{
{ "event", GetEventName() },
{ "source_path", _srcPath },
{ "dest_path", _destPath },
{ "result", _result }
};
}
}; };
private: private: