f91feddada33260bc43a01df040a307f5461e3c5
[apps/agl-service-windowmanager-2017.git] / src / wm_config.cpp
1 /*
2  * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "../include/hmi-debug.h"
18 #include "json_helper.hpp"
19 #include "wm_config.hpp"
20
21 using std::string;
22
23 namespace wm
24 {
25
26 WMConfig::WMConfig(){}
27
28 WMConfig::~WMConfig()
29 {
30     json_object_put(j_setting_conf);
31 }
32
33 WMError WMConfig::loadConfigs()
34 {
35     WMError ret;
36     char const *pRoot = getenv("AFM_APP_INSTALL_DIR");
37     string root_path = pRoot;
38     if (root_path.length() == 0)
39     {
40         HMI_ERROR("wm", "AFM_APP_INSTALL_DIR is not defined");
41     }
42     ret = this->loadSetting(root_path);
43
44     return ret;
45 }
46
47 const string WMConfig::getConfigAspect()
48 {
49     json_object *j;
50     string ret;
51     if (!json_object_object_get_ex(this->j_setting_conf, "settings", &j))
52     {
53         ret = "aspect_fit";
54     }
55     else
56     {
57         const char* scaling = jh::getStringFromJson(j, "scaling");
58         if(scaling == nullptr)
59         {
60             ret = "aspect_fit";
61         }
62         else
63         {
64             ret = scaling;
65         }
66     }
67     return ret;
68 }
69
70 /*
71  ***** Private Functions *****
72  */
73
74 WMError WMConfig::loadSetting(const string &path)
75 {
76     string setting_path = path;
77     int iret = -1;
78     WMError ret = SUCCESS;
79
80     if (setting_path.length() != 0)
81     {
82         setting_path = path + string("/etc/setting.json");
83         iret = jh::inputJsonFilie(setting_path.c_str(), &this->j_setting_conf);
84         if (iret < 0)
85             ret = FAIL;
86     }
87
88     return ret;
89 }
90
91 } // namespace wm