Additional functions of policy and resource management.
[profile/ivi/ico-uxf-homescreen.git] / src / homescreen / home_screen_main.cpp
1 /*
2  * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
3  *
4  * This program is licensed under the terms and conditions of the
5  * Apache License, version 2.0.  The full text of the Apache License is at
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
8  */
9 /**
10  * @brief   homescreen application main
11  *
12  * @date    Feb-15-2013
13  */
14
15 #include <fstream>
16 #include <string>
17 #include <iostream>
18 #include <cstdio>
19 #include <bundle.h>
20 #include <aul/aul.h>
21 #include <home_screen_main.h>
22 #include <cerrno>
23 #include "CicoHomeScreenConfig.h"
24 #include "ico_syc_public.h"
25 #include "CicoSCConf.h"
26 #include "CicoSCSystemConfig.h"
27
28 using namespace std;
29
30 string g_login_user_name;
31
32 bool launchApps(const string& filepath);
33
34 /*--------------------------------------------------------------------------*/
35 /**
36  * @brief   main
37  *          homescreen main. initialize UXF, app manager, and ecore.
38  *
39  * @param[in]   argc                counts of argment
40  * @param[in]   argv                argment
41  * @return      result
42  * @retval      >=0                 success
43  * @retval      -1                  error
44  */
45 /*--------------------------------------------------------------------------*/
46 int
47 main(int argc, char *argv[])
48 {
49     int ret;
50
51     eina_init();
52     eina_log_level_set(EINA_LOG_LEVEL_DBG);
53
54     ico_log_open("HomeScreen");
55
56
57     /* init configuration */
58     ICO_DBG("main: config initialize start");
59     CicoHomeScreenConfig *config = new CicoHomeScreenConfig();
60     config->Initialize(ICO_HOMESCREEN_CONFIG_FILE);
61     ICO_DBG("main: config initialize end");
62
63     /* PARAM GET LOGIN USER */
64     bundle *b = bundle_import_from_argv(argc, argv); // import from argc+argv
65     const char* valusr = bundle_get_val(b, ICO_SYC_APP_BUNDLE_KEY1);
66     const char* valpath = bundle_get_val(b, ICO_SYC_APP_BUNDLE_KEY2);
67     if ((NULL != valusr) && (0 != valusr)) {
68         g_login_user_name = valusr;
69     }
70     else {
71         g_login_user_name.clear();
72     }
73     string user_start_apps_path;
74     if ((NULL != valpath) && (0 != valpath)) {
75         user_start_apps_path = valpath;
76     }
77     else {
78         user_start_apps_path.clear();
79     }
80     ICO_DBG("PARAM=\"%s\", \"%s\"", g_login_user_name.c_str(),
81             user_start_apps_path.c_str());
82     bundle_free(b);
83     valusr = valpath = NULL;
84     
85     /* init home screen soud */
86     ICO_DBG("main: sound initialize start");
87     CicoHomeScreenSound *sound = new CicoHomeScreenSound();
88     sound->Initialize(config);
89     ICO_DBG("main: sound initialize end");
90     
91     /*create homescreen*/
92     ICO_DBG("main: homescreen initialize start");
93     CicoHomeScreen *home_screen = new CicoHomeScreen();
94     
95     ret = home_screen->Initialize(ICO_ORIENTATION_VERTICAL,config);
96     if(ret != ICO_OK){
97         ICO_ERR("main: homescreen initialize failed");
98         /*clear all classes*/
99         delete home_screen;   
100         delete sound;   
101         delete config;
102         exit(8);
103     }
104     ICO_DBG("main: homescreen initialize end");
105
106     ICO_DBG("main: create homescreen ");
107     launchApps(user_start_apps_path);
108     /*home screen start and go into main loop*/
109     home_screen->StartHomeScreen();
110   
111     ICO_DBG("main: end homescreen");
112     
113     /* when loop is terminated */
114     /* delete homescreen */
115     home_screen->Finalize();
116  
117     /*clear all classes*/
118     delete home_screen;   
119
120     delete sound;   
121
122     delete config;
123
124     return 0;
125 }
126
127 /*--------------------------------------------------------------------------*/
128 /**
129  * @brief   launch applications
130  *
131  * @param   filepath  start applications list file path
132  * @return  bool
133  * @retval  true  success
134  * @retval  false fail
135  */
136 /*--------------------------------------------------------------------------*/
137 bool launchApps(const string& filepath)
138 {
139     ICO_DBG("launcApps start = %s", filepath.c_str());
140     struct stat stat_buf;
141     if (0 != stat(filepath.c_str(), &stat_buf)) {
142         ICO_DBG("launcApps end false(%d, %s)", errno, filepath.c_str());
143         return false;
144     }
145     int i = 0;
146     bool rb = false;
147     string tagApp;
148     ifstream ifs(filepath.c_str());
149     while(ifs >> tagApp) {
150         i++;
151         if (true == tagApp.empty()) {
152             continue;
153         }
154         int r = aul_launch_app(tagApp.c_str(), NULL);
155         ICO_DBG("aul_launch_app %d:appid(%s), r(%d)", i, tagApp.c_str(), r);
156         if (AUL_R_OK == r) {
157             rb = true;
158         }
159     }
160     ICO_DBG("launcApps end %s", rb? "true": "false");
161     return rb;
162 }