49875ce8c9751d9044825cfe6fa7d9bd95600af1
[platform/core/uifw/pepper-dali.git] / pepper-dali / internal / shell-impl.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <pepper-dali/internal/shell-impl.h>
20
21 // INTERNAL INCLUDES
22 #include <pepper-dali/internal/compositor-impl.h>
23
24 // EXTERNAL INCLUDES
25 #include <dali/integration-api/debug.h>
26 #include <xdg-shell-server-protocol.h>
27
28 namespace Dali
29 {
30
31 namespace Pepper
32 {
33
34 namespace Internal
35 {
36
37 namespace
38 {
39
40 #if defined(DEBUG_ENABLED)
41 Integration::Log::Filter* gPepperShellLogging  = Integration::Log::Filter::New( Debug::Verbose, false, "LOG_PEPPER_SHELL" );
42 #endif
43
44 static void ClientDestroyed( struct wl_listener* listener, void* data )
45 {
46   ShellClientInfo* shellClientInfo = wl_container_of( listener, shellClientInfo, mDestroyListner );
47
48   shellClientInfo->mShell->OnClientDestroyed( shellClientInfo->mShellClient );
49 }
50
51 } // unnamed namespace
52
53 ShellPtr Shell::New( Pepper::Compositor compositor )
54 {
55   ShellPtr impl = new Shell();
56
57   // Second-phase init of the implementation
58   impl->Initialize( compositor );
59
60   return impl;
61 }
62
63 Shell::Shell()
64 : mShellClientList()
65 {
66 }
67
68 Shell::~Shell()
69 {
70   mShellClientList.clear();
71 }
72
73 void Shell::Initialize( Pepper::Compositor& compositor )
74 {
75   struct wl_display* display;
76
77   mCompositor = compositor;
78
79   display = pepper_compositor_get_display( static_cast< pepper_compositor_t* >( Pepper::GetImplementation( compositor ).GetCompositorHandle() ) );
80
81   if( !wl_global_create( display, &xdg_shell_interface, 1, this, Shell::OnBind ) )
82   {
83     DALI_LOG_INFO( gPepperShellLogging, Debug::General, "wl_global_create is failed\n" );
84   }
85
86   DALI_LOG_INFO( gPepperShellLogging, Debug::Verbose, "Shell::Initialize: success\n" );
87 }
88
89 void Shell::OnBind( struct wl_client* client, void* data, uint32_t version, uint32_t id )
90 {
91   Shell* shell = static_cast< Shell* >( data );
92
93   Pepper::ShellClient shellClient = Pepper::ShellClient::New( shell->mCompositor, client, version, id );
94
95   shell->mShellClientList.push_back( shellClient );
96
97   ShellClientInfo* shellClientInfo = new ShellClientInfo;
98
99   shellClientInfo->mShell = shell;
100   shellClientInfo->mShellClient = shellClient;
101   shellClientInfo->mDestroyListner.notify = ClientDestroyed;
102
103   wl_client_add_destroy_listener( client, &shellClientInfo->mDestroyListner );
104
105   DALI_LOG_INFO( gPepperShellLogging, Debug::Verbose, "Shell::OnBind: success\n" );
106 }
107
108 void Shell::OnClientDestroyed( Pepper::ShellClient shellClient )
109 {
110   for ( std::vector< Pepper::ShellClient >::iterator iter = mShellClientList.begin(); mShellClientList.end() != iter; ++iter )
111   {
112     if( *iter == shellClient )
113     {
114       mShellClientList.erase( iter );
115     }
116   }
117
118   DALI_LOG_INFO( gPepperShellLogging, Debug::Verbose, "Shell::OnClientDestroyed: success\n" );
119 }
120
121 } // namespace Internal
122
123 } // namespace Pepper
124
125 } // namespace Dali