summaryrefslogtreecommitdiff
path: root/src/manager/common/message-buffer.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/manager/common/message-buffer.h')
-rw-r--r--src/manager/common/message-buffer.h80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/manager/common/message-buffer.h b/src/manager/common/message-buffer.h
new file mode 100644
index 00000000..89cd824c
--- /dev/null
+++ b/src/manager/common/message-buffer.h
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Bumjin Im <bj.im@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+/*
+ * @file secket-buffer.h
+ * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
+ * @author Zofia Abramowska (z.abramowska@samsung.com)
+ * @version 1.0
+ * @brief Implementatin of MessageBuffer.
+ */
+
+#ifndef _CENT_KEY_MNG_SOCKET_BUFFER_
+#define _CENT_KEY_MNG_SOCKET_BUFFER_
+
+#include <vector>
+
+#include <dpl/binary_queue.h>
+#include <dpl/exception.h>
+#include <dpl/serialization.h>
+
+namespace CentralKeyManager {
+
+typedef std::vector<unsigned char> RawBuffer;
+
+class MessageBuffer : public CentralKeyManager::IStream {
+public:
+ class Exception
+ {
+ public:
+ DECLARE_EXCEPTION_TYPE(CentralKeyManager::Exception, Base)
+ DECLARE_EXCEPTION_TYPE(Base, OutOfData)
+ };
+
+ MessageBuffer()
+ : m_bytesLeft(0)
+ {}
+
+ void Push(const RawBuffer &data);
+
+ RawBuffer Pop();
+
+ bool Ready();
+
+ virtual void Read(size_t num, void *bytes);
+
+ virtual void Write(size_t num, const void *bytes);
+
+protected:
+
+ inline void CountBytesLeft() {
+ if (m_bytesLeft > 0)
+ return; // we already counted m_bytesLeft nothing to do
+
+ if (m_buffer.Size() < sizeof(size_t))
+ return; // we cannot count m_bytesLeft because buffer is too small
+
+ m_buffer.FlattenConsume(&m_bytesLeft, sizeof(size_t));
+ }
+
+ size_t m_bytesLeft;
+ CentralKeyManager::BinaryQueue m_buffer;
+};
+
+} // namespace CentralKeyManager
+
+#endif // _CENT_KEY_MNG_SOCKET_BUFFER_