tizen beta release
[framework/web/wrt-installer.git] / src / jobs / job_exception_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 /**
17  * @file    job_exception_base.h
18  * @author  Pawel Sikorski (p.sikorski@samgsung.com)
19  * @version
20  * @brief
21  */
22
23 #include <dpl/exception.h>
24
25 #ifndef SRC_INSTALLER_CORE_JOBS_JOB_EXCEPTION_BASE_H_
26 #define SRC_INSTALLER_CORE_JOBS_JOB_EXCEPTION_BASE_H_
27
28 #define DECLARE_JOB_EXCEPTION_BASE(Base, Class, Param)                       \
29     class Class :                                                                    \
30         public Base {                                                       \
31       public:                                                                  \
32         Class(const char *path,                                              \
33               const char *function,                                          \
34               int line,                                                      \
35               const std::string & message = std::string()) :                                                                  \
36                       Base(path, function, line, message)                              \
37               {                                                                    \
38                   m_className = # Class;                                            \
39                   m_param = Param;                                                   \
40               }                                                                    \
41                                                                              \
42               Class(const char *path,                                              \
43                     const char *function,                                          \
44                     int line,                                                      \
45                     const Exception &reason,                                       \
46                     const std::string & message = std::string()) :                                                                  \
47                             Base(path, function, line, reason, message)                      \
48                     {                                                                    \
49                         m_className = # Class;                                            \
50                         m_param = Param;                                                   \
51                     }                                                                    \
52                                                                              \
53                     virtual int getParam() const                                         \
54         {                                                                    \
55             return m_param;                                                  \
56         }                                                                    \
57       protected:                                                               \
58         int m_param;                                                         \
59     };
60 //TODO template for m_param
61
62 #define DECLARE_JOB_EXCEPTION(Base, Class, Param)                            \
63     class Class :                                                                    \
64         public Base {                                                       \
65       public:                                                                  \
66         Class(const char *path,                                              \
67               const char *function,                                          \
68               int line,                                                      \
69               const std::string & message = std::string()) :                                                                  \
70                       Base(path, function, line, message)                              \
71               {                                                                    \
72                   m_className = # Class;                                            \
73                   m_param = Param;                                                   \
74               }                                                                    \
75                                                                              \
76               Class(const char *path,                                              \
77                     const char *function,                                          \
78                     int line,                                                      \
79                     const Exception &reason,                                       \
80                     const std::string & message = std::string()) :                                                                  \
81                             Base(path, function, line, reason, message)                      \
82                     {                                                                    \
83                         m_className = # Class;                                            \
84                         m_param = Param;                                                   \
85                     }                                                                    \
86                                                                              \
87                     virtual int getParam() const                                         \
88         {                                                                    \
89             return m_param;                                                  \
90         }                                                                    \
91     };
92 //TODO template for m_param
93
94 //TODO maybe use DPL:: DECLARE_EXCEPTION_TYPE instead of creating own
95
96 namespace Jobs {
97 DECLARE_JOB_EXCEPTION_BASE(DPL::Exception, JobExceptionBase, 0)
98 }
99
100 #endif /* SRC_INSTALLER_CORE_JOBS_JOB_EXCEPTION_BASE_H_ */