tizen beta release
[framework/web/wrt-installer.git] / src / jobs / job_base.h
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 #ifndef SRC_INSTALLER_CORE_JOBS_JOB_BASE_H
17 #define SRC_INSTALLER_CORE_JOBS_JOB_BASE_H
18
19 #include <string>
20
21 typedef std::string ProgressDescription;
22 typedef float ProgressPercent;
23
24 namespace Jobs {
25 template<typename T_InstallationStep,
26          T_InstallationStep lastElement>
27 class JobProgressBase
28 {
29   protected:
30     bool m_progressFlag;
31     ProgressDescription m_progresDescription;
32     ProgressPercent m_progresPercent;
33
34   public:
35     JobProgressBase() : m_progressFlag(false),
36         m_progresPercent(0.0)
37     {
38     }
39
40     void SetProgressFlag(bool flag)
41     {
42         m_progressFlag = flag;
43     }
44     bool GetProgressFlag() const
45     {
46         return m_progressFlag;
47     }
48
49     ProgressDescription GetProgressDescription() const
50     {
51         return m_progresDescription;
52     }
53
54     ProgressPercent GetProgressPercent() const
55     {
56         return m_progresPercent;
57     }
58
59     void UpdateProgress(T_InstallationStep step,
60             ProgressDescription const &description)
61     {
62         m_progresPercent =
63             ((static_cast<ProgressPercent>(step) + 1.0) /
64              static_cast<ProgressPercent>(lastElement)) * 100;
65         m_progresDescription = description;
66     }
67 };
68
69 template<class T_JobStruct>
70 class JobContextBase
71 {
72   public:
73     JobContextBase(const T_JobStruct& jobStruct) :
74         m_jobStruct(jobStruct)
75     {
76     }
77
78     T_JobStruct getInstallerStruct() const
79     {
80         return m_jobStruct;
81     }                                                                  //TODO RENAME
82
83   protected:
84     T_JobStruct m_jobStruct;
85 };
86
87 template<typename T_finishedCb, typename T_progressCb>
88 struct JobCallbacksBase
89 {
90     T_finishedCb finishedCallback;
91     T_progressCb progressCallback;
92     void *userParam;
93
94     // It must be empty-constructible as a parameter of generic event
95     JobCallbacksBase() :
96         finishedCallback(0),
97         progressCallback(0),
98         userParam(0)
99     {
100     }
101
102     JobCallbacksBase(T_finishedCb finished,
103             T_progressCb progress,
104             void *param) :
105         finishedCallback(finished),
106         progressCallback(progress),
107         userParam(param)
108     {
109     }
110 };
111 } //namespace Jobs
112
113 #endif // SRC_INSTALLER_CORE_JOBS_JOB_BASE_H