merge with master
[framework/web/wrt-installer.git] / src / jobs / plugin_install / job_plugin_install.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /**
17  * @file    job_plugin_install.cpp
18  * @author  Pawel Sikorski (p.sikorski@samgsung.com)
19  * @version
20  * @brief
21  */
22 #include <plugin_install/job_plugin_install.h>
23 #include <plugin_install/plugin_install_task.h>
24 #include <widget_install/widget_installer_struct.h> //TODO remove
25
26 //#include <plugin_logic.h>
27 #include "plugin_objects.h"
28
29 namespace Jobs {
30 namespace PluginInstall {
31 JobPluginInstall::JobPluginInstall(std::string const &pluginPath,
32                                    const PluginInstallerStruct &installerStruct)
33     :
34     Job(PluginInstallation),
35     JobContextBase<PluginInstallerStruct>(installerStruct)
36 {
37     //
38     // Init installer context
39     //
40     m_context.pluginFilePath = pluginPath;
41     m_context.pluginHandle = INVALID_HANDLE;
42     m_context.installationCompleted = false;
43
44     m_context.installerTask = this;
45     //
46     // Create main installation tasks
47     //
48     AddTask(new PluginInstallTask(&m_context));
49 }
50
51 void JobPluginInstall::SendProgress()
52 {
53     if (GetProgressFlag() && getInstallerStruct().progressCallback != NULL) {
54         LogDebug("Call Plugin install progressCallback");
55         getInstallerStruct().progressCallback(getInstallerStruct().userParam,
56                                               GetProgressPercent(),
57                                               GetProgressDescription());
58     }
59 }
60
61 void JobPluginInstall::SendFinishedSuccess()
62 {
63     PluginHandle handle = getNewPluginHandle();
64
65     if (handle != Jobs::PluginInstall::JobPluginInstall::INVALID_HANDLE &&
66         isReadyToInstall())
67     {
68         LogDebug("Call Plugin install success finishedCallback");
69         getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
70                                               Exceptions::Success);
71     } else {
72         LogDebug("Call Plugin install waiting finishedCallback");
73         getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
74                                               Exceptions::InstallationWaiting);
75
76         LogInfo("Installation: " << getFilePath() <<
77                 " NOT possible");
78     }
79 }
80
81 void JobPluginInstall::SendFinishedFailure()
82 {
83     LogError("Error in plugin installation step: " << m_exceptionCaught);
84     LogError("Message: " << m_exceptionMessage);
85
86     LogDebug("Call Plugin install failure finishedCallback");
87     getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
88                                           m_exceptionCaught);
89 }
90
91 void JobPluginInstall::SaveExceptionData(const Jobs::JobExceptionBase &e)
92 {
93     m_exceptionCaught = static_cast<Exceptions::Type>(e.getParam());
94     m_exceptionMessage = e.GetMessage();
95 }
96 } //namespace Jobs
97 } //namespace PluginInstall