DSTraceInfo: print out windows' infomation(pid,title,,etc.)
[platform/core/uifw/libds.git] / src / DSTraceInfo / DSTraceInfo.cpp
1 /*
2 * Copyright © 2020 Samsung Electronics co., Ltd. All Rights Reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 #include "DSTraceInfo.h"
25 #include "DSPolicyAreaPrivate.h"
26
27 namespace display_server
28 {
29 DSTraceInfo::DSTraceInfo()
30         : __policyArea(nullptr),
31           __zone(nullptr),
32           __eventLoop(nullptr),
33           __windowUpdated(false)
34 {
35         __eventLoop = DSEventLoop::getInstance();
36         if (__eventLoop)
37                 __eventLoop->registerCallbackIdleEnterer(this, std::bind(&DSTraceInfo::__onEventIdleEnterer, this, std::placeholders::_1));
38 }
39
40 DSTraceInfo::~DSTraceInfo()
41 {
42         if (__eventLoop)
43                 DSEventLoop::releaseInstance();
44 }
45
46 bool DSTraceInfo::attachPolicyArea(std::shared_ptr<DSPolicyArea> policyArea)
47 {
48         __policyArea = policyArea;
49
50         DSPolicyAreaPrivate *policyAreaPriv = DSPolicyAreaPrivate::getPrivate(__policyArea.get());
51         __zone = policyAreaPriv->getZone();
52
53         if (__zone == nullptr) {
54                 DSLOG_ERR("DSTraceInfo", "No zone attached to this policyArea(%p)", policyArea);
55                 return false;
56         }
57
58         __zone->registerCallbackWindowCreated(this, std::bind(&DSTraceInfo::__onWindowCreated, this, std::placeholders::_1));
59         __zone->registerCallbackWindowStackChanged(this, std::bind(&DSTraceInfo::__onWindowStackChanged, this, std::placeholders::_1));
60         __zone->registerCallbackWindowDestroy(this, std::bind(&DSTraceInfo::__onWindowDestroy, this, std::placeholders::_1));
61
62         __windowList = __zone->getWindowList();
63
64         return true;
65 }
66
67 void DSTraceInfo::__onEventIdleEnterer(void *data)
68 {
69         if (__windowUpdated)
70         {
71                 printWindowsInfo();
72                 __windowUpdated = false;
73         }
74 }
75
76 void DSTraceInfo::printWindowsInfo()
77 {
78         DSLOG_INF("DSTraceInfo", "--------------Top level windows: %d--------------", __windowList.size());
79         DSLOG_INF("DSTraceInfo", " No   Win_ID   PID    w    h    x    y   (S)kipFoc has(F)ocus (U)serGeom (V)kbdFloating Parent   Title");
80
81         for (std::shared_ptr<DSWindow> w : __windowList)
82         {
83                 stPosition pos = w->getPosition();
84                 stSize sz = w->getSize();
85                 DSWaylandSurface *dwlSurface = w->surface();
86                 DSWaylandClient *dwClient = dwlSurface->getClient();
87                 pid_t pid = dwClient->pid();
88                 DSLOG_INF("DSTraceInfo", " %d: %p %d %4d %4d %4d %4d     %c         %c        %c        %c          %p  %s", w->getZOrder(), w.get(), pid, \
89                            sz.w, sz.h, pos.x, pos.y, w->getSkipFocus()?'S':' ', w->hasFocus()?'F':' ', w->isAllowUserGeometry()?'U':' ', w->getVkbdFloating()?'V':' ', \
90                            w->getParent(), (w->getTitle().compare("") == 0)?"No Title":w->getTitle().c_str());
91         }
92
93     DSLOG_INF("DSTraceInfo", "------------------------------------------------");
94 }
95
96 void DSTraceInfo::__onWindowCreated(std::shared_ptr<DSWindow> window)
97 {
98     __windowList.remove(window);
99     __windowList.push_front(window);
100
101     __windowUpdated = true;
102 }
103
104 void DSTraceInfo::__onWindowStackChanged(std::shared_ptr<DSWindow> window)
105 {
106     __windowList = __zone->getWindowList();
107
108     __windowUpdated = true;
109 }
110
111 void DSTraceInfo::__onWindowDestroy(std::shared_ptr<DSWindow> window)
112 {
113     __windowList.remove(window);
114
115     __windowUpdated = true;
116 }
117
118 }