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 timed_event.cpp
18 * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
20 * @brief This file is the implementation file of timed event example
23 #include <dpl/generic_event.h>
24 #include <dpl/application.h>
25 #include <dpl/controller.h>
26 #include <dpl/type_list.h>
27 #include <dpl/thread.h>
28 #include <dpl/log/log.h>
31 DECLARE_GENERIC_EVENT_0(FirstEvent)
32 DECLARE_GENERIC_EVENT_0(SecondEvent)
34 class ControllerInThread
35 : public DPL::Controller<DPL::TypeListDecl<FirstEvent,
39 virtual void OnEventReceived(const FirstEvent &event)
42 LogInfo("First event occurred");
45 virtual void OnEventReceived(const SecondEvent &event)
48 LogInfo("Second event occurred");
52 DECLARE_GENERIC_EVENT_0(QuitEvent)
55 : public DPL::Application,
56 private DPL::Controller<DPL::TypeListDecl<QuitEvent>::Type>
60 ControllerInThread m_controllerInThread;
62 // Quit application event occurred
63 virtual void OnEventReceived(const QuitEvent &event)
70 MyApplication(int argc, char **argv)
71 : Application(argc, argv, "timed_event", false)
75 m_controllerInThread.Touch();
79 m_controllerInThread.SwitchToThread(&m_thread);
81 // Emit thread timed events
82 m_controllerInThread.DPL::ControllerEventHandler<SecondEvent>::PostTimedEvent(SecondEvent(), 3);
83 m_controllerInThread.DPL::ControllerEventHandler<FirstEvent>::PostTimedEvent(FirstEvent(), 2);
85 // Emit framework timed quit event
86 DPL::ControllerEventHandler<QuitEvent>::PostTimedEvent(QuitEvent(), 5);
89 virtual ~MyApplication()
91 m_controllerInThread.SwitchToThread(NULL);
98 int main(int argc, char *argv[])
100 MyApplication app(argc, argv);