37072c7e650288fb4d2832d1558b01b2c4618eac
[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 Mime Type
308 @ingroup AUL_Use_Cases
309 @{
310 <h2 class="pg"> High Level APIs - launch based on mime type(filename, URI) </h2>
311
312 - These AUL functions are used to launch the default application associated with the specified MIME extension. In addition, AUL provides functions to set/get the default application (package name) associated with a MIME type and functions to retrieve the MIME type associated with a specific file.
313
314 - AUL launch default application associated with filename or url(or content)
315
316 - AUL automatically launch "application selection popup" when AUL doesn't find default application.\n
317   App-Selector(application selection popup) shows list of application to process the file(or content).\n
318   User can select application from the list and open file with the application.\n
319   User can determine whether the selected application is set as default application or not.\n
320   If App-Selector doesn't find any application to process the file, App-Selector will show "Cannot get mimetype" or "Cannot find default application".
321
322 @code
323 // the package name of this app is a "org.tizen.caller"
324 #include <aul.h>
325 void func1(char* filename)
326 {
327         aul_open_file(filename);
328 }
329
330 void func2(char* content)
331 {
332         aul_open_content(content);
333 }
334
335 int main (int argc, char **argv)
336 {
337         // launch the application to process 3gp.3gp file
338         func1("/opt/media/Videos/3gp.3gp");
339         // launch the application to process "http://www.samsung.com"
340         func2("http://www.samsung.com");
341 }
342 @endcode
343
344 - We support primitive APIs for MIME operation
345         - aul_get_mime_from_content
346         - aul_get_mime_from_file
347         - aul_get_defapp_from_mime
348         - aul_set_defapp_with_mime
349
350 This is example to launch MIME default applications using primitive APIs
351
352 @code
353 // the package name of this app is a "org.tizen.caller"
354
355 #include <aul.h>
356 #include <bundle.h>
357
358 int main (int argc, char **argv)
359 {
360         int ret;
361         char mimetype[128];
362         char defapp[128];
363         bundle *kb;
364
365         // get MIME type of "3gp.3gp"
366         if( aul_get_mime_from_file("3gp.3gp",mimetype,sizeof(mimetype)) <0)
367                 return -1;
368         printf("3gp.3gp's mime type is %s",mimetype);
369
370         // get default application of the mimetype
371         if( aul_get_defapp_from_mime(mimetype,defapp,sizeof(defapp)) < 0)
372                 return -1;
373         printf("%s types default application is %s\n", mimetype, defapp);
374
375         // Launch the default application with specific mime key
376         kb = bundle_create();
377         bundle_add(kb, AUL_K_MIME_TYPE, mimetype);
378         bundle_add(kb, AUL_K_MIME_CONTENT, "3gp.3gp");
379         aul_launch_app(defapp, kb);
380         bundle_free(kb);
381 }
382 @endcode
383
384
385 - In callee, if you want to process specific MIME type
386   First, you must add mimetype field at desktop file
387   Second, you must process special key "AUL_K_MIME_TYPE", "AUL_K_MIME_CONTENT"
388
389 @code
390 // the package name of this app is a "org.tizen.callee"
391 #include <aul.h>
392 #include <bundle.h>
393
394 // AppCore Reset Handler
395 static int app_reset(bundle *b, void *data)
396 {
397         char* mime_type;
398
399         mime_type = bundle_get_val(b, AUL_K_MIME_TYPE);
400         if (!mime_type)
401                 return 0;
402         else
403                 process_mime(mime_type, bundle_get_val(AUL_K_MIME_CONTENT));
404 }
405 @endcode
406 @}
407
408 @defgroup AUL_Use_Cases4 Launch Based on Service Name and Command
409 @ingroup AUL_Use_Cases
410 @{
411 <h2 class="pg"> High Level APIs - launch based on service name and command </h2>
412
413 - 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.
414
415 - Launch default application associated with service name and service command.
416 - You can use aul_open_service when you launch an application associated with service name and service command
417 - If the service support to receive result, you can add result callback function.
418 - the API is asynchronous.(non-blocking API)
419
420 @code
421 // the package name of this app is a "org.tizen.caller"
422 #include <aul.h>
423 #include <bundle.h>
424 void cb_func( bundle* kb, int reserved, void* data)
425 {
426         char *id;
427         id = bundle_get_val(kb, "searched_id");
428         printf("searched id %s", id);
429 }
430
431 void service_launch_func()
432 {
433         void* user_data;
434         bundle* kb;
435
436         user_data = (void*)strdup("my_priv_data");
437         kb = bundle_create();
438         bundle_add(kb, "storage_type", "SIM");
439         aul_open_appsvc("contact", "search", kb, cb_func, user_data);
440         bundle_free(kb);
441 }
442 @endcode
443
444 - This is sample code to send result to caller in application(callee) given the service.
445 - aul_send_service_result send result msg based on received bundle.
446
447 @code
448 // Callee application
449 // the package name of this app is a "org.tizen.callee"
450
451 #include <aul.h>
452 #include <bundle.h>
453
454 void send_result(bundle *recved_bundle, char* id)
455 {
456         bundle* res_kb;
457         aul_create_result_bundle(recved_bundle,&res_kb);
458         bundle_add(res_kb, "searched_id", id);
459         aul_send_service_result(res_kb);
460         bundle_free(res_kb);
461 }
462 @endcode
463 @}
464
465 */
466
467 /**
468 @addtogroup AUL
469 @{
470         @defgroup AUL_Use_Cases Use Cases
471 @}
472 */
473
474