2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include <agl_wakeup_order.h>
26 #include "system_service/ss_last_to_order.h"
27 #include "ss_last_to_order_local.h"
29 #include "system_service/ss_templates.h"
30 #include "ss_system_if_interfaceunifiedlog.h"
31 #define SCO_STATE_LOG(...) FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, __VA_ARGS__);
32 #define SCO_ERROR_LOG(...) FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, __VA_ARGS__);
33 #define SCO_ASSERT(x) SS_ASERT(x);
35 //************* CONFIG FILE Format ****************
36 #define ORDERNAME_MAX 64
37 #define CONTENT_NAME_MAX 128
40 char lastinfo[SS_CCAT_MAX][CONTENT_NAME_MAX];
41 char orderName[ORDERNAME_MAX];
42 }SS_LASTINFO_TO_OEDER_PACKED_t;
44 //*************************************************
48 SS_LAST_INFO_t lastinfo;
49 std::string orderName;
50 }SS_LASTINFO_TO_OEDER_t;
54 //****************************
55 // load configuration file
56 //****************************
58 loadConfig(std::string &cfgPath, std::list<SS_LASTINFO_TO_OEDER_t> *p_cfgList) throw() { // NOLINT (runtime/references)
62 std::ifstream fin(cfgPath.c_str(), std::ios::in | std::ios::binary);
64 SCO_ERROR_LOG("cfg file error %s", cfgPath.c_str());
65 throw std::domain_error("open error");
69 fin.read(reinterpret_cast<char*>(&magic), sizeof(magic));
71 throw std::domain_error("read magic");
74 if (memcmp(magic, "CTOO", sizeof(magic)) != 0) {
75 throw std::domain_error("magic error");
78 uint32_t numOfElement = 0;
79 fin.read(reinterpret_cast<char*>(&numOfElement), sizeof(numOfElement));
81 throw std::domain_error("read numOfElement");
84 for (uint32_t ii = 0; ii < numOfElement; ii++) {
85 SS_LASTINFO_TO_OEDER_PACKED_t element;
86 fin.read(reinterpret_cast<char*>(&element), sizeof(element));
88 throw std::domain_error("read element");
90 SS_LASTINFO_TO_OEDER_t tmp;
91 tmp.lastinfo[SS_CCAT_F_VIDEO] = element.lastinfo[SS_CCAT_F_VIDEO];
92 tmp.lastinfo[SS_CCAT_F_SUB_VIDEO] = element.lastinfo[SS_CCAT_F_SUB_VIDEO];
93 tmp.lastinfo[SS_CCAT_F_AUDIO] = element.lastinfo[SS_CCAT_F_AUDIO];
94 tmp.lastinfo[SS_CCAT_R_VIDEO] = element.lastinfo[SS_CCAT_R_VIDEO];
95 tmp.lastinfo[SS_CCAT_R_AUDIO] = element.lastinfo[SS_CCAT_R_AUDIO];
96 tmp.orderName = element.orderName;
97 p_cfgList->push_back(tmp);
99 SCO_STATE_LOG("%s is loaded", cfgPath.c_str());
100 } catch (std::exception &e) {
101 if (ret == 0) ret = -1;
102 SCO_ERROR_LOG("%s", e.what());
115 isPassCondition(SS_CONT_CATEGORY_t cat, SS_LAST_INFO_t &lastInfo, SS_LASTINFO_TO_OEDER_t &tblElement) { // NOLINT (runtime/references)
116 std::string &tblStr = tblElement.lastinfo[cat];
118 if (tblStr != "EMPTY") {
119 //Category with content specification
120 SS_LAST_INFO_t::iterator iteCont = lastInfo.find(cat);
121 if (iteCont == lastInfo.end() || iteCont->second != tblStr) {
130 //****************************
131 // SS_ConvLastInfoToOrder
132 //****************************
133 EFrameworkunifiedStatus
134 SS_ConvLastInfoToOrder(SS_LAST_INFO_t &curInfo, std::string &order, const char* p_cfgPath/* = NULL*/) { // NOLINT (runtime/references)
135 std::string cfgPath = (p_cfgPath) ? p_cfgPath : SS_LAST_TO_ORDER_CONF_PATH;
137 static std::list<SS_LASTINFO_TO_OEDER_t> s_convList;
138 static std::string s_readCfgPath = "__default__";
141 // If the same CONFIG, do not READ after the second.
142 if (s_readCfgPath != cfgPath) {
146 ret = loadConfig(cfgPath, &s_convList);
147 if (ret != 0) { goto ERROR; }
148 s_readCfgPath = cfgPath;
151 for (std::list<SS_LASTINFO_TO_OEDER_PACKED_t>::iterator tblElt = s_convList.begin();
152 tblElt != s_convList.end();
154 SCO_STATE_LOG("FV:%s FSV:%s FA:%s RV:%s RA:%s O:%s",
155 tblElt->lastinfo[SS_CCAT_F_VIDEO], tblElt->lastinfo[SS_CCAT_F_SUB_VIDEO], tblElt->lastinfo[SS_CCAT_F_AUDIO],
156 tblElt->lastinfo[SS_CCAT_R_VIDEO], tblElt->lastinfo[SS_CCAT_R_AUDIO], tblElt->orderName);
161 for (std::list<SS_LASTINFO_TO_OEDER_t>::iterator tblElt = s_convList.begin();
162 tblElt != s_convList.end();
164 if (isPassCondition(SS_CCAT_F_VIDEO , curInfo, *tblElt) == false) {
166 } else if (isPassCondition(SS_CCAT_F_SUB_VIDEO, curInfo, *tblElt) == false) {
168 } else if (isPassCondition(SS_CCAT_F_AUDIO , curInfo, *tblElt) == false) {
170 } else if (isPassCondition(SS_CCAT_R_VIDEO , curInfo, *tblElt) == false) {
172 } else if (isPassCondition(SS_CCAT_R_AUDIO , curInfo, *tblElt) == false) {
177 order = tblElt->orderName;
183 return eFrameworkunifiedStatusOK;
185 return eFrameworkunifiedStatusFail;