2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <internal/widget_view/widget_view_impl.h>
24 #include <dali/integration-api/debug.h>
26 #include <widget_service.h>
27 #include <widget_instance.h>
41 #if defined(DEBUG_ENABLED)
42 Integration::Log::Filter* gWidgetViewLogging = Integration::Log::Filter::New( Debug::Verbose, false, "LOG_WIDGET_VIEW" );
45 } // unnamed namespace
47 Dali::WidgetView::WidgetView WidgetView::New( const std::string& widgetId, const std::string& contentInfo, int width, int height, double period )
49 // Create the implementation, temporarily owned on stack
50 IntrusivePtr< WidgetView > internalWidgetView = new WidgetView( widgetId, contentInfo, width, height, period );
52 // Pass ownership to CustomActor
53 Dali::WidgetView::WidgetView widgetView( *internalWidgetView );
55 // Second-phase init of the implementation
56 // This can only be done after the CustomActor connection has been made...
57 internalWidgetView->Initialize();
62 WidgetView::WidgetView()
63 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS ) ),
73 mPermanentDelete( true )
77 WidgetView::WidgetView( const std::string& widgetId, const std::string& contentInfo, int width, int height, double period )
78 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS ) ),
79 mWidgetId( widgetId ),
81 mContentInfo( contentInfo ),
88 mPermanentDelete( true )
92 WidgetView::~WidgetView()
94 if( !mWidgetId.empty() && !mInstanceId.empty() )
96 widget_instance_terminate( mWidgetId.c_str(), mInstanceId.c_str() );
98 if( mPermanentDelete )
100 widget_instance_destroy( mWidgetId.c_str(), mInstanceId.c_str() );
106 bundle_free( mBundle );
110 const std::string& WidgetView::GetWidgetId() const
115 const std::string& WidgetView::GetInstanceId() const
120 const std::string& WidgetView::GetContentInfo() const
125 const std::string& WidgetView::GetTitle() const
130 double WidgetView::GetPeriod() const
135 void WidgetView::ActivateFaultedWidget()
139 // launch widget again
140 mPid = widget_instance_launch( mWidgetId.c_str(), mInstanceId.c_str(), mBundle, mWidth, mHeight );
143 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::ActivateFaultedWidget: widget_instance_launch is failed. [%s]\n", mWidgetId.c_str() );
147 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::ActivateFaultedWidget: widget_instance_launch is called. [%s, mPid = %d]\n", mWidgetId.c_str(), mPid );
151 bool WidgetView::IsWidgetFaulted()
153 return mPid < 0 ? true : false;
156 void WidgetView::SetPermanentDelete( bool permanentDelete )
158 mPermanentDelete = permanentDelete;
161 void WidgetView::AddObjectView( Pepper::ObjectView objectView )
163 mObjectView = objectView;
165 mObjectView.SetParentOrigin( ParentOrigin::CENTER );
166 mObjectView.SetAnchorPoint( AnchorPoint::CENTER );
168 Self().Add( mObjectView );
169 Self().SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
171 mTitle = mObjectView.GetTitle();
174 Dali::WidgetView::WidgetView handle( GetOwner() );
175 mWidgetAddedSignal.Emit( handle );
178 void WidgetView::RemoveObjectView()
181 Dali::WidgetView::WidgetView handle( GetOwner() );
182 mWidgetDeletedSignal.Emit( handle );
187 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetAddedSignal()
189 return mWidgetAddedSignal;
192 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetDeletedSignal()
194 return mWidgetDeletedSignal;
197 void WidgetView::OnInitialize()
199 char* instanceId = NULL;
201 if( !mContentInfo.empty() )
203 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: decode bundle\n" );
205 mBundle = bundle_decode( reinterpret_cast< const bundle_raw* >( mContentInfo.c_str() ), mContentInfo.length() );
208 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: Invalid bundle data.\n" );
212 bundle_get_str( mBundle, WIDGET_K_INSTANCE, &instanceId );
217 int ret = widget_instance_create( mWidgetId.c_str(), &instanceId );
218 if( ret < 0 || !instanceId )
220 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_create is failed [%s].\n", mWidgetId.c_str() );
224 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_create is called. [widget id = %s, instance id = %s]\n",
225 mWidgetId.c_str(), instanceId );
228 mInstanceId = instanceId;
231 mPid = widget_instance_launch( mWidgetId.c_str(), instanceId, mBundle, mWidth, mHeight );
234 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_launch is failed. [%s]\n", mWidgetId.c_str() );
238 DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_launch is called. [%s, mPid = %d]\n", mWidgetId.c_str(), mPid );
241 } // namespace Internal
243 } // namespace WidgetView