Merge from master.
[framework/messaging/msg-service.git] / plugin / mms_plugin / MmsPluginEventHandler.cpp
1 /*
2 * Copyright 2012-2013  Samsung Electronics Co., Ltd
3 *
4 * Licensed under the Flora License, Version 1.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://floralicense.org
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 SmsPluginEventHandler - 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                 MmsPluginInternal::instance()->processRetrieveConf(&msgInfo, pRequest, pRetrievedFilePath);
79
80                 // callback to MSG FW
81                 listener.pfMmsConfIncomingCb(&msgInfo, &pRequest->reqID);
82                 break;
83
84         case eMMS_FORWARD_CONF:
85                 MmsPluginInternal::instance()->processForwardConf(&msgInfo, pRequest);
86                 break;
87
88         case eMMS_READREPORT_CONF:
89                 if (remove(pRetrievedFilePath) != 0)
90                         MSG_DEBUG("remove fail");
91                 break;
92         default:
93                 break;
94         }
95 }
96
97
98 void MmsPluginEventHandler::handleMmsError(mmsTranQEntity *pRequest)
99 {
100         MSG_BEGIN();
101
102         msg_error_t err = MSG_SUCCESS;
103
104         MSG_MESSAGE_INFO_S msgInfo;
105         memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
106
107         MSG_DEBUG("pRequest->msgId [%d]", pRequest->msgId);
108
109         switch (pRequest->eMmsPduType) {
110         case eMMS_SEND_REQ:
111         case eMMS_SEND_CONF:
112                 msgInfo.msgId = pRequest->msgId;
113                 //Set only changed members
114                 msgInfo.msgType.mainType = MSG_MMS_TYPE;
115
116                 if (pRequest->eMmsPduType == eMMS_SEND_REQ)
117                         msgInfo.msgType.subType = MSG_SENDREQ_MMS;
118                 else
119                         msgInfo.msgType.subType = MSG_SENDCONF_MMS;
120
121                 msgInfo.networkStatus = MSG_NETWORK_SEND_FAIL;
122
123                 msgInfo.folderId = MSG_OUTBOX_ID;
124
125                 listener.pfMmsConfIncomingCb(&msgInfo, &pRequest->reqID);
126                 break;
127
128         case eMMS_RETRIEVE_AUTO:
129         case eMMS_RETRIEVE_AUTO_CONF:
130                 msgInfo.msgId = pRequest->msgId;
131                 //Set only changed members
132                 msgInfo.msgType.mainType = MSG_MMS_TYPE;
133                 msgInfo.msgType.subType = MSG_RETRIEVE_AUTOCONF_MMS;
134
135                 msgInfo.networkStatus = MSG_NETWORK_RETRIEVE_FAIL;
136                 msgInfo.folderId = MSG_INBOX_ID;
137
138                 err = listener.pfMmsConfIncomingCb(&msgInfo, &pRequest->reqID);
139
140                 break;
141
142         case eMMS_RETRIEVE_MANUAL:
143         case eMMS_RETRIEVE_MANUAL_CONF:
144                 msgInfo.msgId = pRequest->msgId;
145                 //Set only changed members
146                 msgInfo.msgType.mainType = MSG_MMS_TYPE;
147                 msgInfo.msgType.subType = MSG_RETRIEVE_MANUALCONF_MMS;
148
149                 msgInfo.networkStatus = MSG_NETWORK_RETRIEVE_FAIL;
150                 msgInfo.folderId = MSG_INBOX_ID;
151
152                 err = listener.pfMmsConfIncomingCb(&msgInfo, &pRequest->reqID);
153
154                 break;
155
156         default:
157                 break;
158         }
159
160         MSG_END();
161 }
162