2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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.
17 * @file thread_event_dispatcher.cpp
18 * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
20 * @brief This file is the implementation file of thread event dispatcher
22 #include <dpl/event/thread_event_dispatcher.h>
23 #include <dpl/log/log.h>
24 #include <dpl/assert.h>
31 ThreadEventDispatcher::ThreadEventDispatcher()
36 ThreadEventDispatcher::~ThreadEventDispatcher()
40 void ThreadEventDispatcher::SetThread(Thread *thread)
45 void ThreadEventDispatcher::StaticEventDelete(void *event, void *userParam)
47 AbstractEventCall *abstractEventCall = static_cast<AbstractEventCall *>(event);
48 ThreadEventDispatcher *This = static_cast<ThreadEventDispatcher *>(userParam);
50 LogPedantic("Received static event delete from thread");
52 Assert(abstractEventCall != NULL);
55 This->EventDelete(abstractEventCall);
58 void ThreadEventDispatcher::StaticEventDispatch(void *event, void *userParam)
60 AbstractEventCall *abstractEventCall = static_cast<AbstractEventCall *>(event);
61 ThreadEventDispatcher *This = static_cast<ThreadEventDispatcher *>(userParam);
63 LogPedantic("Received static event dispatch from thread");
65 Assert(abstractEventCall != NULL);
68 This->EventDispatch(abstractEventCall);
71 void ThreadEventDispatcher::EventDelete(AbstractEventCall *abstractEventCall)
73 LogPedantic("Deleting event");
74 delete abstractEventCall;
77 void ThreadEventDispatcher::EventDispatch(AbstractEventCall *abstractEventCall)
79 LogPedantic("Dispatching event to event support");
80 abstractEventCall->Call();
83 void ThreadEventDispatcher::AddEventCall(AbstractEventCall *abstractEventCall)
85 // Thread must be set prior to call
86 Assert(m_thread != NULL);
88 LogPedantic("Adding event to thread event loop");
90 // Call abstract event call in dedicated thread
91 m_thread->PushEvent(abstractEventCall, &StaticEventDispatch, &StaticEventDelete, this);
94 void ThreadEventDispatcher::AddTimedEventCall(AbstractEventCall *abstractEventCall, double dueTime)
96 // Thread must be set prior to call
97 Assert(m_thread != NULL);
99 LogPedantic("Adding timed event to thread event loop");
101 // Call abstract event call in dedicated thread
102 m_thread->PushTimedEvent(abstractEventCall, dueTime, &StaticEventDispatch, &StaticEventDelete, this);