8943d12bb58b93e466952b1fa58ef6c528ecd20c
[framework/web/wrt-plugins-common.git] / src / modules / API / Messaging / MessageFactory.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
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  *
18  *
19  * @file       MessageFactory.cpp
20  * @author     Pawel Misiak (p.misiak@samsung.com)
21  * @version    0.1
22  * @brief
23  */
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"
31
32 using namespace WrtDeviceApis::Commons;
33
34
35 namespace WrtDeviceApis {
36 namespace Messaging {
37 namespace Api {
38 IMessagePtr MessageFactory::createMessage(const MessageType msgType,
39         const std::string& id)
40 {
41     LogInfo("enter");
42     IMessage* retVal = NULL;
43     switch (msgType) {
44     case SMS:
45         LogDebug("creation sms message");
46         retVal = new Sms(id);
47         break;
48
49     case BINARYSMS:
50         LogDebug("creation binary sms message");
51         retVal = new BinarySms(id);
52         break;
53
54     case MMS:
55         LogDebug("creation mms message");
56         retVal = new Mms(id);
57         break;
58
59     case EMAIL:
60         LogDebug("creation email message");
61         retVal = new Email(id);
62         break;
63
64     default:
65         LogError("creation error, unknown message type");
66         break;
67     }
68     return IMessagePtr(retVal);
69 }
70
71 IMessagePtr MessageFactory::createMessage(const MessageType msgType,
72         const int id)
73 {
74     std::ostringstream stream;
75     stream << id;
76     std::string idStr = stream.str();
77     return createMessage(msgType, idStr);
78 }
79
80 IMessagePtr MessageFactory::createVirtualMessage()
81 {
82     return IMessagePtr(new VirtualMessage());
83 }
84
85 VirtualMessagePtr MessageFactory::convertToVirtualMessage(IMessagePtr msg)
86 {
87     VirtualMessagePtr tmp = DPL::DynamicPointerCast<VirtualMessage >(msg);
88     if (!tmp) {
89         ThrowMsg(ConversionException,
90                  "Conversion IMessage to VirtualMessagePtr error");
91     }
92     return tmp;
93 }
94
95 ISmsPtr MessageFactory::convertToSms(IMessagePtr msg)
96 {
97     ISmsPtr tmp = DPL::DynamicPointerCast<ISms >(msg);
98     if (!tmp) {
99         ThrowMsg(ConversionException, "Conversion IMessage to ISms error");
100     }
101     return tmp;
102 }
103
104 IBinarySmsPtr MessageFactory::convertToBinarySms(IMessagePtr msg)
105 {
106     IBinarySmsPtr tmp = DPL::DynamicPointerCast<IBinarySms >(msg);
107     if (!tmp) {
108         ThrowMsg(ConversionException, "Conversion IMessage to IBinarySms error");
109     }
110     return tmp;
111 }
112
113 IMmsPtr MessageFactory::convertToMms(IMessagePtr msg)
114 {
115     IMmsPtr tmp = DPL::DynamicPointerCast<IMms >(msg);
116     if (!tmp) {
117         ThrowMsg(ConversionException, "Conversion IMessage to IMms error");
118     }
119     return tmp;
120 }
121
122 IEmailPtr MessageFactory::convertToEmail(IMessagePtr msg)
123 {
124     IEmailPtr tmp = DPL::DynamicPointerCast<IEmail >(msg);
125     if (!tmp) {
126         ThrowMsg(ConversionException, "Conversion IMessage to IEmail error");
127     }
128     return tmp;
129 }
130 }
131 }
132 }