svace issues fixed
[platform/core/messaging/msg-service.git] / plugin / sms_plugin / SmsPluginUAManager.cpp
1 /*
2  * Copyright (c) 2014 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 #include "MsgDebug.h"
18 #include "MsgCppTypes.h"
19 #include "MsgException.h"
20 #include "SmsPluginEventHandler.h"
21 #include "SmsPluginWapPushHandler.h"
22 #include "SmsPluginConcatHandler.h"
23 #include "SmsPluginTransport.h"
24 #include "SmsPluginUAManager.h"
25
26
27 /*==================================================================================================
28                                      IMPLEMENTATION OF SmsPluginUAManager - Member Functions
29 ==================================================================================================*/
30 SmsPluginUAManager* SmsPluginUAManager::pInstance = NULL;
31
32
33 SmsPluginUAManager::SmsPluginUAManager() : mx(), cv()
34 {
35         start();
36 }
37
38
39 SmsPluginUAManager::~SmsPluginUAManager()
40 {
41 }
42
43
44 SmsPluginUAManager* SmsPluginUAManager::instance()
45 {
46         if (!pInstance)
47                 pInstance = new SmsPluginUAManager();
48
49         return pInstance;
50 }
51
52
53 void SmsPluginUAManager::run()
54 {
55         while (1) {
56                 lock();
57                 while (smsTranQ.empty()) {
58                         wait();
59                 }
60                 SMS_REQUEST_INFO_S request;
61                 smsTranQ.front(&request);
62                 unlock();
63
64                 request.msgInfo.addressList = NULL;
65                 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&request.msgInfo.addressList, unique_ptr_deleter);
66
67                 try {
68                         SmsPluginTransport::instance()->submitRequest(&request);
69                 } catch (MsgException& e) {
70                         MSG_FATAL("%s", e.what());
71
72                         lock();
73                         smsTranQ.pop_front();
74                         unlock();
75                         continue;
76                 } catch (exception& e) {
77                         MSG_FATAL("%s", e.what());
78                         lock();
79                         smsTranQ.pop_front();
80                         unlock();
81                         continue;
82                 }
83
84                 lock();
85                 smsTranQ.pop_front();
86                 unlock();
87         }
88 }
89
90
91 void SmsPluginUAManager::addReqEntity(SMS_REQUEST_INFO_S *request)
92 {
93         SMS_REQUEST_INFO_S reqTmp = {0, };
94
95         memcpy(&reqTmp, request, sizeof(SMS_REQUEST_INFO_S));
96
97         lock();
98
99         smsTranQ.push_back(reqTmp);
100         cv.signal();
101
102         unlock();
103 }
104