forked from organicmaps/organicmaps
[Tizen] Added file_data and platform implementation
This commit is contained in:
parent
d6340c7676
commit
6dcf2791ed
4 changed files with 210 additions and 28 deletions
|
@ -12,8 +12,11 @@
|
|||
#include "../../std/exception.hpp"
|
||||
#include "../../std/cerrno.hpp"
|
||||
|
||||
#ifdef OMIM_OS_WINDOWS
|
||||
#include <io.h>
|
||||
#ifdef OMIM_OS_TIZEN
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wignored-qualifiers"
|
||||
#include <FIo.h>
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -24,10 +27,13 @@ FileData::FileData(string const & fileName, Op op)
|
|||
: m_FileName(fileName), m_Op(op)
|
||||
{
|
||||
char const * const modes [] = {"rb", "wb", "r+b", "ab"};
|
||||
#ifdef OMIM_OS_BADA
|
||||
result error = m_File.Construct(fileName.c_str(), modes[op]);
|
||||
#ifdef OMIM_OS_TIZEN
|
||||
m_File = new Tizen::Io::File();
|
||||
result error = m_File->Construct(fileName.c_str(), modes[op]);
|
||||
if (error == E_SUCCESS)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#else
|
||||
m_File = fopen(fileName.c_str(), modes[op]);
|
||||
if (m_File)
|
||||
|
@ -51,7 +57,9 @@ FileData::FileData(string const & fileName, Op op)
|
|||
|
||||
FileData::~FileData()
|
||||
{
|
||||
#ifndef OMIM_OS_BADA
|
||||
#ifdef OMIM_OS_TIZEN
|
||||
delete m_File;
|
||||
#else
|
||||
if (m_File)
|
||||
{
|
||||
if (fclose(m_File))
|
||||
|
@ -78,9 +86,9 @@ static int64_t const INVALID_POS = -1;
|
|||
|
||||
uint64_t FileData::Size() const
|
||||
{
|
||||
#ifdef OMIM_OS_BADA
|
||||
Osp::Io::FileAttributes attr;
|
||||
result error = Osp::Io::File::GetAttributes(m_FileName.c_str(), attr);
|
||||
#ifdef OMIM_OS_TIZEN
|
||||
Tizen::Io::FileAttributes attr;
|
||||
result error = Tizen::Io::File::GetAttributes(m_FileName.c_str(), attr);
|
||||
if (IsFailed(error))
|
||||
MYTHROW(Reader::SizeException, (m_FileName, m_Op, error));
|
||||
return attr.GetFileSize();
|
||||
|
@ -106,11 +114,11 @@ uint64_t FileData::Size() const
|
|||
|
||||
void FileData::Read(uint64_t pos, void * p, size_t size)
|
||||
{
|
||||
#ifdef OMIM_OS_BADA
|
||||
result error = m_File.Seek(Osp::Io::FILESEEKPOSITION_BEGIN, pos);
|
||||
#ifdef OMIM_OS_TIZEN
|
||||
result error = m_File->Seek(Tizen::Io::FILESEEKPOSITION_BEGIN, pos);
|
||||
if (IsFailed(error))
|
||||
MYTHROW(Reader::ReadException, (error, pos));
|
||||
int const bytesRead = m_File.Read(p, size);
|
||||
int const bytesRead = m_File->Read(p, size);
|
||||
error = GetLastResult();
|
||||
if (static_cast<size_t>(bytesRead) != size || IsFailed(error))
|
||||
MYTHROW(Reader::ReadException, (m_FileName, m_Op, error, bytesRead, pos, size));
|
||||
|
@ -126,8 +134,8 @@ void FileData::Read(uint64_t pos, void * p, size_t size)
|
|||
|
||||
uint64_t FileData::Pos() const
|
||||
{
|
||||
#ifdef OMIM_OS_BADA
|
||||
int const pos = m_File.Tell();
|
||||
#ifdef OMIM_OS_TIZEN
|
||||
int const pos = m_File->Tell();
|
||||
result error = GetLastResult();
|
||||
if (IsFailed(error))
|
||||
MYTHROW(Writer::PosException, (m_FileName, m_Op, error, pos));
|
||||
|
@ -145,9 +153,9 @@ uint64_t FileData::Pos() const
|
|||
void FileData::Seek(uint64_t pos)
|
||||
{
|
||||
ASSERT_NOT_EQUAL(m_Op, OP_APPEND, (m_FileName, m_Op, pos));
|
||||
#ifdef OMIM_OS_BADA
|
||||
result error = m_File.Seek(Osp::Io::FILESEEKPOSITION_BEGIN, pos);
|
||||
if (IsFailed(error))
|
||||
#ifdef OMIM_OS_TIZEN
|
||||
result error = m_File->Seek(Tizen::Io::FILESEEKPOSITION_BEGIN, pos);
|
||||
if ( (error))
|
||||
MYTHROW(Writer::SeekException, (m_FileName, m_Op, error, pos));
|
||||
#else
|
||||
if (fseek64(m_File, pos, SEEK_SET))
|
||||
|
@ -157,8 +165,8 @@ void FileData::Seek(uint64_t pos)
|
|||
|
||||
void FileData::Write(void const * p, size_t size)
|
||||
{
|
||||
#ifdef OMIM_OS_BADA
|
||||
result error = m_File.Write(p, size);
|
||||
#ifdef OMIM_OS_TIZEN
|
||||
result error = m_File->Write(p, size);
|
||||
if (IsFailed(error))
|
||||
MYTHROW(Writer::WriteException, (m_FileName, m_Op, error, size));
|
||||
#else
|
||||
|
@ -170,8 +178,8 @@ void FileData::Write(void const * p, size_t size)
|
|||
|
||||
void FileData::Flush()
|
||||
{
|
||||
#ifdef OMIM_OS_BADA
|
||||
result error = m_File.Flush();
|
||||
#ifdef OMIM_OS_TIZEN
|
||||
result error = m_File->Flush();
|
||||
if (IsFailed(error))
|
||||
MYTHROW(Writer::WriteException, (m_FileName, m_Op, error));
|
||||
#else
|
||||
|
@ -184,8 +192,12 @@ void FileData::Truncate(uint64_t sz)
|
|||
{
|
||||
#ifdef OMIM_OS_WINDOWS
|
||||
int const res = _chsize(fileno(m_File), sz);
|
||||
#else
|
||||
#ifdef OMIM_OS_TIZEN
|
||||
result res = m_File->Truncate(sz);
|
||||
#else
|
||||
int const res = ftruncate(fileno(m_File), sz);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (res)
|
||||
|
@ -232,8 +244,8 @@ bool DeleteFileX(string const & fName)
|
|||
{
|
||||
int res;
|
||||
|
||||
#ifdef OMIM_OS_BADA
|
||||
res = IsFailed(Osp::Io::File::Remove(fName.c_str())) ? -1 : 0;
|
||||
#ifdef OMIM_OS_TIZEN
|
||||
res = IsFailed(Tizen::Io::File::Remove(fName.c_str())) ? -1 : 0;
|
||||
#else
|
||||
res = remove(fName.c_str());
|
||||
#endif
|
||||
|
@ -245,8 +257,8 @@ bool RenameFileX(string const & fOld, string const & fNew)
|
|||
{
|
||||
int res;
|
||||
|
||||
#ifdef OMIM_OS_BADA
|
||||
res = IsFailed(Osp::Io::File::Rename(fOld.c_str(), fNew.c_str())) ? -1 : 0;
|
||||
#ifdef OMIM_OS_TIZEN
|
||||
res = IsFailed(Tizen::Io::File::Move(fOld.c_str(), fNew.c_str())) ? -1 : 0;
|
||||
#else
|
||||
res = rename(fOld.c_str(), fNew.c_str());
|
||||
#endif
|
||||
|
|
|
@ -1,12 +1,21 @@
|
|||
#pragma once
|
||||
|
||||
#include "file64_api.hpp"
|
||||
|
||||
#include "../../base/base.hpp"
|
||||
|
||||
#include "../../std/string.hpp"
|
||||
|
||||
#ifdef OMIM_OS_BADA
|
||||
#include <FIoFile.h>
|
||||
#ifdef OMIM_OS_TIZEN
|
||||
|
||||
namespace Tizen
|
||||
{
|
||||
namespace Io
|
||||
{
|
||||
class File;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -35,8 +44,12 @@ public:
|
|||
string GetName() const { return m_FileName; }
|
||||
|
||||
private:
|
||||
#ifdef OMIM_OS_BADA
|
||||
Osp::Io::File m_File;
|
||||
|
||||
FileData(FileData const & other);
|
||||
FileData const & operator()(FileData const & other);
|
||||
|
||||
#ifdef OMIM_OS_TIZEN
|
||||
Tizen::Io::File * m_File;
|
||||
#else
|
||||
FILE * m_File;
|
||||
#endif
|
||||
|
|
|
@ -40,6 +40,8 @@ INCLUDEPATH += $$ROOT_DIR/3party/jansson/src
|
|||
} else:android* {
|
||||
SOURCES += platform_android.cpp \
|
||||
pthread_video_timer.cpp
|
||||
} else:tizen* {
|
||||
SOURCES += platform_tizen.cpp
|
||||
}
|
||||
|
||||
macx-*|iphone* {
|
||||
|
|
155
platform/platform_tizen.cpp
Normal file
155
platform/platform_tizen.cpp
Normal file
|
@ -0,0 +1,155 @@
|
|||
|
||||
#include "platform.hpp"
|
||||
|
||||
#include <FAppApp.h>
|
||||
#include <FBaseUtilStringUtil.h>
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wignored-qualifiers"
|
||||
#include <FIo.h>
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
#include "constants.hpp"
|
||||
#include "platform_unix_impl.hpp"
|
||||
|
||||
#include "../base/logging.hpp"
|
||||
#include "../coding/file_reader.hpp"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
string FromTizenString(Tizen::Base::String const & str_tizen)
|
||||
{
|
||||
string utf8Str;
|
||||
if (str_tizen.GetLength() == 0)
|
||||
return utf8Str;
|
||||
// str_tizen.GetPointer();
|
||||
Tizen::Base::ByteBuffer* pBuffer = Tizen::Base::Utility::StringUtil::StringToUtf8N(str_tizen);
|
||||
if (pBuffer != null)
|
||||
{
|
||||
int byteCount = pBuffer->GetLimit();
|
||||
char* chPtrBuf = new char[byteCount + 1];
|
||||
if (chPtrBuf != null) {
|
||||
pBuffer->GetArray((byte*) chPtrBuf, 0, byteCount);
|
||||
utf8Str.assign(chPtrBuf, byteCount - 1);
|
||||
delete[] chPtrBuf;
|
||||
}
|
||||
if (pBuffer != null)
|
||||
delete pBuffer;
|
||||
}
|
||||
return utf8Str;
|
||||
}
|
||||
|
||||
|
||||
/// @return directory where binary resides, including slash at the end
|
||||
static bool GetBinaryFolder(string & outPath)
|
||||
{
|
||||
Tizen::App::App * pApp = Tizen::App::App::GetInstance();
|
||||
outPath = FromTizenString(pApp->GetAppRootPath());
|
||||
return true;
|
||||
}
|
||||
|
||||
Platform::Platform()
|
||||
{
|
||||
// init directories
|
||||
string app_root;
|
||||
CHECK(GetBinaryFolder(app_root), ("Can't retrieve path to executable"));
|
||||
|
||||
|
||||
string home = app_root;
|
||||
home += "data/";
|
||||
m_settingsDir = home + ".config/";
|
||||
|
||||
Tizen::Io::Directory::Create(m_settingsDir.c_str(), true);
|
||||
|
||||
m_writableDir = home + ".local/share/";
|
||||
Tizen::Io::Directory::Create((home + ".local/").c_str(), true);
|
||||
Tizen::Io::Directory::Create(m_writableDir.c_str(), true);
|
||||
|
||||
m_resourcesDir = app_root + "res/";
|
||||
m_writableDir = home;
|
||||
|
||||
m_tmpDir = home + "tmp/";
|
||||
Tizen::Io::Directory::Create(m_tmpDir.c_str(), true);
|
||||
|
||||
LOG(LDEBUG, ("App directory:", app_root));
|
||||
LOG(LDEBUG, ("Home directory:", home));
|
||||
LOG(LDEBUG, ("Resources directory:", m_resourcesDir));
|
||||
LOG(LDEBUG, ("Writable directory:", m_writableDir));
|
||||
LOG(LDEBUG, ("Tmp directory:", m_tmpDir));
|
||||
LOG(LDEBUG, ("Settings directory:", m_settingsDir));
|
||||
LOG(LDEBUG, ("Client ID:", UniqueClientId()));
|
||||
}
|
||||
|
||||
int Platform::CpuCores() const
|
||||
{
|
||||
/// @todo
|
||||
// const long numCPU = sysconf(_SC_NPROCESSORS_ONLN);
|
||||
// if (numCPU >= 1)
|
||||
// return static_cast<int>(numCPU);
|
||||
return 1;
|
||||
}
|
||||
|
||||
string Platform::UniqueClientId() const
|
||||
{
|
||||
/// @todo
|
||||
|
||||
// string machineFile = "/var/lib/dbus/machine-id";
|
||||
// if (IsFileExistsByFullPath("/etc/machine-id"))
|
||||
// machineFile = "/etc/machine-id";
|
||||
|
||||
// if (IsFileExistsByFullPath(machineFile))
|
||||
// {
|
||||
// string content;
|
||||
// FileReader(machineFile).ReadAsString(content);
|
||||
// return content.substr(0, 32);
|
||||
// }
|
||||
// else
|
||||
return "n0dbus0n0lsb00000000000000000000";
|
||||
|
||||
}
|
||||
|
||||
void Platform::RunOnGuiThread(TFunctor const & fn)
|
||||
{
|
||||
/// @todo
|
||||
fn();
|
||||
}
|
||||
|
||||
void Platform::RunAsync(TFunctor const & fn, Priority p)
|
||||
{
|
||||
/// @todo
|
||||
fn();
|
||||
}
|
||||
|
||||
ModelReader * Platform::GetReader(string const & file, string const & searchScope) const
|
||||
{
|
||||
return new FileReader(ReadPathForFile(file, searchScope),
|
||||
READER_CHUNK_LOG_SIZE, READER_CHUNK_LOG_COUNT);
|
||||
}
|
||||
|
||||
void Platform::GetFilesByRegExp(string const & directory, string const & regexp, FilesList & res)
|
||||
{
|
||||
pl::EnumerateFilesByRegExp(directory, regexp, res);
|
||||
}
|
||||
|
||||
bool Platform::GetFileSizeByName(string const & fileName, uint64_t & size) const
|
||||
{
|
||||
try
|
||||
{
|
||||
return GetFileSizeByFullPath(ReadPathForFile(fileName, "wr"), size);
|
||||
}
|
||||
catch (RootException const &)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
extern Platform & GetPlatform()
|
||||
{
|
||||
static Platform platform;
|
||||
return platform;
|
||||
}
|
Loading…
Add table
Reference in a new issue