Improve typing of constants data
[platform/core/messaging/msg-service.git] / framework / transaction-manager / MsgCmdHandlerSetting.cpp
1 /*
2  * msg-service
3  *
4  * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18 */
19
20 #include "MsgDebug.h"
21 #include "MsgCmdHandler.h"
22 #include "MsgSettingHandler.h"
23 #include "MsgUtilFunction.h"
24 #include "MsgCppTypes.h"
25
26
27 /*==================================================================================================
28                                      FUNCTION IMPLEMENTATION
29 ==================================================================================================*/
30 int MsgSetConfigHandler(const MSG_CMD_S *pCmd, char **ppEvent)
31 {
32         msg_error_t err = MSG_SUCCESS;
33
34         int eventSize = 0;
35         int eventType = -1;
36
37         // Get Setting Structure
38         MSG_SETTING_S* pSetting = (MSG_SETTING_S*)pCmd->cmdData;
39
40         // Set Config Data
41         err = MsgSetConfigData(pSetting);
42
43         if (err == MSG_SUCCESS)
44         {
45                 MSG_DEBUG("Command Handle Success : MsgSetConfigData()");
46         }
47         else
48         {
49                 MSG_DEBUG("Command Handle Fail : MsgSetConfigData()");
50         }
51
52         // Make Event Data
53         switch (pCmd->cmdType) {
54         case MSG_CMD_SET_SMSC_OPT :
55                 eventType = MSG_EVENT_SET_SMSC_OPT;
56                 break;
57         case MSG_CMD_SET_CB_OPT :
58                 eventType = MSG_EVENT_SET_CB_OPT;
59                 break;
60         case MSG_CMD_SET_SMS_SEND_OPT :
61                 eventType = MSG_EVENT_SET_SMS_SEND_OPT;
62                 break;
63         case MSG_CMD_SET_MMS_SEND_OPT :
64                 eventType = MSG_EVENT_SET_MMS_SEND_OPT;
65                 break;
66         case MSG_CMD_SET_MMS_RECV_OPT :
67                 eventType = MSG_EVENT_SET_MMS_RECV_OPT;
68                 break;
69         case MSG_CMD_SET_PUSH_MSG_OPT :
70                 eventType = MSG_EVENT_SET_PUSH_MSG_OPT;
71                 break;
72         case MSG_CMD_SET_VOICE_MSG_OPT :
73                 eventType = MSG_EVENT_SET_VOICE_MSG_OPT;
74                 break;
75         case MSG_CMD_SET_GENERAL_MSG_OPT :
76                 eventType = MSG_EVENT_SET_GENERAL_MSG_OPT;
77                 break;
78         case MSG_CMD_SET_MSG_SIZE_OPT :
79                         eventType = MSG_EVENT_SET_MSG_SIZE_OPT;
80                         break;
81         default :
82                 break;
83         }
84
85         eventSize = MsgMakeEvent(NULL, 0, eventType, err, (void**)ppEvent);
86
87         return eventSize;
88 }
89
90
91 int MsgGetConfigHandler(const MSG_CMD_S *pCmd, char **ppEvent)
92 {
93         msg_error_t err = MSG_SUCCESS;
94
95         char* encodedData = NULL;
96         AutoPtr<char> buf(&encodedData);
97
98         int dataSize = 0;
99         int eventSize = 0;
100         int eventType = -1;
101
102         // Get Option Type
103         MSG_OPTION_TYPE_T* type = (MSG_OPTION_TYPE_T*)pCmd->cmdData;
104
105         // Get Config Data
106         MSG_SETTING_S setting;
107         setting.type = *type;
108
109         err = MsgGetConfigData(&setting);
110
111         if (err == MSG_SUCCESS)
112         {
113                 MSG_DEBUG("Command Handle Success : MsgGetConfigData()");
114
115                 // Encoding Config Data
116                 switch (setting.type)
117                         {
118                                 case MSG_GENERAL_OPT :
119                                         dataSize += sizeof(MSG_GENERAL_OPT_S);
120                                         break;
121                                 case MSG_SMS_SENDOPT :
122                                         dataSize += sizeof(MSG_SMS_SENDOPT_S);
123                                         break;
124                                 case MSG_SMSC_LIST :
125                                         dataSize += sizeof(MSG_SMSC_LIST_S);
126                                         break;
127                                 case MSG_MMS_SENDOPT :
128                                         dataSize += sizeof(MSG_MMS_SENDOPT_S);
129                                         break;
130                                 case MSG_MMS_RECVOPT :
131                                         dataSize += sizeof(MSG_MMS_RECVOPT_S);
132                                         break;
133                                 case MSG_MMS_STYLEOPT :
134                                         dataSize += sizeof(MSG_MMS_STYLEOPT_S);
135                                         break;
136                                 case MSG_PUSHMSG_OPT :
137                                         dataSize += sizeof(MSG_PUSHMSG_OPT_S);
138                                         break;
139                                 case MSG_CBMSG_OPT :
140                                         dataSize += sizeof(MSG_CBMSG_OPT_S);
141                                         break;
142                                 case MSG_VOICEMAIL_OPT :
143                                         dataSize += sizeof(MSG_VOICEMAIL_OPT_S);
144                                         break;
145                                 case MSG_MSGSIZE_OPT :
146                                         dataSize += sizeof(MSG_MSGSIZE_OPT_S);
147                                         break;
148                                 default:
149                                         break;
150                         }
151
152                         encodedData = (char*)new char[dataSize];
153                         void* p = (void*)encodedData;
154
155                         switch (setting.type)
156                         {
157                         case MSG_GENERAL_OPT :
158                                 memcpy(p, &(setting.option.generalOpt), dataSize);
159                                 break;
160                         case MSG_SMS_SENDOPT :
161                                 memcpy(p, &(setting.option.smsSendOpt), dataSize);
162                                 break;
163                         case MSG_SMSC_LIST :
164                                 memcpy(p, &(setting.option.smscList), dataSize);
165                                 break;
166                         case MSG_MMS_SENDOPT :
167                                 memcpy(p, &(setting.option.mmsSendOpt), dataSize);
168                                 break;
169                         case MSG_MMS_RECVOPT :
170                                 memcpy(p, &(setting.option.mmsRecvOpt), dataSize);
171                                 break;
172                         case MSG_MMS_STYLEOPT :
173                                 memcpy(p, &(setting.option.mmsStyleOpt), dataSize);
174                                 break;
175                         case MSG_PUSHMSG_OPT :
176                                 memcpy(p, &(setting.option.pushMsgOpt), dataSize);
177                                 break;
178                         case MSG_CBMSG_OPT :
179                                 memcpy(p, &(setting.option.cbMsgOpt), dataSize);
180                                 break;
181                         case MSG_VOICEMAIL_OPT :
182                                 memcpy(p, &(setting.option.voiceMailOpt), dataSize);
183                                 break;
184                         case MSG_MSGSIZE_OPT :
185                                 memcpy(p, &(setting.option.msgSizeOpt), dataSize);
186                                 break;
187                         default:
188                                 break;
189                         }
190         } else {
191                 MSG_DEBUG("Command Handle Fail : MsgGetConfigData()");
192         }
193
194         MSG_DEBUG("dataSize [%d]", dataSize);
195
196         switch (pCmd->cmdType) {
197         case MSG_CMD_GET_SMSC_OPT :
198                 eventType = MSG_EVENT_GET_SMSC_OPT;
199                 break;
200         case MSG_CMD_GET_CB_OPT :
201                 eventType = MSG_EVENT_GET_CB_OPT;
202                 break;
203         case MSG_CMD_GET_SMS_SEND_OPT :
204                 eventType = MSG_EVENT_GET_SMS_SEND_OPT;
205                 break;
206         case MSG_CMD_GET_MMS_SEND_OPT :
207                 eventType = MSG_EVENT_GET_MMS_SEND_OPT;
208                 break;
209         case MSG_CMD_GET_MMS_RECV_OPT :
210                 eventType = MSG_EVENT_GET_MMS_RECV_OPT;
211                 break;
212         case MSG_CMD_GET_PUSH_MSG_OPT :
213                 eventType = MSG_EVENT_GET_PUSH_MSG_OPT;
214                 break;
215         case MSG_CMD_GET_VOICE_MSG_OPT :
216                 eventType = MSG_EVENT_GET_VOICE_MSG_OPT;
217                 break;
218         case MSG_CMD_GET_GENERAL_MSG_OPT :
219                 eventType = MSG_EVENT_GET_GENERAL_MSG_OPT;
220                 break;
221         case MSG_CMD_GET_MSG_SIZE_OPT :
222                         eventType = MSG_EVENT_GET_MSG_SIZE_OPT;
223                 break;
224         default :
225                 break;
226         }
227
228         // Make Event Data
229         eventSize = MsgMakeEvent(encodedData, dataSize, eventType, err, (void**)ppEvent);
230
231         return eventSize;
232 }