Coverity fix: check return type
[platform/core/messaging/msg-service.git] / mapi / msg_control.cpp
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 #include <errno.h>
18
19 #include "MsgHandle.h"
20 #include "MsgDebug.h"
21 #include "MsgException.h"
22
23 #include "msg_private.h"
24 #include "msg.h"
25
26 /*==================================================================================================
27                                      FUNCTION IMPLEMENTATION
28 ==================================================================================================*/
29 EXPORT_API int msg_open_msg_handle(msg_handle_t *handle)
30 {
31         CHECK_MSG_SUPPORTED(MSG_TELEPHONY_SMS_FEATURE);
32
33         if (handle == NULL) {
34                 MSG_FATAL("Input Parameter is NULL");
35                 return MSG_ERR_INVALID_PARAMETER;
36         }
37         /* Create MsgHandle */
38         MsgHandle* pHandle = new MsgHandle();
39
40         if (pHandle == NULL)
41                 return MSG_ERR_MEMORY_ERROR;
42         *handle = (msg_handle_t)pHandle;
43
44         try {
45                 /* Connect to Socket */
46                 pHandle->openHandle();
47         } catch (MsgException& e) {
48                 MSG_FATAL("%s", e.what());
49
50                 /* Destroy MsgHandle */
51                 delete pHandle;
52                 *handle = NULL;
53
54                 if (e.errorCode() == MsgException::SERVER_READY_ERROR)
55                         return MSG_ERR_SERVER_NOT_READY;
56                 else if (e.errorCode() == MsgException::SECURITY_ERROR)
57                         return MSG_ERR_PERMISSION_DENIED;
58                 else
59                         return MSG_ERR_COMMUNICATION_ERROR;
60         }
61
62         return MSG_SUCCESS;
63 }
64
65
66 EXPORT_API int msg_close_msg_handle(msg_handle_t *handle)
67 {
68         CHECK_MSG_SUPPORTED(MSG_TELEPHONY_SMS_FEATURE);
69
70         if (handle == NULL || *handle == NULL) {
71                 MSG_FATAL("Input Parameter is NULL");
72                 return MSG_ERR_INVALID_PARAMETER;
73         }
74
75         MsgHandle* pHandle = (MsgHandle*)(*handle);
76
77         try {
78                 /* Disconnect from Socket */
79                 pHandle->closeHandle(pHandle);
80         } catch (MsgException& e) {
81                 MSG_FATAL("%s", e.what());
82                 return MSG_ERR_COMMUNICATION_ERROR;
83         }
84
85         /* Destroy MsgHandle */
86         delete pHandle;
87         *handle = NULL;
88
89         return MSG_SUCCESS;
90 }
91