2 * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Rafal Krypa <r.krypa@samsung.com>
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
19 * @file secket-buffer.h
20 * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
22 * @brief Implementatin of MessageBuffer.
25 #ifndef _SECURITY_MANAGER_SOCKET_BUFFER_
26 #define _SECURITY_MANAGER_SOCKET_BUFFER_
30 #include <dpl/binary_queue.h>
31 #include <dpl/exception.h>
32 #include <dpl/serialization.h>
34 namespace SecurityManager {
36 typedef std::vector<unsigned char> RawBuffer;
38 class MessageBuffer : public SecurityManager::IStream {
43 DECLARE_EXCEPTION_TYPE(SecurityManager::Exception, Base)
44 DECLARE_EXCEPTION_TYPE(Base, OutOfData)
51 void Push(const RawBuffer &data);
57 virtual void Read(size_t num, void *bytes);
59 virtual void Write(size_t num, const void *bytes);
63 inline void CountBytesLeft() {
65 return; // we already counted m_bytesLeft nothing to do
67 if (m_buffer.Size() < sizeof(size_t))
68 return; // we cannot count m_bytesLeft because buffer is too small
70 m_buffer.FlattenConsume(&m_bytesLeft, sizeof(size_t));
74 SecurityManager::BinaryQueue m_buffer;
77 } // namespace SecurityManager
79 #endif // _SECURITY_MANAGER_SOCKET_BUFFER_