update tizen source
[framework/messaging/msg-service.git] / mapi / MapiControl.cpp
1 /*
2 *
3 * Copyright (c) 2000-2012 Samsung Electronics Co., Ltd. All Rights Reserved.
4 *
5 * This file is part of msg-service.
6 *
7 * Contact: Jaeyun Jeong <jyjeong@samsung.com>
8 *          Sangkoo Kim <sangkoo.kim@samsung.com>
9 *          Seunghwan Lee <sh.cat.lee@samsung.com>
10 *          SoonMin Jung <sm0415.jung@samsung.com>
11 *          Jae-Young Lee <jy4710.lee@samsung.com>
12 *          KeeBum Kim <keebum.kim@samsung.com>
13 *
14 * PROPRIETARY/CONFIDENTIAL
15 *
16 * This software is the confidential and proprietary information of
17 * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
18 * disclose such Confidential Information and shall use it only in
19 * accordance with the terms of the license agreement you entered
20 * into with SAMSUNG ELECTRONICS.
21 *
22 * SAMSUNG make no representations or warranties about the suitability
23 * of the software, either express or implied, including but not limited
24 * to the implied warranties of merchantability, fitness for a particular
25 * purpose, or non-infringement. SAMSUNG shall not be liable for any
26 * damages suffered by licensee as a result of using, modifying or
27 * distributing this software or its derivatives.
28 *
29 */
30
31 #include <errno.h>
32
33 #include "MsgHandle.h"
34 #include "MsgDebug.h"
35 #include "MsgException.h"
36 #include "MapiControl.h"
37
38
39 /*==================================================================================================
40                                      FUNCTION IMPLEMENTATION
41 ==================================================================================================*/
42 EXPORT_API int msg_open_msg_handle(MSG_HANDLE_T *handle)
43 {
44         MsgHandle* pHandle = new MsgHandle();
45
46         if (handle == NULL)
47         {
48                 MSG_FATAL("Input Paramter is NULL");
49                 return -EINVAL;
50         }
51
52         // Create MsgHandle
53         *handle = (MSG_HANDLE_T)pHandle;
54
55         if (*handle == NULL)
56                 return -EINVAL;
57
58         try
59         {
60                 // Connect to Socket
61                 pHandle->openHandle();
62         }
63         catch (MsgException& e)
64         {
65                 MSG_FATAL("%s", e.what());
66
67                 if (e.errorCode() == MsgException::SERVER_READY_ERROR)
68                         return MSG_ERR_SERVER_NOT_READY;
69                 else
70                         return MSG_ERR_COMMUNICATION_ERROR;
71         }
72
73         return MSG_SUCCESS;
74 }
75
76
77 EXPORT_API int msg_close_msg_handle(MSG_HANDLE_T *handle)
78 {
79         if (handle == NULL || *handle == NULL)
80         {
81                 MSG_FATAL("Input Paramter is NULL");
82                 return -EINVAL;
83         }
84
85         MsgHandle* pHandle = (MsgHandle*)(*handle);
86
87         try
88         {
89                 // Disconnect to Socket
90                 pHandle->closeHandle(pHandle);
91         }
92         catch (MsgException& e)
93         {
94                 MSG_FATAL("%s", e.what());
95                 return MSG_ERR_COMMUNICATION_ERROR;
96         }
97
98         // Destroy MsgHandle
99         delete (MsgHandle*)(*handle);
100         (*handle) = NULL;
101
102         return MSG_SUCCESS;
103 }
104