Sync with tizen 2.4
[platform/core/messaging/msg-service.git] / plugin / mms_plugin / MmsPluginEventHandler.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 <stdio.h>
18 #include <stdlib.h>
19
20 #include "MmsPluginTypes.h"
21 #include "MmsPluginDebug.h"
22 #include "MmsPluginEventHandler.h"
23 #include "MmsPluginInternal.h"
24
25 /*==================================================================================================
26                                      IMPLEMENTATION OF MmsPluginEventHandler - Member Functions
27 ==================================================================================================*/
28 MmsPluginEventHandler *MmsPluginEventHandler::pInstance = NULL;
29
30
31 MmsPluginEventHandler::MmsPluginEventHandler()
32 {
33         memset(&listener, 0x00, sizeof(MSG_PLUGIN_LISTENER_S));
34 }
35
36
37 MmsPluginEventHandler::~MmsPluginEventHandler()
38 {
39
40 }
41
42
43 MmsPluginEventHandler *MmsPluginEventHandler::instance()
44 {
45         if (!pInstance)
46                 pInstance = new MmsPluginEventHandler();
47
48         return pInstance;
49 }
50
51
52 void MmsPluginEventHandler::registerListener(MSG_PLUGIN_LISTENER_S *pListener)
53 {
54         listener = *pListener;
55 }
56
57
58 void MmsPluginEventHandler::handleMmsReceivedData(mmsTranQEntity *pRequest, char *pRetrievedFilePath)
59 {
60         MSG_MESSAGE_INFO_S msgInfo = {0,};
61
62         switch (pRequest->eMmsPduType) {
63         // received data is send-conf
64         case eMMS_SEND_CONF:
65                 MmsPluginInternal::instance()->processSendConf(&msgInfo, pRequest);
66
67                 // callback to MSG FW
68                 listener.pfMmsConfIncomingCb(&msgInfo, &pRequest->reqID);
69
70                 //MsgDeleteFile(pRetrievedFilePath + strlen(MSG_DATA_PATH)); // not ipc
71                 if (remove(pRetrievedFilePath) != 0)
72                         MSG_DEBUG("remove fail");
73                 break;
74
75         // received data is retrieve-conf
76         case eMMS_RETRIEVE_AUTO_CONF:
77         case eMMS_RETRIEVE_MANUAL_CONF:
78                 MSG_ADDRESS_INFO_S addrInfo;
79                 memset(&addrInfo, 0x00, sizeof(MSG_ADDRESS_INFO_S));
80                 msgInfo.addressList = &addrInfo;
81
82                 MmsPluginInternal::instance()->processRetrieveConf(&msgInfo, pRequest, pRetrievedFilePath);
83
84                 // callback to MSG FW
85                 listener.pfMmsConfIncomingCb(&msgInfo, &pRequest->reqID);
86                 break;
87
88         case eMMS_FORWARD_CONF:
89                 MmsPluginInternal::instance()->processForwardConf(&msgInfo, pRequest);
90                 break;
91
92         case eMMS_READREPORT_CONF:
93                 if (remove(pRetrievedFilePath) != 0)
94                         MSG_DEBUG("remove fail");
95                 break;
96         default:
97                 break;
98         }
99 }
100
101
102 void MmsPluginEventHandler::handleMmsError(mmsTranQEntity *pRequest)
103 {
104         MSG_BEGIN();
105
106         msg_error_t err = MSG_SUCCESS;
107
108         MSG_MESSAGE_INFO_S msgInfo;
109         memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
110
111         MSG_DEBUG("pRequest->msgId [%d]", pRequest->msgId);
112
113         time_t curTime;
114         curTime = time(NULL);
115
116         msgInfo.displayTime = curTime;
117
118         switch (pRequest->eMmsPduType) {
119         case eMMS_SEND_REQ:
120         case eMMS_SEND_CONF:
121                 msgInfo.msgId = pRequest->msgId;
122                 //Set only changed members
123                 msgInfo.msgType.mainType = MSG_MMS_TYPE;
124
125                 if (pRequest->eMmsPduType == eMMS_SEND_REQ)
126                         msgInfo.msgType.subType = MSG_SENDREQ_MMS;
127                 else
128                         msgInfo.msgType.subType = MSG_SENDCONF_MMS;
129
130                 msgInfo.networkStatus = MSG_NETWORK_SEND_FAIL;
131
132                 msgInfo.folderId = MSG_OUTBOX_ID;
133
134                 listener.pfMmsConfIncomingCb(&msgInfo, &pRequest->reqID);
135                 break;
136
137         case eMMS_RETRIEVE_AUTO:
138         case eMMS_RETRIEVE_AUTO_CONF:
139                 msgInfo.msgId = pRequest->msgId;
140                 //Set only changed members
141                 msgInfo.msgType.mainType = MSG_MMS_TYPE;
142                 msgInfo.msgType.subType = MSG_RETRIEVE_AUTOCONF_MMS;
143
144                 msgInfo.networkStatus = MSG_NETWORK_RETRIEVE_FAIL;
145                 msgInfo.folderId = MSG_INBOX_ID;
146
147                 err = listener.pfMmsConfIncomingCb(&msgInfo, &pRequest->reqID);
148
149                 break;
150
151         case eMMS_RETRIEVE_MANUAL:
152         case eMMS_RETRIEVE_MANUAL_CONF:
153                 msgInfo.msgId = pRequest->msgId;
154                 //Set only changed members
155                 msgInfo.msgType.mainType = MSG_MMS_TYPE;
156                 msgInfo.msgType.subType = MSG_RETRIEVE_MANUALCONF_MMS;
157
158                 msgInfo.networkStatus = MSG_NETWORK_RETRIEVE_FAIL;
159                 msgInfo.folderId = MSG_INBOX_ID;
160
161                 err = listener.pfMmsConfIncomingCb(&msgInfo, &pRequest->reqID);
162
163                 break;
164
165         default:
166                 break;
167         }
168
169         MSG_DEBUG("Error value of MsgMmsConfIncomingListner [%d]", err);
170
171         MSG_END();
172 }
173