519c46a3302a9c6f2bfdf4ccdd9e1ca13fe3f81d
[platform/core/security/security-manager.git] / src / server / service / base-service.cpp
1 /*
2  *  Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Contact: Rafal Krypa <r.krypa@samsung.com>
5  *
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License
17  */
18 /*
19  * @file        base-service.cpp
20  * @author      Lukasz Kostyra <l.kostyra@samsung.com>
21  * @author      Rafal Krypa <r.krypa@samsung.com>
22  * @brief       Implementation of security-manager base service.
23  */
24
25 #include <cstring>
26 #include <unordered_set>
27
28 #include <dpl/log/log.h>
29
30 #include "base-service.h"
31
32 namespace SecurityManager {
33
34 BaseService::BaseService()
35 {
36 }
37
38 void BaseService::accept(const AcceptEvent &event)
39 {
40     LogDebug("Accept event. ConnectionID.sock: " << event.connectionID.sock <<
41              " ConnectionID.counter: " << event.connectionID.counter <<
42              " ServiceID: " << event.interfaceID);
43
44     auto &info = m_connectionInfoMap[event.connectionID.counter];
45     info.interfaceID = event.interfaceID;
46 }
47
48 void BaseService::write(const WriteEvent &event)
49 {
50     LogDebug("WriteEvent. ConnectionID: " << event.connectionID.sock <<
51              " Size: " << event.size <<
52              " Left: " << event.left);
53
54     if (event.left == 0)
55         m_serviceManager->Close(event.connectionID);
56 }
57
58 void BaseService::process(const ReadEvent &event)
59 {
60     LogDebug("Read event for counter: " << event.connectionID.counter);
61     auto &info = m_connectionInfoMap[event.connectionID.counter];
62     info.buffer.Push(event.rawBuffer);
63
64     // We can get several requests in one package.
65     // Extract and process them all
66     while (processOne(event.connectionID, info.buffer, info.interfaceID));
67 }
68
69 void BaseService::close(const CloseEvent &event)
70 {
71     LogDebug("CloseEvent. ConnectionID: " << event.connectionID.sock);
72     m_connectionInfoMap.erase(event.connectionID.counter);
73 }
74
75 } // namespace SecurityManager