1 /* 2014, Copyright © Intel Coporation, license APACHE-2.0, see LICENSE file */
2 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3 // Use of this source code is governed by a apache 2.0 license that can be
4 // found in the LICENSE file.
6 #ifndef COMMON_INSTALLER_APP_INSTALLER_H_
7 #define COMMON_INSTALLER_APP_INSTALLER_H_
9 #include <manifest_parser/utils/logging.h>
17 #include "common/archive_info.h"
18 #include "common/history_logger.h"
19 #include "common/pkgmgr_interface.h"
20 #include "common/pkgmgr_signal.h"
21 #include "common/step/step.h"
22 #include "common/utils/file_logbackend.h"
23 #include "common/utils/macros.h"
25 namespace common_installer {
28 * \brief Includes the main “steps” processing mechanisms. It holds
29 * the lists of steps and runs each of the step in the configured
32 class AppInstaller : public Step::IStepErrorSignal {
34 /** Enumeration of possible returned Results */
44 * \brief explicit Constructor
46 * \param package_type package type
47 * \param pkgmgr pointer to PkgMgrInterface object
49 explicit AppInstaller(const char* package_type, PkgMgrPtr pkgmgr);
51 /** virtual desctructor */
52 virtual ~AppInstaller();
54 /** error handler for sending error signal */
55 void on_error(Step::Status result, const std::string& error) override;
58 * \brief Adds new step to installer by specified type
59 * Type of template parameter is used to create requested step
61 * Context of installer is passed to step in this method
62 * and is not being exposed outside installer.
63 * Step arguments are deduced and forwarded to constructor.
65 * \tparam StepT Step object to be added to the step list
66 * \tparam Args constructor arguments for StepT object
67 * \param args argument list
69 template<class StepT, class... Args>
70 void AddStep(Args&&... args) {
71 std::unique_ptr<Step> step(
72 new StepT(context_.get(), std::forward<Args>(args)...));
74 steps_.emplace_back(std::move(step));
78 * \brief Removes specific step in steps list.
79 * \param step_name step name to be removed
81 void RemoveStep(std::string step_name) {
82 auto it = std::find_if(steps_.begin(), steps_.end(),
83 [&](const std::unique_ptr<Step>& s) {
84 return step_name == s->name();
86 if (steps_.end() == it) {
87 LOG(ERROR) << "Can't find the step : " << step_name;
94 * \brief Adds new step to installer by specified type on specyfic place
96 * Type of template parameter is used to create requested step
98 * Context of installer is passed to step in this method
99 * and is not being exposed outside installer.
100 * Step arguments are deduced and forwarded to constructor.
102 * \tparam StepT Step object to be added to the step list
103 * \tparam index index at which the new step is added
104 * \tparam Args constructor arguments for StepT object
105 * \param args argument list
107 template<class StepT, class... Args>
108 void AddStepAtIndex(unsigned int index, Args&&... args) {
109 std::unique_ptr<Step> step(
110 new StepT(context_.get(), std::forward<Args>(args)...));
112 std::list<std::unique_ptr<Step>> tmpList;
113 tmpList.emplace_back(std::move(step));
114 auto it = steps_.begin();
115 std::advance(it, index);
116 steps_.splice(it, tmpList);
120 * \brief Replaces new step to installer by specified type
121 * Type of template parameter is used to create requested step
123 * Context of installer is passed to step in this method
124 * and is not being exposed outside installer.
125 * Step arguments are deduced and forwarded to constructor.
126 * \tparam StepT Step object to be added to the step list
127 * \tparam Args constructor arguments for StepT object
128 * \param step_name step name to replace
129 * \param args argument list
131 template<class StepT, class... Args>
132 void ReplaceStep(std::string step_name, Args&&... args) {
133 auto it = std::find_if(std::begin(steps_), std::end(steps_),
134 [&](const std::unique_ptr<Step>& s) {
135 return step_name == s->name();
138 if (steps_.end() == it) {
139 LOG(ERROR) << "Can't find the step : " << step_name;
143 std::unique_ptr<Step> step(
144 new StepT(context_.get(), std::forward<Args>(args)...));
146 *it = std::move(step);
150 * \brief Adds new step before specified step
151 * Type of template parameter is used to create requested step
153 * Context of installer is passed to step in this method
154 * and is not being exposed outside installer.
155 * Step arguments are deduced and forwarded to constructor.
156 * \tparam StepT Step object to be added to the step list
157 * \tparam Args constructor arguments for StepT object
158 * \param step_name step name to find and add
159 * \param args argument list
161 template<class StepT, class... Args>
162 void AddStepBefore(std::string step_name, Args&&... args) {
163 auto it = std::find_if(std::begin(steps_), std::end(steps_),
164 [&](const std::unique_ptr<Step>& s) {
165 return step_name == s->name();
168 if (steps_.end() == it) {
169 LOG(ERROR) << "Can't find the step : " << step_name;
173 std::unique_ptr<Step> step(
174 new StepT(context_.get(), std::forward<Args>(args)...));
176 steps_.insert(it, std::move(step));
180 * \brief Adds new step after specified step
181 * Type of template parameter is used to create requested step
183 * Context of installer is passed to step in this method
184 * and is not being exposed outside installer.
185 * Step arguments are deduced and forwarded to constructor.
186 * \tparam StepT Step object to be added to the step list
187 * \tparam Args constructor arguments for StepT object
188 * \param step_name step name to find and add
189 * \param args argument list
191 template<class StepT, class... Args>
192 void AddStepAfter(std::string step_name, Args&&... args) {
193 auto it = std::find_if(std::begin(steps_), std::end(steps_),
194 [&](const std::unique_ptr<Step>& s) {
195 return step_name == s->name();
198 if (steps_.end() == it) {
199 LOG(ERROR) << "Can't find the step : " << step_name;
203 std::unique_ptr<Step> step(
204 new StepT(context_.get(), std::forward<Args>(args)...));
206 steps_.insert(++it, std::move(step));
210 * \brief runs the steps in the specific sequence
212 * \return Result of the run (eg Result:OK)
217 * \brief runs the process operations of steps
219 * \return Result of the run (eg Result:OK)
224 * \brief runs the undo operations of steps
226 * \return Result of the run (eg Result:OK)
231 * \brief runs the clean operations of steps
233 * \return Result of the run (eg Result:OK)
238 * \brief This method can be used to check
239 * the number of the registered steps.
241 * \return number of steps registered in app-installer
243 unsigned int StepCount() {
244 return steps_.size();
247 void SetIndex(int index) {
255 virtual std::unique_ptr<ArchiveInfo> GetArchiveInfo() = 0;
259 std::unique_ptr<InstallerContext> context_;
261 virtual void InstallSteps();
262 virtual void UpdateSteps();
263 virtual void UninstallSteps();
264 virtual void ReinstallSteps();
265 virtual void DeltaSteps();
266 virtual void MoveSteps();
267 virtual void RecoverySteps();
268 virtual void MountInstallSteps();
269 virtual void MountUpdateSteps();
270 virtual void ManifestDirectInstallSteps();
271 virtual void ManifestDirectUpdateSteps();
272 virtual void ManifestPartialInstallSteps();
273 virtual void ManifestPartialUpdateSteps();
274 virtual void PartialUninstallSteps();
275 virtual void ReadonlyUpdateInstallSteps();
276 virtual void ReadonlyUpdateUninstallSteps();
277 virtual void DisablePkgSteps();
278 virtual void EnablePkgSteps();
279 virtual void MigrateExtImgSteps();
280 virtual void RecoverDBSteps();
281 virtual void UnknownSteps();
286 std::list<std::unique_ptr<Step>> steps_;
287 std::list<std::unique_ptr<Step>>::iterator it_;
289 // data used to send signal
290 std::unique_ptr<PkgmgrSignal> ps_;
292 bool SendStartIfNotSent(bool is_skippable);
293 void SendProgress(int progress);
294 void SendFinished(Step::Status status);
295 Step::Status SafeExecute(std::unique_ptr<Step> const& step_ptr,
296 Step::Status (Step::*method)(),
298 void HandleStepError(Step::Status result, const std::string& error);
299 std::string GetPackageVersion();
301 std::shared_ptr<utils::FileLogBackend> failure_logger_;
302 Step::Status status_;
306 HistoryLogger history_logger_;
308 friend class InstallerRunner;
310 SCOPE_LOG_TAG(AppInstaller)
312 DISALLOW_COPY_AND_ASSIGN(AppInstaller);
315 } // namespace common_installer
317 #endif // COMMON_INSTALLER_APP_INSTALLER_H_