Add permission check for open handle
[platform/core/messaging/msg-service.git] / include / utils / MsgException.h
1 /*
2  * Copyright (c) 2014 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 #ifndef MSG_EXCEPTION_H
18 #define MSG_EXCEPTION_H
19
20 /*==================================================================================================
21                                          INCLUDE FILES
22 ==================================================================================================*/
23 #include <stdexcept>
24 #include <string>
25
26 using namespace std;
27
28
29 /*==================================================================================================
30                                          DEFINES
31 ==================================================================================================*/
32 #define THROW(errCode, debugFmt, ...) \
33 do {\
34         char __debugBuf[256];\
35         snprintf(__debugBuf, 256, debugFmt, ##__VA_ARGS__);\
36         MsgException e(errCode, __debugBuf);\
37         MSG_FATAL("%s [%d]", e.what(), e.errorCode());\
38     throw e; \
39 } while (0)
40
41
42 /*==================================================================================================
43                                      CLASS DEFINITIONS
44 ==================================================================================================*/
45 class MsgException : public runtime_error /* public exception */
46 {
47 public:
48         MsgException(int errCode, const string& msg = "")
49                 : runtime_error(errorStrings[errCode] + " : " +  msg), eCode(errCode) {
50         }
51
52         enum
53         {
54                 SUCCESS = 0,
55
56                 INVALID_PARAM,
57                 INVALID_RESULT,
58                 SELECT_ERROR,
59                 IPC_ERROR,
60                 OUT_OF_RANGE = 5,
61
62                 SMS_PLG_ERROR,
63                 MMS_PLG_ERROR,
64                 PLUGIN_ERROR,
65                 SENT_STATUS_ERROR,
66                 INCOMING_MSG_ERROR = 10,
67
68                 FILE_ERROR,
69                 SECURITY_ERROR,
70                 SERVER_READY_ERROR = 13,
71
72                 REQ_EXIST_ERROR,
73                 /* dont erase NUM_ERRORS. place a new error code in ahead of NUM_ERRORS */
74                 NUM_ERRORS
75         };
76
77         int errorCode() { return eCode; }
78
79 private:
80         static string errorStrings[NUM_ERRORS];
81         int eCode;
82 };
83
84 #endif /* __MSG_EXCEPTION_H__ */
85
86