tizen 2.3.1 release
[framework/appfw/aul-1.git] / include / SLP_AUL_PG.h
1 /*
2  *  aul
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@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
25  *
26  * @ingroup   SLP_PG
27  * @defgroup   AUL Application Utility Library
28
29
30 @par AUL Programming Guide
31
32 <h1 class="pg"> Introduction</h1>
33 <h2 class="pg"> Purpose of this document</h2>
34 The purpose of this document is to describe how applications can use Application Utility Library APIs.\n
35 This document gives only programming guidelines to application engineers.
36
37 <h2 class="pg"> Scope</h2>
38 The scope of this document is limited to Samsung platform Application Utility Library API usage.
39 @}
40
41 @defgroup AUL_Architecture 1.Architecture
42 @ingroup AUL
43 @{
44 <h1 class="pg">Application Utility Library Architecture</h1>
45 <h2 class="pg"> Architecture overview</h2>
46 Application Utility Library (AUL) is responsible for launching / resuming / terminating application. It support low-level API for it. AUL also support high-level API to launch default applications based on MIME types and URI(based on regular expression). It also provides the information of applications that are running.\n
47
48 In single instance model, if a currently running application is requested to be launched again, the AUL sends the reset event to the application. \n
49
50 Low-level AUL API(primitive APIs) expects the application to provide APN(application package name) it wishes to launch.\n Low-level interface used by AUL are as shown below. Unix Domain Socket is used to send events between launchpad deamon and applications.
51 Launchpad deamon is responsible for setup default configuration of application like "setup authority", " setup application scale",...  DB is used to store / retain default configuration of application.
52
53 @image html low-level2.png "Low-level AUL diagram"
54
55 High-level APIs support to launch based on MIME types(based on filename, URI, service name). This feature is abstraction of APN. Most develpers want to launch based on filename, URI, service name without knowing APN. Below is example list.
56  - When developer open browser appliction with "http://www.samsung.com".
57  - When developer open application with filename "/usr/share/myimage.png"
58  - When developer launching application with service name "camera" and service command "take_picture"
59
60 Internally, AUL finds MIME type with given filename, URI, service name. Next, AUL find APN of default application from DB with associated MIME type. and then, AUL launch the application using primitive AUL APIs.
61
62 @image html high-level2.png "High-Level AUL diagram"
63 @}
64
65 @defgroup AUL_Feature 2.Feature
66 @ingroup AUL
67 @{
68 <h2 class="pg">Application Utility Library Features</h2>
69 Application Utility Library has the following features:\n
70
71  - Launch/Resume/Terminate Application (Primitive APIs)
72         - It can launch an application that is not currently running.
73         - It sends reset/resume/terminate event if application is already running
74
75  - Application List or information
76         - It provides the list of applications that are running.
77         - It provides information of running applications
78
79  - MIME support (High-Level APIs)
80         - AUL can get MIME type associated with the file and content
81         - AUL can get the default application associated with the MIME type.
82         - AUL can launch default applications associated with the MIME(file or content) when AUL find default application.
83         - AUL automatically launch "application selection popup" when AUL don't find default application associated with the MIME(file or content)
84
85  - Application Service support (High-Level APIs)
86         - AUL can launch applications based on service name and service command
87 @}
88
89 @defgroup AUL_Use_Cases1 Launch/Resume/Terminate an Application
90 @ingroup AUL_Use_Cases
91 @{
92 <h1 class="pg"> AUL features with sample code</h1>
93
94 <h2 class="pg"> Launch/Resume/Terminate an application</h2>
95
96 Caller application
97 - LAUNCH or RESET request without return callback function
98 - The first parameter(pkg_name) has to be registered through .desktop file.
99 - The second parameter(bundle) give dictionary style's arguments to launched(callee) application.
100
101 @code
102 // the package name of this app is a "org.tizen.caller"
103 #include <aul.h>
104 #include <bundle.h>
105 void launch_func()
106 {
107         bundle* kb;
108         kb = bundle_create();
109         bundle_add(kb, "key1", "val1");
110         bundle_add(kb, "key2", "val2");
111         bundle_add(kb, "key3", "val3");
112         aul_launch_app("org.tizen.callee",kb);
113         bundle_free(kb);
114 }
115 @endcode
116
117 - Return the application to the foreground
118 - You might want to use aul_open_app when you need to resume,
119         e.g., get it back to foreground, an application
120 - If the application is not running, the application will be launched.
121
122 @code
123 // the package name of this app is a "org.tizen.caller"
124 #include <aul.h>
125 void resume_func()
126 {
127         aul_open_app("org.tizen.callee");
128 }
129 @endcode
130
131
132 Callee application
133
134 - Integated with Appcore
135 - If you use Appcore Library, Aul library already was integrated.\n
136   You must implementation Appcore RESET , RESUME, TERMINATE handler.\n
137   This is example code. This is NOT guidance \n
138 - If you want more information,SEE for AppCore document.
139
140 @code
141 //Callee application with AppCore
142
143 #include <aul.h>
144 #include <appcore-efl.h>
145 #include <bundle.h>
146           :
147
148 static int app_create(void *data)
149 {
150         // initialize your app without argument
151         return 0;
152 }
153
154 static void _app_initialize_with_arg(bundle *b)
155 {
156         // initialize your app with argument
157 }
158
159 //
160 // called by window manager event
161 // or called by aul_open_app
162 // create your resume handler
163 //
164 static int app_resume(void *data){return 0;}
165 static int app_pause(void *data) {return 0;}
166
167 //
168 // called by aul_terminate_api
169 //
170 static int app_terminate(void *data){return 0;}
171
172 //
173 // called by aul_launch_app or aul_launch_api_with_result
174 // this is example code. create your reset handler
175 //
176 static int app_reset(bundle *b, void *data)
177 {
178         char* mime_type;
179         if(bundle_get_val(ad->kb, AUL_K_ARGV0))   // when launch
180                 _app_initialize_with_arg(b);
181         else{                                        // when receiving reset event
182                 mime_type = bundle_get_val(b, AUL_K_MIME_TYPE);
183                 if (!mime_type){
184                         elm_win_activate(..);
185                         return 0;
186                 }else{
187                         update_list(mime_type);
188                 }
189         }
190 }
191
192 int main(int argc, char *argv[])
193 {
194         struct appcore_ops ops = {
195                 .create = app_create,
196                 .terminate = app_terminate,
197                 .pause = app_pause,
198                 .resume = app_resume,
199                 .reset = app_reset,
200         };
201
202         return appcore_efl_main(PACKAGE, &argc, &argv, &ops);
203 }
204 @endcode
205
206
207 - SET with AUL native handler
208 - In special case, if you don't use Appcore library, this is aul callee's example
209
210 @code
211 // Callee application
212 #include <aul.h>
213 #include <bundle.h>
214 #include <Ecore.h>
215
216 static int aul_handler(aul_type type, bundle *kb,void* data)
217 {
218         char* val1, *val2
219         switch(type){
220                 case AUL_START:
221                         // same to Appcore RESET callback
222                         val1 = bundle_get_val(kb, "phone_number");
223                         val2 = bundle_get_val(kb, "store");
224                         break;
225                 case AUL_RESUME:
226                         // same to Appcore RESUME callback
227                         break;
228                 case AUL_TERMINATE:
229                         // same to Appcore TERMINATE callback
230                         break;
231         }
232         return 0;
233 }
234
235 int main(int argc, char** argv)
236 {
237         ecore_init();
238
239         aul_launch_init(aul_handler,NULL);
240         // enable this if you want to handle at aul_handler when launch
241         aul_launch_argv_handler(argc, argv);
242
243         ecore_main_loop_begin();  // You must need ecore or glib mainloop
244         return 0;
245 }
246 @endcode
247 @}
248
249 @defgroup AUL_Use_Cases2 Get Running Application State
250 @ingroup AUL_Use_Cases
251 @{
252 <h2 class="pg"> Get Running Application State </h2>
253
254 - Getting running application list
255 - This AUL function is used to get the list of all the applications that are currently running.
256
257 @code
258 #include <aul.h>
259
260 int iterfunc(const aul_app_info* info, void* data)
261 {
262         printf("package name: %s\n", info->pkg_name);
263         printf("running pid: %d\n", info->pid);
264         printf("application executable path: %s\n", info->app_path);
265         return 0;
266 }
267
268 int main (int argc, char **argv)
269 {
270         aul_app_get_running_app_info(iterfunc,NULL);
271 }
272 @endcode
273
274 - Get application running state
275 - This AUL function is used to get application's state
276
277 @code
278 #include <aul.h>
279
280 int main (int argc, char **argv)
281 {
282         if(aul_app_is_running("org.tizen.app2"))
283                 printf("application is running");
284 }
285 @endcode
286
287 - Dead Handler (Set dead handler)
288 - aul_listen_app_dead_signal track killed application.
289   For example, 3rd party application can register indicator icon at indicator service. When 3rd party application abnormally terminated after set icon at indicator, indicator service should collect garbage icon set by the application.
290
291 @code
292 #include <aul.h>
293
294 int dead_tracker(int pid, void* data)
295 {
296         printf("the application with %d pid was killed",pid);
297         return 0;
298 }
299
300 void set_dead_handler_func()
301 {
302         aul_listen_app_dead_signal(dead_tracker,NULL);
303 }
304 @endcode
305 @}
306
307 @defgroup AUL_Use_Cases3 Launch Based on Service Name and Command
308 @ingroup AUL_Use_Cases
309 @{
310 <h2 class="pg"> High Level APIs - launch based on service name and command </h2>
311
312 - This AUL functions is used to launch default application based on service name and service command. In addition,AUL package support to set/get default application(package name) associated with service name and service command. This APIs also support to receive result from launched(requested) application.
313
314 - Launch default application associated with service name and service command.
315 - You can use aul_open_service when you launch an application associated with service name and service command
316 - If the service support to receive result, you can add result callback function.
317 - the API is asynchronous.(non-blocking API)
318
319 @code
320 // the package name of this app is a "org.tizen.caller"
321 #include <aul.h>
322 #include <bundle.h>
323 void cb_func( bundle* kb, int reserved, void* data)
324 {
325         char *id;
326         id = bundle_get_val(kb, "searched_id");
327         printf("searched id %s", id);
328 }
329
330 void service_launch_func()
331 {
332         void* user_data;
333         bundle* kb;
334
335         user_data = (void*)strdup("my_priv_data");
336         kb = bundle_create();
337         bundle_add(kb, "storage_type", "SIM");
338         aul_open_appsvc("contact", "search", kb, cb_func, user_data);
339         bundle_free(kb);
340 }
341 @endcode
342
343 - This is sample code to send result to caller in application(callee) given the service.
344 - aul_send_service_result send result msg based on received bundle.
345
346 @code
347 // Callee application
348 // the package name of this app is a "org.tizen.callee"
349
350 #include <aul.h>
351 #include <bundle.h>
352
353 void send_result(bundle *recved_bundle, char* id)
354 {
355         bundle* res_kb;
356         aul_create_result_bundle(recved_bundle,&res_kb);
357         bundle_add(res_kb, "searched_id", id);
358         aul_send_service_result(res_kb);
359         bundle_free(res_kb);
360 }
361 @endcode
362 @}
363
364 */
365
366 /**
367 @addtogroup AUL
368 @{
369         @defgroup AUL_Use_Cases Use Cases
370 @}
371 */
372
373