Lfs ---> LfsClientLocalImp

来源:互联网 发布:橙光文字游戏制作软件 编辑:程序博客网 时间:2024/06/06 03:16
#ifndef LFS_CLIENT_LOCAL_IMP_H
#define  LFS_CLIENT_LOCAL_IMPH
#include "CommonDefine.h"
namespace lfs {
class LfsClientLocalImp
{
public:
int Initialize(const char* nsAddr = NULL);
int Close(const int fd);
int Open(const char* fileName, const int flags);
int Write(const int fd, const void* data, int64_t count);
int Read(const int fd, void* buf, const int64_t count);
int Unlink(const char* fileName);
int Fstat(const int fd, common::FileInfo& buf);
int64_t SaveFile(char* fileName, const char* localFile, const int32_t flag, const char* nsAddr = NULL);
int FetchFile(const char* localFile, const char* fileName, const char* nsAddr = NULL);
};
} // Namespace lfs
#endif

#include "LfsClientLocalImp.h"

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include  "Log.h"
namespace lfs{
int LfsClientLocalImp::Initialize(const char* nsAddr)
{
LOG_INFO("Initialized");
// Global Namespace Init --> Maybe read from Config file
return 0;
}
int LfsClientLocalImp::Close(const int fd)
{
if(fd < 0)
{
LOG_ERROR("fd error!");
return -1;
}
return ::close(fd);
}
int LfsClientLocalImp::Open(const char* fileName, const int flags)
{
if(fileName == NULL)
{
LOG_ERROR("file Name NULL");
return -1;
}
return ::open(fileName, flags);
}
int LfsClientLocalImp::Write(const int fd, const void* data, int64_t count)
{
if(fd < 0 || data == NULL || count < 0)
{
LOG_ERROR("fd error or data NULL or count < 0!");
return -1;
}
return ::write(fd, data, count);
}
int LfsClientLocalImp::Read(const int fd, void* buf, const int64_t count)
{
if(fd < 0 || buf == NULL || count < 0)
{
LOG_ERROR("fd error or data NULL or count < 0!");
return -1;
}
return ::read(fd, buf, count);
}
int LfsClientLocalImp::Unlink(const char* fileName)
{
if(fileName == NULL)
{
LOG_ERROR("fileName NULL");
return -1;
}
return unlink(fileName);
}
int LfsClientLocalImp::Fstat(const int fd, common::FileInfo& buf)
{
struct stat fst;
int ret = ::fstat(fd, &fst);
if(ret != 0 )
{
LOG_ERROR("get the file info error from OS!");
return -1;
}
buf.ID = fst.st_ino;
buf.Size = fst.st_size;
    buf.UsedSize = fst.st_blksize * fst.st_blocks;
    buf.ModifyTime = fst.st_mtime;
    buf.CreateTime = fst.st_ctime;
return 0;
}
int64_t LfsClientLocalImp::SaveFile(char* fileName, const char* localFile, const int32_t flag, const char* nsAddr)
{
LOG_INFO("Not Support, save file....");
return 0;
}
int LfsClientLocalImp::FetchFile(const char* localFile, const char* fileName, const char* nsAddr)
{
LOG_INFO("Not Support, fetch file....");
return 0;
}
}/* end namespace lfs */

原创粉丝点击