2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * @file MessageFactory.cpp
22 * @author Pawel Misiak (p.misiak@samsung.com)
26 #include <dpl/log/log.h>
27 #include <Commons/Exception.h>
28 #include <Messaging/Sms.h>
29 #include <Messaging/BinarySms.h>
30 #include <Messaging/Mms.h>
31 #include <Messaging/Email.h>
32 #include "MessageFactory.h"
33 #include <API/Messaging/IAttachment.h>
36 using namespace WrtDeviceApis::Commons;
37 using namespace TizenApis::Platform::Messaging;
43 IMessagePtr MessageFactory::createMessage(const MessageType msgType,
44 const std::string& id)
47 IMessage* retVal = NULL;
50 LogDebug("creation sms message");
55 LogDebug("creation binary sms message");
56 retVal = new BinarySms(id);
60 LogDebug("creation mms message");
65 LogDebug("creation email message");
66 retVal = new Email(id);
70 LogError("creation error, unknown message type");
73 return IMessagePtr(retVal);
76 IMessagePtr MessageFactory::createMessage(const MessageType msgType,
79 std::ostringstream stream;
81 std::string idStr = stream.str();
82 return createMessage(msgType, idStr);
85 IMessagePtr MessageFactory::createMessage(const MessageType msgType,
86 Api::Messaging::EmailAccountInfo& account, const std::string& id )
88 LogInfo("enter, CreateMessage with account");
90 std::ostringstream stream;
92 std::string idStr = stream.str();
94 LogInfo("createMessage with , idstr =" << idStr);
98 LogDebug("Account Address:" << &account);
99 IMessage* retVal = NULL;
100 LogDebug("creation email message with account");
101 retVal = new Email(account);
102 return IMessagePtr(retVal);
105 return createMessage(msgType, idStr);
109 IMessagePtr MessageFactory::createEmailMessage(const int accountId, const int mailId)
111 LogInfo("enter, Create Email Message with account ID");
112 IEmail* email = NULL;
113 LogDebug("creation email message with account ID");
114 std::stringstream stream;
117 ThrowMsg(UnknownException, "Couldn't convert e-mail account id");
120 email = new Email(stream.str(), accountId);
122 IMessagePtr imsg(email);
124 std::vector<IAttachmentPtr> attachments = email->getAttachments();
127 for (; idx < attachments.size() ; idx++ )
129 LogDebug("set Messsage ID = " << attachments[idx]->getAttachmentID());
130 attachments[idx]->setMessage(imsg);
137 IMessage* retVal = NULL;
138 LogDebug("creation email message with account ID");
141 std::stringstream stream;
144 ThrowMsg(UnknownException, "Couldn't convert e-mail account id");
147 retVal = new Email(stream.str(), accountId);
153 return IMessagePtr(retVal);
157 IMessagePtr MessageFactory::createEmailMessage()
159 LogInfo("enter, Create Temporary Email Message without account");
161 IEmail* email = NULL;
163 email = new Email(Api::Messaging::TEMP_FOLDER); //create dumy email.
165 IMessagePtr imsg(email);
170 IMessagePtr MessageFactory::createVirtualMessage()
172 return IMessagePtr(new VirtualMessage());
175 VirtualMessagePtr MessageFactory::convertToVirtualMessage(IMessagePtr msg)
177 VirtualMessagePtr tmp = DPL::DynamicPointerCast<VirtualMessage >(msg);
179 ThrowMsg(ConversionException,
180 "Conversion IMessage to VirtualMessagePtr error");
185 ISmsPtr MessageFactory::convertToSms(IMessagePtr msg)
187 ISmsPtr tmp = DPL::DynamicPointerCast<ISms >(msg);
189 ThrowMsg(ConversionException, "Conversion IMessage to ISms error");
194 IBinarySmsPtr MessageFactory::convertToBinarySms(IMessagePtr msg)
196 IBinarySmsPtr tmp = DPL::DynamicPointerCast<IBinarySms >(msg);
198 ThrowMsg(ConversionException, "Conversion IMessage to IBinarySms error");
203 IMmsPtr MessageFactory::convertToMms(IMessagePtr msg)
205 IMmsPtr tmp = DPL::DynamicPointerCast<IMms >(msg);
207 ThrowMsg(ConversionException, "Conversion IMessage to IMms error");
212 IEmailPtr MessageFactory::convertToEmail(IMessagePtr msg)
214 IEmailPtr tmp = DPL::DynamicPointerCast<IEmail >(msg);
216 ThrowMsg(ConversionException, "Conversion IMessage to IEmail error");