sync with master
[framework/osp/common-service.git] / src / FUi_UiManagerStub.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file         FUi_UiManagerStub.cpp
20  * @brief       This is the implementation for the _UiManagerStub class.
21  */
22
23 #include <cstdio>
24 #include <dlfcn.h>
25 #include <utilX.h>
26 #include <Ecore_X.h>
27 #include <FBaseSysLog.h>
28 #include <FBase_StringConverter.h>
29 #include <FIo_IpcServer.h>
30 #include <FSec_AccessController.h>
31 #include <FUi_UiManagerIpcMessages.h>
32 #include "FUi_UiManagerStub.h"
33
34 using namespace std;
35 using namespace Tizen::Base;
36 using namespace Tizen::Base::Collection;
37 using namespace Tizen::Io;
38 using namespace Tizen::Security;
39
40 namespace Tizen { namespace Ui
41 {
42
43 enum _ZOrderGroup
44 {
45         _Z_ORDER_GROUP_HIGHEST,
46         _Z_ORDER_GROUP_HIGH,
47         _Z_ORDER_GROUP_NORMAL,
48 };
49
50 _UiManagerStub::_UiManagerStub(void)
51 {
52 }
53
54 _UiManagerStub::~_UiManagerStub(void)
55 {
56         if (__pIpcServer)
57         {
58                 __pIpcServer->Stop();
59         }
60 }
61
62 result
63 _UiManagerStub::Construct(void)
64 {
65         result r = StartIpcServer();
66         SysTryReturnResult(NID_UI, r == E_SUCCESS, r, "Propagating.");
67
68         return E_SUCCESS;
69 }
70
71 result
72 _UiManagerStub::StartIpcServer(void)
73 {
74         unique_ptr<_IpcServer> pIpcServer(new (std::nothrow) _IpcServer());
75         SysTryReturnResult(NID_UI, pIpcServer, E_OUT_OF_MEMORY, "Memory is insufficient.");
76
77         result r = pIpcServer->Construct(L"osp.ui.ipcserver.uimanager", *this, true);
78         SysTryReturnResult(NID_UI, r == E_SUCCESS, r, "Propagating.");
79
80         r = pIpcServer->Start();
81         SysTryReturnResult(NID_UI, r == E_SUCCESS, r, "Propagating.");
82
83         __pIpcServer = move(pIpcServer);
84
85         return E_SUCCESS;
86 }
87
88 bool
89 _UiManagerStub::OnSetZOrderGroup(unsigned int window, int windowZOrderGroup, result* pResult)
90 {
91         SysLog(NID_UI, "IPC message(0x%x, %d) is received.", window, windowZOrderGroup);
92
93         *pResult = _AccessController::CheckSystemPrivilege(__pIpcServer->GetClientAppId(), _PRV_UIMANAGER);
94         SysTryReturn(NID_UI, *pResult == E_SUCCESS, true, *pResult, "[%s] Propagating.", GetErrorMessage(*pResult));
95
96         Ecore_X_Window win = (Ecore_X_Window)window;
97         ecore_x_icccm_transient_for_unset(win);
98         
99         if (windowZOrderGroup == _Z_ORDER_GROUP_NORMAL)
100         {
101                 ecore_x_netwm_window_type_set(win, ECORE_X_WINDOW_TYPE_NORMAL);
102         }
103         else if (windowZOrderGroup == _Z_ORDER_GROUP_HIGHEST)
104         {
105                 ecore_x_netwm_window_type_set(win, ECORE_X_WINDOW_TYPE_NOTIFICATION);
106                 utilx_set_system_notification_level((Display*)ecore_x_display_get(), win, UTILX_NOTIFICATION_LEVEL_HIGH);
107         }
108         else if (windowZOrderGroup == _Z_ORDER_GROUP_HIGH)
109         {
110                 ecore_x_netwm_window_type_set(win, ECORE_X_WINDOW_TYPE_NOTIFICATION);
111                 utilx_set_system_notification_level((Display*)ecore_x_display_get(), win, UTILX_NOTIFICATION_LEVEL_NORMAL);
112         }
113
114         return true;
115 }
116
117 void
118 _UiManagerStub::OnIpcRequestReceived(_IpcServer& server, const IPC::Message& message)
119 {
120         IPC_BEGIN_MESSAGE_MAP(_UiManagerStub, message)
121                 IPC_MESSAGE_HANDLER_EX(UiManager_SetZOrderGroup, &server, OnSetZOrderGroup)
122         IPC_END_MESSAGE_MAP()
123 }
124
125 void
126 _UiManagerStub::OnIpcServerStarted(const _IpcServer& server)
127 {
128 }
129
130 void
131 _UiManagerStub::OnIpcServerStopped(const _IpcServer& server)
132 {
133 }
134
135 void
136 _UiManagerStub::OnIpcClientConnected(const _IpcServer& server, int clientId)
137 {
138 }
139
140 void
141 _UiManagerStub::OnIpcClientDisconnected(const _IpcServer&server, int clientId)
142 {
143 }
144
145 }} // Tizen::Ui