Initialize Tizen 2.3
[framework/osp/messaging.git] / src / FMsgMmsManager.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file                FMsgMmsManager.cpp
19  * @brief               This is the implementation file for the %MmsManager class.
20  *
21  * This file contains the implementation of the %MmsManager class.
22  */
23
24 #include <msg.h>
25 #include <msg_transport.h>
26 #include <msg_storage.h>
27 #include <dbus/dbus.h>
28 #include <email-api.h>
29 #include <FMsgMmsManager.h>
30 #include <FMsgMmsMessage.h>
31 #include <FBaseSysLog.h>
32 #include <FSec_AccessController.h>
33 #include <FSys_SystemInfoImpl.h>
34 #include "FMsg_Types.h"
35 #include "FMsg_MmsEvent.h"
36 #include "FMsg_MsgUtil.h"
37 #include "FMsg_MmsManagerImpl.h"
38 #include "FMsg_RecipientListImpl.h"
39
40 using namespace Tizen::Base;
41 using namespace Tizen::Messaging;
42 using namespace Tizen::Base::Collection;
43 using namespace Tizen::Security;
44
45 namespace Tizen { namespace Messaging
46 {
47
48 MmsManager::MmsManager(void)
49         : __pImpl(null)
50 {
51 }
52
53 MmsManager::~MmsManager(void)
54 {
55         if (__pImpl)
56         {
57                 delete __pImpl;
58                 __pImpl = null;
59         }
60 }
61
62 result
63 MmsManager::Construct(IMmsListener& listener)
64 {
65         // method return code
66         result r = E_SUCCESS;
67         bool isMmsSupported = false;
68
69         SysAssertf(__pImpl == null, "The MmsManager instance is already constructed.");
70
71         r = Tizen::System::_SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/network.telephony.mms", isMmsSupported);
72         SysTryReturnResult(NID_MSG, (r == E_SUCCESS) && (isMmsSupported == true), E_UNSUPPORTED_OPERATION, " MMS is not supported.");   
73         
74         // create an _MmsManagerImpl instance
75         __pImpl = new (std::nothrow) _MmsManagerImpl();
76         SysTryReturn(NID_MSG, __pImpl != null, E_OUT_OF_MEMORY, r = E_OUT_OF_MEMORY, "Failed to allocate memory");
77
78         r = __pImpl->Construct(listener);
79         SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to construct an instance.", GetErrorMessage(r));
80
81         return r;
82
83 CATCH:
84         if (__pImpl)
85         {
86                 delete __pImpl;
87                 __pImpl = null;
88         }
89
90         return r;
91 }
92
93 result
94 MmsManager::Send(const MmsMessage& message, const RecipientList& recipientList, bool saveToSentBox)
95 {
96         result r = E_SUCCESS;
97
98         // checking privilege
99         r = _AccessController::CheckUserPrivilege(_PRV_MESSAGING_MMS, _PRV_MESSAGING_WRITE);
100         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
101         SysTryReturnResult(NID_MSG, r == E_SUCCESS, r, "The application is not permitted to call this method.");
102
103         SysAssertf(__pImpl != null, "The MmsManager instance is not constructed yet.");
104         SysTryReturnResult(NID_MSG,
105                 MAX_MMS_RECIPIENT_COUNT >= _RecipientListImpl::GetInstance(recipientList)->GetTotalRecipientCount(), E_MAX_EXCEEDED,
106                 "The number of recipients exceeds the limit (%d).", MAX_MMS_RECIPIENT_COUNT);
107         SysTryReturnResult(NID_MSG,
108                 0 != _RecipientListImpl::GetInstance(recipientList)->GetTotalRecipientCount(), E_INVALID_ARG,
109                 "[E_INVALID_ARG] The number of recipients is 0.");
110
111         ////////////////////////////////////////////////////////////////////////////////
112         // address-check will be done in SHP layer.
113         ////////////////////////////////////////////////////////////////////////////////
114
115         // mms address validity check
116         r = _MsgUtil::CheckPhoneNumberValidity(_MSG_MMS, recipientList);
117
118         if (IsFailed(r))
119         {
120                 SysLogException(NID_MSG, r, "[%s] There is an invalid phone number in the recipient list.", GetErrorMessage(r));
121                 goto CATCH;
122         }
123
124         // not allow the empty message.
125         if (message.GetSubject().IsEmpty() && message.GetText().IsEmpty() && message.GetAttachment(MMS_IMAGE).IsEmpty() &&
126                 message.GetAttachment(MMS_AUDIO).IsEmpty() && message.GetAttachment(MMS_VIDEO).IsEmpty())
127         {
128                 r = E_INVALID_ARG;
129                 SysLogException(NID_MSG, r, "[E_INVALID_ARG] The message is empty.");
130                 return E_INVALID_ARG;
131         }
132
133         // send an MMS message
134         r = __pImpl->Send(message, recipientList, saveToSentBox);
135         if (IsFailed(r))
136         {
137                 SysLogException(NID_MSG, r, "[%s] Failed to send the MMS message.", GetErrorMessage(r));
138                 goto CATCH;
139         }
140
141         return E_SUCCESS;
142
143 CATCH:
144         return r;
145 }
146 } } // Tizen::Messaging