b3d9d8f811025ae313cb65663ddee07d3c9f520b
[framework/web/wrt-plugins-common.git] / src / modules / API / Messaging / EventSendMessage.h
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       EventSendMessage.h
20  * @author     Pawel Misiak (p.misiak@samsung.com)
21  * @version    0.1
22  * @brief
23  */
24 #ifndef EVENTSENDMESSAGE_H
25 #define EVENTSENDMESSAGE_H
26
27 #include <string>
28 #include <vector>
29 #include <dpl/shared_ptr.h>
30
31 #include <Commons/IEvent.h>
32 #include "IMessaging.h"
33
34 namespace WrtDeviceApis {
35 namespace Messaging {
36 namespace Api {
37 class EventSendMessage;
38
39 typedef DPL::SharedPtr<EventSendMessage> EventSendMessagePtr;
40
41 class EventSendMessage :
42     public WrtDeviceApis::Commons::IEvent<EventSendMessage>
43 {
44 public:
45     struct RecipientSendResult
46     {
47         RecipientSendResult(const std::string& recipient, bool send)
48             : recipient(recipient),
49               send(send)
50         { }
51         std::string recipient;
52         bool send;
53     };
54
55     explicit EventSendMessage(const IMessagePtr& message)
56         : m_message(message),
57           m_store(false)
58     { }
59
60     IMessagePtr getMessage() const
61     {
62         return m_message;
63     }
64
65     bool getStore() const
66     {
67         return m_store;
68     }
69
70     void setStore(bool store)
71     {
72         m_store = store;
73     }
74
75     void addRecipientSendResult(const std::string& recipient, bool send)
76     {
77         m_results.push_back(RecipientSendResult(recipient, send));
78     }
79
80     void addRecipientsSendResult(const std::vector<std::string>& recipients,
81                                  bool send)
82     {
83         for_each(recipients.begin(),
84                  recipients.end(),
85                  [&m_results, &send](const std::string& recipient)
86                  {
87                      m_results.push_back(RecipientSendResult(recipient, send));
88                  });
89     }
90
91     std::vector<RecipientSendResult> getRecipientSendResults() const
92     {
93         return m_results;
94     }
95
96   private:
97     IMessagePtr m_message;
98     bool m_store;
99     std::vector<RecipientSendResult> m_results;
100 };
101 }
102 }}
103 #endif