7e383012d21857a914eedf020bef01ce94a7bb93
[platform/core/multimedia/libmm-session.git] / mm_session.h
1 /*
2  * libmm-session
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Seungbae Shin <seungbae.shin@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22
23 /**
24  * This file declares common data structure of multimedia framework.
25  *
26  * @file                mm_session.h
27  * @author
28  * @version             1.0
29  * @brief               This file declares multimedia framework session type.
30  */
31 #ifndef _MM_SESSION_H_
32 #define _MM_SESSION_H_
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 /**
38         @addtogroup MMSESSION
39         @{
40         @par
41         This part is describes multimedia framework session type and function
42  */
43
44 /**
45   * This enumeration defines application's session types.
46   */
47 enum MMSessionType {
48         MM_SESSION_TYPE_SHARE = 0,      /**< Share type : this type shares it's session with other share type application */
49         MM_SESSION_TYPE_EXCLUSIVE,      /**< Exclusive type : this type make previous session stop. And it does not allow other share type session start */
50         MM_SESSION_TYPE_NUM,
51 };
52
53 /**
54   * This enumeration defines session callback message type.
55   */
56 typedef enum {
57         MM_SESSION_MSG_STOP,    /**< Message Stop : this messages means that session of application has interrupted by policy.
58                                                                                                 So application should stop it's multi-media context when this message has come */
59         MM_SESSION_MSG_RESUME,  /**< Message Stop : this messages means that session interrupt of application has ended.
60                                                                                                 So application could resume it's multi-media context when this message has come */
61         MM_SESSION_MSG_NUM
62 }session_msg_t;
63
64 typedef enum {
65         MM_SESSION_EVENT_MEDIA = 0,
66         MM_SESSION_EVENT_CALL,
67         MM_SESSION_EVENT_ALARM,
68         MM_SESSION_EVENT_EARJACK_UNPLUG,
69         MM_SESSION_EVENT_RESOURCE_CONFLICT,
70         MM_SESSION_EVENT_EMERGENCY,
71         MM_SESSION_EVENT_RESUMABLE_MEDIA,
72 }session_event_t;
73
74 typedef void (*session_callback_fn) (session_msg_t msg, session_event_t event, void *user_param);
75
76 /**
77  * This function defines application's Multimedia Session policy
78  *
79  * @param       sessiontype     [in] Multimedia Session type
80  *
81  * @return      This function returns MM_ERROR_NONE on success, or negative value
82  *                      with error code.
83  * @remark      Session type is unique for each application (each PID actually).
84  *                      if application want to change session type, Finish session first and Init again
85  * @see         MMSessionType mm_session_finish
86  * @since
87  * @pre         There should be pre-initialized session type for caller application.
88  * @post        A session type of caller application will be defined process widely.
89  * @par Example
90  * @code
91 #include <mm_session.h>
92
93 static int _create(void *data)
94 {
95         int ret = 0;
96
97         // Initialize Multimedia Session Type
98         ret = mm_session_init(MM_SESSION_TYPE_SHARE);
99         if(ret < 0)
100         {
101                 printf("Can not initialize session \n");
102         }
103         ...
104 }
105
106 static int _terminate(void* data)
107 {
108         int ret = 0;
109
110         // Deinitialize Multimedia Session Type
111         ret = mm_session_finish();
112         if(ret < 0)
113         {
114                 printf("Can not finish session\n");
115         }
116         ...
117 }
118
119 int main()
120 {
121         ...
122         struct appcore_ops ops = {
123                 .create = _create,
124                 .terminate = _terminate,
125                 .pause = _pause,
126                 .resume = _resume,
127                 .reset = _reset,
128         };
129         ...
130         return appcore_efl_main(PACKAGE, ..., &ops);
131 }
132
133  * @endcode
134  */
135 int mm_session_init(int sessiontype);
136
137
138
139
140 /**
141  * This function defines application's Multimedia Session policy
142  *
143  * @param       sessiontype     [in] Multimedia Session type
144  * @param       session_callback_fn [in] session message callback function pointer
145  * @param       user_param [in] callback function user parameter
146  *
147  * @return      This function returns MM_ERROR_NONE on success, or negative value
148  *                      with error code.
149  * @remark      Session type is unique for each application (each PID actually).
150  *                      if application want to change session type, Finish session first and Init again
151  * @pre         There should be pre-initialized session type for caller application.
152  * @post        A session type of caller application will be defined process widely.
153  *                      And session callback will be registered as given function pointer with given user_param
154  * @see         MMSessionType mm_session_finish
155  * @since
156  * @par Example
157  * @code
158 #include <mm_session.h>
159
160 session_callback_fn session_cb(session_msg_t msg,  session_event_t event, void *user_param)
161 {
162         struct appdata* ad = (struct appdata*) user_param;
163
164         switch(msg)
165         {
166         case MM_SESSION_MSG_STOP:
167                 // Stop multi-media context here
168                 ...
169                 break;
170         case MM_SESSION_MSG_RESUME:
171                 // Resume multi-media context here
172                 ...
173                 break;
174         default:
175                 break;
176         }
177         ...
178 }
179
180 static int _create(void *data)
181 {
182         struct appdata* ad = (struct appdata*) data;
183         int ret = 0;
184
185         // Initialize Multimedia Session Type with callback
186         ret = mm_session_init_ex(MM_SESSION_TYPE_SHARE, session_cb, (void*)ad);
187         if(ret < 0)
188         {
189                 printf("Can not initialize session \n");
190         }
191         ...
192 }
193
194 static int _terminate(void* data)
195 {
196         int ret = 0;
197
198         // Deinitialize Multimedia Session Type
199         ret = mm_session_finish();
200         if(ret < 0)
201         {
202                 printf("Can not finish session\n");
203         }
204         ...
205 }
206
207
208 int main()
209 {
210         ...
211         struct appcore_ops ops = {
212                 .create = _create,
213                 .terminate = _terminate,
214                 .pause = _pause,
215                 .resume = _resume,
216                 .reset = _reset,
217         };
218         ...
219         return appcore_efl_main(PACKAGE, ..., &ops);
220 }
221
222  * @endcode
223  */
224 int mm_session_init_ex(int sessiontype, session_callback_fn callback, void* user_param);
225
226
227
228 /**
229  * This function finish application's Multimedia Session.
230  *
231  * 
232  * @return      This function returns MM_ERROR_NONE on success, or negative value
233  *                      with error code.
234  * @remark      Session type is unique for each application (each PID actually).
235  *                      if application want to change session type, Finish session first and Init again
236  * @see         mm_session_init
237  * @pre         A session type should be initialized for caller application.
238  * @post        A session type for caller application will be cleared.
239  * @since
240  * @par Example
241  * @code
242 #include <mm_session.h>
243
244 static int _create(void *data)
245 {
246         int ret = 0;
247
248         // Initialize Multimedia Session Type
249         ret = mm_session_init(MM_SESSION_TYPE_SHARE);
250         if(ret < 0)
251         {
252                 printf("Can not initialize session \n");
253         }
254         ...
255 }
256
257 static int _terminate(void* data)
258 {
259         int ret = 0;
260
261         // Deinitialize Multimedia Session Type
262         ret = mm_session_finish();
263         if(ret < 0)
264         {
265                 printf("Can not finish session\n");
266         }
267         ...
268 }
269
270 int main()
271 {
272         ...
273         struct appcore_ops ops = {
274                 .create = _create,
275                 .terminate = _terminate,
276                 .pause = _pause,
277                 .resume = _resume,
278                 .reset = _reset,
279         };
280         ...
281         return appcore_efl_main(PACKAGE, ..., &ops);
282 }
283  * @endcode
284  */
285 int mm_session_finish(void);
286
287 /**
288  * This function get current application's Multimedia Session type
289  *
290  * @param       sessiontype     [out] Current Multimedia Session type
291  * @return      This function returns MM_ERROR_NONE on success, or negative value
292  *                      with error code.
293  * @see         mm_session_init
294  * @since
295  */
296 int mm_session_get_current_type (int *sessiontype);
297
298
299 /**
300         @}
301  */
302
303 #ifdef __cplusplus
304 }
305 #endif
306
307 #endif