Notification launch support. (TIVI-2926/1892)
[profile/ivi/ico-uxf-homescreen.git] / lib / system-controller / CicoSCResourceManager.cpp
1 /*
2  * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
3  *
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
7  *
8  */
9
10 //==========================================================================
11 /**
12  *  @file   CicoSCResourceManager.cpp
13  *
14  *  @brief  This file implementation of CicoSCResourceManager class
15  */
16 //==========================================================================
17
18 #include <sstream>
19 using namespace std;
20
21 #include "CicoSCResourceManager.h"
22 #include "CicoLog.h"
23 #include "ico_syc_error.h"
24 #include "ico_syc_mrp_resource_private.h"
25
26 #include "ico_syc_msg_cmd_def.h"
27 #include "CicoSystemConfig.h"
28 #include "CicoConf.h"
29 #include "CicoSCCommand.h"
30 #include "CicoSCPolicyManager.h"
31 #include "CicoSCLifeCycleController.h"
32 #include "CicoAilItems.h"
33 #include "CicoSCWindow.h"
34 #include "CicoSCWindowController.h"
35 #include "CicoSCInputController.h"
36 #include "CicoSCPolicyDef.h"
37 #include "CicoSCMessage.h"
38 #include "CicoSCMessageRes.h"
39 #include "CicoSCServer.h"
40
41 struct CompDisplayResourceRequest
42 {
43     CompDisplayResourceRequest(const resource_request_t *req)
44         : m_req(req) {}
45
46     bool operator() (const resource_request_t *req)
47     {
48         if (NULL == req) {
49             return false;
50         }
51         ICO_DBG("appid=%s:%s", req->appid, m_req->appid);
52         if ((0 == strcmp(m_req->appid, req->appid)) &&
53             (m_req->pid == req->pid) &&
54             ((m_req->resid & RESID_TYPE_MASK) == (req->resid & RESID_TYPE_MASK)) &&
55             (m_req->surfaceid == req->surfaceid)) {
56             return true;
57         }
58         return false;
59     }
60
61     const resource_request_t *m_req;
62 };
63
64 struct CompSoundResourceRequest
65 {
66     CompSoundResourceRequest(const resource_request_t *req)
67         : m_req(req) {}
68
69     bool operator() (const resource_request_t *req)
70     {
71         if (NULL == req) {
72             return false;
73         }
74
75         ICO_DBG("appid=%s:%s", req->appid, m_req->appid);
76         if ((0 == strcmp(m_req->appid, req->appid)) &&
77             (m_req->pid == req->pid) &&
78             ((m_req->resid & RESID_TYPE_MASK) == (req->resid & RESID_TYPE_MASK)) &&
79             (m_req->soundid == req->soundid)) {
80             return true;
81         }
82         return false;
83     }
84
85     const resource_request_t *m_req;
86 };
87
88 struct CompInputResourceRequest
89 {
90     CompInputResourceRequest(const resource_request_t *req)
91         : m_req(req) {}
92
93     bool operator() (const resource_request_t *req)
94     {
95         if (NULL == req) {
96             return false;
97         }
98
99         ICO_DBG("appid=%s:%s", req->appid, m_req->appid);
100         if ((0 == strcmp(m_req->appid, req->appid)) &&
101             (0 == strcmp(m_req->device, req->device)) &&
102             (m_req->pid == req->pid) &&
103             ((m_req->resid & RESID_TYPE_MASK) == (req->resid & RESID_TYPE_MASK))) {
104             return true;
105         }
106         return false;
107     }
108
109     const resource_request_t *m_req;
110 };
111
112
113 CicoSCResourceManager::CicoSCResourceManager()
114     : m_policyMgr(NULL), m_winCtrl(NULL), m_inputCtrl(NULL),
115       m_animaName("Fade"), m_animaTime(400)
116 {
117     m_policyMgr = new CicoSCPolicyManager(this);
118
119     CicoSystemConfig *sysConf = CicoSystemConfig::getInstance();
120     list<resource_request_t*> l;
121
122     {
123         // initialize display current request and waiting queue
124         const vector<CicoSCDisplayConf*>& dispConfList
125             = sysConf->getDisplayConfList();
126         vector<CicoSCDisplayConf*>::const_iterator itr;
127         itr = dispConfList.begin();
128         for (; itr != dispConfList.end(); ++itr) {
129             vector<CicoSCDisplayZoneConf*>::iterator itr2;
130             itr2 = (*itr)->zoneConfList.begin();
131             for (; itr2 != (*itr)->zoneConfList.end(); ++itr2) {
132                 m_curDispResOwerReq[(*itr2)->id] = NULL;
133             }
134         }
135     }
136
137     {
138         // initialize sound current request and waiting queue
139         const vector<CicoSCSoundConf*>& soundConfList
140             = sysConf->getSoundConfList();
141         vector<CicoSCSoundConf*>::const_iterator itr;
142         itr = soundConfList.begin();
143         for (; itr != soundConfList.end(); ++itr) {
144             vector<CicoSCSoundZoneConf*>::iterator itr2;
145             itr2 = (*itr)->zoneConfList.begin();
146             for (; itr2 != (*itr)->zoneConfList.end(); ++itr2) {
147                 m_curSoundResReq[(*itr2)->id] = NULL;
148                 m_soundReqQueue[(*itr2)->id]  = l;
149             }
150         }
151     }
152
153    {
154         // initialize input current request and waiting queue
155         const vector<CicoSCInputDevConf*>& inputDevConfList
156             = sysConf->getInputDevConfList();
157         vector<CicoSCInputDevConf*>::const_iterator itr;
158         itr = inputDevConfList.begin();
159         for (; itr != inputDevConfList.end(); ++itr) {
160             vector<CicoSCSwitchConf*>::iterator itr2;
161             itr2 = (*itr)->switchConfList.begin();
162             for (; itr2 != (*itr)->switchConfList.end(); ++itr2) {
163                 m_curInputResReq[(*itr2)->id] = NULL;
164                 m_inputReqQueue[(*itr2)->id]  = l;
165             }
166         }
167     }
168     m_rrtHO = (resource_request_t*)NULL;
169 }
170
171 CicoSCResourceManager::~CicoSCResourceManager()
172 {
173     delete m_policyMgr;
174 }
175
176 int
177 CicoSCResourceManager::initialize(void)
178 {
179     ICO_TRA("CicoSCResourceManager::initialize Enter");
180
181     int ret = ICO_SYC_EOK;
182
183     ret = ico_syc_mrp_init(enforceSound, this);
184     if (ICO_SYC_EOK != ret) {
185         ICO_TRA("CicoSCResourceManager::initialize Leave");
186         return ret;
187     }
188
189     ret = m_policyMgr->initialize();
190     if (ICO_SYC_EOK != ret) {
191         ICO_TRA("CicoSCResourceManager::initialize Leave");
192         return ret;
193     }
194
195
196     ICO_TRA("CicoSCResourceManager::initialize Leave");
197     return ret;
198 }
199
200 void
201 CicoSCResourceManager::terminate(void)
202 {
203     ICO_TRA("CicoSCResourceManager::terminate Enter");
204     m_policyMgr->terminate();
205     ico_syc_mrp_term();
206     ICO_TRA("CicoSCResourceManager::terminate Leave");
207 }
208
209 void
210 CicoSCResourceManager::handleCommand(const CicoSCCommand &cmd,
211                                      bool internal)
212 {
213     ICO_TRA("CicoSCResourceManager::handleCommand Enter"
214             "(cmdid=0x%08X internal=%s)",
215             cmd.cmdid, internal ? "true" : "false");
216
217     CicoSCCmdResCtrlOpt *opt = (CicoSCCmdResCtrlOpt*)cmd.opt;
218
219     // request command from application or internal
220     int reqtype = internal ? REQTYPE_AUTO : REQTYPE_APP;
221     if ((MSG_CMD_CREATE_RES == cmd.cmdid) ||
222         (MSG_CMD_ACQUIRE_RES == cmd.cmdid)) {
223
224         if (true == opt->dispres) {
225             resource_request_t *req = newResourceRequest(RESID_KIND_DISPLAY,
226                                                          reqtype,
227                                                          cmd);
228             if (MSG_CMD_CREATE_RES == cmd.cmdid) {
229                 acquireDisplayResource(req, false);
230             }
231             else {
232                 // cmdid is MSG_CMD_ACQUIRE_RES
233                 if (true == isTypeOnScreen(*req)) {
234                     acquireOnScreenDisplayResource(req);
235                 }
236                 else
237                 if ((true == m_policyMgr->getRegulation()) &&
238                     (false == isMatchDisplayed())) {
239                     updateDispResRegulationPreProc(req);
240                     updateDisplayResourceRegulation(STID_DRVREGULATION_ON);
241                 }
242                 else {
243                     acquireDisplayResource(req);
244                 }
245             }
246
247         }
248         if (true == opt->soundres) {
249             resource_request_t *req = newResourceRequest(RESID_KIND_SOUND,
250                                                          reqtype,
251                                                          cmd);
252             if ((true == m_policyMgr->getRegulation()) &&
253                 (false == isMatchDisplayed())) {
254                 updateSoundResRegulationPreProc(req);
255                 updateSoundResourceRegulation(STID_DRVREGULATION_ON);
256             }
257             else {
258                 acquireSoundResource(req);
259             }
260
261         }
262         if (true == opt->inputres) {
263             resource_request_t *req = newResourceRequest(RESID_KIND_INPUT,
264                                                          reqtype,
265                                                          cmd);
266             if ((true == m_policyMgr->getRegulation()) &&
267                 (false == isMatchDisplayed())) {
268                 updateInputResRegulationPreProc(req);
269                 updateInputResourceRegulation(STID_DRVREGULATION_ON);
270             }
271             else {
272                 acquireInputResource(req);
273             }
274         }
275     }
276     else if ((MSG_CMD_RELEASE_RES == cmd.cmdid) ||
277              (MSG_CMD_DESTORY_RES == cmd.cmdid)) {
278
279         if (true == opt->dispres) {
280             resource_request_t *req = newResourceRequest(RESID_KIND_DISPLAY,
281                                                          reqtype,
282                                                          cmd);
283             if (true == isTypeOnScreen(*req)) {
284                 releaseOnScreenDisplayResource(req);
285             }
286             else {
287                 releaseDisplayResource(req);
288             }
289         }
290         if (true == opt->soundres) {
291             resource_request_t *req = newResourceRequest(RESID_KIND_SOUND,
292                                                          reqtype,
293                                                          cmd);
294             releaseSoundResource(req);
295         }
296         if (true == opt->inputres) {
297             resource_request_t *req = newResourceRequest(RESID_KIND_INPUT,
298                                                          reqtype,
299                                                          cmd);
300             releaseInputResource(req);
301         }
302     }
303     else {
304         ICO_WRN("Unknown command");
305     }
306
307     ICO_TRA("CicoSCResourceManager::handleCommand Leave");
308 }
309
310 void
311 CicoSCResourceManager::setWindowController(CicoSCWindowController *winCtrl)
312 {
313     m_winCtrl = winCtrl;
314 }
315
316 void
317 CicoSCResourceManager::setInputController(CicoSCInputController *inputCtrl)
318 {
319     m_inputCtrl = inputCtrl;
320 }
321
322 #if 0
323 resource_request_t *
324 CicoSCResourceManager::popDispResReq(resource_request_t *req)
325 {
326     ICO_TRA("CicoSCResourceManager::popDispResReq Enter");
327
328     map<int, list<resource_request_t*> >::iterator itr;
329     itr = m_dispReqQueue.begin();
330     CompDisplayResourceRequest comp(req);
331     for (; itr != m_dispReqQueue.end(); ++itr) {
332         list<resource_request_t*>::iterator itr2;
333         itr2 = find_if(itr->second.begin(), itr->second.end(), comp);
334         if (itr->second.end() != itr2) {
335             ICO_DBG("Dequeue waiting display request queue zone=%d req=0x%08x",
336                     itr->first, *itr2);
337             m_dispReqQueue[req->dispzoneid].erase(itr2);
338             ICO_TRA("CicoSCResourceManager::popDispResReq Leave"
339                     "(0x%08x)", *itr2);
340             return *itr2;
341         }
342     }
343
344     ICO_TRA("CicoSCResourceManager::popDispResReq Leave(NULL)");
345     return NULL;
346 }
347 #endif
348
349 resource_request_t *
350 CicoSCResourceManager::popSoundResReq(resource_request_t *req)
351 {
352     ICO_TRA("CicoSCResourceManager::popSoundResReq Enter");
353
354     map<int, list<resource_request_t*> >::iterator itr;
355     itr = m_soundReqQueue.begin();
356     CompSoundResourceRequest comp(req);
357     for (; itr != m_soundReqQueue.end(); ++itr) {
358         list<resource_request_t*>::iterator itr2;
359         itr2 = find_if(itr->second.begin(), itr->second.end(), comp);
360         if (itr->second.end() != itr2) {
361             ICO_DBG("Dequeue waiting sound request queue"
362                     "(req=0x%08x zone:%02d:%s appid=%s)",
363                     *itr2, itr->first, (*itr2)->soundzone, (*itr2)->appid);
364             m_soundReqQueue[req->soundzoneid].erase(itr2);
365             ICO_TRA("CicoSCResourceManager::popSoundResReq Leave"
366                     "(0x%08x)", *itr2);
367             return *itr2;
368         }
369     }
370     ICO_TRA("CicoSCResourceManager::popSoundResReq Leave(NULL)");
371     return NULL;
372 }
373
374 resource_request_t *
375 CicoSCResourceManager::popInputResReq(resource_request_t *req)
376 {
377     ICO_TRA("CicoSCResourceManager::popInputResReq Enter");
378
379     map<int, list<resource_request_t*> >::iterator itr;
380     itr = m_inputReqQueue.begin();
381     CompInputResourceRequest comp(req);
382     for (; itr != m_inputReqQueue.end(); ++itr) {
383         list<resource_request_t*>::iterator itr2;
384         itr2 = find_if(itr->second.begin(), itr->second.end(), comp);
385         if (itr->second.end() != itr2) {
386             ICO_DBG("Dequeue waiting input request queue"
387                     "(req=0x%08x input:%d appid=%s)",
388                     *itr2, (*itr2)->input, (*itr2)->appid);
389             m_inputReqQueue[req->input].erase(itr2);
390             ICO_TRA("CicoSCResourceManager::popInputResReq Leave"
391                     "(0x%08x)", *itr2);
392             return *itr2;
393         }
394     }
395
396     ICO_TRA("CicoSCResourceManager::popDispResReq Leave(NULL)");
397     return NULL;
398 }
399
400
401 bool
402 CicoSCResourceManager::acquireDisplayResource(resource_request_t *newreq,
403                                               bool control)
404 {
405     ICO_TRA("CicoSCResourceManager::acquireDisplayResource Enter");
406
407     CicoSystemConfig *sysConf = CicoSystemConfig::getInstance();
408     const CicoSCAppKindConf *appKindConf = NULL;
409     appKindConf = sysConf->findAppKindConfbyId(newreq->appkind);
410     if (NULL == appKindConf) {
411         ICO_ERR("not found CicoSCAppKindConf instance");
412         ICO_TRA("CicoSCResourceManager::acquireDisplayResource Leave(false)");
413         return false;
414     }
415
416     if ((appKindConf->privilege == CicoSCAppKindConf::PRIVILEGE_ALMIGHTY) ||
417         (appKindConf->privilege == CicoSCAppKindConf::PRIVILEGE_SYSTEM)   ||
418         (appKindConf->privilege == CicoSCAppKindConf::PRIVILEGE_SYSTEM_VISIBLE)) {
419
420         if ((NULL != m_winCtrl) && (true == control)) {
421             m_winCtrl->show(newreq->surfaceid,
422                             newreq->animation,
423                             newreq->animationTime);
424         }
425         delResourceRequest(newreq);
426
427         ICO_DBG("kind of system application");
428         ICO_TRA("CicoSCResourceManager::acquireDisplayResource Leave(true)");
429         return true;
430     }
431
432     // if exist current ower request, pop request
433     resource_request_t *req = findCurDispResOwerReq(newreq);
434     int chgzone = -1;
435     if (NULL != req) {
436         ICO_DBG("dispzoneid=%d/%d zone=%s/%s",
437                 req->dispzoneid, newreq->dispzoneid,
438                 req->dispzone, newreq->dispzone);
439         if (req->dispzoneid != newreq->dispzoneid) {
440             req = popCurDispResOwerReq(req);
441             m_policyMgr->releaseDisplayResource(req->dispzoneid, req->prio);
442             chgzone = newreq->dispzoneid;
443         }
444     }
445
446     // if exist in wating request list, pop request
447     if (NULL == req) {
448         req = popWaitingDispResReq(newreq);
449         if (NULL != req) {
450             ICO_DBG("dispzoneid=%d/%d zone=%s/%s",
451                     req->dispzoneid, newreq->dispzoneid,
452                     req->dispzone, newreq->dispzone);
453             if (req->dispzoneid != newreq->dispzoneid) {
454                 chgzone = newreq->dispzoneid;
455             }
456         }
457         else {
458             req = newreq;
459         }
460     }
461
462     bool displayMatch = false;
463     //
464     if (req != newreq) {
465         char zoneO[128],zoneN[128];
466         zoneO[0] = zoneN[0] = '\0';
467         if ((NULL != req) && (NULL != req->dispzone)) {
468             char* d = zoneO;
469             const char* s = req->dispzone;
470             while ('\0' != *s) {  // is stop code
471                 if ('.' == *s) {  // DISPLAY.ZONE found a period
472                     break;  // break of while
473                 }
474                 *d++ = *s++; // char copy
475             }
476             *d='\0';  // set stop code
477         }
478         if ((NULL != newreq) && (NULL != newreq->dispzone)) {
479             char* d = zoneO;
480             const char* s = newreq->dispzone;
481             while ('\0' != *s) {  // is stop code
482                 if ('.' == *s) {  // DISPLAY.ZONE found a period
483                     break;  // break of while
484                 }
485                 *d++ = *s++;  // char copy
486             }
487             *d='\0';  // set stop code
488         }
489         if ((0 != strlen(zoneO)) || (0 != strlen(zoneN))) {
490             if (0 == strcmp(zoneO, zoneN)) {
491                 displayMatch = true;
492             }
493         }
494         // update request data
495         req->dispzoneid = newreq->dispzoneid;
496         free(req->dispzone);
497         req->dispzone = strdup(newreq->dispzone);
498         req->layerid = newreq->layerid;
499         free(req->animation);
500         req->animation = strdup(newreq->animation);
501         req->animationTime = newreq->animationTime;
502
503         // delete new request
504         delResourceRequest(newreq);
505     }
506
507     if (false == control) {
508         ICO_TRA("Enqueue waiting display resource request"
509                 "(req=0x%08x appid=%s)", req, req->appid);
510         m_waitingDispResReq.push_front(req);
511 #if 1   //DEBUG
512         dumpWaitingDispResReq();
513 #endif  //DEBUG
514         return true;
515     }
516
517     int type = req->resid & RESID_TYPE_MASK;
518     bool state = m_policyMgr->acquireDisplayResource(type,
519                                                      req->dispzoneid,
520                                                      req->prio);
521     if ((true == state) && (false == displayMatch)){
522         updateDisplayResource(req, chgzone);
523     }
524     else {
525         if ((-1 != chgzone) || (true == displayMatch)) {
526             if (NULL != m_winCtrl) {
527                 // move request window
528                 m_winCtrl->setGeometry(req->surfaceid, req->dispzone, req->layerid,
529                                        req->animation, req->animationTime,
530                                        req->animation, req->animationTime);
531             }
532         }
533         else {
534             // just in case, hide window
535             if (NULL != m_winCtrl) {
536                 // hide request window
537                 m_winCtrl->hide(req->surfaceid, NULL, 0);
538             }
539         }
540         ICO_DBG("Enqueue waiting display resource request"
541                     "(req=0x%08x appid=%s)", req, req->appid);
542         m_waitingDispResReq.push_front(req);
543 #if 1   //DEBUG
544         dumpWaitingDispResReq();
545 #endif  //DEBUG
546     }
547
548     ICO_TRA("CicoSCResourceManager::acquireDisplayResource Leave");
549     return true;
550 }
551
552 void
553 CicoSCResourceManager::releaseDisplayResource(resource_request_t *newreq)
554 {
555     ICO_TRA("CicoSCResourceManager::releaseDisplayResource Enter"
556             "(newreq=0x%08x)", newreq);
557
558     // if exist in wating request list, pop request
559     resource_request_t *req = popWaitingDispResReq(newreq);
560     if (NULL != req) {
561         delResourceRequest(req);
562         delResourceRequest(newreq);
563         ICO_TRA("CicoSCResourceManager::releaseDisplayResource Leave");
564         return;
565     }
566
567     // if exist current ower request, pop request
568     req = popCurDispResOwerReq(newreq);
569     if (NULL != req) {
570         m_policyMgr->releaseDisplayResource(req->dispzoneid, req->prio);
571         delResourceRequest(req);
572     }
573     delResourceRequest(newreq);
574
575     list<resource_request_t*>::iterator itr;
576     itr = m_waitingDispResReq.begin();
577     for (; itr != m_waitingDispResReq.end(); ++itr) {
578         if (NULL != m_curDispResOwerReq[(*itr)->dispzoneid]) {
579             continue;
580         }
581         int type = (*itr)->resid & RESID_TYPE_MASK;
582         bool active = m_policyMgr->acquireDisplayResource(type,
583                                                          (*itr)->dispzoneid,
584                                                          (*itr)->prio);
585         if (true == active) {
586             resource_request_t* popreq = popWaitingDispResReq(*itr);
587             updateDisplayResource(popreq);
588             m_winCtrl->activeCB(NULL, NULL, popreq->surfaceid, -1);
589             break;
590         }
591     }
592
593     ICO_TRA("CicoSCResourceManager::releaseDisplayResource Leave");
594 }
595
596 bool
597 CicoSCResourceManager::acquireSoundResource(resource_request_t *newreq)
598 {
599     ICO_TRA("CicoSCResourceManager::acquireSoundResource Enter");
600
601     CicoSystemConfig *sysConf = CicoSystemConfig::getInstance();
602     const CicoSCAppKindConf *appKindConf = NULL;
603     appKindConf = sysConf->findAppKindConfbyId(newreq->appkind);
604     if (NULL == appKindConf) {
605         ICO_ERR("not found CicoSCAppKindConf instance");
606         ICO_TRA("CicoSCResourceManager::acquireSoundResource Leave(false)");
607         return false;
608     }
609
610     if ((appKindConf->privilege == CicoSCAppKindConf::PRIVILEGE_ALMIGHTY) ||
611         (appKindConf->privilege == CicoSCAppKindConf::PRIVILEGE_SYSTEM)   ||
612         (appKindConf->privilege == CicoSCAppKindConf::PRIVILEGE_SYSTEM_AUDIO)) {
613
614         delResourceRequest(newreq);
615
616         ICO_DBG("kind of system application");
617         ICO_TRA("CicoSCResourceManager::acquireSoundResource Leave(true)");
618         return true;
619     }
620
621     resource_request_t *req = popSoundResReq(newreq);
622     if (NULL == req) {
623         req = newreq;
624     }
625
626     // is change zone?
627     CompSoundResourceRequest comp(req);
628     if (true == comp(m_curSoundResReq[req->soundzoneid])) {
629         ICO_DBG("already acquired appid=%s pid=%d soundid=0x%08X",
630                 req->appid, req->pid, req->soundid);
631         ICO_TRA("CicoSCResourceManager::acquireSoundResource Leave(true)");
632         // free new request
633         delResourceRequest(newreq);
634         return true;
635     }
636
637     int type = req->resid & RESID_TYPE_MASK;
638     bool state = m_policyMgr->acquireSoundResource(type,
639                                                    req->soundzoneid,
640                                                    req->prio);
641     if (true == state) {
642         updateSoundResource(req);
643     }
644     else {
645         ICO_DBG("Enqueue waiting sound request queue"
646                 "(req=0x%08x zone:%02d:%s appid=%s)",
647                 req, req->soundzoneid, req->soundzone, req->appid);
648         m_soundReqQueue[req->soundzoneid].push_front(req);
649     }
650
651     ICO_TRA("CicoSCResourceManager::acquireSoundResource Leave");
652     return true;
653 }
654
655 void
656 CicoSCResourceManager::releaseSoundResource(resource_request_t *newreq)
657 {
658     ICO_TRA("CicoSCResourceManager::releaseSoundResource Enter");
659
660     bool curchg = false;
661     CompSoundResourceRequest comp(newreq);
662     for (int i = 0; i < (int)m_curSoundResReq.size(); ++i) {
663          if (NULL == m_curSoundResReq[i]) {
664             continue;
665          }
666
667          if (true == comp(m_curSoundResReq[i])) {
668             ICO_DBG("Dequeue current sound resource ower request"
669                     "(req=0x%08x zoneid=%02d:%s appid=%s)",
670                     m_curSoundResReq[i], m_curSoundResReq[i]->dispzoneid,
671                     m_curSoundResReq[i]->dispzone,
672                     m_curSoundResReq[i]->appid);
673             ICO_PRF("CHG_GUI_RES sound   deprived zone=%02d:%s appid=%s",
674                     m_curSoundResReq[i]->dispzoneid,
675                     m_curSoundResReq[i]->dispzone,
676                     m_curSoundResReq[i]->appid);
677             ico_syc_mrp_release_sound_resource(m_curSoundResReq[i]);
678             delResourceRequest(newreq);
679             delResourceRequest(m_curSoundResReq[i]);
680             m_curSoundResReq[i] = NULL;
681             curchg = true;
682             break;
683          }
684     }
685
686     // If current request is not changed,
687     // remove the request from the waiting queue.
688     if (false == curchg) {
689        resource_request_t *req = popSoundResReq(newreq);
690         if (NULL != req) {
691             ico_syc_mrp_release_sound_resource(req);
692             delResourceRequest(req);
693             req = NULL;
694         }
695         delResourceRequest(newreq);
696         ICO_TRA("CicoSCResourceManager::releaseSoundResource Leave");
697         return;
698     }
699
700     map<int, list<resource_request_t*> >::iterator itr;
701     itr = m_soundReqQueue.begin();
702     for (; itr != m_soundReqQueue.end(); ++itr) {
703         list<resource_request_t*>::iterator itr2;
704         itr2 = itr->second.begin();
705         for (; itr2 !=  itr->second.end(); ++itr2) {
706             if (NULL != m_curSoundResReq[(*itr2)->soundzoneid]) {
707                 continue;
708             }
709
710             int type = (*itr2)->resid & RESID_TYPE_MASK;
711             bool active = m_policyMgr->acquireSoundResource(type,
712                                                             (*itr2)->soundzoneid,
713                                                             (*itr2)->prio);
714             if (true == active) {
715                 resource_request_t* req = *itr2;
716                 ICO_DBG("Dequeue waiting sound request queue "
717                         "(req=0x%08x zone:%02d:%s appid=%s)",
718                         *itr2, itr->first, (*itr2)->soundzone, (*itr2)->appid);
719                 itr->second.erase(itr2);
720                 updateSoundResource(req);
721                 break;
722             }
723         }
724     }
725
726     ICO_TRA("CicoSCResourceManager::releaseSoundResource Leave");
727 }
728
729 bool
730 CicoSCResourceManager::acquireInputResource(resource_request_t *newreq)
731 {
732     ICO_TRA("CicoSCResourceManager::acquireInputResource Enter");
733
734     resource_request_t *req = popInputResReq(newreq);
735     if (NULL == req) {
736         req = newreq;
737     }
738
739     // is change zone?
740     CompInputResourceRequest comp(req);
741     if (true == comp(m_curInputResReq[req->input])) {
742         ICO_DBG("already acquired appid=%s pid=%d input=0x%08X",
743                 req->appid, req->pid, req->input);
744         ICO_TRA("CicoSCResourceManager::acquireInputResource Leave(true)");
745         // free new request
746         delResourceRequest(newreq);
747         return true;
748     }
749
750     bool state = m_policyMgr->acquireInputResource(req->input, req->prio);
751     if (true == state) {
752         updateInputResource(req);
753     }
754     else {
755         ICO_DBG("Enqueue waiting input request queue"
756                 "(req=0x%08x input:%d appid=%s)", req, req->input, req->appid);
757         m_inputReqQueue[req->input].push_front(req);
758     }
759
760     ICO_TRA("CicoSCResourceManager::acquireInputResource Leave(true)");
761     return true;
762 }
763
764 void
765 CicoSCResourceManager::releaseInputResource(resource_request_t *newreq)
766 {
767     ICO_TRA("CicoSCResourceManager::releaseInputResource Enter");
768     bool curchg = false;
769     CompInputResourceRequest comp(newreq);
770     for (int i = 0; i < (int)m_curInputResReq.size(); ++i) {
771          if (NULL == m_curInputResReq[i]) {
772             continue;
773          }
774
775          if (true == comp(m_curInputResReq[i])) {
776             if (NULL != m_inputCtrl) {
777                 m_inputCtrl->delInputApp(m_curInputResReq[i]->appid,
778                                          m_curInputResReq[i]->device,
779                                          m_curInputResReq[i]->input);
780             }
781             ICO_DBG("Dequeue current input resource ower request"
782                     "(req=0x%08x input=%d appid=%s)",
783                     m_curInputResReq[i], m_curInputResReq[i]->input,
784                     m_curInputResReq[i]->appid);
785             ICO_PRF("CHG_GUI_RES input   deprived input=%d appid=%s",
786                     m_curInputResReq[i]->input, m_curInputResReq[i]->appid);
787             delResourceRequest(newreq);
788             delResourceRequest(m_curInputResReq[i]);
789             m_curInputResReq[i] = NULL;
790             curchg = true;
791             break;
792          }
793     }
794
795     // If current request is not changed,
796     // remove the request from the waiting queue.
797     if (false == curchg) {
798        resource_request_t *req = popInputResReq(newreq);
799         if (NULL != req) {
800             delResourceRequest(req);
801             req = NULL;
802         }
803         delResourceRequest(newreq);
804         ICO_TRA("CicoSCResourceManager::releaseInputResource Leave");
805         return;
806     }
807
808     map<int, list<resource_request_t*> >::iterator itr;
809     itr = m_inputReqQueue.begin();
810     for (; itr != m_inputReqQueue.end(); ++itr) {
811         list<resource_request_t*>::iterator itr2;
812         itr2 = itr->second.begin();
813         for (; itr2 !=  itr->second.end(); ++itr2) {
814             if (NULL != m_curInputResReq[(*itr2)->input]) {
815                 continue;
816             }
817             bool active = m_policyMgr->acquireInputResource((*itr2)->input,
818                                                             (*itr2)->prio);
819             if (true == active) {
820                 resource_request_t* req = *itr2;
821                 ICO_DBG("Dequeue waiting input request queue "
822                         "(req=0x%08x input:%d appid=%s)",
823                         *itr2, (*itr2)->input, (*itr2)->appid);
824                 itr->second.erase(itr2);
825                 updateInputResource(req);
826                 break;
827             }
828         }
829     }
830     ICO_TRA("CicoSCResourceManager::releaseInputResource Leave");
831 }
832
833 resource_request_t *
834 CicoSCResourceManager::newResourceRequest(int resid,
835                                           int reqtype,
836                                           const CicoSCCommand &cmd)
837 {
838     ICO_TRA("CicoSCResourceManager::newResourceRequest Enter");
839
840     resource_request_t *req = NULL;
841     req = (resource_request_t*)calloc(1, sizeof(resource_request_t));
842     CicoSCCmdResCtrlOpt *opt = (CicoSCCmdResCtrlOpt*)cmd.opt;
843     CicoSystemConfig *systemConfig = CicoSystemConfig::getInstance();
844
845     req->reqtype = reqtype;
846
847     CicoSCLifeCycleController *lifeCycle =
848         CicoSCLifeCycleController::getInstance();
849     const CicoAilItems* ailItem = lifeCycle->findAIL(cmd.appid);
850     if (NULL != ailItem) {
851         req->category = ailItem->m_categoryID;
852         req->appkind = ailItem->m_kindID;
853     }
854
855     req->prio = req->category;
856
857     req->released = 0;
858
859     /* set resource id */
860     switch (opt->type) {
861     case ICO_SYC_RES_INTERRUPT:
862         req->resid = RESID_TYPE_INTERRUPT;
863         break;
864     case ICO_SYC_RES_ONSCREEN:
865         req->resid = RESID_TYPE_ONSCREEN;
866         break;
867     default: // include case ICO_SYC_RES_BASIC:
868         req->resid = RESID_TYPE_BASIC;
869         break;
870     }
871     req->resid |= resid;
872
873     req->resid |= RESID_CMD_RELEASE;
874     if (MSG_CMD_ACQUIRE_RES == cmd.cmdid) {
875         req->resid |= RESID_CMD_ACQUIRE;
876     }
877
878     /* set application information */
879     req->appid = strdup(cmd.appid.c_str());
880     req->pid   = cmd.pid;
881     req->state = RES_STATE_WAITING;
882
883     if (resid == RESID_KIND_DISPLAY) {
884         req->dispzone   = strdup(opt->dispzone.c_str());
885         req->dispzoneid = systemConfig->getDizplayZoneIdbyFullName(req->dispzone);
886         req->layerid    = opt->layerid;
887         req->winname    = strdup(opt->winname.c_str());
888         req->surfaceid  = opt->surfaceid;
889         req->id         = opt->surfaceid;
890         req->animation  = strdup(opt->animation.c_str());
891         req->animationTime = opt->animationTime;
892         req->bEx        = opt->dispresEx;
893         req->ECU        = strdup(opt->ECU.c_str());  // name to identify ECU
894         req->display    = strdup(opt->display.c_str());  // name to identify Display in ECU
895         req->layer      = strdup(opt->layer.c_str());  // name to identify Layer in Display
896         req->layout     = strdup(opt->layout.c_str());  // name to identify layout in Layer
897         req->area       = strdup(opt->area.c_str());  // name to Output position in Layout
898         req->dispatchApp= strdup(opt->dispatchApp.c_str());  // dispatch of application
899         req->role       = strdup(opt->role.c_str());  // role of notice
900         req->resourceId = opt->resourceID;  // ID number of resource
901     }
902     else if (resid == RESID_KIND_SOUND) {
903         req->soundzone   = strdup(opt->soundzone.c_str());
904         req->soundzoneid = systemConfig->getSoundZoneIdbyFullName(req->soundzone);
905         ICO_DBG("req->soundzoneid=%d", req->soundzoneid);
906         req->soundname   = strdup(opt->soundname.c_str());
907         req->soundid     = opt->soundid;
908         req->soundadjust = opt->adjust;
909         req->id          = opt->soundid;
910     }
911     else if (resid == RESID_KIND_INPUT) {
912         req->device = strdup(opt->device.c_str());
913         req->input  = opt->input;
914         req->id     = opt->input;
915     }
916
917     ICO_TRA("CicoSCResourceManager::newResourceRequest Leave"
918             "(req=0x%08x appid=%s)", req, req->appid);
919     return req;
920 }
921
922 void
923 CicoSCResourceManager::delResourceRequest(resource_request_t *req)
924 {
925     if (NULL == req) return;
926
927     free(req->appid);
928     free(req->dispzone);
929     free(req->winname);
930     free(req->animation);
931     free(req->soundzone);
932     free(req->soundname);
933     free(req->device);
934     free(req->ECU);             // name to identify ECU
935     free(req->display);         // name to identify Display in ECU
936     free(req->layer);           // name to identify Layer in Display
937     free(req->layout);          // name to identify layout in Layer
938     free(req->area);            // name to Output position in Layout
939     free(req->dispatchApp);     // origin of application
940     free(req->role);            // role of notice
941     free(req);
942 }
943
944 void
945 CicoSCResourceManager::enforceSound(unsigned short state,
946                                     resource_request_t *req,
947                                     void *user_data)
948 {
949     ICO_TRA("CicoSCResourceManager::enforceSound Enter");
950     /* NOP */
951     ICO_TRA("CicoSCResourceManager::enforceSound Leave");
952 }
953
954 // receive changed state
955 void
956 CicoSCResourceManager::receiveChangedState(int state)
957 {
958     ICO_TRA("CicoSCResourceManager::receiveChangedState Enter"
959             "(state=%d)", state);
960
961     if (STID_DRVREGULATION_ON == state) {
962         if (true == isMatchDisplayed()) {
963             updateDisplayResourceRegulation(state);
964             updateSoundResourceRegulation(state);
965             updateInputResourceRegulation(state);
966         }
967     }
968     else {
969         updateDisplayResourceRegulation(state);
970         updateSoundResourceRegulation(state);
971         updateInputResourceRegulation(state);
972     }
973
974     ICO_TRA("CicoSCResourceManager::receiveChangedState Leave");
975 }
976
977 //--------------------------------------------------------------------------
978 /**
979  *  @brief  get policy manager instance
980  *
981  *  @return resource manager instace
982  */
983 //--------------------------------------------------------------------------
984 CicoSCPolicyManager *
985 CicoSCResourceManager::getPolicyManager(void)
986 {
987     return m_policyMgr;
988 }
989
990 void
991 CicoSCResourceManager::updateDisplayResource(resource_request_t *req,
992                                              int chgzoneid)
993 {
994     ICO_TRA("CicoSCResourceManager::updateDisplayResource Enter"
995             "(req=0x%08x)", req);
996
997     std::map<unsigned int, resource_request_t*>::iterator itr;
998     itr = m_curDispResOwerReq.find(req->dispzoneid);
999     if ((m_curDispResOwerReq.end() != itr) && (NULL != itr->second)) {
1000         // already ower
1001         if (itr->second == req) {
1002             ICO_DBG("already ower appid=%s pid=%d surfaceid=0x%08X",
1003                     req->appid, req->pid, req->surfaceid);
1004             // show request window
1005             m_winCtrl->show(req->surfaceid, req->animation, req->animationTime);
1006 #if 0
1007             m_winCtrl->activeCB(NULL, NULL, req->surfaceid, -1);
1008 #endif
1009             ICO_TRA("CicoSCResourceManager::updateDisplayResource Leave");
1010             return;
1011         }
1012         resource_request_t *popreq = popCurDispResOwerReq(itr->second);
1013         if (NULL != popreq) {
1014             if (NULL != m_winCtrl) {
1015                 // hide current window
1016                 m_winCtrl->hide(popreq->surfaceid, NULL, 0);
1017             }
1018
1019             // state change to waiting
1020             popreq->state = RES_STATE_WAITING;
1021             // enqueue request
1022             ICO_DBG("Enqueue waiting display resource request"
1023                     "(req=0x%08x zone=%02d:%s appid=%s",
1024                     popreq, popreq->dispzoneid,
1025                     popreq->dispzone, popreq->appid);
1026             m_waitingDispResReq.push_front(popreq);
1027 #if 1   //DEBUG
1028         dumpWaitingDispResReq();
1029 #endif  //DEBUG
1030         }
1031     }
1032
1033     std::map<unsigned int, resource_request_t*>::iterator itr2;
1034     itr2 = m_curDispResOwerReq.begin();
1035     for (; itr2 != m_curDispResOwerReq.end(); ++itr2) {
1036         resource_request_t *tmpreq = itr2->second;
1037
1038         if (true == m_policyMgr->getDispZoneState(itr2->first)) {
1039             continue;
1040         }
1041
1042         if (NULL == itr2->second) {
1043             continue;
1044         }
1045
1046         ICO_DBG("Dequeue current display resource ower request"
1047                 "(req=0x%08x zoneid=%02d:%s appid=%s)",
1048                 tmpreq, tmpreq->dispzoneid, tmpreq->dispzone, tmpreq->appid);
1049         ICO_PRF("CHG_GUI_RES display deprived zone=%02d:%s appid=%s",
1050                 tmpreq->dispzoneid, tmpreq->dispzone, tmpreq->appid);
1051         itr2->second = NULL;
1052
1053         // hide current window
1054         m_winCtrl->hide(tmpreq->surfaceid, NULL, 0);
1055
1056         ICO_DBG("Enqueue waiting display resource request"
1057                 "(req=0x%08x zone=%02d:%s appid=%s",
1058                 tmpreq, tmpreq->dispzoneid, tmpreq->dispzone, tmpreq->appid);
1059         m_waitingDispResReq.push_front(tmpreq);
1060     }
1061
1062     if (NULL != m_winCtrl) {
1063         int ret = ICO_SYC_EOK;
1064         if (-1 != chgzoneid) {
1065             // move request window
1066             ret = m_winCtrl->setGeometry(req->surfaceid, req->dispzone,
1067                                          req->layerid,
1068                                          req->animation, req->animationTime,
1069                                          req->animation, req->animationTime);
1070             if (ICO_SYC_EOK != ret) {
1071                 return;
1072             }
1073         }
1074
1075         // show request window
1076         m_winCtrl->show(req->surfaceid, req->animation, req->animationTime);
1077     }
1078     // state change to acquired
1079     req->state = RES_STATE_ACQUIRED;
1080     // update current zone request
1081     ICO_DBG("Enqueue current display resource ower request"
1082             "(req=0x%08x zoneid=%02d:%s appid=%s)",
1083             req, req->dispzoneid, req->dispzone, req->appid);
1084     ICO_PRF("CHG_GUI_RES display acquired zone=%02d:%s appid=%s",
1085             req->dispzoneid, req->dispzone, req->appid);
1086     m_curDispResOwerReq[req->dispzoneid] = req;
1087 #if 1   //DEBUG
1088     dumpCurDispResOwerReq();
1089 #endif  //DEBUG
1090
1091     // if current zone ower not exist after zone change
1092     if (-1 != chgzoneid) {
1093         list<resource_request_t*>::iterator itr;
1094         itr = m_waitingDispResReq.begin();
1095         for (; itr !=  m_waitingDispResReq.end(); ++itr) {
1096             if (m_curDispResOwerReq[(*itr)->dispzoneid] != NULL) {
1097                 continue;
1098             }
1099
1100             if (true == m_policyMgr->isExistDisplayZoneOwer((*itr)->dispzoneid)) {
1101                 continue;
1102             }
1103
1104             int type = (*itr)->resid & RESID_TYPE_MASK;
1105             bool active = false;
1106             active = m_policyMgr->acquireDisplayResource(type,
1107                                                          (*itr)->dispzoneid,
1108                                                          (*itr)->prio);
1109             if (true == active) {
1110                 resource_request_t* req = *itr;
1111                 ICO_DBG("Dequeue waiting display resource request"
1112                         "(req=0x%08x zone=%02d:%s appid=%s)",
1113                         *itr, (*itr)->dispzoneid,
1114                         (*itr)->dispzone, (*itr)->appid);
1115                 m_waitingDispResReq.erase(itr);
1116 #if 1   //DEBUG
1117                 dumpWaitingDispResReq();
1118 #endif  //DEBUG
1119                 updateDisplayResource(req);
1120 #if 0
1121                 m_winCtrl->active(req->surfaceid, -1);
1122 #endif
1123                 break;
1124             }
1125         }
1126     }
1127
1128     ICO_TRA("CicoSCResourceManager::updateDisplayResource Leave");
1129 }
1130
1131 void
1132 CicoSCResourceManager::updateSoundResource(resource_request_t *req)
1133 {
1134     ICO_TRA("CicoSCResourceManager::updateSoundResource Enter"
1135             "(req=0x%08x)", req);
1136     for (int i = 0; i < (int)m_curSoundResReq.size(); ++i) {
1137         ICO_DBG("zoneid=%d active=%d current=0x%08x",
1138                 i, m_policyMgr->getSoundZoneState(i), m_curSoundResReq[i]);
1139
1140         if (NULL == m_curSoundResReq[i]) {
1141             continue;
1142         }
1143
1144         if ((i == req->soundzoneid) ||
1145             (false == m_policyMgr->getSoundZoneState(i))) {
1146
1147             // state change to waiting
1148             m_curSoundResReq[i]->state = RES_STATE_WAITING;
1149             // enqueue request
1150             ICO_DBG("Enqueue waiting sound request queue "
1151                     "(req=0x%08x zone:%02d:%s appid=%s)",
1152                     m_curSoundResReq[i], i,
1153                     m_curSoundResReq[i]->soundzone, m_curSoundResReq[i]->appid);
1154             m_soundReqQueue[i].push_front(m_curSoundResReq[i]);
1155
1156             // initialize current zone request
1157             ICO_DBG("Dequeue current sound request queue "
1158                     "(req=0x%08x zone:%02d:%s appid=%s)",
1159                     m_curSoundResReq[i], i,
1160                     m_curSoundResReq[i]->soundzone, m_curSoundResReq[i]->appid);
1161             ICO_PRF("CHG_GUI_RES sound   deprived zone=%02d:%s appid=%s",
1162                     i, m_curSoundResReq[i]->soundzone,
1163                     m_curSoundResReq[i]->appid);
1164             m_curSoundResReq[i] = NULL;
1165         }
1166     }
1167
1168     if (req != m_curSoundResReq[req->soundzoneid]) {
1169         ico_syc_mrp_acquire_sound_resource(req);
1170         ico_syc_mrp_active_app(req->appid);
1171
1172         // state change to acquired
1173         req->state = RES_STATE_ACQUIRED;
1174         // update current zone request
1175         ICO_DBG("Enqueue current sound request queue "
1176                 "(req=0x%08x zone:%02d:%s appid=%s)",
1177                 req, req->soundzoneid, req->soundzone, req->appid);
1178         ICO_PRF("CHG_GUI_RES sound   acquired zone=%02d:%s appid=%s",
1179                 req->soundzoneid, req->soundzone, req->appid);
1180         m_curSoundResReq[req->soundzoneid] = req;
1181     }
1182     ICO_TRA("CicoSCResourceManager::updateSoundResource Leave");
1183 }
1184
1185 void
1186 CicoSCResourceManager::updateInputResource(resource_request_t *req)
1187 {
1188     ICO_TRA("CicoSCResourceManager::updateInputResource Enter"
1189             "(req=0x%08x)", req);
1190     for (int i = 0; i < (int)m_curInputResReq.size(); ++i) {
1191         ICO_DBG("input=%d active=%d current=0x%08x",
1192                 i, m_policyMgr->getInputState(i), m_curInputResReq[i]);
1193
1194         if (NULL == m_curInputResReq[i]) {
1195             continue;
1196         }
1197
1198         if ((i == req->input) ||
1199             (false == m_policyMgr->getInputState(i))) {
1200
1201             if (NULL != m_inputCtrl) {
1202                 // add input control
1203                 m_inputCtrl->delInputApp(req->appid, req->device, req->input);
1204             }
1205
1206             // state change to waiting
1207             m_curInputResReq[i]->state = RES_STATE_WAITING;
1208             // enqueue request
1209             ICO_DBG("Enqueue waiting input request queue "
1210                     "(req=0x%08x input:%d appid=%s)",
1211                     m_curInputResReq[i], i, m_curInputResReq[i]->appid);
1212             m_inputReqQueue[i].push_front(m_curInputResReq[i]);
1213             // initialize current zone request
1214             ICO_DBG("Dequeue current input request queue "
1215                     "(req=0x%08x input:%d appid=%s)",
1216                     m_curInputResReq[i],
1217                     m_curInputResReq[i]->input, m_curInputResReq[i]->appid);
1218             ICO_PRF("CHG_GUI_RES input   deprived input=%d appid=%s",
1219                     m_curInputResReq[i]->input,
1220                     m_curInputResReq[i]->appid);
1221             m_curInputResReq[i] = NULL;
1222         }
1223     }
1224
1225     if (req != m_curInputResReq[req->input]) {
1226         // delete input control
1227         m_inputCtrl->addInputApp(req->appid, req->device, req->input, 0, 0);
1228         // state change to acquired
1229         req->state = RES_STATE_ACQUIRED;
1230         // update current zone request
1231         ICO_DBG("Enqueue current input request queue "
1232                 "(req=0x%08x input:%d appid=%s)", req, req->input, req->appid);
1233         ICO_PRF("CHG_GUI_RES input   acquired input=%d appid=%s",
1234                 req->input, req->appid);
1235         m_curInputResReq[req->input] = req;
1236     }
1237     ICO_TRA("CicoSCResourceManager::updateInputResource Leave");
1238 }
1239
1240 void
1241 CicoSCResourceManager::updateDisplayResourceRegulation(int state)
1242 {
1243     ICO_TRA("CicoSCResourceManager::updateDisplayResourceRegulation Enter"
1244             "(state=%d)", state);
1245
1246     if (STID_DRVREGULATION_ON == state) {
1247         bool curchg = false;
1248         std::map<unsigned int, resource_request_t*>::iterator itr;
1249         itr = m_curDispResOwerReq.begin();
1250         for (; itr != m_curDispResOwerReq.end(); ++itr) {
1251             resource_request_t *current = itr->second;
1252             if (NULL == current) {
1253                 continue;
1254             }
1255
1256             int type = current->resid & RESID_TYPE_MASK;
1257             bool active = false;
1258             active = m_policyMgr->acquireDisplayResource(type,
1259                                                          current->dispzoneid,
1260                                                          current->prio);
1261             if (false == active) {
1262                 if (NULL != m_winCtrl) {
1263                     // hide current window
1264                     m_winCtrl->hide(current->surfaceid,
1265                                     m_animaName.c_str(), m_animaTime);
1266                 }
1267                 curchg = true;
1268             }
1269         }
1270
1271         if (false == curchg) {
1272             ICO_TRA("CicoSCResourceManager::updateDisplayResourceRegulation "
1273                     "Leave");
1274             return;
1275         }
1276
1277         list<resource_request_t*>::iterator itr2;
1278         itr2 = m_waitingDispResReq.begin();
1279         for (; itr2 !=  m_waitingDispResReq.end(); ++itr2) {
1280             int type = (*itr2)->resid & RESID_TYPE_MASK;
1281             bool active = false;
1282             active = m_policyMgr->acquireDisplayResource(type,
1283                                                          (*itr2)->dispzoneid,
1284                                                          (*itr2)->prio);
1285             if (true == active) {
1286                 if (NULL != m_winCtrl) {
1287                     // show current window
1288                     m_winCtrl->show((*itr2)->surfaceid,
1289                                     m_animaName.c_str(), m_animaTime);
1290                 }
1291                 break;
1292             }
1293         }
1294     }
1295     else if (STID_DRVREGULATION_OFF == state) {
1296         std::map<unsigned int, resource_request_t*>::iterator itr;
1297         itr = m_curDispResOwerReq.begin();
1298         for (; itr != m_curDispResOwerReq.end(); ++itr) {
1299             resource_request_t *current = itr->second;
1300             if (NULL == current) {
1301                 if (true == m_policyMgr->isExistDisplayZoneOwer(itr->first)) {
1302                     if (NULL != m_winCtrl) {
1303                         int surfaceid = m_winCtrl->getDisplayedWindow(itr->first);
1304
1305 #if 0
1306                         if ((surfaceid > 0) && (NULL != itr->second) &&
1307                             (itr->second->surfaceid != surfaceid)) {
1308                             m_winCtrl->hide(surfaceid,
1309                                             m_animaName.c_str(),
1310                                             m_animaTime);
1311                         }
1312 #else
1313                         if (surfaceid > 0) {
1314                             m_winCtrl->hide(surfaceid,
1315                                             m_animaName.c_str(),
1316                                             m_animaTime);
1317                         }
1318
1319 #endif
1320                     }
1321                     continue;
1322                 }
1323                 list<resource_request_t*>::iterator itr2;
1324                 itr2 = m_waitingDispResReq.begin();
1325                 for (; itr2 != m_waitingDispResReq.end(); ++itr2) {
1326                     resource_request_t *req = *itr2;
1327                     if (itr->first != (unsigned int)req->dispzoneid) {
1328                         continue;
1329                     }
1330                     int type = req->resid & RESID_TYPE_MASK;
1331                     bool active = false;
1332                     active = m_policyMgr->acquireDisplayResource(type,
1333                                                                  req->dispzoneid,
1334                                                                  req->prio);
1335                     if (true == active) {
1336                         ICO_DBG("Dequeue waiting display resource request"
1337                                 "(req=0x%08x zone=%02d:%s appid=%s)",
1338                                 req, req->dispzoneid,
1339                                 req->dispzone, req->appid);
1340                         m_waitingDispResReq.erase(itr2);
1341                         ICO_DBG("Enqueue current display resource request"
1342                                 "(req=0x%08x zone=%02d:%s appid=%s)",
1343                                 req, req->dispzoneid,
1344                                 req->dispzone, req->appid);
1345                         ICO_PRF("CHG_GUI_RES display acquired zone=%02d:%s "
1346                                 "appid=%s",
1347                                 req->dispzoneid, req->dispzone, req->appid);
1348                         m_curDispResOwerReq[req->dispzoneid] = req;
1349 #if 1   //DEBUG
1350                         dumpCurDispResOwerReq();
1351                         dumpWaitingDispResReq();
1352 #endif  //DEBUG
1353                         m_winCtrl->show(req->surfaceid,
1354                                         m_animaName.c_str(), m_animaTime);
1355                         m_winCtrl->active(req->surfaceid, -1);
1356                         break;
1357                     }
1358                 }
1359             }
1360             else {
1361                 int type = current->resid & RESID_TYPE_MASK;
1362                 bool active = false;
1363                 active = m_policyMgr->acquireDisplayResource(type,
1364                                                              current->dispzoneid,
1365                                                              current->prio);
1366                 if (true == active) {
1367                     if (NULL != m_winCtrl) {
1368                         int surfaceid = m_winCtrl->getDisplayedWindow(
1369                                                     itr->second->dispzoneid);
1370                         if ((itr->second->surfaceid != surfaceid) &&
1371                             (surfaceid > 0)) {
1372                             m_winCtrl->hide(surfaceid,
1373                                             m_animaName.c_str(), m_animaTime);
1374                         }
1375
1376                         // show current window
1377                         m_winCtrl->show(current->surfaceid,
1378                                         m_animaName.c_str(), m_animaTime);
1379                     }
1380                 }
1381 #if 1   //DEBUG
1382                         dumpCurDispResOwerReq();
1383                         dumpWaitingDispResReq();
1384 #endif  //DEBUG
1385             }
1386         }
1387     }
1388
1389     ICO_TRA("CicoSCResourceManager::updateDisplayResourceRegulation Leave");
1390 }
1391
1392 void
1393 CicoSCResourceManager::updateSoundResourceRegulation(int state)
1394 {
1395     ICO_TRA("CicoSCResourceManager::updateSoundResourceRegulation Enter"
1396             "(state=%d)", state);
1397
1398     bool curchg = false;
1399     for (int i = 0; i < (int)m_curSoundResReq.size(); ++i) {
1400         resource_request_t *current = m_curSoundResReq[i];
1401         if (NULL == current) {
1402             continue;
1403         }
1404
1405         int type = current->resid & RESID_TYPE_MASK;
1406         bool active = false;
1407         active = m_policyMgr->acquireSoundResource(type,
1408                                                    current->soundzoneid,
1409                                                    current->prio);
1410         if (false == active) {
1411             // state change to waiting
1412             current->state = RES_STATE_WAITING;
1413             // enqueue request
1414             ICO_DBG("Enqueue waiting sound request queue "
1415                     "(req=0x%08x zone:%02d:%s appid=%s)",
1416                     current,  i, current->soundzone, current->appid);
1417             m_soundReqQueue[i].push_front(current);
1418             // initialize current zone request
1419             m_curSoundResReq[i] = NULL;
1420             curchg = true;
1421          }
1422     }
1423
1424     if ((false == curchg) && (STID_DRVREGULATION_ON == state)) {
1425         ICO_TRA("CicoSCResourceManager::updateSoundResourceRegulation Leave");
1426         return;
1427     }
1428
1429     map<int, list<resource_request_t*> >::iterator itr;
1430     itr = m_soundReqQueue.begin();
1431     for (; itr != m_soundReqQueue.end(); ++itr) {
1432         if (NULL != m_curSoundResReq[itr->first]) {
1433             continue;
1434         }
1435
1436         list<resource_request_t*>::iterator itr2;
1437         itr2 = itr->second.begin();
1438         for (; itr2 !=  itr->second.end(); ++itr2) {
1439             int type = (*itr2)->resid & RESID_TYPE_MASK;
1440             bool active = false;
1441             active = m_policyMgr->acquireSoundResource(type,
1442                                                        (*itr2)->soundzoneid,
1443                                                        (*itr2)->prio);
1444             if (true == active) {
1445                 resource_request_t* req = *itr2;
1446                 ICO_DBG("Dequeue waiting sound request queue "
1447                         "(req=0x%08x zone:%02d:%s appid=%s)",
1448                         *itr2, itr->first, (*itr2)->soundzone, (*itr2)->appid);
1449                 itr->second.erase(itr2);
1450                 updateSoundResource(req);
1451                 break;
1452             }
1453         }
1454     }
1455
1456     ICO_TRA("CicoSCResourceManager::updateSoundResourceRegulation Leave");
1457 }
1458
1459 void
1460 CicoSCResourceManager::updateInputResourceRegulation(int state)
1461 {
1462     ICO_TRA("CicoSCResourceManager::updateInputResourceRegulation Enter"
1463             "(state=%d)", state);
1464
1465     bool curchg = false;
1466     for (int i = 0; i < (int)m_curInputResReq.size(); ++i) {
1467         resource_request_t *current = m_curInputResReq[i];
1468         if (NULL == current) {
1469             continue;
1470         }
1471
1472         bool active = false;
1473         active = m_policyMgr->acquireInputResource(current->input,
1474                                                    current->prio);
1475         if (false == active) {
1476             if (NULL != m_inputCtrl) {
1477                 // hide current window
1478                 m_inputCtrl->delInputApp(current->appid,
1479                                          current->device,
1480                                          current->input);
1481             }
1482             // state change to waiting
1483             current->state = RES_STATE_WAITING;
1484             // enqueue request
1485             ICO_DBG("Enqueue waiting input request queue "
1486                     "(req=0x%08x input:%d appid=%s)",
1487                     current, i, current->appid);
1488             m_inputReqQueue[i].push_front(current);
1489             // initialize current zone request
1490             m_curInputResReq[i] = NULL;
1491             curchg = true;
1492          }
1493     }
1494
1495     if ((false == curchg) && (STID_DRVREGULATION_ON == state)) {
1496         ICO_TRA("CicoSCResourceManager::updateInputResourceRegulation Leave");
1497         return;
1498     }
1499
1500     map<int, list<resource_request_t*> >::iterator itr;
1501     itr = m_inputReqQueue.begin();
1502     for (; itr != m_inputReqQueue.end(); ++itr) {
1503         if (NULL != m_curInputResReq[itr->first]) {
1504             continue;
1505         }
1506
1507         list<resource_request_t*>::iterator itr2;
1508         itr2 = itr->second.begin();
1509         for (; itr2 !=  itr->second.end(); ++itr2) {
1510             bool active = false;
1511             active = m_policyMgr->acquireInputResource((*itr2)->input,
1512                                                        (*itr2)->prio);
1513             if (true == active) {
1514                 resource_request_t* req = *itr2;
1515                 ICO_DBG("Dequeue waiting input request queue "
1516                         "(req=0x%08x input:%d appid=%s)",
1517                         *itr2, (*itr2)->input, (*itr2)->appid);
1518                 itr->second.erase(itr2);
1519                 updateInputResource(req);
1520                 break;
1521             }
1522         }
1523     }
1524
1525     ICO_TRA("CicoSCResourceManager::updateInputResourceRegulation Leave");
1526 }
1527
1528 //--------------------------------------------------------------------------
1529 /**
1530  *  @brief   find currnet dipalay resource ower request
1531  *
1532  *  @param [in] request  compare requset
1533  *
1534  *  @return request object on same requeset found, NULL on not found
1535  */
1536 //--------------------------------------------------------------------------
1537 resource_request_t *
1538 CicoSCResourceManager::findCurDispResOwerReq(resource_request_t *req)
1539 {
1540     if (NULL == req) {
1541         ICO_WRN("invalid argument. req is null");
1542         return NULL;
1543     }
1544     std::map<unsigned int, resource_request_t*>::iterator itr;
1545     itr = m_curDispResOwerReq.begin();
1546     for (; itr != m_curDispResOwerReq.end(); ++itr) {
1547         CompDisplayResourceRequest comp(req);
1548         if (true == comp(itr->second)) {
1549             return itr->second;
1550         }
1551     }
1552     return NULL;
1553 }
1554
1555 //--------------------------------------------------------------------------
1556 /**
1557  *  @brief  pop currnet dipalay resource ower request from list
1558  *
1559  *  @param [in] request  compare requset
1560  *
1561  *  @return request object on same requeset found, NULL on not found
1562  */
1563 //--------------------------------------------------------------------------
1564 resource_request_t *
1565 CicoSCResourceManager::popCurDispResOwerReq(resource_request_t *req)
1566 {
1567     if (NULL == req) {
1568         ICO_WRN("invalid argument. req is null");
1569         return NULL;
1570     }
1571     std::map<unsigned int, resource_request_t*>::iterator itr;
1572     itr = m_curDispResOwerReq.begin();
1573     for (; itr != m_curDispResOwerReq.end(); ++itr) {
1574         CompDisplayResourceRequest comp(req);
1575         if (true == comp(itr->second)) {
1576             ICO_DBG("Dequeue current display resource ower request"
1577                     "(req=0x%08x zoneid=%02d:%s appid=%s)",
1578                     itr->second, itr->first,
1579                     itr->second->dispzone, itr->second->appid);
1580             ICO_PRF("CHG_GUI_RES display deprived zone=%02d:%s appid=%s",
1581                     itr->first, itr->second->dispzone, itr->second->appid);
1582             resource_request_t *findreq = itr->second;
1583             itr->second = NULL;
1584 #if 1   //DEBUG
1585             dumpCurDispResOwerReq();
1586 #endif  //DEBUG
1587             return findreq;
1588         }
1589     }
1590     return NULL;
1591 }
1592
1593 //--------------------------------------------------------------------------
1594 /**
1595  *  @brief   dump currnet dipalay resource ower request
1596  */
1597 //--------------------------------------------------------------------------
1598 void
1599 CicoSCResourceManager::dumpCurDispResOwerReq(void)
1600 {
1601     std::map<unsigned int, resource_request_t*>::iterator itr;
1602     itr = m_curDispResOwerReq.begin();
1603     for (; itr != m_curDispResOwerReq.end(); ++itr) {
1604         if (NULL == itr->second) {
1605             ICO_DBG("current req=0x%08x zone=%02d:(null) appid=(null)",
1606                     itr->second, itr->first);
1607         }
1608         else {
1609             ICO_DBG("current req=0x%08x zone=%02d:%s appid=%s",
1610                     itr->second, itr->first, itr->second->dispzone,
1611                     itr->second->appid);
1612         }
1613     }
1614 }
1615
1616 //--------------------------------------------------------------------------
1617 /**
1618  *  @brief  find waiting dipalay resource request
1619  *
1620  *  @param [in] request  compare requset
1621  *
1622  *  @return request object on same requeset found, NULL on not found
1623  */
1624 //--------------------------------------------------------------------------
1625 resource_request_t *
1626 CicoSCResourceManager::findWaitingDispResReq(resource_request_t *req)
1627 {
1628     if (NULL == req) {
1629         ICO_WRN("invalid argument. req is null");
1630         return NULL;
1631     }
1632     CompDisplayResourceRequest comp(req);
1633     std::list<resource_request_t*>::iterator itr;
1634     itr = find_if(m_waitingDispResReq.begin(), m_waitingDispResReq.end(), comp);
1635     if (m_waitingDispResReq.end() != itr) {
1636         return *itr;
1637     }
1638     return NULL;
1639 }
1640
1641 //--------------------------------------------------------------------------
1642 /**
1643  *  @brief  pop waiting dipalay resource request from waiting list
1644  *
1645  *  @param [in] request  compare requset
1646  *
1647  *  @return request object on same requeset found, NULL on not found
1648  */
1649 //--------------------------------------------------------------------------
1650 resource_request_t *
1651 CicoSCResourceManager::popWaitingDispResReq(resource_request_t *req)
1652 {
1653     if (NULL == req) {
1654         ICO_WRN("invalid argument. req is null");
1655         return NULL;
1656     }
1657     CompDisplayResourceRequest comp(req);
1658     std::list<resource_request_t*>::iterator itr;
1659     itr = find_if(m_waitingDispResReq.begin(), m_waitingDispResReq.end(), comp);
1660     if (m_waitingDispResReq.end() != itr) {
1661         ICO_DBG("Dequeue waiting display resource request"
1662                 "(req=0x%08x zone:%02d:%s appid=%s)",
1663                 *itr, (*itr)->dispzoneid, (*itr)->dispzone, (*itr)->appid);
1664         resource_request_t *findreq = *itr;
1665         m_waitingDispResReq.erase(itr);
1666 #if 1   //DEBUG
1667         dumpWaitingDispResReq();
1668 #endif  //DEBUG
1669         return findreq;
1670     }
1671     return NULL;
1672 }
1673
1674 //--------------------------------------------------------------------------
1675 /**
1676  *  @brief  dump waiting dipalay resource request
1677  */
1678 //--------------------------------------------------------------------------
1679 void
1680 CicoSCResourceManager::dumpWaitingDispResReq(void)
1681 {
1682     std::list<resource_request_t*>::iterator itr;
1683     itr = m_waitingDispResReq.begin();
1684     for (; itr != m_waitingDispResReq.end(); ++itr) {
1685         if (NULL == *itr) {
1686             ICO_DBG("waiting req=null");
1687         }
1688         else {
1689             ICO_DBG("waiting req=0x%08x zone=%02d:%s appid=%s",
1690                     *itr, (*itr)->dispzoneid, (*itr)->dispzone, (*itr)->appid);
1691         }
1692     }
1693 }
1694
1695 //--------------------------------------------------------------------------
1696 /**
1697  *  @brief  update display request for regulation pre-process
1698  */
1699 //--------------------------------------------------------------------------
1700 void
1701 CicoSCResourceManager::updateDispResRegulationPreProc(resource_request_t *req)
1702 {
1703     ICO_TRA("CicoSCResourceManager::updateDispResRegulationPreProc Enter");
1704 #if 1   //DEBUG
1705     dumpCurDispResOwerReq();
1706     dumpWaitingDispResReq();
1707 #endif  //DEBUG
1708
1709     if (NULL == req) {
1710         ICO_TRA("CicoSCResourceManager::updateDispResRegulationPreProc Leave");
1711         return;
1712     }
1713
1714     if (false == m_policyMgr->getRegulation()) {
1715         ICO_TRA("CicoSCResourceManager::updateDispResRegulationPreProc Leave");
1716         return;
1717     }
1718
1719     CicoSystemConfig *sysConf = CicoSystemConfig::getInstance();
1720     const CicoSCAppKindConf *appKindConf = NULL;
1721     appKindConf = sysConf->findAppKindConfbyId(req->appkind);
1722     if (NULL == appKindConf) {
1723         ICO_ERR("not found CicoSCAppKindConf instance");
1724         ICO_TRA("CicoSCResourceManager::updateDispResRegulationPreProc Leave");
1725         return;
1726     }
1727
1728     if ((appKindConf->privilege == CicoSCAppKindConf::PRIVILEGE_ALMIGHTY) ||
1729         (appKindConf->privilege == CicoSCAppKindConf::PRIVILEGE_SYSTEM)   ||
1730         (appKindConf->privilege == CicoSCAppKindConf::PRIVILEGE_SYSTEM_VISIBLE)) {
1731
1732         if (NULL != m_winCtrl) {
1733             m_winCtrl->show(req->surfaceid,
1734                             req->animation,
1735                             req->animationTime);
1736         }
1737         delResourceRequest(req);
1738
1739         ICO_DBG("kind of system application");
1740         ICO_TRA("CicoSCResourceManager::updateDispResRegulationPreProc Leave");
1741         return;
1742     }
1743
1744     int surfaceid = req->surfaceid;
1745     if (NULL != m_winCtrl) {
1746         surfaceid = m_winCtrl->getDisplayedWindow(req->dispzoneid);
1747         if (-1 == surfaceid) {
1748             ICO_WRN("displayed surface id is invalid.");
1749             surfaceid = req->surfaceid;
1750         }
1751     }
1752
1753     if (req->surfaceid != surfaceid) {
1754         ICO_WRN("req->surfaceid(0x%08X) != displayedsurfaceid(0x%08X)",
1755                 req->surfaceid, surfaceid);
1756     }
1757
1758     resource_request_t *curreq = NULL;
1759     int min = ICO_DISPLAY0_ZONEID_MIN;
1760     int max = ICO_DISPLAY0_ZONEID_MAX;
1761     if ((req->dispzoneid >= min) && (req->dispzoneid <= max)) {
1762         for (int i = min; i <= max; ++i) {
1763             std::map<unsigned int, resource_request_t*>::iterator itr;
1764             itr = m_curDispResOwerReq.find(i);
1765             if (itr != m_curDispResOwerReq.end()) {
1766                 if (NULL != itr->second) {
1767                     curreq = itr->second;
1768                     break;
1769                 }
1770             }
1771         }
1772     }
1773
1774     min = ICO_DISPLAY1_ZONEID_MIN;
1775     max = ICO_DISPLAY1_ZONEID_MAX;
1776     if ((NULL == curreq) &&
1777         (req->dispzoneid >= min) && (req->dispzoneid <= max)) {
1778         for (int i = min; i <= max; ++i) {
1779             std::map<unsigned int, resource_request_t*>::iterator itr;
1780             itr = m_curDispResOwerReq.find(i);
1781             if (itr != m_curDispResOwerReq.end()) {
1782                 if (NULL != itr->second) {
1783                     curreq = itr->second;
1784                     break;
1785                 }
1786             }
1787         }
1788     }
1789
1790 #if 0
1791     resource_request_t *curreq = NULL;
1792     std::map<unsigned int, resource_request_t*>::iterator itr;
1793     itr = m_curDispResOwerReq.find(req->dispzoneid);
1794     if (itr != m_curDispResOwerReq.end()) {
1795         curreq = itr->second;
1796     }
1797 #endif
1798
1799     if (NULL != curreq) {
1800         ICO_DBG("Dequeue current display resource request"
1801                 "(req=0x%08x zone:%02d:%s appid=%s)",
1802                 curreq, curreq->dispzoneid, curreq->dispzone, curreq->appid);
1803         ICO_PRF("CHG_GUI_RES display deprived zone=%02d:%s appid=%s",
1804                 curreq->dispzoneid, curreq->dispzone, curreq->appid);
1805         m_curDispResOwerReq[curreq->dispzoneid] = NULL;
1806
1807         if (curreq->surfaceid != req->surfaceid) {
1808             resource_request_t *waitreq = popWaitingDispResReq(req);
1809             ICO_DBG("Enqueue waiting display resource request"
1810                     "(req=0x%08x zone:%02d:%s appid=%s)",
1811                     curreq, curreq->dispzoneid,
1812                     curreq->dispzone, curreq->appid);
1813             m_waitingDispResReq.push_front(curreq);
1814
1815             if (NULL != waitreq) {
1816                 ICO_DBG("Enqueue current display resource request"
1817                         "(req=0x%08x zone:%02d:%s appid=%s)",
1818                         waitreq, waitreq->dispzoneid,
1819                         waitreq->dispzone, waitreq->appid);
1820                 ICO_PRF("CHG_GUI_RES display acquired zone=%02d:%s appid=%s",
1821                         waitreq->dispzoneid, waitreq->dispzone, waitreq->appid);
1822                 m_curDispResOwerReq[waitreq->dispzoneid] = waitreq;
1823             }
1824         }
1825         else {
1826             ICO_DBG("Enqueue current display resource request"
1827                     "(req=0x%08x zone:%02d:%s appid=%s)",
1828                     curreq, curreq->dispzoneid,
1829                     curreq->dispzone, curreq->appid);
1830             ICO_PRF("CHG_GUI_RES display acquired zone=%02d:%s appid=%s",
1831                     curreq->dispzoneid, curreq->dispzone, curreq->appid);
1832             m_curDispResOwerReq[curreq->dispzoneid] = curreq;
1833         }
1834     }
1835     delResourceRequest(req);
1836
1837 #if 1   //DEBUG
1838     dumpCurDispResOwerReq();
1839     dumpWaitingDispResReq();
1840 #endif  //DEBUG
1841     ICO_TRA("CicoSCResourceManager::updateDispResRegulationPreProc Leave");
1842 }
1843
1844 //--------------------------------------------------------------------------
1845 /**
1846  *  @brief  update sound request for regulation pre-process
1847  */
1848 //--------------------------------------------------------------------------
1849 void
1850 CicoSCResourceManager::updateSoundResRegulationPreProc(resource_request_t *req)
1851 {
1852     ICO_TRA("CicoSCResourceManager::updateSoundResRegulationPreProc Enter");
1853
1854     if (NULL == req) {
1855         return;
1856     }
1857
1858     if (false == m_policyMgr->getRegulation()) {
1859         return;
1860     }
1861
1862     CicoSystemConfig *sysConf = CicoSystemConfig::getInstance();
1863     const CicoSCAppKindConf *appKindConf = NULL;
1864     appKindConf = sysConf->findAppKindConfbyId(req->appkind);
1865     if (NULL == appKindConf) {
1866         ICO_ERR("not found CicoSCAppKindConf instance");
1867         ICO_TRA("CicoSCResourceManager::updateSoundResRegulationPreProc Leave");
1868         return;
1869     }
1870
1871     if ((appKindConf->privilege == CicoSCAppKindConf::PRIVILEGE_ALMIGHTY) ||
1872         (appKindConf->privilege == CicoSCAppKindConf::PRIVILEGE_SYSTEM)   ||
1873         (appKindConf->privilege == CicoSCAppKindConf::PRIVILEGE_SYSTEM_AUDIO)) {
1874
1875         delResourceRequest(req);
1876
1877         ICO_DBG("kind of system application");
1878         ICO_TRA("CicoSCResourceManager::updateSoundResRegulationPreProc Leave");
1879         return;
1880     }
1881
1882     resource_request_t *curreq = NULL;
1883     std::map<int, resource_request_t*>::iterator itr;
1884     itr = m_curSoundResReq.find(req->soundzoneid);
1885     if (itr != m_curSoundResReq.end()) {
1886         curreq = itr->second;
1887     }
1888
1889     if (NULL != curreq) {
1890         ICO_DBG("Dequeue current sound resource request"
1891                 "(req=0x%08x zone:%02d:%s appid=%s)",
1892                 curreq, curreq->soundzoneid, curreq->soundzone, curreq->appid);
1893         ICO_PRF("CHG_GUI_RES sound   deprived zone=%02d:%s appid=%s",
1894                 curreq->soundzoneid, curreq->soundzone, curreq->appid);
1895         m_curSoundResReq[curreq->soundzoneid] = NULL;
1896
1897         if (0 != strcmp(curreq->appid, req->appid)) {
1898             resource_request_t *waitreq = popSoundResReq(req);
1899             ICO_DBG("Enqueue waiting sound resource request"
1900                     "(req=0x%08x zone:%02d:%s appid=%s)",
1901                     curreq, curreq->soundzoneid,
1902                     curreq->soundzone, curreq->appid);
1903             m_soundReqQueue[curreq->soundzoneid].push_front(curreq);
1904
1905             if (NULL != waitreq) {
1906                 ICO_DBG("Enqueue current sound resource request"
1907                         "(req=0x%08x zone:%02d:%s appid=%s)",
1908                         waitreq, waitreq->soundzoneid,
1909                         waitreq->soundzone, waitreq->appid);
1910                 ICO_PRF("CHG_GUI_RES sound   acquired zone=%02d:%s appid=%s",
1911                         waitreq->soundzoneid, waitreq->soundzone,
1912                         waitreq->appid);
1913                 m_curSoundResReq[curreq->soundzoneid] = waitreq;
1914             }
1915         }
1916         else {
1917             ICO_DBG("Enqueue current sound resource request"
1918                     "(req=0x%08x zone:%02d:%s appid=%s)",
1919                     curreq, curreq->soundzoneid,
1920                     curreq->soundzone, curreq->appid);
1921             ICO_PRF("CHG_GUI_RES sound   acquired zone=%d:%s appid=%s",
1922                     curreq->soundzoneid, curreq->soundzone, curreq->appid);
1923             m_curSoundResReq[curreq->soundzoneid] = curreq;
1924         }
1925     }
1926     delResourceRequest(req);
1927     ICO_TRA("CicoSCResourceManager::updateSoundResRegulationPreProc Leave");
1928 }
1929
1930 //--------------------------------------------------------------------------
1931 /**
1932  *  @brief  update input request for regulation pre-process
1933  */
1934 //--------------------------------------------------------------------------
1935 void
1936 CicoSCResourceManager::updateInputResRegulationPreProc(resource_request_t *req)
1937 {
1938     ICO_TRA("CicoSCResourceManager::updateInputResRegulationPreProc Enter");
1939
1940     if (NULL == req) {
1941         return;
1942     }
1943
1944     if (false == m_policyMgr->getRegulation()) {
1945         return;
1946     }
1947
1948     resource_request_t *curreq = NULL;
1949     std::map<int, resource_request_t*>::iterator itr;
1950     itr = m_curInputResReq.find(req->input);
1951     if (itr != m_curInputResReq.end()) {
1952         curreq = itr->second;
1953     }
1954
1955     if (NULL != curreq) {
1956         ICO_DBG("Dequeue current input resource request"
1957                 "(req=0x%08x input:%d appid=%s)",
1958                 curreq, curreq->input, curreq->appid);
1959         ICO_PRF("CHG_GUI_RES input   deprived input=%d appid=%s",
1960                 curreq->input, curreq->appid);
1961         m_curInputResReq[curreq->input] = NULL;
1962
1963         if (0 != strcmp(curreq->appid, req->appid)) {
1964             resource_request_t *waitreq = popInputResReq(req);
1965             ICO_DBG("Enqueue waiting input resource request"
1966                     "(req=0x%08x input:%d appid=%s)",
1967                     curreq, curreq->input, curreq->appid);
1968             m_inputReqQueue[curreq->input].push_front(curreq);
1969
1970             if (NULL != waitreq) {
1971                 ICO_DBG("Enqueue current input resource request"
1972                         "(req=0x%08x input:%d appid=%s)",
1973                         waitreq, waitreq->input, waitreq->appid);
1974                 ICO_PRF("CHG_GUI_RES input   acquired input=%d appid=%s",
1975                         waitreq->input, waitreq->appid);
1976                 m_curInputResReq[curreq->input] = waitreq;
1977             }
1978         }
1979         else {
1980             ICO_DBG("Enqueue current input resource request"
1981                     "(req=0x%08x input:%d appid=%s)",
1982                     curreq, curreq->input, curreq->appid);
1983             ICO_PRF("CHG_GUI_RES input   acquired input=%d appid=%s",
1984                     curreq->input, curreq->appid);
1985             m_curInputResReq[curreq->input] = curreq;
1986         }
1987     }
1988     delResourceRequest(req);
1989     ICO_TRA("CicoSCResourceManager::updateInputResRegulationPreProc Leave");
1990 }
1991
1992 //--------------------------------------------------------------------------
1993 /**
1994  *  @brief  compare displayed surface and ower surface
1995  */
1996 //--------------------------------------------------------------------------
1997 bool
1998 CicoSCResourceManager::isMatchDisplayed(void)
1999 {
2000     bool ret = false;
2001     std::map<unsigned int, resource_request_t*>::iterator itr;
2002     itr = m_curDispResOwerReq.begin();
2003     for (; itr != m_curDispResOwerReq.end(); ++itr) {
2004         if (NULL == itr->second) {
2005             continue;
2006         }
2007         if (NULL != m_winCtrl) {
2008             int surfaceid = m_winCtrl->getDisplayedWindow(
2009                                         itr->second->dispzoneid);
2010             std::map<unsigned int, resource_request_t*>::iterator itr2;
2011             itr2 = m_curDispResOwerReq.begin();
2012             for (; itr2 != m_curDispResOwerReq.end(); ++itr2) {
2013                 if (NULL == itr2->second) {
2014                     continue;
2015                 }
2016                 if ((itr2->second->surfaceid == surfaceid)) {
2017                     ret = true;
2018                     break;  // break of for itr2
2019                 }
2020             }
2021         }
2022         if (true == ret) {
2023             break;  // break of for itr
2024         }
2025     }
2026     return ret;
2027 }
2028
2029 bool
2030 CicoSCResourceManager::acquireOnScreenDisplayResource(resource_request_t *newreq)
2031 {
2032     ICO_TRA("Enter (%08x)", newreq);
2033     if (NULL == newreq) {
2034         ICO_TRA("Leave param is NULL pointer");
2035         return false;
2036     }
2037     CicoSystemConfig *sysConf = CicoSystemConfig::getInstance();
2038
2039     if (0 == newreq->role_stt) {
2040         newreq->role_stt = sysConf->getRoleStt(newreq->role);
2041     }
2042     m_OnScreenItems.push_back(newreq);
2043
2044     const resource_request_t* rrtHO = getNoticeOfHighOder();
2045     if (NULL == rrtHO) {
2046         ICO_TRA("Leave %s, %d is not notice", newreq->role, newreq->resourceId);
2047         return false;
2048     }
2049 #if 1
2050     const CicoSCWindow* nwo = m_winCtrl->findWindowObj(newreq->pid,
2051                                                        newreq->resourceId);
2052 #endif
2053     const CicoSCWindow* bwo = NULL; // before window oject
2054     const CicoSCWindow* awo = NULL; // after window object
2055
2056     if (NULL != m_rrtHO) {
2057         bwo = m_winCtrl->findWindowObj(m_rrtHO->pid, m_rrtHO->resourceId);
2058     }
2059     if (NULL != rrtHO) {
2060         awo = m_winCtrl->findWindowObj(rrtHO->pid, rrtHO->resourceId);
2061     }
2062     if ((NULL == m_rrtHO) && (NULL != rrtHO)) { // none -> on notice
2063         ICO_TRA("_____ OPEN Layer \"%s\":%d", rrtHO->role, rrtHO->resourceId);
2064         if (NULL != awo) {
2065             m_winCtrl->showLayer(awo->displayid, awo->layerid);
2066         }
2067         else {
2068             ICO_WRN("ON SCREEN none layer");
2069         }
2070     }
2071 #if 1
2072     if ((NULL != nwo) && (awo != nwo) && (bwo != nwo)) {
2073         ICO_TRA("_____ HIDW new REQUEST %x:%s:%d", newreq, newreq->role,
2074                 newreq->resourceId);
2075         m_winCtrl->hide(nwo->surfaceid, NULL, 0);
2076     }
2077 #endif
2078     if (rrtHO != m_rrtHO) { // change Hige Oder notice
2079         if (NULL != m_rrtHO) {
2080             ICO_TRA("_____ HIDE surface %x:%s:%d", m_rrtHO, m_rrtHO->role,
2081                     m_rrtHO->resourceId);
2082             if (NULL != bwo) {
2083                 m_winCtrl->hide(bwo->surfaceid, NULL, 0);
2084             }
2085             else {
2086                 ICO_WRN("ON SCREEN none Hide control");
2087             }
2088             resCB(ICO_SYC_EV_RES_WAITING, *m_rrtHO);
2089         }
2090         ICO_TRA("_____ SHOW surface %x:%s:%d", rrtHO, rrtHO->role, rrtHO->resourceId);
2091         if (NULL != awo) {
2092             m_winCtrl->show(awo->surfaceid, NULL, 0);
2093         }
2094         else {
2095             ICO_WRN("ON SCREEN none show control");
2096         }
2097         resCB(ICO_SYC_EV_RES_ACQUIRE, *rrtHO);
2098         ICO_TRA("_____ change %x -> %x", m_rrtHO, rrtHO);
2099         m_rrtHO = rrtHO;
2100     }
2101 //-    if (m_rrtHO != newreq) {
2102 //-        resCB(ICO_SYC_EV_RES_WAITING, *newreq);
2103 //-    }
2104     else {
2105         ICO_TRA("_____ no change %x", m_rrtHO);
2106         if (NULL != awo) {
2107             m_winCtrl->show(awo->surfaceid, NULL, 0);
2108             m_winCtrl->raise(awo->surfaceid, NULL, 0);
2109         }
2110         if (m_rrtHO != newreq) {
2111             resCB(ICO_SYC_EV_RES_WAITING, *newreq);
2112         }
2113     }
2114     ICO_TRA("Leave");
2115     return true;
2116 }
2117
2118 bool
2119 CicoSCResourceManager::releaseOnScreenDisplayResource(resource_request_t *req)
2120 {
2121     ICO_TRA("Enter %08x", req);
2122     if (NULL == req) {
2123         ICO_TRA("Leave param is NULL pointer");
2124         return false;
2125     }
2126     resource_request_t* tgt = NULL;
2127     list<resource_request_t*>::iterator itr = m_OnScreenItems.begin();
2128     for (; itr != m_OnScreenItems.end(); ++itr) {
2129         if ((req->pid == (*itr)->pid) &&
2130             (req->resourceId == (*itr)->resourceId)) {
2131             tgt = (*itr);
2132             break;  // break of for itr
2133         }
2134     }
2135
2136     if (NULL != tgt) {
2137         ICO_TRA("_____ erase list %x", tgt);
2138         m_OnScreenItems.erase(itr);
2139     }
2140
2141     const resource_request_t* rrtHO = getNoticeOfHighOder();
2142
2143     const CicoSCWindow* bwo = NULL; // before window oject
2144     const CicoSCWindow* awo = NULL; // after window object
2145     if (NULL != m_rrtHO) {
2146         bwo = m_winCtrl->findWindowObj(m_rrtHO->pid, m_rrtHO->resourceId);
2147     }
2148     if (NULL != rrtHO) {
2149         awo = m_winCtrl->findWindowObj(rrtHO->pid, rrtHO->resourceId);
2150     }
2151
2152     if ((NULL == rrtHO) && (NULL == m_rrtHO)) {
2153         ICO_WRN("ON SCREEN Resource NG");
2154         if (NULL != tgt) {
2155             resCB(ICO_SYC_EV_RES_RELEASE, *tgt);
2156             delResourceRequest(tgt);
2157         }
2158         delResourceRequest(req);
2159         ICO_TRA("Leave ON SCREEN Resource NG");
2160         return false;
2161     }
2162
2163     if (rrtHO != m_rrtHO) {
2164         if (NULL != m_rrtHO) {
2165             if (NULL != bwo) {
2166                 m_winCtrl->hide(bwo->surfaceid, NULL, 0);
2167                 if (m_rrtHO != tgt) {
2168                     ICO_DBG("_____ NG Control OnScreen Resource %x(%d, %d), %x",
2169                             m_rrtHO, m_rrtHO->pid, m_rrtHO->resourceId, tgt);
2170                     resCB(ICO_SYC_EV_RES_WAITING, *m_rrtHO);
2171                 }
2172             }
2173             else {
2174                 ICO_WRN("ON SCREEN Hide control NG");
2175             }
2176         }
2177         if (NULL != rrtHO) {
2178             if (NULL != awo) {
2179                 m_winCtrl->show(awo->surfaceid, NULL, 0);
2180                 m_winCtrl->raise(awo->surfaceid, NULL, 0);
2181                 resCB(ICO_SYC_EV_RES_ACQUIRE, *rrtHO);
2182             }
2183             else {
2184                 ICO_WRN("ON SCREEN Hide control NG");
2185             }
2186         }
2187         else {
2188             if (NULL != bwo) {
2189                 m_winCtrl->hideLayer(bwo->displayid, bwo->layerid);
2190             }
2191             else {
2192                 ICO_WRN("ON SCREEN layer hide control NG");
2193             }
2194         }
2195         m_rrtHO = rrtHO;
2196     }
2197     else {
2198         ICO_TRA("_____ no change");
2199     }
2200     // memory free
2201     if (NULL != tgt) {
2202         resCB(ICO_SYC_EV_RES_RELEASE, *tgt);
2203         delResourceRequest(tgt);
2204     }
2205     delResourceRequest(req);
2206     ICO_TRA("Leave");
2207     return true;
2208 }
2209
2210 bool
2211 CicoSCResourceManager::resCB(const ico_syc_ev_e ev, const resource_request_t& p) const
2212 {
2213     ICO_TRA("Enter %d", (int)ev);
2214     if ((NULL == p.appid) || (0 == strlen(p.appid))) {
2215         ICO_TRA("Leave false");
2216         return false;
2217     }
2218     if (false == p.bEx) {
2219         ICO_TRA("Leave false");
2220         return false;
2221     }
2222     int nEv = -1;
2223     if (ICO_SYC_EV_RES_ACQUIRE == ev) {
2224         nEv = MSG_CMD_ACQUIRE_RES;
2225     }
2226     else if (ICO_SYC_EV_RES_DEPRIVE == ev) {
2227         nEv = MSG_CMD_DEPRIVE_RES;
2228     }
2229     else if (ICO_SYC_EV_RES_WAITING == ev) {
2230         nEv = MSG_CMD_WAITING_RES;
2231     }
2232     else if (ICO_SYC_EV_RES_REVERT == ev) {
2233         nEv = MSG_CMD_REVERT_RES;
2234     }
2235     else if (ICO_SYC_EV_RES_RELEASE == ev) {
2236         nEv = MSG_CMD_RELEASE_RES;
2237     }
2238     else if (ICO_SYC_EV_RES_WINDOW_ID == ev) {
2239         nEv = MSG_CMD_WINDOW_ID_RES;
2240     }
2241     else {
2242         ICO_TRA("Leave false ev(%d) is not supp.",(int)ev);
2243         return false;
2244     }
2245
2246     bool r;
2247     r = resCB(p.appid, nEv, p.ECU, p.display, p.layer, p.layout, p.area,
2248               p.dispatchApp, p.role, p.resourceId);
2249     ICO_TRA("Leave %s", r? "true":"false");
2250     return r;
2251 }
2252
2253 bool
2254 CicoSCResourceManager::resCB(const char* sendToAppid, const int ev,
2255                              const char* ECU, const char* display,
2256                              const char* layer, const char* layout,
2257                              const char* area, const char* dispatchApp,
2258                              const char* role, uint32_t resourceId) const
2259 {
2260     ICO_TRA("Enter");
2261     if (NULL == sendToAppid) {
2262         ICO_TRA("Leave false");
2263         return false;
2264     }
2265     CicoSCMessageRes* msg = new CicoSCMessageRes();
2266     msg->addRootObject("command", ev);
2267     if (NULL != ECU) {
2268         msg->addWinObject("ECU", ECU);
2269     }
2270     if (NULL != display) {
2271         msg->addWinObject("display", display);
2272     }
2273     if (NULL != layer) {
2274         msg->addWinObject("layer", layer);
2275     }
2276     if (NULL != layout) {
2277         msg->addWinObject("layout", layout);
2278     }
2279     if (NULL != area) {
2280         msg->addWinObject("area", area);
2281     }
2282     if (NULL != dispatchApp) {
2283         msg->addWinObject("dispatchApp", dispatchApp);
2284     }
2285     if (NULL != role) {
2286         msg->addWinObject("role", role);
2287     }
2288     msg->addWinObject("resourceId", resourceId);
2289     CicoSCServer *cscs = CicoSCServer::getInstance();
2290     int r = cscs->sendMessage(sendToAppid, (CicoSCMessage*)msg);
2291     if (ICO_SYC_EOK != r) {
2292         ICO_TRA("Leave false(%d)", r);
2293         return false;
2294     }
2295     ICO_TRA("Leave true");
2296     return true;
2297 }
2298
2299 const resource_request_t* CicoSCResourceManager::getNoticeOfHighOder()
2300 {
2301     ICO_TRA("Enter (%d)", (int)m_OnScreenItems.size());
2302     const CicoSCRoleConf* rC = CicoSystemConfig::getInstance()->getRoleConf();
2303     m_policyMgr->sendSMEvent(rC->m_rst); // RESET OnScreen State
2304     const resource_request_t* r = NULL;
2305     list<resource_request_t*>::iterator itr = m_OnScreenItems.begin();
2306     for (; itr != m_OnScreenItems.end(); ++itr) {
2307         short hEv = (*itr)->role_stt;
2308         if ((ICO_SYC_ROLE_CONF_DEF == hEv) || (0 == hEv)) {
2309             continue;  // continue of for itr
2310         }
2311         bool test = m_policyMgr->testSMEvent(hEv);
2312         if (true == m_policyMgr->sendSMEvent(hEv)) {
2313             r = (*itr);
2314         }
2315         else if (true == test) {
2316             r = (*itr);
2317         }
2318     }
2319     ICO_TRA("Leave %x", r);
2320     return r;
2321 }
2322
2323 // vim:set expandtab ts=4 sw=4: