Initialize Tizen 2.3
[framework/web/wrt-installer.git] / src_wearable / 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     void SetProgressFlag(bool flag)
40     {
41         m_progressFlag = flag;
42     }
43     bool GetProgressFlag() const
44     {
45         return m_progressFlag;
46     }
47
48     ProgressDescription GetProgressDescription() const
49     {
50         return m_progresDescription;
51     }
52
53     ProgressPercent GetProgressPercent() const
54     {
55         return m_progresPercent;
56     }
57
58     void UpdateProgress(T_InstallationStep step,
59                         ProgressDescription const &description)
60     {
61         m_progresPercent =
62             ((static_cast<ProgressPercent>(step)) /
63              static_cast<ProgressPercent>(lastElement)) * 100;
64         m_progresDescription = description;
65     }
66 };
67
68 template<class T_JobStruct>
69 class JobContextBase
70 {
71   public:
72     JobContextBase(const T_JobStruct& jobStruct) :
73         m_jobStruct(jobStruct)
74     {}
75
76     T_JobStruct GetInstallerStruct() const
77     {
78         return m_jobStruct;
79     }
80
81   protected:
82     T_JobStruct m_jobStruct;
83 };
84
85 template<typename T_finishedCb, typename T_progressCb>
86 struct JobCallbacksBase
87 {
88     T_finishedCb finishedCallback;
89     T_progressCb progressCallback;
90     void *userParam;
91
92     // It must be empty-constructible as a parameter of generic event
93     JobCallbacksBase() :
94         finishedCallback(0),
95         progressCallback(0),
96         userParam(0)
97     {}
98
99     JobCallbacksBase(T_finishedCb finished,
100                      T_progressCb progress,
101                      void *param) :
102         finishedCallback(finished),
103         progressCallback(progress),
104         userParam(param)
105     {}
106 };
107 } //namespace Jobs
108
109 #endif // SRC_INSTALLER_CORE_JOBS_JOB_BASE_H