f6f4cec026f6885a7d43759e8f40f0131488b0a2
[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 <dali/public-api/common/dali-common.h>
23 #include <dali/public-api/signals/callback.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     /**
43      * Determines the priority of the call back
44      */
45     enum Priority
46     {
47       IDLE_PRIORITY,     ///< idle priority
48       DEFAULT_PRIORITY,  ///< priority of the callback will be the same as input handlers and timer callbacks.
49     };
50
51     /**
52      * Controls whether an event once processed by the handler is passed on to other
53      * handlers, or not.
54      */
55     enum EventControl
56     {
57       CALLBACK_PASS_ON,   ///< Pass the event on to any other handlers registered for this event
58       CALLBACK_DONE,      ///< Don't pass the event to any other handlers
59     };
60
61     /**
62      * Create a new call back interface
63      */
64     static CallbackManager* New();
65
66     /**
67      * Virtual destructor
68      */
69     virtual ~CallbackManager() {}
70
71     /**
72      * Adds a call back asynchronously.
73      * Can be called from any thread.
74      * @param callback custom call back function
75      * @param priority call back priority
76      * @return true on success
77      */
78     virtual bool AddCallback( CallbackBase* callback, Priority priority ) = 0;
79
80     /**
81      * Adds a call back asynchronously to handle an event.
82      * E.g. to handle a CTRL-C event.
83      * Can be called from any thread.
84      * @param callback custom call back function
85      * @return true on success
86      */
87     virtual bool AddEventCallback( CallbackBase* callback, int type, EventControl control ) = 0;
88
89     /**
90      * Starts the callback manager.
91      */
92     virtual void Start() = 0;
93
94     /**
95      * Stop the callback manager and can remove all pending callbacks synchronously.
96      * This call will synchronise with the main loop and not return
97      * until all call backs have been deleted.
98      */
99     virtual void Stop() = 0;
100
101 protected:
102
103     /**
104      * constructor
105      */
106     CallbackManager() {}
107
108 private:
109
110     // Undefined copy constructor.
111     CallbackManager( const CallbackManager& );
112
113     // Undefined assignment operator.
114     CallbackManager& operator=( const CallbackManager& );
115
116 };
117
118 } // namespace Adaptor
119
120 } // namespace Internal
121
122 } // namespace Dali
123
124 #endif // __DALI_INTERNAL_CALLBACK_MANAGER_H__