3 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
5 * Licensed under the Flora License, Version 1.1 (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
9 * http://floralicense.org/license/
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.
19 #include <internal/widget_view_manager/widget_view_manager_impl.h>
22 #include <internal/widget_view/widget_view_impl.h>
25 #include <dali/public-api/object/type-registry.h>
26 #include <dali/public-api/object/type-registry-helper.h>
27 #include <dali/integration-api/debug.h>
28 #include <system_info.h>
29 #include <cynara-client.h>
33 #include <widget_errno.h>
34 #include <widget_instance.h>
35 #include <aul_rsm_viewer.h>
49 #define SMACK_LABEL_LENGTH 255
51 #if defined(DEBUG_ENABLED)
52 Integration::Log::Filter* gWidgetViewManagerLogging = Integration::Log::Filter::New( Debug::Verbose, false, "LOG_WIDGET_VIEW_MANAGER" );
57 return Dali::BaseHandle();
60 DALI_TYPE_REGISTRATION_BEGIN( Dali::WidgetView::WidgetViewManager, Dali::BaseHandle, Create );
62 static bool IsWidgetFeatureEnabled()
64 static bool feature = false;
65 static bool retrieved = false;
68 if( retrieved == true )
71 ret = system_info_get_platform_bool( "http://tizen.org/feature/shell.appwidget", &feature );
72 if( ret != SYSTEM_INFO_ERROR_NONE )
82 static bool CheckPrivilege( const char* privilege )
87 char subjectLabel[SMACK_LABEL_LENGTH + 1] = "";
88 char uid[10] = { 0, };
89 const char* clientSession = "";
91 ret = cynara_initialize( &cynara, NULL );
92 if( ret != CYNARA_API_SUCCESS )
97 fd = open( "/proc/self/attr/current", O_RDONLY );
100 cynara_finish( cynara );
104 ret = read( fd, subjectLabel, SMACK_LABEL_LENGTH );
108 cynara_finish( cynara );
114 snprintf( uid, 10, "%d", getuid() );
116 ret = cynara_check( cynara, subjectLabel, clientSession, uid, privilege );
117 if( ret != CYNARA_API_ACCESS_ALLOWED )
119 cynara_finish( cynara );
123 cynara_finish( cynara );
128 } // unnamed namespace
130 WidgetViewManagerPtr WidgetViewManager::New( Application application, const std::string& name )
132 WidgetViewManagerPtr impl = new WidgetViewManager();
134 // Second-phase init of the implementation
135 if( impl->Initialize( application, name ) != WIDGET_ERROR_NONE )
137 DALI_LOG_INFO( gWidgetViewManagerLogging, Debug::Verbose, "WidgetViewManager::New: Fail to create WidgetViewManager.\n" );
144 WidgetViewManager::WidgetViewManager()
148 WidgetViewManager::~WidgetViewManager()
150 aul_rsm_viewer_fini();
151 widget_instance_unlisten_event( WidgetViewManager::WidgetEventCallback );
152 widget_instance_fini();
155 int WidgetViewManager::Initialize( Application application, const std::string& name )
157 if( !IsWidgetFeatureEnabled() )
159 DALI_LOG_INFO( gWidgetViewManagerLogging, Debug::Verbose, "WidgetViewManager::Initialize: Widget feature is not enabled.\n" );
160 return WIDGET_ERROR_NOT_SUPPORTED;
163 if( !CheckPrivilege( "http://tizen.org/privilege/widget.viewer" ) )
165 DALI_LOG_INFO( gWidgetViewManagerLogging, Debug::Verbose, "WidgetViewManager::Initialize: Privilege error.\n" );
166 return WIDGET_ERROR_PERMISSION_DENIED;
169 // Binds tizen remote surface manager & connects callback
170 if( aul_rsm_viewer_init() < 0 )
172 return WIDGET_ERROR_FAULT;
175 // init widget service
176 widget_instance_init( name.c_str() );
177 widget_instance_listen_event( WidgetViewManager::WidgetEventCallback, this );
179 DALI_LOG_INFO( gWidgetViewManagerLogging, Debug::Verbose, "WidgetViewManager::Initialize: success.\n" );
181 return WIDGET_ERROR_NONE;
184 Dali::WidgetView::WidgetView WidgetViewManager::AddWidget( const std::string& widgetId, const std::string& contentInfo, int width, int height, float updatePeriod )
186 // Add a new widget view
187 Dali::WidgetView::WidgetView widgetView = Dali::WidgetView::WidgetView::New( widgetId, contentInfo, width, height, updatePeriod );
189 std::string instanceId;
190 Property::Value value = widgetView.GetProperty( Dali::WidgetView::WidgetView::Property::INSTANCE_ID );
191 value.Get( instanceId );
193 if( !instanceId.empty() )
196 mWidgetViewContainer.insert( std::pair<std::string, Dali::WidgetView::WidgetView>( instanceId, widgetView ) );
199 DALI_LOG_INFO( gWidgetViewManagerLogging, Debug::Verbose, "WidgetViewManager::AddWidget: success [%s]\n", widgetId.c_str() );
204 int WidgetViewManager::WidgetEventCallback( const char* widgetId, const char* instanceId, int event, void* data )
206 WidgetViewManager* widgetViewManager = static_cast< WidgetViewManager* >( data );
208 if( widgetViewManager->mWidgetViewContainer.size() > 0)
210 WidgetViewIter iter = widgetViewManager->mWidgetViewContainer.find( std::string( instanceId ) );
211 if( iter != widgetViewManager->mWidgetViewContainer.end() )
213 Dali::WidgetView::WidgetView widgetView = iter->second;
215 Dali::WidgetView::GetImplementation( widgetView ).SendWidgetEvent( event );
221 DALI_LOG_INFO( gWidgetViewManagerLogging, Debug::Verbose, "WidgetViewManager::WidgetEventCallback: WidgetView is not found! [%s, %s]\n", widgetId, instanceId );
226 } // namespace Internal
228 } // namespace WidgetView