Merge "add missing packages requires" into tizen
[profile/ivi/ico-uxf-homescreen.git] / lib / system-controller / CicoSCUserManager.h
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 //==========================================================================
11 /**
12  *  @file   CicoSCUserManager.h
13  *
14  *  @brief  This file is definition of CicoSCUserManager class
15  */
16 //==========================================================================
17 #ifndef __CICO_SC_USER_MANAGER_H__
18 #define __CICO_SC_USER_MANAGER_H__
19
20 #include <string.h>
21 #include <vector>
22
23 //==========================================================================
24 //  Forward declaration
25 //==========================================================================
26 class CicoSCCommand;
27 class CicoSCUser;
28 class CicoSCUserConf;
29
30 typedef std::pair<int, std::string> pairPidAppid;
31
32 //==========================================================================
33 /*
34  *  @brief  This class manages control of user and access to user information
35  */
36 //==========================================================================
37 class CicoSCUserManager
38 {
39 public:
40     // get CicoSCUserManager instance
41     static CicoSCUserManager* getInstance(void);
42
43     // handle command
44     void handleCommand(const CicoSCCommand * cmd);
45
46     // load configuration file
47     int load(const std::string & confFile);
48     // initialize
49     int initialize(void);
50
51     // get information
52     const CicoSCUser* getLoginUser(void);
53     const std::vector<CicoSCUser*>& getUserList(void);
54     const std::vector<std::string>& getHomeScreenList(void);
55
56     // change user
57     void changeUser(const std::string & name, const std::string & passwd);
58     void cloaseUser();
59
60     // dump log
61     void dumpUserList(void);
62     void dumpHomeScreenList(void);
63
64     // application daed watcher
65     bool appDeadHandler(int pid);
66
67     bool isStoppingNow();
68
69     // working user directory make
70     void getWorkingDir(const std::string& usr, std::string& dir);
71     const std::string& getHomeDir() const;
72 private:
73     // default constructor
74     CicoSCUserManager();
75
76     // destructor
77     ~CicoSCUserManager();
78
79     // assignment operator
80     CicoSCUserManager& operator=(const CicoSCUserManager &object);
81
82     // copy constructor
83     CicoSCUserManager(const CicoSCUserManager &object);
84
85     // callback
86     void userlistCB(const std::string & appid);
87     void lastinfoCB(const std::string & appid);
88
89     // save last user name to file
90     void saveLastUser(void);
91     // load last user name from file
92     void loadLastUser(void);
93     // load last information from file
94     void loadLastInfo(void);
95
96     // set login user info from config file
97     void setLoginUser(const boost::property_tree::ptree & root);
98     // create list from config file
99     void createUserList(const boost::property_tree::ptree & root);
100     void createHomeScreenList(const boost::property_tree::ptree & root);
101
102     // set application's last information
103     void setLastInfo(const std::string & appid, const std::string & info);
104
105     // find user config by user name
106     const CicoSCUser* findUserConfbyName(const std::string & name);
107
108     // Imprinting to file, that file is application's running information 
109     bool impritingLastApps(const std::string& ofnm);
110
111     // Killing running application and homeScreen
112     bool killingAppsAndHS(const std::string& usrnm);
113
114     // launch homescreen request
115     bool launchHomescreenReq(const std::string& usr,
116                              const std::string& appid_hs);
117
118     // flag file control
119     void flagFileOn(const char* text = NULL);
120     void flagFileOff();
121
122 private:
123     static CicoSCUserManager*   ms_myInstance;  ///< CicoSCUserManager Object
124
125     std::string                 m_login;           ///< Login User Name
126     std::vector<CicoSCUser*>    m_userList;        ///< User List
127     std::vector<std::string>    m_homescreenList;  ///< HomeScreen List
128     std::string                 m_parentDir;       ///  login-user use directory
129     const CicoSCUserConf*       m_uConfig;
130     std::string                 m_flagPath;        ///  history save control flag file
131     std::vector<pairPidAppid>   m_vppa;            ///  app dead watcher
132     bool                        m_wait;            ///  app dead wait flag
133     std::string                 m_waitName;        ///  wait backup login name
134     std::string                 m_waitHS;          ///  wait backup homescreen appid
135 };
136
137 /**
138  * @brief get Homescreen Stopping Status
139  * @ret bool
140  * @retval true: stopping now
141  * @retval false: no stop
142  *
143  */
144 inline bool CicoSCUserManager::isStoppingNow(){
145     return !m_vppa.empty();
146 }
147
148 /**
149  * @brief close User
150  */
151 inline void CicoSCUserManager::cloaseUser()
152 {
153     flagFileOn();
154     killingAppsAndHS(m_login);
155 }
156
157 /**
158  *
159  */
160 inline const std::string& CicoSCUserManager::getHomeDir() const
161 {
162     return m_parentDir;
163 }
164
165 #endif  // __CICO_SC_USER_MANAGER_H__
166 // vim:set expandtab ts=4 sw=4: