082b6d61c675d340c44c4f71841841177591bfb5
[platform/core/system/sensord.git] / src / server / device_config.cpp
1 /*
2  * sensord
3  *
4  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #include <device_config.h>
21 #include <fstream>
22 #include <string>
23
24 using std::ifstream;
25 using std::string;
26 using std::istringstream;
27
28 device_config::device_config(void)
29 {
30 }
31
32 device_config::~device_config(void)
33 {
34 }
35
36 bool device_config::get_device_id(void)
37 {
38         const string INFO_INI_PATH = "/etc/info.ini";
39         const string START_DELIMETER = "Model=";
40         const string END_DELIMETER = ";";
41         string line;
42         ifstream in_file;
43         std::size_t start_pos, end_pos;
44         bool ret = false;
45
46         in_file.open(INFO_INI_PATH);
47
48         if (!in_file.is_open())
49                 return false;
50
51         while (!in_file.eof()) {
52                 getline(in_file, line);
53                 start_pos = line.find(START_DELIMETER);
54
55                 if (start_pos == std::string::npos)
56                         continue;
57
58                 start_pos = start_pos + START_DELIMETER.size();
59                 end_pos = line.find(END_DELIMETER, start_pos);
60
61                 if (end_pos == std::string::npos)
62                         continue;
63
64                 m_device_id = line.substr(start_pos, end_pos - start_pos);
65                 ret = true;
66                 break;
67         }
68
69         in_file.close();
70
71         return ret;
72 }