1. support alias id
authorJaeho Lee <jaeho81.lee@samsung.com>
Fri, 30 Nov 2012 11:37:53 +0000 (20:37 +0900)
committerJaeho Lee <jaeho81.lee@samsung.com>
Fri, 30 Nov 2012 11:37:53 +0000 (20:37 +0900)
2. added category feature

CMakeLists.txt
include/appsvc.h
include/priv_key.h
packaging/app-svc.spec
src/appsvc.c
test/appsvc_test.c

index 0f7c521..ebd300c 100755 (executable)
@@ -23,7 +23,7 @@ MESSAGE("Build type: ${CMAKE_BUILD_TYPE}")
 INCLUDE(FindPkgConfig)
 
 pkg_check_modules(pkgs REQUIRED dlog ecore x11 libprivilege-control aul)
-pkg_check_modules(libpkgs REQUIRED dlog bundle dbus-glib-1 ail xdgmime aul glib-2.0 ecore-x ecore libsoup-2.4)
+pkg_check_modules(libpkgs REQUIRED dlog bundle dbus-glib-1 ail xdgmime aul glib-2.0 ecore-x ecore libsoup-2.4 iniparser pkgmgr-info)
 
 FIND_LIBRARY(LIB_DL dl)
 
index f70077d..95602dc 100755 (executable)
@@ -394,6 +394,41 @@ int appsvc_set_appid(bundle *b, const char *appid);
 
 /**
  * @par Description:
+ * This function sets a appid to launch application based on appsvc.
+ *
+ * @param[in] b bundle object
+ * @param[in] application category
+ *
+ * @return 0 if success, negative value(<0) if fail
+ * @retval APPSVC_RET_OK - success
+ * @retval APPSVC_RET_ERROR - general error
+ * @retval APPSVC_RET_EINVAL - invalid argument(content)
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <appsvc.h>
+
+...
+{
+       bundle *b = NULL;
+
+       b = bundle_create();
+
+       appsvc_set_operation(b, APPSVC_OPERATION_VIEW);
+       appsvc_set_category(b, "http://tizen.org/category/app/browser");
+}
+ * @endcode
+ *
+ */
+int appsvc_set_category(bundle *b, const char *category);
+
+/**
+ * @par Description:
  * This API launch application based on appsvc.
  *
  * @param[in] b bundle to be passed to callee
@@ -619,6 +654,33 @@ const char *appsvc_get_appid(bundle *b);
 
 /**
  * @par Description:
+ * This function gets a application category from bundle.
+ *
+ * @param[in] b bundle object
+ *
+ * @return Pointer for application category string if success, NULL if fail
+ *
+ * @pre None.
+ * @post None.
+ * @see None.
+ * @remarks None.
+ *
+ * @par Sample code:
+ * @code
+#include <appsvc.h>
+
+...
+{
+       char *val;
+       val = appsvc_get_category(b);
+}
+ * @endcode
+ *
+ */
+const char *appsvc_get_category(bundle *b);
+
+/**
+ * @par Description:
  * This function gets value from key.
  *
  * @param[in] b bundle object 
index 1279448..71ab27d 100755 (executable)
@@ -35,6 +35,8 @@
 /** APP SVC internal private key */
 #define APP_SVC_K_PKG_NAME     "__APP_SVC_PKG_NAME__"
 /** APP SVC internal private key */
+#define APP_SVC_K_CATEGORY     "__APP_SVC_CATEGORY__"
+/** APP SVC internal private key */
 #define APP_SVC_K_RES_VAL      "__APP_SVC_K_RES_VAL__"
 
 /** APP SVC internal private key */
index 2e930fe..2e7bc2f 100644 (file)
@@ -1,7 +1,7 @@
 #sbs-git:slp/pkgs/a/app-svc app-svc 0.1.19 de68cdc468eaded317b4f5be9cdafebb01639aa0
 Name:      app-svc
 Summary:    App svc
-Version: 0.1.33
+Version: 0.1.34
 Release:    1
 Group:      System/Libraries
 License:    Apache License, Version 2.0
@@ -24,6 +24,8 @@ BuildRequires: pkgconfig(xdgmime)
 BuildRequires: pkgconfig(aul)
 BuildRequires: pkgconfig(glib-2.0)
 BuildRequires: pkgconfig(libsoup-2.4)
+BuildRequires: pkgconfig(iniparser)
+BuildRequires: pkgconfig(pkgmgr-info)
 
 
 %description
index 69cbd92..772407b 100755 (executable)
@@ -30,6 +30,8 @@
 #include <libsoup/soup.h>
 #include <Ecore_X.h>
 #include <Ecore.h>
+#include <iniparser.h>
+#include <pkgmgr-info.h>
 
 #include "appsvc.h"
 #include "appsvc_db.h"
@@ -64,6 +66,7 @@ typedef struct _appsvc_resolve_info_t{
        char *mime;     
        char *m_type;
        char *s_type;
+       char *category;
        int mime_set;
 }appsvc_resolve_info_t;
 
@@ -215,6 +218,7 @@ static int __get_resolve_info(bundle *b, appsvc_resolve_info_t *info)
        info->uri = (char *)appsvc_get_uri(b);
        info->origin_mime = info->mime = (char *)appsvc_get_mime(b);
        info->pkgname = (char *)appsvc_get_pkgname(b);
+       info->category = (char *)appsvc_get_category(b);
 
        if(info->uri) {
                if(strncmp(info->uri,"/",1) == 0){
@@ -429,14 +433,62 @@ SLPAPI int appsvc_set_pkgname(bundle *b, const char *pkg_name)
        return __set_bundle(b, APP_SVC_K_PKG_NAME, pkg_name);
 }
 
+static char* __get_alias_appid(char *appid)
+{
+       char *alias_id = NULL;
+       char *val = NULL;
+       char key_string[MAX_PACKAGE_STR_SIZE+5];
+       dictionary *dic;
+
+       dic = iniparser_load("/usr/share/appsvc/alias.ini");
+
+       if(dic == NULL)
+               return NULL;
+
+       sprintf(key_string, "Alias:%s", appid);
+       val = iniparser_getstr(dic, key_string);
+
+       _D("alias_id : %s", val);
+
+       if(val != NULL) {
+               alias_id = malloc(MAX_PACKAGE_STR_SIZE);
+               strncpy(alias_id, val, MAX_PACKAGE_STR_SIZE-1);
+       }
+
+       iniparser_freedict(dic);
+
+       return alias_id;
+}
+
 SLPAPI int appsvc_set_appid(bundle *b, const char *appid)
 {
-       if(b == NULL){
+       char *alias_id = NULL;
+       int ret;
+
+       if(b == NULL || appid == NULL){
                _E("bundle for appsvc_set_appid is NULL");
                return APPSVC_RET_EINVAL;
        }
 
-       return __set_bundle(b, APP_SVC_K_PKG_NAME, appid);
+       alias_id = __get_alias_appid(appid);
+       if(alias_id == NULL) {
+               ret = __set_bundle(b, APP_SVC_K_PKG_NAME, appid);
+       } else {
+               ret = __set_bundle(b, APP_SVC_K_PKG_NAME, alias_id);
+               free(alias_id);
+       }
+
+       return ret;
+}
+
+SLPAPI int appsvc_set_category(bundle *b, const char *category)
+{
+       if(b == NULL){
+               _E("bundle for appsvc_set_category is NULL");
+               return APPSVC_RET_EINVAL;
+       }
+
+       return __set_bundle(b, APP_SVC_K_CATEGORY, category);
 }
 
 static int __get_list_with_condition_mime_extened(char *op, char *uri, char *mime,
@@ -463,6 +515,59 @@ static int __get_list_with_condition_mime_extened(char *op, char *uri, char *mim
        return 0;
 }
 
+GSList *tmp_list;
+static int __app_list_cb(pkgmgrinfo_appinfo_h handle, void *user_data)
+{
+       char *appid = NULL;
+       GSList **app_list = (GSList **)user_data;
+       char *str = NULL;
+       GSList *iter = NULL;
+
+       pkgmgrinfo_appinfo_get_appid(handle, &str);
+       _D("Matching application is %s",str);
+
+       for (iter = tmp_list; iter != NULL; iter = g_slist_next(iter)) {
+               if (strncmp(str, (char *)iter->data, MAX_PACKAGE_STR_SIZE-1) == 0) {
+                       appid = strdup(str);
+                       *app_list = g_slist_append(*app_list, (void *)appid);
+                       _D("%s is added",appid);
+               }
+       }
+
+       return 0;
+}
+
+static int __get_list_with_category(char *category, GSList **pkg_list)
+{
+       int ret;
+       pkgmgrinfo_appinfo_filter_h handle;
+       GSList *app_list;
+       GSList *iter = NULL;
+       char *list_item = NULL;
+       int match;
+
+       ret = pkgmgrinfo_appinfo_filter_create(&handle);
+       ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_CATEGORY, category);
+
+       tmp_list = *pkg_list;
+       ret = pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, __app_list_cb, &app_list);
+       if (ret != PMINFO_R_OK) {
+               pkgmgrinfo_appinfo_filter_destroy(handle);
+               return -1;
+       }
+       pkgmgrinfo_appinfo_filter_destroy(handle);
+
+       for (iter = *pkg_list; iter != NULL; iter = g_slist_next(iter)) {
+               list_item = (char *)iter->data;
+               g_free(list_item);
+       }
+       g_slist_free(*pkg_list);
+
+       *pkg_list = app_list;
+
+       return 0;
+}
+
 SLPAPI int appsvc_run_service(bundle *b, int request_code, appsvc_res_fn cbfunc, void *data)
 {
        appsvc_resolve_info_t info;
@@ -507,7 +612,12 @@ SLPAPI int appsvc_run_service(bundle *b, int request_code, appsvc_res_fn cbfunc,
                                __get_list_with_condition_mime_extened(info.op, info.scheme,
                                        info.mime, info.m_type, info.s_type, &pkg_list);
 
+                               if(info.category) {
+                                       __get_list_with_category(info.category, &pkg_list);
+                               }
+
                                pkg_count = g_slist_length(pkg_list);
+                               _D("pkg_count : %d", pkg_count);
 
                                if(pkg_count == 1){
                                        pkgname = (char *)pkg_list->data;
@@ -539,7 +649,13 @@ SLPAPI int appsvc_run_service(bundle *b, int request_code, appsvc_res_fn cbfunc,
        if(pkgname==NULL){
                __get_list_with_condition_mime_extened(info.op, info.scheme,
                        info.mime, info.m_type, info.s_type, &pkg_list);
+
+               if(info.category) {
+                       __get_list_with_category(info.category, &pkg_list);
+               }
+
                pkg_count = g_slist_length(pkg_list);
+               _D("pkg_count : %d", pkg_count);
 
                if(pkg_count == 1){
                        pkgname = (char *)pkg_list->data;
@@ -661,6 +777,11 @@ SLPAPI const char *appsvc_get_appid(bundle *b)
        return bundle_get_val(b, APP_SVC_K_PKG_NAME);
 }
 
+SLPAPI const char *appsvc_get_category(bundle *b)
+{
+       return bundle_get_val(b, APP_SVC_K_CATEGORY);
+}
+
 SLPAPI int appsvc_create_result_bundle(bundle *inb, bundle **outb)
 {
        int ret = -1;
index 30a4eff..d900b2b 100755 (executable)
@@ -49,10 +49,11 @@ void __set_bundle_from_args(bundle * kb)
        char *mime = NULL;
        char *uri = NULL;
        char *package = NULL;
+       char *category = NULL;
        char* key = NULL;
        char* val_array[128];
        
-       while( (opt = getopt(gargc,gargv,"d:o:m:u:p:")) != -1){
+       while( (opt = getopt(gargc,gargv,"d:o:m:u:p:c:")) != -1){
                switch(opt) {
                        case 'o':
                                if(optarg)
@@ -70,6 +71,10 @@ void __set_bundle_from_args(bundle * kb)
                                if(optarg)
                                        package = strdup(optarg);
                                break;
+                       case 'c':
+                               if(optarg)
+                                       category = strdup(optarg);
+                               break;
                        case 'd':
                                if(optarg){
                                        int i = 0;
@@ -106,6 +111,10 @@ void __set_bundle_from_args(bundle * kb)
                appsvc_set_appid(kb,package);
                free(package);
        }
+       if(category) {
+               appsvc_set_category(kb,category);
+               free(category);
+       }
 }
 
 int run_svc()