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 * @author Wojciech Bielawski (w.bielawski@samsung.com)
23 #include <Commons/Exception.h>
24 #include <API/Messaging/EventGetMessagingService.h>
25 #include "MessagingServiceManager.h"
26 #include "MessagingService.h"
29 #include <emf-types.h>
34 using namespace TizenApis::Api::Messaging;
40 MessagingServiceManager::MessagingServiceManager() :
42 messaging_service_handler(-1)
48 MessagingServiceManager::~MessagingServiceManager() {
52 std::vector<Api::Messaging::EmailAccountInfo> MessagingServiceManager::getEmailAccounts()
54 emf_account_t* accounts = NULL;
56 std::vector<Api::Messaging::EmailAccountInfo> result;
59 if (email_get_account_list(&accounts, &count)) {
63 for (int i = 0; i < count; ++i) {
64 LogDebug("account ID :" << accounts[i].account_id << "Name :" << accounts[i].user_name << "Addr :" << accounts[i].email_addr );
65 Api::Messaging::EmailAccountInfo account(accounts[i].account_id,
66 accounts[i].user_name,
67 accounts[i].email_addr );
68 result.push_back(account);
71 if (accounts != NULL) {
72 email_free_account(&accounts, count);
78 Catch(WrtDeviceApis::Commons::PlatformException) {
80 if (accounts != NULL) {
81 email_free_account(&accounts, count);
89 void MessagingServiceManager::getMessagingServiceManager(const EventGetMessagingServicePtr& event) {
92 LogDebug("event->getAccountID():" << event->getAccountID());
94 if (m_initialized == false) {
98 EventRequestReceiver<EventGetMessagingService>::PostRequest(event);
103 //get the request which posted from the standard layer
104 void MessagingServiceManager::OnRequestReceived(const EventGetMessagingServicePtr& event)
110 m_messagingServices.clear(); //clear services
111 if (m_messagingServices.empty())
113 //ToDo: The Message Service Code will be inserted here.
114 LogDebug("Message Service Type : " << event->getMessagingServiceType());
115 if ( event->getMessagingServiceType() == Api::Messaging::SMS)
117 MessagingService* messagingService = new MessagingService();
118 messagingService->setMessagingServiceType(Api::Messaging::SMS);
119 messagingService->setMessagingServiceName("SMS");
121 //ToDol: set messaging Service instance.
122 m_messagingServices.push_back(Api::Messaging::IMessagingServicePtr(messagingService));
124 else if ( event->getMessagingServiceType() == Api::Messaging::MMS)
126 MessagingService* messagingService = new MessagingService();
127 messagingService->setMessagingServiceType(Api::Messaging::MMS);
128 messagingService->setMessagingServiceName("MMS");
130 m_messagingServices.push_back(Api::Messaging::IMessagingServicePtr(messagingService));
132 else if (event->getMessagingServiceType() == Api::Messaging::EMAIL)
134 std::vector<Api::Messaging::EmailAccountInfo> EmailAccounts = getEmailAccounts();
135 LogDebug("get Account list, size:" << EmailAccounts.size());
138 for ( idx = 0 ; idx < (int)EmailAccounts.size(); idx++)
140 LogDebug("Account ID:" << EmailAccounts[idx].getIntId() );
142 MessagingService* messagingService = NULL;
143 messagingService = new MessagingService();
144 messagingService->setMessagingServiceType(Api::Messaging::EMAIL);
145 messagingService->setCurrentEmailAccount( EmailAccounts[idx] );
147 LogDebug("Account ID:" << event->getAccountID());
148 if ( event->getAccountID() >= 0 )
150 if (event->getAccountID() == EmailAccounts[idx].getIntId())
151 m_messagingServices.push_back(Api::Messaging::IMessagingServicePtr(messagingService));
153 delete messagingService; //remove service.
157 m_messagingServices.push_back(Api::Messaging::IMessagingServicePtr(messagingService));
167 event->setMessagingServicesRef(m_messagingServices); //set message services
169 catch (WrtDeviceApis::Commons::Exception &exc)
171 LogError("Exception has occurred: " << std::hex << exc.getCode());
172 event->setExceptionCode(exc.getCode());
178 // create platform's resources. For examples, it could be camera handle, location handle and so on.
180 void MessagingServiceManager::initialize() {
183 if (!m_initialized) {
184 // retVal = create_messaging_service();
185 // if(retVal != MessagingServiceManager_ERROR_NONE){
186 // ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Couldn't init MEssagingServiceManager module.");
188 m_initialized = true;
195 void MessagingServiceManager::getEmailAccountList( vector<Api::Messaging::EmailAccountInfo>& accounts )
199 emf_account_t* emf_accounts = NULL;
202 if (!email_get_account_list(&emf_accounts, &count)) {
203 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
204 "Couldn't get e-mail accounts.");
208 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "No e-mail account found.");
211 for (int i = 0; i < count; ++i) {
212 //make email account info.
214 LogDebug("account id :" << emf_accounts[i].account_id );
215 LogDebug("account name :" << emf_accounts[i].user_name );
216 LogDebug("account addr :" << emf_accounts[i].email_addr );
218 Api::Messaging::EmailAccountInfo account(emf_accounts[i].account_id,
219 emf_accounts[i].user_name,
220 emf_accounts[i].email_addr);
221 if (std::find(accounts.begin(), accounts.end(), account) == accounts.end()) {
222 LogDebug( "push " << emf_accounts[i].account_id << "account" );
223 accounts.push_back(account);
227 if (emf_accounts != NULL) {
228 email_free_account(&emf_accounts, count); //free
231 Catch(WrtDeviceApis::Commons::PlatformException) {
232 if (emf_accounts != NULL) {
233 email_free_account(&emf_accounts, count);
243 } //namespace Platform
244 } //namespace WrtPlugins