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