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.
19 * @file MessageFactory.cpp
20 * @author Pawel Misiak (p.misiak@samsung.com)
24 #include <dpl/log/log.h>
25 #include <Commons/Exception.h>
26 #include <Messaging/Sms.h>
27 #include <Messaging/BinarySms.h>
28 #include <Messaging/Mms.h>
29 #include <Messaging/Email.h>
30 #include "MessageFactory.h"
32 using namespace WrtDeviceApis::Commons;
35 namespace WrtDeviceApis {
38 IMessagePtr MessageFactory::createMessage(const MessageType msgType,
39 const std::string& id)
42 IMessage* retVal = NULL;
45 LogDebug("creation sms message");
50 LogDebug("creation binary sms message");
51 retVal = new BinarySms(id);
55 LogDebug("creation mms message");
60 LogDebug("creation email message");
61 retVal = new Email(id);
65 LogError("creation error, unknown message type");
68 return IMessagePtr(retVal);
71 IMessagePtr MessageFactory::createMessage(const MessageType msgType,
74 std::ostringstream stream;
76 std::string idStr = stream.str();
77 return createMessage(msgType, idStr);
80 IMessagePtr MessageFactory::createVirtualMessage()
82 return IMessagePtr(new VirtualMessage());
85 VirtualMessagePtr MessageFactory::convertToVirtualMessage(IMessagePtr msg)
87 VirtualMessagePtr tmp = DPL::DynamicPointerCast<VirtualMessage >(msg);
89 ThrowMsg(ConversionException,
90 "Conversion IMessage to VirtualMessagePtr error");
95 ISmsPtr MessageFactory::convertToSms(IMessagePtr msg)
97 ISmsPtr tmp = DPL::DynamicPointerCast<ISms >(msg);
99 ThrowMsg(ConversionException, "Conversion IMessage to ISms error");
104 IBinarySmsPtr MessageFactory::convertToBinarySms(IMessagePtr msg)
106 IBinarySmsPtr tmp = DPL::DynamicPointerCast<IBinarySms >(msg);
108 ThrowMsg(ConversionException, "Conversion IMessage to IBinarySms error");
113 IMmsPtr MessageFactory::convertToMms(IMessagePtr msg)
115 IMmsPtr tmp = DPL::DynamicPointerCast<IMms >(msg);
117 ThrowMsg(ConversionException, "Conversion IMessage to IMms error");
122 IEmailPtr MessageFactory::convertToEmail(IMessagePtr msg)
124 IEmailPtr tmp = DPL::DynamicPointerCast<IEmail >(msg);
126 ThrowMsg(ConversionException, "Conversion IMessage to IEmail error");