sensor-hal: rename interface of HAL for managing it easily
[platform/adaptation/tm1/sensor-hal-tm1.git] / src / lib / cconfig.cpp
1 /*
2  * libsensord-share
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 <cconfig.h>
21 #include <fstream>
22 #include <string>
23
24 using std::ifstream;
25 using std::string;
26 using std::istringstream;
27
28 cconfig::cconfig(void)
29 {
30
31 }
32
33 cconfig::~cconfig(void)
34 {
35
36 }
37
38 bool cconfig::get_device_id(void)
39 {
40         const string INFO_INI_PATH = "/etc/info.ini";
41         const string START_DELIMETER = "Model=";
42         const string END_DELIMETER = ";";
43         string line;
44         ifstream in_file;
45         std::size_t start_pos, end_pos;
46         bool ret = false;
47
48         in_file.open(INFO_INI_PATH);
49
50         if (!in_file.is_open())
51                 return false;
52
53         while (!in_file.eof()) {
54                 getline(in_file, line);
55                 start_pos = line.find(START_DELIMETER);
56
57                 if (start_pos != std::string::npos) {
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                                 m_device_id = line.substr(start_pos, end_pos - start_pos);
63                                 ret = true;
64                                 break;
65                         }
66                 }
67         }
68
69         in_file.close();
70
71         return ret;
72 }