merge with master
[platform/framework/web/wrt.git] / src / wrt-launcher / wrt-launcher.cpp
index a1c2fa7..16f8d00 100644 (file)
@@ -31,6 +31,7 @@
 #include <dpl/wrt-dao-ro/wrt_db_types.h>
 #include <dpl/wrt-dao-rw/global_dao.h>
 #include <dpl/wrt-dao-ro/global_dao_read_only.h>
+#include <dpl/wrt-dao-ro/config_parser_data.h>
 #include <dpl/exception.h>
 
 #define TIMEOUT_DEFAULT     10
@@ -62,12 +63,14 @@ static std::unique_ptr<DBConnection> g_dbConnection;
 typedef struct
 {
     char* guid;           /**< the widget's id
-                           (read from its config.xml during installation)*/
+                           (read from its config.xml during installation)*/
     char* name;         /**< the widget's name
-                           (read from its config.xml during installation)*/
+                         * (read from its config.xml during installation)*/
     char* version;      /**< the widget's varsion
-                           (read from its config.xml during installation)*/
-    char* pkg_name;     /**< the widget's pkg name */
+                         * (read from its config.xml during installation)*/
+    char* pkg_id;       /**< the widget's pkg id */
+
+    char* app_id;
 } widget_info;
 
 static void free_widget_info(widget_info* widget_info)
@@ -76,7 +79,8 @@ static void free_widget_info(widget_info* widget_info)
         delete[] widget_info->guid;
         delete[] widget_info->name;
         delete[] widget_info->version;
-        delete[] widget_info->pkg_name;
+        delete[] widget_info->pkg_id;
+        delete[] widget_info->app_id;
         delete widget_info;
     }
 }
@@ -96,7 +100,7 @@ static bool attachDbConnection()
             g_dbConnection.reset(new DBConnection());
             g_dbConnection->AttachDatabase();
         }
-        Catch (DPL::DB::SqlConnection::Exception::Base) {
+        Catch(DPL::DB::SqlConnection::Exception::Base) {
             LogDebug("Fail to connect DB");
             return FALSE;
         }
@@ -106,15 +110,17 @@ static bool attachDbConnection()
 
 static bool display_widget_info()
 {
-    if(!attachDbConnection()) return FALSE;
+    if (!attachDbConnection()) {
+        return FALSE;
+    }
 
     WidgetDAOReadOnlyList widgetList =
-            WrtDB::WidgetDAOReadOnly::getWidgetList();
+        WrtDB::WidgetDAOReadOnly::getWidgetList();
 
-    printf("%3s %32s %16s %64s %16s\n",
-           "No", "Name", "Version", "GUID", "Package Name");
-    printf("%3s %32s %16s %64s %16s\n",
-           "--", "--", "----", "-------", "----");
+    printf("%3s %32s %16s %64s %16s %24s\n",
+           "No", "Name", "Version", "GUID", "Package ID", "App ID");
+    printf("%3s %32s %16s %64s %16s %24s\n",
+           "--", "--", "----", "-------", "-----", "-----");
 
     int number = 1;
     FOREACH(dao, widgetList) {
@@ -123,7 +129,9 @@ static bool display_widget_info()
 
         WrtDB::WidgetGUID guid = (*dao)->getGUID();
         DPL::Optional<DPL::String> version = (*dao)->getVersion();
-        WrtDB::WidgetPkgName package_name = (*dao)->getPkgName();
+        WrtDB::TizenAppId appid = (*dao)->getTzAppId();
+        WrtDB::TizenPkgId pkgid = (*dao)->getTizenPkgId();
+
 
         /*get WidgetName*/
         DPL::Optional<DPL::String> widget_name;
@@ -153,15 +161,16 @@ static bool display_widget_info()
             info->guid = new_strdup(DPL::ToUTF8String(*guid).c_str());
         }
 
-        info->pkg_name = new_strdup(DPL::ToUTF8String(package_name).c_str());
-
+        info->app_id = new_strdup(DPL::ToUTF8String(appid).c_str());
+        info->pkg_id = new_strdup(DPL::ToUTF8String(pkgid).c_str());
 
-        printf("%3i %32s %16s %64s %16s\n",
+        printf("%3i %32s %16s %64s %16s %24s\n",
                number++,
                !info->name ? "[NULL]" : info->name,
                !info->version ? "[NULL]" : info->version,
                !info->guid ? "[NULL]" : info->guid,
-               !info->pkg_name ? "[NULL]" : info->pkg_name);
+               !info->pkg_id ? "[NULL]" : info->pkg_id,
+               !info->app_id ? "[NULL]" : info->app_id);
 
         free_widget_info(info);
     }
@@ -172,21 +181,22 @@ static bool display_widget_info()
 static void print_help(FILE *stream, int /*exit_code*/)
 {
     fprintf(stream, "Usage : %s [ ... ]\n", program);
-    fprintf(stream,
-            "   -h                       --help              Display this usage information.\n"
-            "   -l                       --list              Display installed widgets list\n"
-            "   -s [GUID]or[PkgName]     --start             Launch widget with package name or GUID\n"
-            "   -k [GUID]or[PkgName]     --kill              Kill widget with package name or GUID\n"
-            "   -r [GUID]or[PkgName]     --is-running        Check whether widget is running by package name or GUID,\n"
-            "                                                If widget is running, 0(zero) will be returned.\n"
-            "   -d                       --debug             Activate debug mode\n"
-            "   -t [second]              --timeout           Set timeout of response from widget in debug mode\n"
-            "   -v [1]or[0]              --developer-mode    Set developermode\n"
-            "   -c [1]or[0]              --compliance-mode   Set compliancemode\n"
-            "   -i [imei]                --fake-imei         Set fakeimei\n"
-            "   -m [meid]                --fake-meid         Set fakemeid\n"
-            "    if you emit this option, 5 seconds is set in debug mode\n"
-            );
+    fprintf(
+        stream,
+        "   -h                       --help              Display this usage information.\n"
+        "   -l                       --list              Display installed widgets list\n"
+        "   -s [GUID]or[PkgName]     --start             Launch widget with package name or GUID\n"
+        "   -k [GUID]or[PkgName]     --kill              Kill widget with package name or GUID\n"
+        "   -r [GUID]or[PkgName]     --is-running        Check whether widget is running by package name or GUID,\n"
+        "                                                If widget is running, 0(zero) will be returned.\n"
+        "   -d                       --debug             Activate debug mode\n"
+        "   -t [second]              --timeout           Set timeout of response from widget in debug mode\n"
+        "   -v [1]or[0]              --developer-mode    Set developermode\n"
+        "   -c [1]or[0]              --compliance-mode   Set compliancemode\n"
+        "   -i [imei]                --fake-imei         Set fakeimei\n"
+        "   -m [meid]                --fake-meid         Set fakemeid\n"
+        "    if you emit this option, 5 seconds is set in debug mode\n"
+        );
 }
 
 static void sighandler(int signo, siginfo_t *si, void *data);
@@ -212,18 +222,18 @@ int main(int argc, char* argv[])
         program = argv[0];
 
         static struct option long_options[] = {
-            {"help", no_argument, 0, 'h'},
-            {"list", no_argument, 0, 'l'},
-            {"start", required_argument, 0, 's'},
-            {"kill", required_argument, 0, 'k'},
-            {"is-running", required_argument, 0, 'r'},
-            {"debug", no_argument, 0, 'd'},
-            {"timeout", required_argument, 0, 't'},
-            {"developer-mode", required_argument, 0, 'v'},
-            {"compliance-mode", required_argument, 0, 'c'},
-            {"fake-imei", required_argument, 0, 'i'},
-            {"fake-meid", required_argument, 0, 'm'},
-            {0, 0, 0, 0}
+            { "help", no_argument, 0, 'h' },
+            { "list", no_argument, 0, 'l' },
+            { "start", required_argument, 0, 's' },
+            { "kill", required_argument, 0, 'k' },
+            { "is-running", required_argument, 0, 'r' },
+            { "debug", no_argument, 0, 'd' },
+            { "timeout", required_argument, 0, 't' },
+            { "developer-mode", required_argument, 0, 'v' },
+            { "compliance-mode", required_argument, 0, 'c' },
+            { "fake-imei", required_argument, 0, 'i' },
+            { "fake-meid", required_argument, 0, 'm' },
+            { 0, 0, 0, 0 }
         };
 
         if (argv[1] == NULL) {
@@ -252,15 +262,16 @@ int main(int argc, char* argv[])
 
             switch (next_opt) {
             case 'h':
-                if(!dispHelp){
+                if (!dispHelp) {
                     print_help(stdout, 0);
                     dispHelp = true;
-                 }
+                }
                 break;
 
             case 'l':
-                if(dispList)
+                if (dispList) {
                     break;
+                }
                 if (!display_widget_info()) {
                     printf("Fail to display the list of installed widgets");
                     return -1;
@@ -277,7 +288,7 @@ int main(int argc, char* argv[])
 
             case 't':
                 timeout = atoi(optarg);
-                if (timeout < 0 ) {
+                if (timeout < 0) {
                     timeout = TIMEOUT_DEFAULT;
                 }
                 break;
@@ -315,7 +326,9 @@ int main(int argc, char* argv[])
 
             case 'v':
                 strncpy(temp_arg, optarg, strlen(optarg));
-                if(!attachDbConnection()) return FALSE;
+                if (!attachDbConnection()) {
+                    return FALSE;
+                }
                 if (!strcmp("1", temp_arg)) {
                     WrtDB::GlobalDAO::SetDeveloperMode(true);
                 } else {
@@ -324,8 +337,10 @@ int main(int argc, char* argv[])
                 break;
             case 'c':
                 strncpy(temp_arg, optarg, strlen(optarg));
-                if(!attachDbConnection()) return FALSE;
-                if(!strcmp("1", temp_arg)) {
+                if (!attachDbConnection()) {
+                    return FALSE;
+                }
+                if (!strcmp("1", temp_arg)) {
                     WrtDB::GlobalDAO::setComplianceMode(true);
                 } else {
                     WrtDB::GlobalDAO::setComplianceMode(false);
@@ -333,12 +348,16 @@ int main(int argc, char* argv[])
                 break;
             case 'i':
                 strncpy(temp_arg, optarg, strlen(optarg));
-                if(!attachDbConnection()) return FALSE;
+                if (!attachDbConnection()) {
+                    return FALSE;
+                }
                 WrtDB::GlobalDAO::setComplianceFakeImei(temp_arg);
                 break;
             case 'm':
                 strncpy(temp_arg, optarg, strlen(optarg));
-                if(!attachDbConnection()) return FALSE;
+                if (!attachDbConnection()) {
+                    return FALSE;
+                }
                 WrtDB::GlobalDAO::setComplianceFakeMeid(temp_arg);
                 break;
 
@@ -351,7 +370,7 @@ int main(int argc, char* argv[])
             }
         } while (next_opt != -1);
 
-        if ((op == 's') || (op == 'k') || (op =='r')) {
+        if ((op == 's') || (op == 'k') || (op == 'r')) {
             std::string temp;
 
             if (NULL == g_dbConnection.get()) {
@@ -359,14 +378,17 @@ int main(int argc, char* argv[])
                     g_dbConnection.reset(new DBConnection());
                     g_dbConnection->AttachDatabase();
                 }
-                Catch (DPL::DB::SqlConnection::Exception::Base) {
+                Catch(DPL::DB::SqlConnection::Exception::Base) {
                     LogDebug("Fail to connect DB");
                     return FALSE;
                 }
             }
+            DPL::OptionalString normal_str = DPL::FromUTF8String(temp_arg);
+            WrtDB::NormalizeAndTrimSpaceString(normal_str);
+            std::string normal_arg = DPL::ToUTF8String(*normal_str);
 
             WidgetDAOReadOnlyList widgetList =
-                    WrtDB::WidgetDAOReadOnly::getWidgetList();
+                WrtDB::WidgetDAOReadOnly::getWidgetList();
             FOREACH(dao, widgetList) {
                 WrtDB::WidgetGUID d_guid = (*dao)->getGUID();
                 WrtDB::WidgetPkgName d_pkgname = (*dao)->getPkgName();
@@ -377,7 +399,9 @@ int main(int argc, char* argv[])
                     temp = DPL::ToUTF8String(package_name);
                     break;
                 }
-                if (!strcmp(DPL::ToUTF8String(d_pkgname).c_str(), temp_arg)) {
+                if (!strcmp(DPL::ToUTF8String(d_pkgname).c_str(),
+                            normal_arg.c_str()))
+                {
                     WrtDB::WidgetPkgName package_name = (*dao)->getPkgName();
                     temp = DPL::ToUTF8String(package_name);
                     break;
@@ -421,12 +445,12 @@ int main(int argc, char* argv[])
                 gid_t group_list[1];
                 group_list[0] = LOGGING_DEFAULT_GID;
 
-                if(setgroups(sizeof(group_list), group_list) < 0) {
+                if (setgroups(sizeof(group_list), group_list) < 0) {
                     printf("result: %s\n", "failed");
                     return -1;
                 }
 
-                if(setreuid(WEBAPP_DEFAULT_UID, WEBAPP_DEFAULT_GID) < 0) {
+                if (setreuid(WEBAPP_DEFAULT_UID, WEBAPP_DEFAULT_GID) < 0) {
                     printf("result: %s\n", "failed");
                     return -1;
                 }
@@ -540,6 +564,6 @@ static void sighandler(int signo, siginfo_t *si, void* /*data*/)
     } else {
         printf("Not RT signal : %d\n", signo);
     }
-    exit (0);
+    exit(0);
 }