Welcome to mirror list, hosted at ThFree Co, Russian Federation.

platform_linux.cpp « platform - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4de81fe05a3a2cd8c18bb18a13c26d29157d459d (plain)
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
#include "platform.hpp"

#include "../base/logging.hpp"

#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>

//static bool GetUserWritableDir(string & outDir)
//{
//  char * path = ::getenv("HOME");
//  if (path)
//  {
//    outDir = path;
//    outDir += "/.MapsWithMe/";
//    ::mkdir(outDir.c_str(), 0755);
//    return true;
//  }
//  return false;
//}

/// @return directory where binary resides, including slash at the end
static bool GetBinaryFolder(string & outPath)
{
  char path[4096] = {0};
  if (0 < ::readlink("/proc/self/exe", path, ARRAY_SIZE(path)))
  {
    outPath = path;
    outPath.erase(outPath.find_last_of('/') + 1);
    return true;
  }
  return false;
}

Platform::Platform()
{
  // init directories
  string path;
  CHECK(GetBinaryFolder(path), ("Can't retrieve path to executable"));

  // @TODO implement correct resources and writable directories for public releases
  m_resourcesDir = path + "../../data/";
  m_writableDir = m_resourcesDir;

  LOG(LDEBUG, ("Resources directory:", m_resourcesDir));
  LOG(LDEBUG, ("Writable directory:", m_writableDir));
}

Platform::~Platform()
{
}

bool Platform::IsFileExists(string const & file) const
{
  struct stat s;
  return stat(file.c_str(), &s) == 0;
}

int Platform::CpuCores() const
{
  long numCPU = sysconf(_SC_NPROCESSORS_ONLN);
  if (numCPU >= 1)
    return static_cast<int>(numCPU);
  return 1;
}

string Platform::UniqueClientId() const
{
  return "@TODO";
}