7783da1d562c4bfe695f4c76d8c010babd18ae9e
[platform/core/uifw/dali-adaptor.git] / adaptors / tizen / internal / common / callback-manager.h
1 #ifndef __DALI_CALLBACK_MANAGER_H__
2 #define __DALI_CALLBACK_MANAGER_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.0 (the License);
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //     http://floralicense.org/license/
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an AS IS BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19
20 // EXTERNAL INCLUDES
21 #include <boost/function.hpp>
22 #include <dali/public-api/common/dali-common.h>
23
24 namespace Dali
25 {
26
27 namespace Internal
28 {
29
30 namespace Adaptor
31 {
32
33 /**
34  * Abstract interface to install call backs in to an applications main loop.
35  */
36 class DALI_IMPORT_API CallbackManager
37 {
38
39 public:
40
41     typedef boost::function<void(void)> Callback;   ///< Callback typedef
42
43     /**
44      * Determines the priority of the call back
45      */
46     enum Priority
47     {
48       IDLE_PRIORITY,     ///< idle priority
49       DEFAULT_PRIORITY,  ///< priority of the callback will be the same as input handlers and timer callbacks.
50     };
51
52     /**
53      * Controls whether an event once processed by the handler is passed on to other
54      * handlers, or not.
55      */
56     enum EventControl
57     {
58       CALLBACK_PASS_ON,   ///< Pass the event on to any other handlers registered for this event
59       CALLBACK_DONE,      ///< Don't pass the event to any other handlers
60     };
61
62     /**
63      * Create a new call back interface
64      */
65     static CallbackManager* New();
66
67     /**
68      * Virtual destructor
69      */
70     virtual ~CallbackManager() {}
71
72     /**
73      * Adds a call back asynchronously.
74      * Can be called from any thread.
75      * @param callback custom call back function
76      * @param priority call back priority
77      * @return true on success
78      */
79     virtual bool AddCallback( Callback callback, Priority priority ) = 0;
80
81     /**
82      * Adds a call back asynchronously to handle an event.
83      * E.g. to handle a CTRL-C event.
84      * Can be called from any thread.
85      * @param callback custom call back function
86      * @return true on success
87      */
88     virtual bool AddEventCallback( Callback callback, int type, EventControl control ) = 0;
89
90     /**
91      * Starts the callback manager.
92      */
93     virtual void Start() = 0;
94
95     /**
96      * Stop the callback manager and can remove all pending callbacks synchronously.
97      * This call will synchronise with the main loop and not return
98      * until all call backs have been deleted.
99      */
100     virtual void Stop() = 0;
101
102 protected:
103
104     /**
105      * constructor
106      */
107     CallbackManager() {}
108
109 private:
110
111     // Undefined copy constructor.
112     CallbackManager( const CallbackManager& );
113
114     // Undefined assignment operator.
115     CallbackManager& operator=( const CallbackManager& );
116
117 };
118
119 } // namespace Adaptor
120
121 } // namespace Internal
122
123 } // namespace Dali
124
125 #endif // __DALI_CALLBACK_MANAGER_H__