tizen beta release
[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     Job(PluginInstallation),
34     JobContextBase<PluginInstallerStruct>(installerStruct)
35 {
36     //
37     // Init installer context
38     //
39     m_context.pluginFilePath = pluginPath;
40     m_context.pluginHandle = INVALID_HANDLE;
41     m_context.installationCompleted = false;
42
43     m_context.installerTask = this;
44     //
45     // Create main installation tasks
46     //
47     AddTask(new PluginInstallTask(&m_context));
48 }
49
50 void JobPluginInstall::SendProgress()
51 {
52     if (GetProgressFlag() && getInstallerStruct().progressCallback != NULL) {
53         LogDebug("Call Plugin install progressCallback");
54         getInstallerStruct().progressCallback(getInstallerStruct().userParam,
55                 GetProgressPercent(), GetProgressDescription());
56     }
57 }
58
59 void JobPluginInstall::SendFinishedSuccess()
60 {
61     PluginHandle handle = getNewPluginHandle();
62
63     if (handle != Jobs::PluginInstall::JobPluginInstall::INVALID_HANDLE &&
64         isReadyToInstall())
65     {
66         LogDebug("Call Plugin install success finishedCallback");
67         getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
68                 Exceptions::Success);
69     } else {
70         LogDebug("Call Plugin install waiting finishedCallback");
71         getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
72                 Exceptions::InstallationWaiting);
73
74         LogInfo("Installation: " << getFilePath() <<
75                 " NOT possible");
76     }
77 }
78
79 void JobPluginInstall::SendFinishedFailure()
80 {
81     LogError("Error in plugin installation step: " << m_exceptionCaught);
82     LogError("Message: " << m_exceptionMessage);
83
84     LogDebug("Call Plugin install failure finishedCallback");
85     getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
86             m_exceptionCaught);
87 }
88
89 void JobPluginInstall::SaveExceptionData(const Jobs::JobExceptionBase &e)
90 {
91     m_exceptionCaught = static_cast<Exceptions::Type>(e.getParam());
92     m_exceptionMessage = e.GetMessage();
93 }
94 } //namespace Jobs
95 } //namespace PluginInstall