Sleds/cppcore/component/storagenodestatus.h

145 lines
4.2 KiB
C++

// Copyright (c) 2013, IOnU Security, Inc.
// Copyright (c) 2016, Sequence Logic, Inc. All rights reserved.
/*
* Storage node status enum.
*/
#ifndef STORAGE_NODE_STATUS_HEADER
#define STORAGE_NODE_STATUS_HEADER
#include <string>
#ifdef WIN32
#ifdef SL_CPPCORE_DLLEXPORT
#define SL_CPPCORE_EXPORT __declspec(dllexport)
#else
#define SL_CPPCORE_EXPORT __declspec(dllimport)
#endif
#else
#define SL_CPPCORE_EXPORT
#endif
namespace sequencelogic
{
/*
* Keep this enumeration in sync with the name array declared in the utils class below!
*/
enum StorageNodeStatus
{
unknown, // treat this as a no-op
informational, // node is info only
pendingDownload, // queued
pendingDownloadAndOpen, // queued
downloading, // actively moving
local, // local to device, used for new or unmanaged files
localModified, // local and modified, used for new or unmanaged files
pendingUpload, // queued
uploading, // actively moving
offline, // peers/storage/cloud unavailable
online, // ... available
syncable, // syncable root
remote, // not yet locally cached (flushed)
cached, // a remote file locally cached
cachedModified, // cached and modified
not_found, // node not found
deleted, // eye file deleted by user, node can persist
// CPP ONLY
ioPending, // temporary file operation in progress on device, node not sync'able
deletedCached, // eye file deleted by user, locally and on storage guard
// ported from Java 1.2.9 2/17/15 TEB
shredded, // file exists and is shredded
// new per FxData
pendingMetadata,
pruned, // like "remote" except will not download on full sync
error,
// group/team status
joined,
removed,
rejected,
invited,
stub,
// device status
disabled,
inactive,
passreset,
// sentinel
last_stat // NOT A VALID STATUS, used to keep track of how many entries are in this enumeration
};
class SL_CPPCORE_EXPORT StorageNodeStatusUtil
{
public:
/**
* @brief Eye file dirty flag
*/
static inline bool isModified(StorageNodeStatus status)
{
return (status == cachedModified || status == localModified);
}
/**
* Only sync nodes with these statii.
* @return
*/
static inline bool isSyncableStatus (StorageNodeStatus status)
{
return (status == syncable)
|| (status == remote)
|| (status == deleted)
|| (status == not_found)
|| (status == cached)
|| (status == cachedModified)
|| (status == local)
|| (status == localModified);
}
static inline bool isRemote (StorageNodeStatus status)
{
return (status == remote || status == pruned);
}
/*
* Get a string representation for this status.
*/
static inline std::string toString (StorageNodeStatus status)
{
if ((status >= unknown) && (status < last_stat))
return STATUS_NAMES[status];
else
return STATUS_NAMES[0];
}
/**
* @brief True when file attributes can be fetched directly from host
* file system instead of from client db
*/
static inline bool useFileSystemInfo(StorageNodeStatus status)
{
return (status == local)
|| (status == localModified)
|| (status == pendingUpload)
|| (status == uploading)
|| (status == cached)
|| (status == cachedModified);
}
/*
* Get enumeration value for this status.
*/
static inline StorageNodeStatus valueOf (const std::string &status)
{
for (int i = 0; i < last_stat; ++i)
if (status == STATUS_NAMES[i])
return static_cast<StorageNodeStatus>(i);
return unknown;
}
private:
static const char STATUS_NAMES[][24];
};
};
#endif //STORAGE_NODE_STATUS_HEADER