2 * Copyright (c) 2019 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 <dali-extension/vector-animation-renderer/tizen-vector-animation-manager.h>
22 #include <dali/integration-api/debug.h>
23 #include <dali/integration-api/adaptor-framework/adaptor.h>
31 TizenVectorAnimationManager& TizenVectorAnimationManager::Get()
33 static TizenVectorAnimationManager animationManager;
34 return animationManager;
37 TizenVectorAnimationManager::TizenVectorAnimationManager()
45 TizenVectorAnimationManager::~TizenVectorAnimationManager()
47 DALI_LOG_RELEASE_INFO( "TizenVectorAnimationManager::~TizenVectorAnimationManager: this = %p\n", this );
50 void TizenVectorAnimationManager::AddEventHandler( TizenVectorAnimationEventHandler& handler )
52 if( mEventHandlers.end() == std::find( mEventHandlers.begin(), mEventHandlers.end(), &handler ) )
54 if( mEventHandlers.empty() )
56 Adaptor::Get().RegisterProcessor( *this );
61 mEventTrigger = std::unique_ptr< EventThreadCallback >( new EventThreadCallback( MakeCallback( this, &TizenVectorAnimationManager::OnEventTriggered ) ) );
64 mEventHandlers.push_back( &handler );
68 void TizenVectorAnimationManager::RemoveEventHandler( TizenVectorAnimationEventHandler& handler )
70 auto iter = std::find( mEventHandlers.begin(), mEventHandlers.end(), &handler );
71 if( iter != mEventHandlers.end() )
73 mEventHandlers.erase( iter );
75 if( mEventHandlers.empty() )
77 if( Adaptor::IsAvailable() )
79 Adaptor::Get().UnregisterProcessor( *this );
82 mEventTrigger.release();
87 Dali::Mutex::ScopedLock lock( mMutex );
89 auto triggeredHandler = std::find( mTriggeredHandlers.begin(), mTriggeredHandlers.end(), &handler );
90 if( triggeredHandler != mTriggeredHandlers.end() )
92 mTriggeredHandlers.erase( triggeredHandler );
97 void TizenVectorAnimationManager::TriggerEvent( TizenVectorAnimationEventHandler& handler )
99 Dali::Mutex::ScopedLock lock( mMutex );
101 if( mTriggeredHandlers.end() == std::find( mTriggeredHandlers.begin(), mTriggeredHandlers.end(), &handler ) )
103 mTriggeredHandlers.push_back( &handler );
105 mEventTrigger->Trigger();
109 void TizenVectorAnimationManager::Process()
114 // This function is called in the main thread.
115 void TizenVectorAnimationManager::OnEventTriggered()
117 std::vector< TizenVectorAnimationEventHandler* > handlers;
120 Dali::Mutex::ScopedLock lock( mMutex );
122 // Copy the list to the local variable and clear
123 handlers = mTriggeredHandlers;
124 mTriggeredHandlers.clear();
127 for( auto&& iter : handlers )
129 // Check if it is valid
130 auto handler = std::find( mEventHandlers.begin(), mEventHandlers.end(), iter );
131 if( handler != mEventHandlers.end() )
138 } // namespace Plugin