1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
#include "platform.hpp"
#include <FAppApp.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>
#include "tizen_string_utils.hpp"
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;
}
|