update tizen source
[framework/messaging/msg-service.git] / proxy / MsgHandleSetting.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 "MsgDebug.h"
32 #include "MsgUtilFunction.h"
33 #include "MsgCppTypes.h"
34 #include "MsgException.h"
35 #include "MsgHandle.h"
36
37
38 /*==================================================================================================
39                                      IMPLEMENTATION OF MsgHandle - Setting Member Functions
40 ==================================================================================================*/
41 MSG_ERROR_T MsgHandle::setConfig(const MSG_SETTING_S *pSetting)
42 {
43         // Allocate Memory to Command Data
44         int cmdSize = getSettingCmdSize(pSetting->type);
45
46         char cmdBuf[cmdSize];
47         bzero(cmdBuf, cmdSize);
48         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
49
50         // Set Command Parameters
51         pCmd->cmdType = MSG_CMD_SET_CONFIG;
52
53         // Copy Cookie
54         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
55
56         // Copy Command Data
57         memcpy(pCmd->cmdData, pSetting, cmdSize-sizeof(MSG_CMD_S));
58
59         // Send Command to Messaging FW
60         char* pEventData = NULL;
61         AutoPtr<char> eventBuf(&pEventData);
62
63         write((char*)pCmd, cmdSize, &pEventData);
64
65         // Get Return Data
66         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
67
68         if (pEvent->eventType != MSG_EVENT_SET_CONFIG)
69         {
70                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
71         }
72
73         return pEvent->result;
74 }
75
76
77 MSG_ERROR_T MsgHandle::getConfig(MSG_SETTING_S *pSetting)
78 {
79         // Allocate Memory to Command Data
80         int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_OPTION_TYPE_T);
81
82         char cmdBuf[cmdSize];
83         bzero(cmdBuf, cmdSize);
84         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
85
86         // Set Command Parameters
87         pCmd->cmdType = MSG_CMD_GET_CONFIG;
88
89         // Copy Cookie
90         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
91
92         // Copy Command Data
93         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &(pSetting->type), sizeof(MSG_OPTION_TYPE_T));
94
95         // Send Command to Messaging FW
96         char* pEventData = NULL;
97         AutoPtr<char> eventBuf(&pEventData);
98
99
100         write((char*)pCmd, cmdSize, &pEventData);
101
102         // Get Return Data
103         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
104
105         if (pEvent->eventType != MSG_EVENT_GET_CONFIG)
106         {
107                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
108         }
109
110         if (pEvent->result == MSG_SUCCESS)
111                 MsgDecodeSetting(pEvent->data, pSetting);
112
113         return pEvent->result;
114 }
115