2 * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
4 * This program is licensed under the terms and conditions of the
5 * Apache License, version 2.0. The full text of the Apache License is at
6 * http://www.apache.org/licenses/LICENSE-2.0
20 #include "CicoAulItems.h"
21 #include "CicoAilItems.h"
23 #include "CicoSystemConfig.h"
28 * @brief AUL Items class constructor
30 CicoAulItems::CicoAulItems()
33 m_appid.clear(); // appid
35 m_category = DINITm_categoryID;
45 * @brief AUL Items class constructor
47 CicoAulItems::CicoAulItems(const char* appid, int pid, int ctgry,
48 int aulstt, const void* obj)
49 :m_appid(appid), m_pid(pid), m_category(ctgry), m_aulstt(aulstt)
51 ICO_TRA("start %s, %d, %x", appid? appid: "(NIL)", pid, obj);
53 getPidCgroupInfo(pid, m_defCgrpMem, m_defCgrpCpu);
56 if (DINITm_categoryID != m_category) {
57 CicoSystemConfig* conf = CicoSystemConfig::getInstance();
58 const CicoSCCategoryConf* objX =
59 conf->getCategoryObjbyCaategoryID(m_category);
61 m_cpucgroup = objX->rctrl;
62 ICO_DBG("categ:%d -> cgroup: %d", m_category, m_cpucgroup);
69 * @brief AUL Items class constructor
71 CicoAulItems::CicoAulItems(const CicoAulItems& s)
75 m_category = s.m_category;
76 m_cpucgroup = s.m_cpucgroup;
77 m_memcgroup = s.m_memcgroup;
79 m_CSCWptrs = s.m_CSCWptrs;
81 int sz = s.m_CSCWptrs.size();
82 for (int i = 0; i < sz; i++) {
83 m_CSCWptrs.push_back(s.m_CSCWptrs[i]);
86 m_defCgrpCpu = s.m_defCgrpCpu;
87 m_defCgrpMem = s.m_defCgrpMem;
88 m_aulstt = s.m_aulstt;
92 * @brief AUL Items class destructor
94 CicoAulItems::~CicoAulItems()
96 // ICO_TRA("CicoAulItems::~CicoAulItems");
101 * @brief window information pointer entry
102 * @param obj entry pointer
104 void CicoAulItems::enterWindow(const void* obj)
106 ICO_TRA("CicoAulItems::enterWindow %x", obj);
107 if ((NULL == obj) || (0 == obj)) {
108 ICO_TRA("CicoAulItems::enterWindow");
111 bool bingo = false; // Registered flag off
113 vector<const void*>::iterator it = m_CSCWptrs.begin();
114 vector<const void*>::iterator theEnd = m_CSCWptrs.end();
115 for(; it != theEnd; ++it) {
116 if (obj == *it) { // if Registered ?
117 bingo = true; // Registered flag on
118 break; // break of for
122 int sz = m_CSCWptrs.size();
123 for (int i = 0; i < sz; i++) {
124 if (obj == m_CSCWptrs[i]) {
126 break; // break of for
130 if (false == bingo) {
131 ICO_TRA("add window pointer");
132 m_CSCWptrs.push_back(obj);
134 ICO_TRA("CicoAulItems::enterWindow");
139 * @brief remove window information pointer
140 * @param obj remove target
142 void CicoAulItems::rmWindow(const void* obj)
144 ICO_TRA("CicoAulItems::rmWindow %x", obj);
145 vector<const void*>::iterator it = m_CSCWptrs.begin();
146 vector<const void*>::iterator theEnd = m_CSCWptrs.end();
147 for(; it != theEnd; ++it) {
149 ICO_TRA("CicoAulItems::rmWindow");
150 m_CSCWptrs.erase(it);
151 break; // break of for
154 ICO_TRA("CicoAulItems::rmWindow");
159 * @brief get cgroup data by /proc/[pid]/cgroup file
160 * @parm pid target pid number
161 * @param m store cgroup memory directory data
162 * @param c store cgroup cpu,cpuacct directory data
164 static const char* g_procPidCgroupFileFmt="/proc/%d/cgroup";
165 static const char* g_cpuWord = "cpuacct,cpu:";
166 static const char* g_memWord = "memory:";
167 bool CicoAulItems::getPidCgroupInfo(int pid, string& m, string& c)
171 sprintf(fn, g_procPidCgroupFileFmt, pid);
172 const size_t cpuWdSz = strlen(g_cpuWord);
173 const size_t memWdSz = strlen(g_memWord);
180 if (true == tmp.empty()) {
183 const char* pT = tmp.c_str();
185 for (;pS != '\0'; pS++) {
188 if (0 == strncmp(pS, g_cpuWord, cpuWdSz)) { //cpu
189 pC = pS + cpuWdSz; // get cgroup cpu directory
191 else if (0 == strncmp(pS, g_memWord, memWdSz)) { // memory
192 pM = pS + memWdSz; // get cgroup memory directory
194 break; // break of for
197 if ((0 != pC) && (0 != pM)) {
198 ICO_DBG("CicoAulItems::getPidCgroupInfo m=%s, c=%s", pM, pC);
202 break; // break of while
206 ICO_TRA("end %s", bR? "true": "false");
211 * @brief appid update
213 void CicoAulItems::update_appid()
215 if (AUL_R_OK == m_aulstt) {
218 ICO_TRA("update start %d, %s", m_aulstt, m_appid.c_str());
220 buf[0] = '\0'; // STOP CODE
221 m_aulstt = aul_app_get_appid_bypid(m_pid, buf, sizeof(buf));
222 if (AUL_R_OK == m_aulstt) {
225 ICO_TRA("update end %d, %s", m_aulstt, m_appid.c_str());
228 // vim:set expandtab ts=4 sw=4: