[dali_1.0.9] Merge branch 'tizen'
[platform/core/uifw/dali-adaptor.git] / adaptors / common / callback-manager.h
1 #ifndef __DALI_INTERNAL_CALLBACK_MANAGER_H__
2 #define __DALI_INTERNAL_CALLBACK_MANAGER_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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
21 // EXTERNAL INCLUDES
22 #include <boost/function.hpp>
23 #include <dali/public-api/common/dali-common.h>
24
25 namespace Dali
26 {
27
28 namespace Internal
29 {
30
31 namespace Adaptor
32 {
33
34 /**
35  * Abstract interface to install call backs in to an applications main loop.
36  */
37 class CallbackManager
38 {
39
40 public:
41
42     typedef boost::function<void(void)> Callback;   ///< Callback typedef
43
44     /**
45      * Determines the priority of the call back
46      */
47     enum Priority
48     {
49       IDLE_PRIORITY,     ///< idle priority
50       DEFAULT_PRIORITY,  ///< priority of the callback will be the same as input handlers and timer callbacks.
51     };
52
53     /**
54      * Controls whether an event once processed by the handler is passed on to other
55      * handlers, or not.
56      */
57     enum EventControl
58     {
59       CALLBACK_PASS_ON,   ///< Pass the event on to any other handlers registered for this event
60       CALLBACK_DONE,      ///< Don't pass the event to any other handlers
61     };
62
63     /**
64      * Create a new call back interface
65      */
66     static CallbackManager* New();
67
68     /**
69      * Virtual destructor
70      */
71     virtual ~CallbackManager() {}
72
73     /**
74      * Adds a call back asynchronously.
75      * Can be called from any thread.
76      * @param callback custom call back function
77      * @param priority call back priority
78      * @return true on success
79      */
80     virtual bool AddCallback( Callback callback, Priority priority ) = 0;
81
82     /**
83      * Adds a call back asynchronously to handle an event.
84      * E.g. to handle a CTRL-C event.
85      * Can be called from any thread.
86      * @param callback custom call back function
87      * @return true on success
88      */
89     virtual bool AddEventCallback( Callback callback, int type, EventControl control ) = 0;
90
91     /**
92      * Starts the callback manager.
93      */
94     virtual void Start() = 0;
95
96     /**
97      * Stop the callback manager and can remove all pending callbacks synchronously.
98      * This call will synchronise with the main loop and not return
99      * until all call backs have been deleted.
100      */
101     virtual void Stop() = 0;
102
103 protected:
104
105     /**
106      * constructor
107      */
108     CallbackManager() {}
109
110 private:
111
112     // Undefined copy constructor.
113     CallbackManager( const CallbackManager& );
114
115     // Undefined assignment operator.
116     CallbackManager& operator=( const CallbackManager& );
117
118 };
119
120 } // namespace Adaptor
121
122 } // namespace Internal
123
124 } // namespace Dali
125
126 #endif // __DALI_INTERNAL_CALLBACK_MANAGER_H__